One step closer to world domination
Programmatically create users in Drupal 6.x
You can create a Drupal user by sending user_save() a null parameter and an array of user information. You can also assign a role by setting an array that is keyed with the role ID (rid). This can be obtained by calling user_roles() as shown in the example below.
// Get an array of roles $roles = user_roles(); // Basic account information $user = array( 'name' => 'Some User', 'pass' => 'some_password', 'mail' => 'user@example.com', 'status' => 1, 'init' => 'user@example.com', 'roles' => array(array_search('some_role', $roles) => 1), ); // See if the user exists by calling Drupal's user_load() $existing_user = user_load(array('name' => $user['name'])); if (!$existing_user->uid) { // Save the user $user = user_save(NULL, $user); }
| Print article | This entry was posted by Matt Danger on December 16, 2009 at 9:30 pm, and is filed under Drupal. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.










