Multisite: Introduce minimum_site_name_length
filter.
Prior to this change, the minimum site name length checked in `wpmu_validate_blog_signup()` was set to a fixed value of 4. The new filter allows tweaking this value, as there may be cases where shorter site names may be required. Fixes #39676. git-svn-id: https://develop.svn.wordpress.org/trunk@40589 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4469ab9d66
commit
48661c4b00
@ -577,8 +577,18 @@ function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) {
|
||||
if ( in_array( $blogname, $illegal_names ) )
|
||||
$errors->add('blogname', __( 'That name is not allowed.' ) );
|
||||
|
||||
if ( strlen( $blogname ) < 4 ) {
|
||||
$errors->add('blogname', __( 'Site name must be at least 4 characters.' ) );
|
||||
/**
|
||||
* Filters the minimum site name length required when validating a site signup.
|
||||
*
|
||||
* @since 4.8.0
|
||||
*
|
||||
* @param int $length The minimum site name length. Default 4.
|
||||
*/
|
||||
$minimum_site_name_length = apply_filters( 'minimum_site_name_length', 4 );
|
||||
|
||||
if ( strlen( $blogname ) < $minimum_site_name_length ) {
|
||||
/* translators: %s: minimum site name length */
|
||||
$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 ) ) );
|
||||
}
|
||||
|
||||
// do not allow users to create a blog that conflicts with a page on the main blog.
|
||||
|
@ -14,6 +14,8 @@ class Tests_Multisite_WpmuValidateBlogSignup extends WP_UnitTestCase {
|
||||
protected static $existing_blog_name = 'existingsitefoo';
|
||||
protected static $existing_blog_id;
|
||||
|
||||
protected $minimum_site_name_length = 4;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$super_admin_id = $factory->user->create();
|
||||
grant_super_admin( self::$super_admin_id );
|
||||
@ -86,6 +88,42 @@ class Tests_Multisite_WpmuValidateBlogSignup extends WP_UnitTestCase {
|
||||
$result = wpmu_validate_blog_signup( self::$existing_user_login, 'Foo Site Title', get_userdata( self::$existing_user_id ) );
|
||||
$this->assertEmpty( $result['errors']->get_error_codes() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39676
|
||||
*
|
||||
* @dataProvider data_filter_minimum_site_name_length
|
||||
*/
|
||||
public function test_filter_minimum_site_name_length( $site_name, $minimum_length, $expect_error ) {
|
||||
$this->minimum_site_name_length = $minimum_length;
|
||||
add_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) );
|
||||
|
||||
$result = wpmu_validate_blog_signup( $site_name, 'Site Title', get_userdata( self::$super_admin_id ) );
|
||||
|
||||
remove_filter( 'minimum_site_name_length', array( $this, 'filter_minimum_site_name_length' ) );
|
||||
$this->minimum_site_name_length = 4;
|
||||
|
||||
if ( $expect_error ) {
|
||||
$this->assertContains( 'blogname', $result['errors']->get_error_codes() );
|
||||
} else {
|
||||
$this->assertEmpty( $result['errors']->get_error_codes() );
|
||||
}
|
||||
}
|
||||
|
||||
public function data_filter_minimum_site_name_length() {
|
||||
return array(
|
||||
array( 'fooo', 5, true ),
|
||||
array( 'foooo', 5, false ),
|
||||
array( 'foo', 4, true ),
|
||||
array( 'fooo', 4, false ),
|
||||
array( 'fo', 3, true ),
|
||||
array( 'foo', 3, false ),
|
||||
);
|
||||
}
|
||||
|
||||
public function filter_minimum_site_name_length() {
|
||||
return $this->minimum_site_name_length;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
Loading…
Reference in New Issue
Block a user