You are here

function user_role_grant_permissions in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/user/user.module \user_role_grant_permissions()
  2. 9 core/modules/user/user.module \user_role_grant_permissions()

Grant permissions to a user role.

Parameters

$rid: The ID of a user role to alter.

$permissions: A list of permission names to grant.

See also

user_role_change_permissions()

user_role_revoke_permissions()

14 calls to user_role_grant_permissions()
BookTestCase::testBookExport in modules/book/book.test
Tests book export ("printer-friendly version") functionality.
CommentBlockFunctionalTest::testRecentCommentBlock in modules/comment/comment.test
Test the recent comments block.
ContactPersonalTestCase::testPersonalContactAccess in modules/contact/contact.test
Tests access to the personal contact form.
ContactSitewideTestCase::testSiteWideContact in modules/contact/contact.test
Tests configuration options and the site-wide contact form.
DrupalWebTestCase::drupalCreateRole in modules/simpletest/drupal_web_test_case.php
Creates a role with specified permissions.

... See full list

File

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

Code

function user_role_grant_permissions($rid, array $permissions = array()) {
  $modules = user_permission_get_modules();

  // Grant new permissions for the role.
  foreach ($permissions as $name) {
    db_merge('role_permission')
      ->key(array(
      'rid' => $rid,
      'permission' => $name,
    ))
      ->fields(array(
      'module' => $modules[$name],
    ))
      ->execute();
  }

  // Clear the user access cache.
  drupal_static_reset('user_access');
  drupal_static_reset('user_role_permissions');
}