You are here

function views_bulk_operations_user_roles_action in Views Bulk Operations (VBO) 7.3

Same name and namespace in other branches
  1. 6.3 user_roles.action.inc \views_bulk_operations_user_roles_action()
  2. 6 actions/user_roles.action.inc \views_bulk_operations_user_roles_action()

File

actions/user_roles.action.inc, line 48

Code

function views_bulk_operations_user_roles_action($user, $context) {
  $wrapper = entity_metadata_wrapper('user', $user);
  if (!$wrapper->roles
    ->access("update")) {

    // No access.
    return;
  }
  $roles = $wrapper->roles
    ->value();
  if (is_array($context['add_roles'])) {
    $roles = array_merge($roles, $context['add_roles']);
  }
  if (is_array($context['remove_roles'])) {
    $roles = array_diff($roles, $context['remove_roles']);
  }
  $wrapper->roles
    ->set($roles);
  $wrapper
    ->save();
}