8.5.x user.module user_role_permissions(array $roles)
8.0.x user.module user_role_permissions(array $roles)
8.1.x user.module user_role_permissions(array $roles)
8.2.x user.module user_role_permissions(array $roles)
8.3.x user.module user_role_permissions(array $roles)
8.4.x user.module user_role_permissions(array $roles)
8.6.x user.module user_role_permissions(array $roles)
7.x user.module user_role_permissions($roles = array())

Determine the permissions for one or more roles.


$roles: An array whose keys are the role IDs of interest, such as $user->roles.

Return value

If $roles is a non-empty array, an array indexed by role ID is returned. Each value is an array whose keys are the permission strings for the given role ID. If $roles is empty nothing is returned.

2 calls to user_role_permissions()
user_access in modules/user/user.module
Determine whether the user has a given privilege.
user_admin_permissions in modules/user/user.admin.inc
Menu callback: administer permissions.
5 string references to 'user_role_permissions'
UserPermissionsTestCase::testUserPermissionChanges in modules/user/user.test
Change user permissions and check user_access().
user_role_delete in modules/user/user.module
Delete a user role from database.
user_role_grant_permissions in modules/user/user.module
Grant permissions to a user role.
user_role_revoke_permissions in modules/user/user.module
Revoke permissions from a user role.
user_role_save in modules/user/user.module
Save a user role to the database.


modules/user/user.module, line 747
Enables the user registration and login system.


function user_role_permissions($roles = array()) {
  $cache =& drupal_static(__FUNCTION__, array());
  $role_permissions = $fetch = array();
  if ($roles) {
    foreach ($roles as $rid => $name) {
      if (isset($cache[$rid])) {
        $role_permissions[$rid] = $cache[$rid];
      else {

        // Add this rid to the list of those needing to be fetched.
        $fetch[] = $rid;

        // Prepare in case no permissions are returned.
        $cache[$rid] = array();
    if ($fetch) {

      // Get from the database permissions that were not in the static variable.
      // Only role IDs with at least one permission assigned will return rows.
      $result = db_query("SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)", array(
        ':fetch' => $fetch,
      foreach ($result as $row) {
        $cache[$row->rid][$row->permission] = TRUE;
      foreach ($fetch as $rid) {

        // For every rid, we know we at least assigned an empty array.
        $role_permissions[$rid] = $cache[$rid];
  return $role_permissions;


pkosenko’s picture

Note that the $roles parameter is NOT CLEARLY DESCRIBED. What is wanted is an array of role names INDEXED by the role ID, NOT an array of role IDs. You can check the following in the Devel "Run PHP" box.

$roles = array(3 => 'administrator');
$permissions= user_role_permissions($roles);

dgtlmoon’s picture

Just so the RID is not hardcoded

    $admin_role = user_role_load_by_name('administrator');
    $roles = array($admin_role->rid => $admin_role->name);
samaphp’s picture

Same as your code but to get role permissions directly:

  $administrator = user_role_load_by_name('administrator');
  $roles = array($administrator->rid => $administrator->name);
  $role_permissions = user_role_permissions($roles);
  $administrator_permissions = $role_permissions[$administrator->rid];