Make WordPress Core

Ticket #39915: 39915.diff

File 39915.diff, 3.4 KB (added by jeremyfelt, 7 years ago)
  • src/wp-includes/ms-functions.php

     
    442442                $errors->add( 'user_name',  __( 'Sorry, that username is not allowed.' ) );
    443443        }
    444444
    445         if ( is_email_address_unsafe( $user_email ) )
    446                 $errors->add('user_email',  __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.'));
     445        if ( ! is_email( $user_email ) ) {
     446                $errors->add( 'user_email', __( 'Please enter a valid email address.' ) );
     447        } elseif ( is_email_address_unsafe( $user_email ) ) {
     448                $errors->add( 'user_email', __( 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.' ) );
     449        }
    447450
    448451        if ( strlen( $user_name ) < 4 )
    449452                $errors->add('user_name',  __( 'Username must be at least 4 characters.' ) );
     
    456459        if ( preg_match( '/^[0-9]*$/', $user_name ) )
    457460                $errors->add('user_name', __('Sorry, usernames must have letters too!'));
    458461
    459         if ( !is_email( $user_email ) )
    460                 $errors->add('user_email', __( 'Please enter a valid email address.' ) );
    461 
    462462        $limited_email_domains = get_site_option( 'limited_email_domains' );
    463463        if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) {
    464464                $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
  • tests/phpunit/tests/multisite/wpmuValidateUserSignup.php

     
    122122                $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
    123123        }
    124124
     125        public function test_invalid_email_address_with_no_banned_domains_results_in_error() {
     126                $valid = wpmu_validate_user_signup( 'validusername', 'invalid-email' );
     127
     128                $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
     129        }
     130
     131        public function test_invalid_email_address_with_banned_domains_results_in_error() {
     132                update_site_option( 'banned_email_domains', "bar.com" );
     133                $valid = wpmu_validate_user_signup( 'validusername', 'invalid-email' );
     134                delete_site_option( 'banned_email_domains' );
     135
     136                $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
     137        }
     138
     139        public function test_incomplete_email_address_with_no_banned_domains_results_in_error() {
     140                $valid = wpmu_validate_user_signup( 'validusername', 'incomplete@email' );
     141
     142                $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
     143        }
     144
     145        public function test_valid_email_address_matching_banned_domain_results_in_error() {
     146                update_site_option( 'banned_email_domains', "bar.com" );
     147                $valid = wpmu_validate_user_signup( 'validusername', 'email@bar.com' );
     148                delete_site_option( 'banned_email_domains' );
     149
     150                $this->assertContains( 'user_email', $valid['errors']->get_error_codes() );
     151        }
     152
     153        public function test_valid_email_address_not_matching_banned_domain_returns_in_success() {
     154                update_site_option( 'banned_email_domains', "bar.com" );
     155                $valid = wpmu_validate_user_signup( 'validusername', 'email@example.com' );
     156                delete_site_option( 'banned_email_domains' );
     157
     158                $this->assertNotContains( 'user_email', $valid['errors']->get_error_codes() );
     159        }
    125160}
    126161
    127162endif;