Title: wp_update_user vs wp_insert_user
Last modified: August 19, 2016

---

# wp_update_user vs wp_insert_user

 *  [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * (@gilzow)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wp_update_user-vs-wp_insert_user/)
 * Have a plugin that I manage where I have been using wp_update_user to both create
   new users and update existing users. I’ve had a couple of users inform me that
   my plugin is failing at the point where it should be creating a new user via 
   wp_update_user. If I have them change it to wp_insert_user then it functions 
   just fine. In looking at registration.php it appears that the ONLY advantage 
   of using wp_update_user is if you are updating a user’s password.
 * Is this assumption correct? If so, can anyone think of a reason I shouldnt go
   ahead and switch to using wp_insert_user?
 * Also, can anyone think of a reason that wp_update_user would fail but wp_insert_user
   wouldnt when the array of user data passed to both of them is identical?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Tim Moore](https://wordpress.org/support/users/tmoorewp/)
 * (@tmoorewp)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wp_update_user-vs-wp_insert_user/#post-1983063)
 * What does the data array look like when a user needs to be created? If the ID
   is being set, even if empty, WordPress will assume it is updating a user and 
   then fail because the ID is empty. wp_insert_user is likely ignoring the ID variable,
   or setting it as usermeta.
 *  Thread Starter [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * (@gilzow)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wp_update_user-vs-wp_insert_user/#post-1983089)
 * data array contains
    - user_pass
    - user_login
    - user_email
    - nickname
    - display_name
    - role
 * Specifically this is the array that is being handed to the wp_insert_user function
   from within wp_update_user
 * `array ( 0 => '', 'user_pass' => 'XXX', 'user_login' => 'somename', 'user_email'
   => 'some@email.com', 'nickname' => 'somenick', 'display_name' => 'some name','
   role' => 'editor', )`
 * The 0 key is set by the wp_update_user function due to passing a false value 
   to add_magic_quotes (line 1552).
 * and this is after I run checks on user_name and user_email via sanitize_user(),
   username_exists() and email_exists(). I’ve walked through all of the wordpress
   code in wp_update_user and the various functions it calls and cant see where 
   it would fail versus using wp_insert_user directly.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wp_update_user vs wp_insert_user’ is closed to new replies.

## Tags

 * [wp_update_user()](https://wordpress.org/support/topic-tag/wp_update_user/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Paul Gilzow](https://wordpress.org/support/users/gilzow/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/wp_update_user-vs-wp_insert_user/#post-1983089)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
