function drush_user_add_role

8.0.x user.drush.inc drush_user_add_role($role, $users = '')
6.x user.drush.inc drush_user_add_role($role, $users = '')
7.x user.drush.inc drush_user_add_role($role, $users = '')
4.x user.drush.inc drush_user_add_role($role, $users = '')
5.x user.drush.inc drush_user_add_role($role, $users = '')
master user.drush.inc drush_user_add_role($role, $users = '')

Add a role to the specified user accounts.

1 string reference to 'drush_user_add_role'
user_drush_command in commands/user/user.drush.inc
Implementation of hook_drush_command().

File

commands/user/user.drush.inc, line 213
Drush User Management commands

Code

function drush_user_add_role($role, $users = '') {
  $uids = _drush_user_get_users_from_options_and_arguments($users);
  if (drush_drupal_major_version() >= 7) {
    $rid_query = db_query("SELECT rid FROM {role} WHERE name = :role", array(':role' => $role));
  }
  else {
    $rid_query = db_query("SELECT rid FROM {role} WHERE name = '%s'", $role);
  }
  if (!empty($uids)) {
    if ($rid = drush_db_result($rid_query)) {
      drush_op('user_multiple_role_edit', $uids, 'add_role', $rid);
      foreach ($uids as $uid) {
        drush_log(dt("Added the %role role to uid %uid", array('%role' => $role, '%uid' => $uid)), 'success');
      }
    }
    else {
      return drush_set_error("There is no role named: \"$role\"!");
    }
  }
  else {
    return drush_set_error("Could not find any valid uids!");
  }
}