diff options
author | David Rothstein <drothstein@gmail.com> | 2015-03-30 02:09:35 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2015-03-30 02:09:35 -0400 |
commit | 5a17a54c48e59a2798dd68a8d1e939149523dab9 (patch) | |
tree | fd8e04aee2377c5cb1fcd9f7cba7c7780ceac86a /modules/user | |
parent | f56b706c3d3c9e774740f16ab8572d4fa538fa73 (diff) | |
download | brdo-5a17a54c48e59a2798dd68a8d1e939149523dab9.tar.gz brdo-5a17a54c48e59a2798dd68a8d1e939149523dab9.tar.bz2 |
Issue #2394517 by opdavies: Add a function to check if a user has a certain role
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.module | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index bdfd36fa3..d74ed2f40 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -849,6 +849,26 @@ function user_is_blocked($name) { } /** + * 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(). */ function user_permission() { |