Ticket #27317: 27317.4.diff
File 27317.4.diff, 4.5 KB (added by , 11 years ago) |
---|
-
src/wp-includes/user.php
1542 1542 if ( !$update && username_exists( $user_login ) ) 1543 1543 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 1544 1544 1545 if ( in_array( $user_login, apply_filters( 'illegal_user_logins', array() ) ) ) { 1546 return new WP_Error( 'illegal-user-login', __( "Sorry, that username is not allowed." ) ); 1547 } 1548 1545 1549 if ( empty($user_nicename) ) 1546 1550 $user_nicename = sanitize_title( $user_login ); 1547 1551 … … 1982 1986 $sanitized_user_login = ''; 1983 1987 } elseif ( username_exists( $sanitized_user_login ) ) { 1984 1988 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); 1989 } elseif ( in_array( $sanitized_user_login, apply_filters( 'illegal_user_logins', array() ) ) ) { 1990 $errors->add( 'illegal_user_login', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); 1985 1991 } 1986 1992 1987 1993 // Check the e-mail address -
src/wp-includes/ms-functions.php
489 489 if ( in_array( $user_name, $illegal_names ) == true ) 490 490 $errors->add('user_name', __( 'That username is not allowed.' ) ); 491 491 492 if ( in_array( $user_name, apply_filters( 'illegal_user_logins', array() ) ) ) { 493 $errors->add('user_name', __( 'That username is not allowed.' ) ); 494 } 495 492 496 if ( is_email_address_unsafe( $user_email ) ) 493 497 $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.')); 494 498 -
src/wp-admin/includes/user.php
176 176 $user_id = wp_update_user( $user ); 177 177 } else { 178 178 $user_id = wp_insert_user( $user ); 179 wp_new_user_notification( $user_id, isset( $_POST['send_password'] ) ? wp_unslash( $pass1 ) : '' ); 179 if ( ! is_wp_error( $user_id ) ) { 180 wp_new_user_notification( $user_id, isset( $_POST['send_password'] ) ? wp_unslash( $pass1 ) : '' ); 181 } 180 182 } 181 183 return $user_id; 182 184 } -
tests/phpunit/tests/user.php
627 627 // If this test fails, it will error out for calling the to_array() method on a non-object. 628 628 $this->assertInstanceOf( 'WP_Error', wp_update_user( array( 'ID' => $user_id ) ) ); 629 629 } 630 631 /** 632 * @ticket 27317 633 */ 634 function test_illegal_user_logins_single() { 635 636 $user_data = array( 637 'user_login' => 'testuser', 638 'user_email' => 'testuser@example.com', 639 'user_pass' => wp_generate_password(), 640 ); 641 642 add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 643 644 $response = wp_insert_user( $user_data ); 645 $this->assertInstanceOf( 'WP_Error', $response ); 646 $this->assertEquals( 'illegal-user-login', $response->get_error_code() ); 647 648 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 649 650 $user_id = wp_insert_user( $user_data ); 651 $user = get_user_by( 'id', $user_id ); 652 $this->assertInstanceOf( 'WP_User', $user ); 653 } 654 655 /** 656 * @ticket 27317 657 */ 658 function test_illegal_user_logins_multisite() { 659 660 if ( ! is_multisite() ) { 661 return; 662 } 663 664 $user_data = array( 665 'user_login' => 'testuser', 666 'user_email' => 'testuser@example.com', 667 ); 668 669 add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 670 671 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 672 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 673 $this->assertEquals( 'user_name', $response['errors']->get_error_code() ); 674 675 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); 676 677 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 678 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 679 $this->assertEquals( 0, count( $response['errors']->get_error_codes() ) ); 680 } 681 682 function _illegal_user_logins() { 683 return array( 'testuser' ); 684 } 630 685 }