Make WordPress Core


Ignore:
Timestamp:
01/17/2019 09:24:47 PM (6 years ago)
Author:
desrosj
Message:

REST API: Allow a user to change the letter casing of their email.

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r43987 r44641  
    642642        }
    643643
    644         if ( email_exists( $request['email'] ) && $request['email'] !== $user->user_email ) {
     644        $owner_id = email_exists( $request['email'] );
     645
     646        if ( $owner_id && $owner_id !== $id ) {
    645647            return new WP_Error( 'rest_user_invalid_email', __( 'Invalid email address.' ), array( 'status' => 400 ) );
    646648        }
Note: See TracChangeset for help on using the changeset viewer.