1 user.module user_has_role($role_name, User $account = NULL)

Checks if a user has a role.

@since 1.14.0 First parameter changed from $rid to $role_name.

Parameters

string $role_name: A string representing the role name.

User $account: (optional) A user account. Defaults to the current user.

Return value

bool: TRUE or FALSE.

File

core/modules/user/user.module, line 576
Enables the user registration and login system.

Code

function user_has_role($role_name, User $account = NULL) {
  if (!$account) {
    $account = $GLOBALS['user'];
  }

  return in_array($role_name, $account->roles);
}