From 56bb62543d485f491f7f614c827638e426019d93 Mon Sep 17 00:00:00 2001 From: desrosj Date: Thu, 17 Jan 2019 21:25:51 +0000 Subject: [PATCH] REST API: Allow a user to change the letter casing of their email. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a `PUT` request is performed to update a user, a `rest_user_invalid_email` error is incorrectly being returned when the email exists with different letter casing, even if it belongs to the user being updated. `email_exists()` performs a case insensitive lookup, but the conditional statement following that lookup was performing a strict comparison between the new email and the user’s current email. This changes that comparison to instead compare the user ID returned by `email_exists()` with the user ID being updated. This more closely matches the logic used in `edit_user()` and allows a user to change the letter casing of their email. Props fuchsws, rachelbaker, desrosj. Fixes #44672. Built from https://develop.svn.wordpress.org/trunk@44641 git-svn-id: http://core.svn.wordpress.org/trunk@44472 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../rest-api/endpoints/class-wp-rest-users-controller.php | 4 +++- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 6c9611c87b..207198e54c 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -641,7 +641,9 @@ class WP_REST_Users_Controller extends WP_REST_Controller { return new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); } - if ( email_exists( $request['email'] ) && $request['email'] !== $user->user_email ) { + $owner_id = email_exists( $request['email'] ); + + if ( $owner_id && $owner_id !== $id ) { return new WP_Error( 'rest_user_invalid_email', __( 'Invalid email address.' ), array( 'status' => 400 ) ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7c859ab584..3a87ea9cf5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta1-44640'; +$wp_version = '5.1-beta1-44641'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.