author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
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 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
13 |
// Don't load directly. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
14 |
if ( ! defined( 'ABSPATH' ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
15 |
die( '-1' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
16 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
17 |
|
7
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 |
* Objects representing the current network and current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* 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
|
22 |
* 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
|
23 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @global WP_Network $current_site The current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @global object $current_blog The current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* @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
|
27 |
* Use `get_site()->domain` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
* @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
|
29 |
* Use `get_site()->path` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* @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
|
31 |
* Use `get_current_network_id()` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* @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
|
33 |
* Use `get_site()->public` instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* @since 3.0.0 |
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 |
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
|
38 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
/** WP_Network class */ |
16 | 40 |
require_once ABSPATH . WPINC . '/class-wp-network.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
/** WP_Site class */ |
16 | 43 |
require_once ABSPATH . WPINC . '/class-wp-site.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
/** Multisite loader */ |
16 | 46 |
require_once ABSPATH . WPINC . '/ms-load.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
/** Default Multisite constants */ |
16 | 49 |
require_once ABSPATH . WPINC . '/ms-default-constants.php'; |
0 | 50 |
|
5 | 51 |
if ( defined( 'SUNRISE' ) ) { |
16 | 52 |
include_once WP_CONTENT_DIR . '/sunrise.php'; |
5 | 53 |
} |
0 | 54 |
|
55 |
/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */ |
|
56 |
ms_subdomain_constants(); |
|
57 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
// 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
|
59 |
// have not been populated in the global scope through something like `sunrise.php`. |
9 | 60 |
if ( ! isset( $current_site ) || ! isset( $current_blog ) ) { |
0 | 61 |
|
5 | 62 |
$domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
63 |
if ( str_ends_with( $domain, ':80' ) ) { |
9 | 64 |
$domain = substr( $domain, 0, -3 ); |
5 | 65 |
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
66 |
} elseif ( str_ends_with( $domain, ':443' ) ) { |
9 | 67 |
$domain = substr( $domain, 0, -4 ); |
5 | 68 |
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 ); |
69 |
} |
|
70 |
||
71 |
$path = stripslashes( $_SERVER['REQUEST_URI'] ); |
|
72 |
if ( is_admin() ) { |
|
73 |
$path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path ); |
|
74 |
} |
|
75 |
list( $path ) = explode( '?', $path ); |
|
76 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
$bootstrap_result = ms_load_current_site_and_network( $domain, $path, is_subdomain_install() ); |
5 | 78 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
if ( true === $bootstrap_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
// `$current_blog` and `$current_site are now populated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
} elseif ( false === $bootstrap_result ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
ms_not_installed( $domain, $path ); |
5 | 83 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
header( 'Location: ' . $bootstrap_result ); |
5 | 85 |
exit; |
0 | 86 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
unset( $bootstrap_result ); |
0 | 88 |
|
89 |
$blog_id = $current_blog->blog_id; |
|
90 |
$public = $current_blog->public; |
|
91 |
||
5 | 92 |
if ( empty( $current_blog->site_id ) ) { |
93 |
// This dates to [MU134] and shouldn't be relevant anymore, |
|
94 |
// but it could be possible for arguments passed to insert_blog() etc. |
|
0 | 95 |
$current_blog->site_id = 1; |
5 | 96 |
} |
0 | 97 |
|
5 | 98 |
$site_id = $current_blog->site_id; |
99 |
wp_load_core_site_options( $site_id ); |
|
0 | 100 |
} |
5 | 101 |
|
16 | 102 |
$wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php. |
0 | 103 |
$wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id ); |
9 | 104 |
$table_prefix = $wpdb->get_blog_prefix(); |
0 | 105 |
$_wp_switched_stack = array(); |
9 | 106 |
$switched = false; |
0 | 107 |
|
16 | 108 |
// Need to init cache again after blog_id is set. |
0 | 109 |
wp_start_object_cache(); |
110 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
if ( ! $current_site instanceof WP_Network ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
$current_site = new WP_Network( $current_site ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
if ( ! $current_blog instanceof WP_Site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
$current_blog = new WP_Site( $current_blog ); |
5 | 117 |
} |
118 |
||
16 | 119 |
// Define upload directory constants. |
0 | 120 |
ms_upload_constants(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
|
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 |
* 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
|
124 |
* in multisite's bootstrap. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
do_action( 'ms_loaded' ); |