You are here

function rules_condition_user_has_role in Rules 7.2

Condition user: condition to check whether user has particular roles.

Related topics

1 string reference to 'rules_condition_user_has_role'
rules_user_condition_info in modules/user.rules.inc
Implements hook_rules_condition_info() on behalf of the user module.

File

modules/user.eval.inc, line 15
Contains rules integration for the user module needed during evaluation.

Code

function rules_condition_user_has_role($account, $roles, $operation = 'AND') {
  switch ($operation) {
    case 'OR':
      foreach ($roles as $rid) {
        if (isset($account->roles[$rid])) {
          return TRUE;
        }
      }
      return FALSE;
    case 'AND':
      foreach ($roles as $rid) {
        if (!isset($account->roles[$rid])) {
          return FALSE;
        }
      }
      return TRUE;
  }
}