diff --git src/wp-admin/includes/user.php src/wp-admin/includes/user.php
index 3d37bdf..0052668 100644
|
|
function edit_user( $user_id = 0 ) { |
146 | 146 | $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
147 | 147 | |
148 | 148 | if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ) ) ) { |
149 | | $errors->add( 'illegal_user_login', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); |
| 149 | $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); |
150 | 150 | } |
151 | 151 | |
152 | 152 | /* checking email address */ |
diff --git src/wp-includes/user.php src/wp-includes/user.php
index 32b0ec7..4600dff 100644
|
|
function wp_insert_user( $userdata ) { |
1331 | 1331 | $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
1332 | 1332 | |
1333 | 1333 | if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ) ) ) { |
1334 | | return new WP_Error( 'illegal_user_login', __( 'Sorry, that username is not allowed.' ) ); |
| 1334 | return new WP_Error( 'invalid_username', __( 'Sorry, that username is not allowed.' ) ); |
1335 | 1335 | } |
1336 | 1336 | |
1337 | 1337 | /* |
… |
… |
function register_new_user( $user_login, $user_email ) { |
2124 | 2124 | $sanitized_user_login = ''; |
2125 | 2125 | } elseif ( username_exists( $sanitized_user_login ) ) { |
2126 | 2126 | $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( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); |
| 2133 | } |
2127 | 2134 | } |
2128 | 2135 | |
2129 | 2136 | // Check the email address |
diff --git tests/phpunit/tests/user.php tests/phpunit/tests/user.php
index 3644ffc..6ec0d36 100644
|
|
class Tests_User extends WP_UnitTestCase { |
622 | 622 | |
623 | 623 | $response = wp_insert_user( $user_data ); |
624 | 624 | $this->assertInstanceOf( 'WP_Error', $response ); |
625 | | $this->assertEquals( 'illegal_user_login', $response->get_error_code() ); |
| 625 | $this->assertEquals( 'invalid_username', $response->get_error_code() ); |
626 | 626 | |
627 | 627 | remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); |
628 | 628 | |
… |
… |
class Tests_User extends WP_UnitTestCase { |
633 | 633 | |
634 | 634 | /** |
635 | 635 | * @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( 'invalid_username', $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 |
636 | 657 | */ |
637 | 658 | function test_illegal_user_logins_multisite() { |
638 | 659 | if ( ! is_multisite() ) { |
… |
… |
class Tests_User extends WP_UnitTestCase { |
658 | 679 | } |
659 | 680 | |
660 | 681 | function _illegal_user_logins_data() { |
661 | | return array( |
662 | | array( 'testuser' ), |
663 | | array( 'TestUser' ), |
| 682 | $data = array( |
| 683 | array( 'testuser' ) |
664 | 684 | ); |
| 685 | |
| 686 | // Multisite doesn't allow mixed case logins ever |
| 687 | if ( ! is_multisite() ) { |
| 688 | $data[] = array( 'TestUser' ); |
| 689 | } |
| 690 | return $data; |
665 | 691 | } |
666 | 692 | |
667 | 693 | function _illegal_user_logins() { |