Posted By

Phibo on 05/24/11


Tagged

drupal user


Versions (?)

DRUPAL : creation + update user


 / Published in: PHP
 

URL: http://www.michaelphipps.com/how-create-users-programmatically-drupal-6x

  1. <?php
  2. $newUser = array(
  3. 'name' => 'username',
  4. 'pass' => 'password', // note: do not md5 the password
  5. 'mail' => 'email address',
  6. 'status' => 1,
  7. 'init' => 'email address'
  8. );
  9. user_save(null, $newUser);
  10. ?>
  11.  
  12. And, here's how you can update an existing user:
  13.  
  14. <?php
  15. // load user object
  16. $existingUser = user_load('USERID');
  17.  
  18. // update some user property
  19. $existingUser->some_property = 'blah';
  20.  
  21. // save existing user
  22. user_save((object) array('uid' => $existingUser->uid), (array) $existingUser);
  23. ?>

Report this snippet  

You need to login to post a comment.