You are here

function uif_create_user in User Import Framework 6

Same name and namespace in other branches
  1. 7 uif.admin.inc \uif_create_user()

Create a new user.

1 call to uif_create_user()
uif_import_user in ./uif.admin.inc
Import one user.

File

./uif.admin.inc, line 434
Simple, extensible user import from a CSV file.

Code

function uif_create_user($user_data, $notify, $form_state) {
  $account = array();
  $account['mail'] = $user_data['email'];
  $account['init'] = $user_data['email'];
  $account['status'] = 1;

  // Use the provided username if any, or derive it from the email
  $username = empty($user_data['username']) ? preg_replace('/@.*$/', '', $user_data['email']) : $user_data['username'];
  $account['name'] = uif_unique_username($username);

  // Use the provided password if any, otherwise a random one
  $pass = $user_data['password'] ? $user_data['password'] : user_password();
  $account['pass'] = $pass;

  // If access is not set, no users will be able to view the
  // new user's profile until such time that the newly
  // created user logs in for the first time.
  $account['access'] = time();
  $account = array_merge($account, module_invoke_all('uif_pre_create', $account, $user_data, $form_state));
  $account = user_save('', $account);
  module_invoke_all('uif_post_create', $account, $user_data, $form_state);
  if ($notify) {
    $account->password = $pass;

    // For mail token; _user_mail_notify() expects this
    _user_mail_notify('register_admin_created', $account);
  }
  return $account;
}