Skip to content

Instantly share code, notes, and snippets.

@sirviejo
Created February 21, 2013 13:33
Show Gist options
  • Save sirviejo/5004751 to your computer and use it in GitHub Desktop.
Save sirviejo/5004751 to your computer and use it in GitHub Desktop.
Create a Drupal user programatically
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$account->name = 'user_name';
$account->pass = user_hash_password('password_string');
$account->mail = 'user@mail.com';
$account->status = 1;
// Add Role with rid 3 to this user
$roles = array('3' => true);
$account->roles = $roles;
$user = user_save($account);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment