In a previous post I’ve showed some code to add nodes to Drupal, in this blog I will show that the same can be done with user objects.


$roles = array( 5 => 'visitor' );$fields = array(
'name' => $username, 'mail' =>$email,
'pass' => $password, 'status' => 1, 'init' => 'email address', 'roles' =>$roles
);

//the first parameter is left blank so a new user is created
$account = user_save('',$fields);

// \$account will contain the new created user object


The fields are rather simple and easy to understand what they do:

• name; loginname of the user