You are here

function rules_action_user_addrole in Rules 6

Action user: adds roles to a particular user

Related topics

File

rules/modules/user.rules.inc, line 184
rules integration for the user module

Code

function rules_action_user_addrole($user, $settings) {
  if ($user->uid) {

    // Get role list (minus the anonymous)
    $role_list = user_roles(TRUE);
    foreach ($settings['roles'] as $rid) {
      $user->roles[$rid] = $role_list[$rid];
    }
    user_save($user, array(
      'roles' => $user->roles,
    ), NULL);
    return array(
      'user' => $user,
    );
  }
}