Ticket #27317: 27317.6.patch
File 27317.6.patch, 4.5 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/user.php
142 142 if ( !$update && username_exists( $user->user_login ) ) 143 143 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' )); 144 144 145 $usernames = array(); 146 /** 147 * Restrict allowed usernames 148 * 149 * @since 4.4.0 150 * 151 * @param array $usernames Array of blacklisted usernames 152 */ 153 $usernames = apply_filters( 'illegal_user_logins', $usernames ); 154 if ( in_array( $user->user_login, $usernames ) ) { 155 $errors->add( 'illegal_user_login', __( "Sorry, that username is not allowed." ) ); 156 } 157 145 158 /* checking email address */ 146 159 if ( empty( $user->user_email ) ) { 147 160 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) ); -
src/wp-includes/ms-functions.php
430 430 if ( in_array( $user_name, $illegal_names ) ) 431 431 $errors->add('user_name', __( 'That username is not allowed.' ) ); 432 432 433 /** This filter is documented in wp-admin/includes/user.php */ 434 if ( in_array( $user_name, apply_filters( 'illegal_user_logins', array() ) ) ) { 435 $errors->add('user_name', __( 'That username is not allowed.' ) ); 436 } 437 433 438 if ( is_email_address_unsafe( $user_email ) ) 434 439 $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.')); 435 440 -
src/wp-includes/user-functions.php
1315 1315 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 1316 1316 } 1317 1317 1318 /** This filter is documented in wp-admin/includes/user.php */ 1319 if ( in_array( $user_login, apply_filters( 'illegal_user_logins', array() ) ) ) { 1320 $return new WP_Error( 'illegal_user_login', __( "Sorry, that username is not allowed." ) ); 1321 } 1322 1318 1323 /* 1319 1324 * If a nicename is provided, remove unsafe user characters before using it. 1320 1325 * Otherwise build a nicename from the user_login. -
tests/phpunit/tests/user.php
596 596 if ( ! defined( 'WP_IMPORTING' ) ) { 597 597 $this->assertWPError( $return ); 598 598 } 599 } 600 601 /** 602 * @ticket 27317 603 */ 604 function test_illegal_user_logins_single() { 605 606 $user_data = array( 607 'user_login' => 'testuser', 608 'user_email' => 'testuser@example.com', 609 'user_pass' => wp_generate_password(), 610 ); 611 612 add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 613 614 $response = wp_insert_user( $user_data ); 615 $this->assertInstanceOf( 'WP_Error', $response ); 616 $this->assertEquals( 'illegal_user_login', $response->get_error_code() ); 617 618 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 619 620 $user_id = wp_insert_user( $user_data ); 621 $user = get_user_by( 'id', $user_id ); 622 $this->assertInstanceOf( 'WP_User', $user ); 623 } 624 625 /** 626 * @ticket 27317 627 */ 628 function test_illegal_user_logins_multisite() { 629 630 if ( ! is_multisite() ) { 631 return; 599 632 } 633 634 $user_data = array( 635 'user_login' => 'testuser', 636 'user_email' => 'testuser@example.com', 637 ); 638 639 add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 640 641 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 642 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 643 $this->assertEquals( 'user_name', $response['errors']->get_error_code() ); 644 645 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 646 647 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 648 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 649 $this->assertEquals( 0, count( $response['errors']->get_error_codes() ) ); 600 650 } 601 651 652 function _illegal_user_logins() { 653 return array( 'testuser' ); 654 } 655 602 656 /** 603 657 * @ticket 24618 604 658 */