From 85a6189ad8a3d8a2764afe567f84568e3e691d0f Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 20 Oct 2015 05:28:24 +0000 Subject: [PATCH] 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 --- wp-includes/user-functions.php | 8 +++++++- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/wp-includes/user-functions.php b/wp-includes/user-functions.php index 48c7791939..36c245d7ae 100644 --- a/wp-includes/user-functions.php +++ b/wp-includes/user-functions.php @@ -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 { diff --git a/wp-includes/version.php b/wp-includes/version.php index e15f4b980d..0cf4552b8a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.