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 User_Capability_Condition extends Condition {
* Check if a user has any of the supplied capabilities
* @param array<string> $capabilities
* @return boolean
protected function user_can_any( $user_id, $capabilities ) {
foreach ( $capabilities as $cap ) {
if ( user_can( $user_id, $cap ) ) {
return true;
}
return false;
* Check if the condition is fulfilled
* @param array $environment
* @return bool
public function is_fulfilled( $environment ) {
$user_id = $environment['user_id'];
switch ( $this->get_comparison_operator() ) {
case '=':
return user_can( $user_id, $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 ! user_can( $user_id, $this->get_value() );
case 'IN':
return $this->user_can_any( $user_id, $this->get_value() );
case 'NOT IN':
return ! $this->user_can_any( $user_id, $this->get_value() );
return $this->first_supported_comparer_is_correct(
$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.