Ticket #39676: 39676.4.diff
| File 39676.4.diff, 3.1 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/ms-functions.php
577 577 if ( in_array( $blogname, $illegal_names ) ) 578 578 $errors->add('blogname', __( 'That name is not allowed.' ) ); 579 579 580 if ( strlen( $blogname ) < 4 ) { 581 $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); 580 /** 581 * Filters the minimum site name length required when validating a site signup. 582 * 583 * @since 4.8.0 584 * 585 * @param int $length The minimum site name length. Default 4. 586 */ 587 $minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 ); 588 589 if ( strlen( $blogname ) < $minimum_site_name_length ) { 590 /* translators: %s: minimum site name length */ 591 $errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) ); 582 592 } 583 593 584 594 // do not allow users to create a blog that conflicts with a page on the main blog. -
tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php
14 14 protected static $existing_blog_name = 'existingsitefoo'; 15 15 protected static $existing_blog_id; 16 16 17 protected $minimum_site_name_length = 4; 18 17 19 public static function wpSetUpBeforeClass( $factory ) { 18 20 self::$super_admin_id = $factory->user->create(); 19 21 grant_super_admin( self::$super_admin_id ); … … 86 88 $result = wpmu_validate_blog_signup( self::$existing_user_login, 'Foo Site Title', get_userdata( self::$existing_user_id ) ); 87 89 $this->assertEmpty( $result['errors']->get_error_codes() ); 88 90 } 91 92 /** 93 * @ticket 39676 94 * 95 * @dataProvider data_filter_minimum_site_name_length 96 */ 97 public function test_filter_minimum_site_name_length( $site_name, $minimum_length, $expect_error ) { 98 $this->minimum_site_name_length = $minimum_length; 99 add_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) ); 100 101 $result = wpmu_validate_blog_signup( $site_name, 'Site Title', get_userdata( self::$super_admin_id ) ); 102 103 remove_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) ); 104 $this->minimum_site_name_length = 4; 105 106 if ( $expect_error ) { 107 $this->assertContains( 'blogname', $result['errors']->get_error_codes() ); 108 } else { 109 $this->assertEmpty( $result['errors']->get_error_codes() ); 110 } 111 } 112 113 public function data_filter_minimum_site_name_length() { 114 return array( 115 array( 'fooo', 5, true ), 116 array( 'foooo', 5, false ), 117 array( 'foo', 4, true ), 118 array( 'fooo', 4, false ), 119 array( 'fo', 3, true ), 120 array( 'foo', 3, false ), 121 ); 122 } 123 124 public function filter_minimum_site_name_length() { 125 return $this->minimum_site_name_length; 126 } 89 127 } 90 128 91 129 endif;
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)