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.

Built from https://develop.svn.wordpress.org/trunk@35280


git-svn-id: http://core.svn.wordpress.org/trunk@35246 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-10-20 05:28:24 +00:00
parent 5d63788d9a
commit 85a6189ad8
2 changed files with 8 additions and 2 deletions

View File

@ -1275,11 +1275,17 @@ function wp_insert_user( $userdata ) {
} elseif ( $userdata instanceof WP_User ) {
$userdata = $userdata->to_array();
}
// Are we updating or creating?
if ( ! empty( $userdata['ID'] ) ) {
$ID = (int) $userdata['ID'];
$update = true;
$old_user_data = WP_User::get_data_by( 'id', $ID );
$old_user_data = get_userdata( $ID );
if ( ! $old_user_data ) {
return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
}
// hashed in wp_update_user(), plaintext if called directly
$user_pass = $userdata['user_pass'];
} else {

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35279';
$wp_version = '4.4-alpha-35280';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.