Grant permissions to a user role.
$rid: The ID of a user role to alter.
$permissions: A list of permission names to grant.
user_role_change_permissions()
user_role_revoke_permissions()
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');
}