WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/09/2017 02:58:39 PM (4 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/wpmuValidateBlogSignup.php

    r40391 r40589  
    1414    protected static $existing_blog_name = 'existingsitefoo';
    1515    protected static $existing_blog_id;
     16
     17    protected $minimum_site_name_length = 4;
    1618
    1719    public static function wpSetUpBeforeClass( $factory ) {
     
    8789        $this->assertEmpty( $result['errors']->get_error_codes() );
    8890    }
     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    }
    89127}
    90128
Note: See TracChangeset for help on using the changeset viewer.