Ticket #57394: 57394.diff
File 57394.diff, 3.3 KB (added by , 15 months ago) |
---|
-
src/wp-includes/user.php
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 8e230708e4ee..5e9195ed9d48 100644
a b function wp_insert_user( $userdata ) { 2124 2124 return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); 2125 2125 } 2126 2126 2127 if ( ! $update && username_exists( $user_login ) ) { 2128 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 2127 // Check additional restrictions for new users. 2128 if ( ! $update ) { 2129 2130 // Username must be unique. 2131 if ( username_exists( $user_login ) ) { 2132 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 2133 } 2134 2135 // Username must not match an existing user email. 2136 if ( email_exists( $user_login ) ) { 2137 return new WP_Error( 'existing_user_email_as_login', __( 'Sorry, that username is not available.' ) ); 2138 } 2129 2139 } 2130 2140 2131 2141 /** … … function register_new_user( $user_login, $user_email ) { 3354 3364 $sanitized_user_login = ''; 3355 3365 } elseif ( username_exists( $sanitized_user_login ) ) { 3356 3366 $errors->add( 'username_exists', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) ); 3367 } elseif ( email_exists( $sanitized_user_login ) ) { 3368 $errors->add( 'username_exists_as_email', __( '<strong>Error:</strong> This username is not available. Please choose another one.' ) ); 3357 3369 } else { 3358 3370 /** This filter is documented in wp-includes/user.php */ 3359 3371 $illegal_user_logins = (array) apply_filters( 'illegal_user_logins', array() ); -
tests/phpunit/tests/user.php
diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 7157a00cfa9f..044c7ccbd6a0 100644
a b public function test_wp_insert_user_should_reject_user_nicename_over_50_characte 915 915 $this->assertSame( 'user_nicename_too_long', $u->get_error_code() ); 916 916 } 917 917 918 919 /** 920 * @ticket 57394 921 */ 922 public function test_wp_insert_user_should_reject_user_login_that_matches_existing_user_email() { 923 // When creating a user, the user_login should not match an existing user's email. 924 $existing_email = get_option( 'admin_email' ); 925 $user_id = wp_insert_user( 926 array( 927 'user_login' => $existing_email, 928 'user_email' => 'whatever@example.com', 929 'user_pass' => 'whatever', 930 'user_nicename' => 'whatever', 931 ) 932 ); 933 $this->assertWPError( $user_id ); 934 $this->assertSame( 'existing_user_email_as_login', $user_id->get_error_code() ); 935 936 // When updating a user, the user_login can match an existing user's email. 937 $new_email = 'new.email@example.com'; 938 939 $user_id = wp_insert_user( 940 array( 941 'user_login' => $new_email, 942 'user_email' => $new_email, 943 'user_pass' => 'whatever', 944 'user_nicename' => 'whatever', 945 ) 946 ); 947 $this->assertNotWPError( $user_id ); 948 949 $user_id = wp_update_user( 950 array( 951 'ID' => $user_id, 952 'user_login' => $new_email, 953 'user_email' => $new_email, 954 'user_nicename' => 'new-nicename', 955 ) 956 ); 957 // No error should be returned. 958 $this->assertNotWPError( $user_id ); 959 // The user_nicename should have been updated. 960 $this->assertSame( 'new-nicename', get_userdata( $user_id )->user_nicename ); 961 } 962 918 963 /** 919 964 * @ticket 33793 920 965 */