From 138d68a58ac469e24c133a9286d8238fa1edea8c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 7 Jul 2015 19:28:46 +0000 Subject: [PATCH] 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 --- src/wp-includes/user.php | 2 +- tests/phpunit/tests/user.php | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 1c8a5b36d4..fca15065f0 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -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` * 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' ) && email_exists( $user_email ) ) { diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index c32b778593..f63d8382f7 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -756,4 +756,48 @@ class Tests_User extends WP_UnitTestCase { $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' ); + } + }