Title: Issue with wp_insert_user()
Last modified: July 28, 2020

---

# Issue with wp_insert_user()

 *  [usamakhalid](https://wordpress.org/support/users/usamakhalid/)
 * (@usamakhalid)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/issue-with-wp_insert_user/)
 * Hey,
    I hope you are fine. I was working in WordPress and I want to insert user
   information for that I use the ‘wp_insert_user()’ function. It was working fine
   a few days ago then suddenly this function starts generating 0 instead of the
   user id. What is the issue? and why this function is behaving like this. ?
 * `$user = wp_insert_user($params); //this generate 0 everytime`
    -  This topic was modified 5 years, 10 months ago by [usamakhalid](https://wordpress.org/support/users/usamakhalid/).
    -  This topic was modified 5 years, 10 months ago by [usamakhalid](https://wordpress.org/support/users/usamakhalid/).

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

 *  [Ian Sackofwits](https://wordpress.org/support/users/plantprogrammer/)
 * (@plantprogrammer)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/issue-with-wp_insert_user/#post-13181026)
 * Hi, usamakhalid, I see from [https://developer.wordpress.org/reference/functions/wp_insert_user/](https://developer.wordpress.org/reference/functions/wp_insert_user/)
   that somebody experienced an issue, as:
 * >  The user_url length in database is limited to 100.
   > But wp_insert_user won’t return a WP_Error if this size is exceeded, it returns
   > 0.
 * If that wasn’t the culprit, I would investigate how `wp_insert_user` returns 
   values, specifically with these lines of its function implementation:
 *     ```
       if ( $update ) {
               if ( $user_email !== $old_user_data->user_email ) {
                   $data['user_activation_key'] = '';
               }
               $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
               $user_id = (int) $ID;
           } else {
               $wpdb->insert( $wpdb->users, $data );
               $user_id = (int) $wpdb->insert_id;
           }
       ```
   
 * As this is where `$user_id` is set prior to being return if no problems exist,
   I believe.
 *  Thread Starter [usamakhalid](https://wordpress.org/support/users/usamakhalid/)
 * (@usamakhalid)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/issue-with-wp_insert_user/#post-13181576)
 * Hy [@plantprogrammer](https://wordpress.org/support/users/plantprogrammer/) I
   don’t understand that this function is working a few days ago. Then why it is
   not creating a new user and returning 0 instead of an error. ?

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

The topic ‘Issue with wp_insert_user()’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [usamakhalid](https://wordpress.org/support/users/usamakhalid/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/issue-with-wp_insert_user/#post-13181576)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
