function user_role_grant_permissions

7.x user.module user_role_grant_permissions($rid, array $permissions = array())

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()

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

... See full list

File

drupal-7.x/modules/user/user.module, line 3101
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');
}