summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2015-03-30 02:09:35 -0400
committerDavid Rothstein <drothstein@gmail.com>2015-03-30 02:09:35 -0400
commit5a17a54c48e59a2798dd68a8d1e939149523dab9 (patch)
treefd8e04aee2377c5cb1fcd9f7cba7c7780ceac86a /modules
parentf56b706c3d3c9e774740f16ab8572d4fa538fa73 (diff)
downloadbrdo-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')
-rw-r--r--modules/user/user.module20
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() {