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

19 calls to user_role_grant_permissions()
AccessDeniedTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php
Sets up a Drupal site for running functional and integration tests.
BreadcrumbTest::testBreadCrumbs in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
CommentAnonymousTest::setUp in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php
Sets up a Drupal site for running functional and integration tests.
CommentBlockTest::testRecentCommentBlock in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
Tests the recent comments block.
CommentCSSTest::setUp in drupal/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php
Sets up a Drupal site for running functional and integration tests.

... See full list

File

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