You are here

function rules_action_user_removerole in Rules 6

User Action: deletes roles from a given user

Related topics

File

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

Code

function rules_action_user_removerole($user, $settings) {
  if ($user->uid) {
    $roles = $settings['roles'];
    foreach ($roles as $rid) {

      // If the user has this role, delete it
      if (isset($user->roles[$rid])) {
        unset($user->roles[$rid]);
      }
    }
    user_save($user, array(
      'roles' => $user->roles,
    ), NULL);
    return array(
      'user' => $user,
    );
  }
}