function og_role_grant_permissions in Organic groups 7
Same name and namespace in other branches
- 7.2 og.module \og_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()
1 call to og_role_grant_permissions()
- og_role_change_permissions in ./
og.module - Change permissions for a user role.
File
- ./
og.module, line 2836 - Enable users to create and manage groups with roles and permissions.
Code
function og_role_grant_permissions($rid, array $permissions = array()) {
$modules = array();
foreach (og_get_permissions() as $name => $value) {
$modules[$name] = $value['module'];
}
// Grant new permissions for the role.
foreach ($permissions as $name) {
// Prevent WSOD, if the permission name is wrong, and we can't find its
// module.
if (!empty($modules[$name])) {
db_merge('og_role_permission')
->key(array(
'rid' => $rid,
'permission' => $name,
'module' => $modules[$name],
))
->execute();
}
}
og_invalidate_cache();
}