Issue #2394517 by opdavies: Add a function to check if a user has a certain role

merge-requests/26/head
David Rothstein 2015-03-30 02:09:35 -04:00
parent f56b706c3d
commit 5a17a54c48
2 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,8 @@
Drupal 7.36, xxxx-xx-xx (development version)
-----------------------
- Added a user_has_role() function to check whether a user has a particular
role (API addition).
- Fixed installation failures when an opcode cache is enabled.
- Fixed a bug in the Drupal 6 to Drupal 7 upgrade path which caused private
files to be inaccessible.

View File

@ -848,6 +848,26 @@ function user_is_blocked($name) {
->execute()->fetchObject();
}
/**
* Checks if a user has a role.
*
* @param int $rid
* A role ID.
*
* @param object|null $account
* (optional) A user account. Defaults to the current user.
*
* @return bool
* TRUE if the user has the role, or FALSE if not.
*/
function user_has_role($rid, $account = NULL) {
if (!$account) {
$account = $GLOBALS['user'];
}
return isset($account->roles[$rid]);
}
/**
* Implements hook_permission().
*/