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 role
*
* Operator "CUSTOM" is passed an array of all user roles
*/
class User_Role_Condition extends Condition {
* Get roles for a user from the environment
* @param array $environment
* @return array<string>
protected function get_user_roles( $environment ) {
return $environment['roles'];
}
* Check if the condition is fulfilled
* @return bool
public function is_fulfilled( $environment ) {
$roles = $this->get_user_roles( $environment );
return $this->compare(
$roles,
$this->get_comparison_operator(),
$this->get_value()
);