Make WordPress Core

Ticket #27317: 27317.2.diff

File 27317.2.diff, 1.9 KB (added by boonebgorges, 9 years ago)
  • src/wp-includes/user.php

    diff --git src/wp-includes/user.php src/wp-includes/user.php
    index 32b0ec7..af04ff7 100644
    function register_new_user( $user_login, $user_email ) { 
    21242124                $sanitized_user_login = '';
    21252125        } elseif ( username_exists( $sanitized_user_login ) ) {
    21262126                $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );
     2127
     2128        } else {
     2129                /** This filter is documented in wp-includes/user.php */
     2130                $illegal_user_logins = array_map( 'strtolower', (array) apply_filters( 'illegal_user_logins', array() ) );
     2131                if ( in_array( strtolower( $sanitized_user_login ), $illegal_user_logins ) ) {
     2132                        $errors->add( 'illegal_user_login', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) );
     2133                }
    21272134        }
    21282135
    21292136        // Check the email address
  • tests/phpunit/tests/user.php

    diff --git tests/phpunit/tests/user.php tests/phpunit/tests/user.php
    index 3644ffc..35cb5e6 100644
    class Tests_User extends WP_UnitTestCase { 
    633633
    634634        /**
    635635         * @ticket 27317
     636         * @dataProvider _illegal_user_logins_data
     637         */
     638        function test_illegal_user_logins_single_wp_create_user( $user_login ) {
     639                $user_email = 'testuser-' . $user_login . '@example.com';
     640
     641                add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
     642
     643                $response = register_new_user( $user_login, $user_email );
     644                $this->assertInstanceOf( 'WP_Error', $response );
     645                $this->assertEquals( 'illegal_user_login', $response->get_error_code() );
     646
     647                remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
     648
     649                $response = register_new_user( $user_login, $user_email );
     650                $user = get_user_by( 'id', $response );
     651                $this->assertInstanceOf( 'WP_User', $user );
     652        }
     653
     654
     655        /**
     656         * @ticket 27317
    636657         */
    637658        function test_illegal_user_logins_multisite() {
    638659                if ( ! is_multisite() ) {