Issue #2394517 by opdavies: Add a function to check if a user has a certain role
parent
f56b706c3d
commit
5a17a54c48
|
@ -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.
|
||||
|
|
|
@ -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().
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue