You are here

function rules_condition_user_hasrole in Rules 6

Condition user: condition to check whether user has particular roles

Related topics

File

rules/modules/user.rules.inc, line 115
rules integration for the user module

Code

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