Make WordPress Core


Ignore:
Timestamp:
05/20/2016 08:56:54 PM (9 years ago)
Author:
jeremyfelt
Message:

Multisite: Wrap the main bootstrap process in a function

Introduce ms_load_current_site_and_network. This is used by core during the multisite bootstrap process to populate the $current_site and $current_blog globals based on a requested domain and path.

Return values from this function inform ms-settings.php as to whether a page view should continue, ms_not_installed() should fire, or a redirect to a new location should occur.

This was previously a procedural block in ms-settings.php. Wrapping this code and providing specific return values allows us to write tests that do not rely on the manual and repeated inclusion of ms-settings.php.

This should not be used by plugins or themes. Please.

See #34941.

File:
1 edited

Legend:

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

    r37241 r37475  
    159159        );
    160160
    161         $this->_setup_host_request( $domain, $path );
     161        ms_load_current_site_and_network( $domain, $path );
    162162        $actual = array(
    163163            'network_id' => $current_blog->site_id,
    164164            'site_id' => $current_blog->blog_id,
    165165        );
    166         $this->_setup_host_request( WP_TESTS_DOMAIN, '/' );
     166        ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
    167167
    168168        $this->assertEqualSetsWithIndex( $expected, $actual );
     
    198198        );
    199199        add_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
    200         $this->_setup_host_request( 'wordpress.org', '/foo/bar/' );
     200        ms_load_current_site_and_network( 'wordpress.org', '/foo/bar/' );
    201201        $actual = array(
    202202            'network_id' => $current_blog->site_id,
     
    204204        );
    205205        remove_filter( 'site_by_path_segments_count', array( $this, 'filter_path_segments_to_two' ) );
    206         $this->_setup_host_request( WP_TESTS_DOMAIN, '/' );
     206        ms_load_current_site_and_network( WP_TESTS_DOMAIN, '/' );
    207207
    208208        $this->assertEqualSetsWithIndex( $expected, $actual );
     
    212212        return 2;
    213213    }
    214 
    215     /**
    216      * Reset various globals required for a 'clean' multisite boot.
    217      *
    218      * The $wpdb and $table_prefix globals are required for ms-settings.php to
    219      * load properly.
    220      *
    221      * @param string $domain HTTP_HOST of the bootstrap request.
    222      * @param string $path   REQUEST_URI of the boot strap request.
    223      */
    224     function _setup_host_request( $domain, $path ) {
    225         global $current_site, $current_blog, $table_prefix, $wpdb;
    226 
    227         $table_prefix = WP_TESTS_TABLE_PREFIX;
    228         $current_site = $current_blog = null;
    229         $_SERVER['HTTP_HOST'] = $domain;
    230         $_SERVER['REQUEST_URI'] = $path;
    231 
    232         include ABSPATH . '/wp-includes/ms-settings.php';
    233     }
    234214}
    235215
Note: See TracChangeset for help on using the changeset viewer.