for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Carbon_Fields\Container\Condition;
/**
* Check if user has a specific capability
*
* Operator "CUSTOM" is passed the user id
*/
class Current_User_Capability_Condition extends Condition {
* Check if a user has any of the supplied capabilities
* @param array<string> $capabilities
* @return boolean
protected function current_user_can_any( $capabilities ) {
foreach ( $capabilities as $cap ) {
if ( current_user_can( $cap ) ) {
return true;
}
return false;
* Check if the condition is fulfilled
* @param array $environment
* @return bool
public function is_fulfilled( $environment ) {
switch ( $this->get_comparison_operator() ) {
case '=':
return current_user_can( $this->get_value() );
break;
break
The break statement is not necessary if it is preceded for example by a return statement:
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case '!=':
return ! current_user_can( $this->get_value() );
case 'IN':
return $this->current_user_can_any( $this->get_value() );
case 'NOT IN':
return ! $this->current_user_can_any( $this->get_value() );
return $this->first_supported_comparer_is_correct(
get_current_user_id(),
$this->get_comparison_operator(),
$this->get_value()
);
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.