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

Adds a role to a user account.

Parameters

User $account: The user entity to which the role will be added.

Related topics

File

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

Code

function user_add_role_action($account, &$context) {
  $role_name = $context['action_info']['role_name'];
  if (!in_array($role_name, $account->roles)) {
    $account->roles[] = $role_name;
    $account->save();
  }
}