function drush_role_perm

8.0.x drush_role_perm($action, $rid, $permission = NULL)
6.x drush_role_perm($action, $rid, $permission = NULL)
7.x drush_role_perm($action, $rid, $permission = NULL)
master drush_role_perm($action, $rid, $permission = NULL)

Implement permission add / remove operations.


string $action 'add' | 'remove':

string $rid:

string|null $permission:

Return value


See also


2 calls to drush_role_perm()
drush_role_add_perm in commands/core/
Add one or more permission(s) to the specified role.
drush_role_remove_perm in commands/core/
Remove permission(s) from the specified role.


commands/core/, line 228


function drush_role_perm($action, $rid, $permission = NULL) {
  $role = drush_role_get_class($rid);
  if (!$role) {
    return FALSE;

  // If a permission wasn't provided, but the module option is specified,
  // provide a list of permissions provided by that module.
  if (!$permission && $module = drush_get_option('module', FALSE)) {
    drush_include_engine('drupal', 'environment');
    if (!drush_module_exists($module)) {
      return drush_set_error('DRUSH_ROLE_ERROR', dt('!module not enabled!', array('!module' => $module)));
    $module_perms = $role->getModulePerms($module);
    if (empty($module_perms)) {
      return drush_set_error('DRUSH_ROLE_NO_PERMISSIONS', dt('No permissions found for module !module', array('!module' => $module)));
    $choice = drush_choice($module_perms, "Enter a number to choose which permission to $action.");
    if ($choice === FALSE) {
      return drush_user_abort();
    $permission = $module_perms[$choice];
  else {
    $permissions = $role->getAllModulePerms();
    if (!in_array($permission, $permissions)) {
      return drush_set_error(dt('Could not find the permission: !perm', array('!perm' => $permission)));

  $result = $role->{$action}($permission);
  if ($result === FALSE) {
    return FALSE;
  return $role;