Programmatically create users WITH custom fields

Public

Code to generate new user BUT the custom fields fail to populate.

Get raw version
php
  1. 100$fields = array(
  2. 101 ▸ ▸ 'name' => $new_username,
  3. 102 ▸ ▸ 'field_first_name' => $firstname,
  4. 103 ▸ ▸ 'field_last_name' => $lastname,
  5. 104 ▸ ▸ 'mail' => $email,
  6. 105 ▸ ▸ 'pass' => $auto_pass,
  7. 106 ▸ ▸ 'status' => 1,
  8. 107 ▸ ▸ 'init' => 'email address',
  9. 108 ▸ ▸ 'roles' => array(
  10. 109 ▸ ▸ DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  11. 110 ▸ ▸ )
  12. 111);
  13. 112
  14. 113$account = user_save('', $fields);
  15. 114