3 * Used to set up and fix common variables and include
4 * the Multisite procedural and class library.
6 * Allows for some configuration in wp-config.php (see ms-default-constants.php)
9 * @subpackage Multisite
14 * Objects representing the current network and current site.
16 * These may be populated through a custom `sunrise.php`. If not, then this
17 * file will attempt to populate them based on the current request.
19 * @global WP_Network $current_site The current network.
20 * @global object $current_blog The current site.
23 global $current_site, $current_blog;
25 /** WP_Network class */
26 require_once( ABSPATH . WPINC . '/class-wp-network.php' );
29 require_once( ABSPATH . WPINC . '/class-wp-site.php' );
31 /** Multisite loader */
32 require_once( ABSPATH . WPINC . '/ms-load.php' );
34 /** Default Multisite constants */
35 require_once( ABSPATH . WPINC . '/ms-default-constants.php' );
37 if ( defined( 'SUNRISE' ) ) {
38 include_once( WP_CONTENT_DIR . '/sunrise.php' );
41 /** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
42 ms_subdomain_constants();
44 // This block will process a request if the current network or current site objects
45 // have not been populated in the global scope through something like `sunrise.php`.
46 if ( !isset( $current_site ) || !isset( $current_blog ) ) {
48 $domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) );
49 if ( substr( $domain, -3 ) == ':80' ) {
50 $domain = substr( $domain, 0, -3 );
51 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
52 } elseif ( substr( $domain, -4 ) == ':443' ) {
53 $domain = substr( $domain, 0, -4 );
54 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
57 $path = stripslashes( $_SERVER['REQUEST_URI'] );
59 $path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path );
61 list( $path ) = explode( '?', $path );
63 $bootstrap_result = ms_load_current_site_and_network( $domain, $path, is_subdomain_install() );
65 if ( true === $bootstrap_result ) {
66 // `$current_blog` and `$current_site are now populated.
67 } elseif ( false === $bootstrap_result ) {
68 ms_not_installed( $domain, $path );
70 header( 'Location: ' . $bootstrap_result );
73 unset( $bootstrap_result );
75 $blog_id = $current_blog->blog_id;
76 $public = $current_blog->public;
78 if ( empty( $current_blog->site_id ) ) {
79 // This dates to [MU134] and shouldn't be relevant anymore,
80 // but it could be possible for arguments passed to insert_blog() etc.
81 $current_blog->site_id = 1;
84 $site_id = $current_blog->site_id;
85 wp_load_core_site_options( $site_id );
88 $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php
89 $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
90 $table_prefix = $wpdb->get_blog_prefix();
91 $_wp_switched_stack = array();
94 // need to init cache again after blog_id is set
95 wp_start_object_cache();
97 if ( ! $current_site instanceof WP_Network ) {
98 $current_site = new WP_Network( $current_site );
101 if ( ! $current_blog instanceof WP_Site ) {
102 $current_blog = new WP_Site( $current_blog );
105 // Define upload directory constants
106 ms_upload_constants();
109 * Fires after the current site and network have been detected and loaded
110 * in multisite's bootstrap.
114 do_action( 'ms_loaded' );