You are here

function auto_username_user_presave in Automatic User Names 7

Implements hook_user_presave().

File

./auto_username.module, line 59
Allows a user's username to be assigned based on tokens.

Code

function auto_username_user_presave(&$edit, $account, $category) {
  if (!empty($account->is_new) || variable_get('aun_update_on_edit', TRUE)) {
    $new_name = auto_username_generate_username($edit, $account);

    // No point updating anything if the generated name was just the same.
    if ($account->name == $new_name) {
      return;
    }

    // Replace with generated username.
    $edit['name'] = $new_name;
  }
}