Make WordPress Core


Ignore:
Timestamp:
10/20/2015 05:27:32 AM (11 years ago)
Author:
wonderboymusic
Message:

Users: when calling wp_insert_user() with an valid user ID, return WP_Error instead of arbitrarily updating user meta.

Adds unit test.

Props swissspidy, bilalcoder.
Fixes #28004.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user-functions.php

    r35189 r35280  
    12761276        $userdata = $userdata->to_array();
    12771277    }
     1278
    12781279    // Are we updating or creating?
    12791280    if ( ! empty( $userdata['ID'] ) ) {
    12801281        $ID = (int) $userdata['ID'];
    12811282        $update = true;
    1282         $old_user_data = WP_User::get_data_by( 'id', $ID );
     1283        $old_user_data = get_userdata( $ID );
     1284
     1285        if ( ! $old_user_data ) {
     1286            return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
     1287        }
     1288
    12831289        // hashed in wp_update_user(), plaintext if called directly
    12841290        $user_pass = $userdata['user_pass'];
Note: See TracChangeset for help on using the changeset viewer.