You are here

function rules_action_user_remove_role in Rules 7.2

Action: Remove roles from a given user.

Related topics

1 string reference to 'rules_action_user_remove_role'
rules_user_action_info in modules/user.rules.inc
Implements hook_rules_action_info() on behalf of the user module.

File

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

Code

function rules_action_user_remove_role($account, $roles) {
  if ($account->uid || !empty($account->is_new)) {
    foreach ($roles as $rid) {

      // If the user has this role, remove it.
      if (isset($account->roles[$rid])) {
        unset($account->roles[$rid]);
      }
    }
    if (!empty($account->is_new) && $account->uid) {

      // user_save() inserts roles after invoking hook_user_insert() anyway, so
      // we skip saving to avoid errors due saving them twice.
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}