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

Adds a role to a user account.

Parameters

User $account: The user entity whose account will be blocked.

Related topics

File

core/modules/user/user.actions.inc, line 72
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();
  }
}