function user_has_role

user_has_role($rid, $account = NULL)

Checks if a user has a role.

Parameters

int $rid: A role ID.

object|null $account: (optional) A user account. Defaults to the current user.

Return value

bool TRUE if the user has the role, or FALSE if not.

File

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

Code

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

  return isset($account->roles[$rid]);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!user!user.module/function/user_has_role/7.x