Ticket #27317: 27317.7.patch
File 27317.7.patch, 4.7 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 /** This filter is documented in wp-includes/user-functions.php */ 146 $usernames = apply_filters( 'illegal_user_logins', array() ); 147 if ( in_array( $user->user_login, $usernames ) ) { 148 $errors->add( 'illegal_user_login', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); 149 } 150 145 151 /* checking email address */ 146 152 if ( empty( $user->user_email ) ) { 147 153 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) ); -
src/wp-includes/ms-functions.php
427 427 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); 428 428 add_site_option( 'illegal_names', $illegal_names ); 429 429 } 430 if ( in_array( $user_name, $illegal_names ) ) 431 $errors->add('user_name', __( 'That username is not allowed.' ) ); 430 if ( in_array( $user_name, $illegal_names ) ) { 431 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); 432 } 432 433 434 /** This filter is documented in wp-includes/user-functions.php */ 435 if ( in_array( $user_name, apply_filters( 'illegal_user_logins', array() ) ) ) { 436 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); 437 } 438 433 439 if ( is_email_address_unsafe( $user_email ) ) 434 440 $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 441 -
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 /** 1319 * Filter the list of blacklisted usernames. 1320 * 1321 * @since 4.4.0 1322 * 1323 * @param array $usernames Array of blacklisted usernames. 1324 */ 1325 if ( in_array( $user_login, apply_filters( 'illegal_user_logins', array() ) ) ) { 1326 return new WP_Error( 'illegal_user_login', __( 'Sorry, that username is not allowed.' ) ); 1327 } 1328 1318 1329 /* 1319 1330 * If a nicename is provided, remove unsafe user characters before using it. 1320 1331 * Otherwise build a nicename from the user_login. -
tests/phpunit/tests/user.php
600 600 } 601 601 602 602 /** 603 * @ticket 27317 604 */ 605 function test_illegal_user_logins_single() { 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 if ( ! is_multisite() ) { 630 return; 631 } 632 633 $user_data = array( 634 'user_login' => 'testuser', 635 'user_email' => 'testuser@example.com', 636 ); 637 638 add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 639 640 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 641 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 642 $this->assertEquals( 'user_name', $response['errors']->get_error_code() ); 643 644 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 645 646 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 647 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 648 $this->assertEquals( 0, count( $response['errors']->get_error_codes() ) ); 649 } 650 651 function _illegal_user_logins() { 652 return array( 'testuser' ); 653 } 654 655 /** 603 656 * @ticket 24618 604 657 */ 605 658 public function test_validate_username_string() {