• 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.
    • This topic was modified 5 years, 10 months ago by usamakhalid.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, usamakhalid, I see from https://developer.ww.wp.xz.cn/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

    (@usamakhalid)

    Hy @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.