From 0fccadaa359e50bf6f33df6c1c8ba6037d6f9ef7 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 1 Apr 2015 18:23:28 +0000 Subject: [PATCH] When updating the email address for an existing user, make sure the email address is not already in use. Adds unit tests. Props rittesh.patel, DrewAPicture. Fixes #30647. Built from https://develop.svn.wordpress.org/trunk@31963 git-svn-id: http://core.svn.wordpress.org/trunk@31942 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 10 +++++++++- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 3a03ea0425..adb134a148 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -1894,7 +1894,15 @@ function wp_insert_user( $userdata ) { */ $user_email = apply_filters( 'pre_user_email', $raw_user_email ); - if ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists( $user_email ) ) { + /* + * If there is no update, just check for `email_exists`. If there is an update, + * 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 ) ) + && ! defined( 'WP_IMPORTING' ) + && email_exists( $user_email ) + ) { return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); } $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; diff --git a/wp-includes/version.php b/wp-includes/version.php index 0dcfbfbfb2..e72f3ef6f6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-beta3-31962'; +$wp_version = '4.2-beta3-31963'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.