Make WordPress Core

Changeset 55360


Ignore:
Timestamp:
02/17/2023 10:13:36 AM (15 months ago)
Author:
SergeyBiryukov
Message:

Users: Correct the error code in wp_insert_user() when login matches an existing email.

Move the test next to the other tests for user_login.

Follow-up to [55358].

See #57394.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r55358 r55360  
    21312131    // Username must not match an existing user email.
    21322132    if ( email_exists( $user_login ) ) {
    2133         return new WP_Error( 'existing_user_login_as_email', __( 'Sorry, that username is not available.' ) );
     2133        return new WP_Error( 'existing_user_email_as_login', __( 'Sorry, that username is not available.' ) );
    21342134    }
    21352135
  • trunk/tests/phpunit/tests/user.php

    r55358 r55360  
    899899
    900900    /**
     901     * @ticket 57394
     902     */
     903    public function test_wp_insert_user_should_reject_user_login_that_matches_existing_user_email() {
     904        $existing_email = get_option( 'admin_email' );
     905        $user_id        = wp_insert_user(
     906            array(
     907                'user_login'    => $existing_email,
     908                'user_email'    => 'whatever@example.com',
     909                'user_pass'     => 'whatever',
     910                'user_nicename' => 'whatever',
     911            )
     912        );
     913
     914        $this->assertWPError( $user_id );
     915        $this->assertSame( 'existing_user_email_as_login', $user_id->get_error_code() );
     916    }
     917
     918    /**
    901919     * @ticket 33793
    902920     */
     
    933951        $expected = str_repeat( 'a', 50 );
    934952        $this->assertSame( $expected, $user->user_nicename );
    935     }
    936 
    937     /**
    938      * @ticket 57394
    939      */
    940     public function test_wp_insert_user_should_reject_username_that_matches_existing_user_email() {
    941         $existing_email = get_option( 'admin_email' );
    942         $username       = wp_insert_user(
    943             array(
    944                 'user_login'    => $existing_email,
    945                 'user_email'    => 'whatever@example.com',
    946                 'user_pass'     => 'whatever',
    947                 'user_nicename' => 'whatever',
    948             )
    949         );
    950 
    951         $this->assertWPError( $username );
    952         $this->assertSame( 'existing_user_login_as_email', $username->get_error_code() );
    953953    }
    954954
Note: See TracChangeset for help on using the changeset viewer.