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.


git-svn-id: https://develop.svn.wordpress.org/trunk@31963 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-04-01 18:22:16 +00:00
parent f898c8bd3d
commit 2418711c47
2 changed files with 44 additions and 1 deletions

View File

@@ -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'];