In wp_insert_user()
, comparing an email address against the user's old email address should not be case-sensitive.
Adds unit tests. Props tyxla. Fixes #32158. git-svn-id: https://develop.svn.wordpress.org/trunk@33115 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a297e1532e
commit
138d68a58a
@ -1945,7 +1945,7 @@ function wp_insert_user( $userdata ) {
|
|||||||
* check if current email and new email are the same, or not, and check `email_exists`
|
* check if current email and new email are the same, or not, and check `email_exists`
|
||||||
* accordingly.
|
* accordingly.
|
||||||
*/
|
*/
|
||||||
if ( ( ! $update || ( ! empty( $old_user_data ) && $user_email !== $old_user_data->user_email ) )
|
if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) )
|
||||||
&& ! defined( 'WP_IMPORTING' )
|
&& ! defined( 'WP_IMPORTING' )
|
||||||
&& email_exists( $user_email )
|
&& email_exists( $user_email )
|
||||||
) {
|
) {
|
||||||
|
@ -756,4 +756,48 @@ class Tests_User extends WP_UnitTestCase {
|
|||||||
|
|
||||||
$this->assertTrue( in_array( $id, $users ) );
|
$this->assertTrue( in_array( $id, $users ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 32158
|
||||||
|
*/
|
||||||
|
function test_email_case() {
|
||||||
|
// Create a test user with a lower-case email address.
|
||||||
|
$user_id = $this->factory->user->create( array(
|
||||||
|
'user_email' => 'test@test.com',
|
||||||
|
) );
|
||||||
|
|
||||||
|
// Alter the case of the email address (which stays the same).
|
||||||
|
$userdata = array(
|
||||||
|
'ID' => $user_id,
|
||||||
|
'user_email' => 'test@TEST.com',
|
||||||
|
);
|
||||||
|
$update = wp_update_user( $userdata );
|
||||||
|
|
||||||
|
$this->assertEquals( $user_id, $update );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 32158
|
||||||
|
*/
|
||||||
|
function test_email_change() {
|
||||||
|
// Create a test user.
|
||||||
|
$user_id = $this->factory->user->create( array(
|
||||||
|
'user_email' => 'test@test.com',
|
||||||
|
) );
|
||||||
|
|
||||||
|
// Change the email address.
|
||||||
|
$userdata = array(
|
||||||
|
'ID' => $user_id,
|
||||||
|
'user_email' => 'test2@test.com',
|
||||||
|
);
|
||||||
|
$update = wp_update_user( $userdata );
|
||||||
|
|
||||||
|
// Was this successful?
|
||||||
|
$this->assertEquals( $user_id, $update );
|
||||||
|
|
||||||
|
// Verify that the email address has been updated.
|
||||||
|
$user = get_userdata( $user_id );
|
||||||
|
$this->assertEquals( $user->user_email, 'test2@test.com' );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user