1 user.actions.inc user_remove_role_action($account, &$context)

Removes a role from a user account.

Parameters

User $account: The user entity from which the role will be removed.

Related topics

File

core/modules/user/user.actions.inc, line 101
Action callbacks for User module.

Code

function user_remove_role_action($account, &$context) {
  $role_name = $context['action_info']['role_name'];
  $index = array_search($role_name, $account->roles);
  if ($index !== FALSE) {
    unset($account->roles[$index]);
    $account->save();
  }
}