function user_role_grant_permissions
Same name in other branches
- 9 core/modules/user/user.module \user_role_grant_permissions()
- 8.9.x core/modules/user/user.module \user_role_grant_permissions()
- 10 core/modules/user/user.module \user_role_grant_permissions()
- 11.x 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.
File
-
modules/
user/ user.module, line 3205
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');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.