summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt2
-rw-r--r--modules/user/user.module20
2 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 4060fcba6..3414ff833 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -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.
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() {