author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Used to set up and fix common variables and include |
|
4 |
* the Multisite procedural and class library. |
|
5 |
* |
|
6 |
* Allows for some configuration in wp-config.php (see ms-default-constants.php) |
|
7 |
* |
|
8 |
* @package WordPress |
|
9 |
* @subpackage Multisite |
|
10 |
* @since 3.0.0 |
|
11 |
*/ |
|
12 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* Objects representing the current network and current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* These may be populated through a custom `sunrise.php`. If not, then this |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* file will attempt to populate them based on the current request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @global WP_Network $current_site The current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @global object $current_blog The current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @global string $domain Deprecated. The domain of the site found on load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* Use `get_site()->domain` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @global string $path Deprecated. The path of the site found on load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* Use `get_site()->path` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @global int $site_id Deprecated. The ID of the network found on load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* Use `get_current_network_id()` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* @global bool $public Deprecated. Whether the site found on load is public. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
* Use `get_site()->public` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
global $current_site, $current_blog, $domain, $path, $site_id, $public; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
/** WP_Network class */ |
16 | 35 |
require_once ABSPATH . WPINC . '/class-wp-network.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
/** WP_Site class */ |
16 | 38 |
require_once ABSPATH . WPINC . '/class-wp-site.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
/** Multisite loader */ |
16 | 41 |
require_once ABSPATH . WPINC . '/ms-load.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
/** Default Multisite constants */ |
16 | 44 |
require_once ABSPATH . WPINC . '/ms-default-constants.php'; |
0 | 45 |
|
5 | 46 |
if ( defined( 'SUNRISE' ) ) { |
16 | 47 |
include_once WP_CONTENT_DIR . '/sunrise.php'; |
5 | 48 |
} |
0 | 49 |
|
50 |
/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */ |
|
51 |
ms_subdomain_constants(); |
|
52 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
// This block will process a request if the current network or current site objects |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
// have not been populated in the global scope through something like `sunrise.php`. |
9 | 55 |
if ( ! isset( $current_site ) || ! isset( $current_blog ) ) { |
0 | 56 |
|
5 | 57 |
$domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) ); |
16 | 58 |
if ( ':80' === substr( $domain, -3 ) ) { |
9 | 59 |
$domain = substr( $domain, 0, -3 ); |
5 | 60 |
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 ); |
16 | 61 |
} elseif ( ':443' === substr( $domain, -4 ) ) { |
9 | 62 |
$domain = substr( $domain, 0, -4 ); |
5 | 63 |
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 ); |
64 |
} |
|
65 |
||
66 |
$path = stripslashes( $_SERVER['REQUEST_URI'] ); |
|
67 |
if ( is_admin() ) { |
|
68 |
$path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path ); |
|
69 |
} |
|
70 |
list( $path ) = explode( '?', $path ); |
|
71 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
$bootstrap_result = ms_load_current_site_and_network( $domain, $path, is_subdomain_install() ); |
5 | 73 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
if ( true === $bootstrap_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
// `$current_blog` and `$current_site are now populated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
} elseif ( false === $bootstrap_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
ms_not_installed( $domain, $path ); |
5 | 78 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
header( 'Location: ' . $bootstrap_result ); |
5 | 80 |
exit; |
0 | 81 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
unset( $bootstrap_result ); |
0 | 83 |
|
84 |
$blog_id = $current_blog->blog_id; |
|
85 |
$public = $current_blog->public; |
|
86 |
||
5 | 87 |
if ( empty( $current_blog->site_id ) ) { |
88 |
// This dates to [MU134] and shouldn't be relevant anymore, |
|
89 |
// but it could be possible for arguments passed to insert_blog() etc. |
|
0 | 90 |
$current_blog->site_id = 1; |
5 | 91 |
} |
0 | 92 |
|
5 | 93 |
$site_id = $current_blog->site_id; |
94 |
wp_load_core_site_options( $site_id ); |
|
0 | 95 |
} |
5 | 96 |
|
16 | 97 |
$wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php. |
0 | 98 |
$wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id ); |
9 | 99 |
$table_prefix = $wpdb->get_blog_prefix(); |
0 | 100 |
$_wp_switched_stack = array(); |
9 | 101 |
$switched = false; |
0 | 102 |
|
16 | 103 |
// Need to init cache again after blog_id is set. |
0 | 104 |
wp_start_object_cache(); |
105 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
if ( ! $current_site instanceof WP_Network ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
$current_site = new WP_Network( $current_site ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
if ( ! $current_blog instanceof WP_Site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
$current_blog = new WP_Site( $current_blog ); |
5 | 112 |
} |
113 |
||
16 | 114 |
// Define upload directory constants. |
0 | 115 |
ms_upload_constants(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* Fires after the current site and network have been detected and loaded |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* in multisite's bootstrap. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
do_action( 'ms_loaded' ); |