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 |
/** |
|
4 |
* Site/blog functions that work with the blogs table and related data. |
|
5 |
* |
|
6 |
* @package WordPress |
|
7 |
* @subpackage Multisite |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
* @since MU (3.0.0) |
0 | 9 |
*/ |
10 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
11 |
// Don't load directly. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
12 |
if ( ! defined( 'ABSPATH' ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
13 |
die( '-1' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
14 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
15 |
|
16 | 16 |
require_once ABSPATH . WPINC . '/ms-site.php'; |
17 |
require_once ABSPATH . WPINC . '/ms-network.php'; |
|
9 | 18 |
|
0 | 19 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
20 |
* Updates the last_updated field for the current site. |
0 | 21 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @since MU (3.0.0) |
0 | 23 |
*/ |
24 |
function wpmu_update_blogs_date() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
$site_id = get_current_blog_id(); |
0 | 26 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) ); |
5 | 28 |
/** |
29 |
* Fires after the blog details are updated. |
|
30 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* @since MU (3.0.0) |
5 | 32 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @param int $blog_id Site ID. |
5 | 34 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
do_action( 'wpmu_blog_updated', $site_id ); |
0 | 36 |
} |
37 |
||
38 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
39 |
* Gets a full site URL, given a site ID. |
0 | 40 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* @since MU (3.0.0) |
0 | 42 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
43 |
* @param int $blog_id Site ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
44 |
* @return string Full site URL if found. Empty string if not. |
0 | 45 |
*/ |
46 |
function get_blogaddress_by_id( $blog_id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
$bloginfo = get_site( (int) $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
if ( empty( $bloginfo ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
$scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
$scheme = empty( $scheme ) ? 'http' : $scheme; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path ); |
0 | 57 |
} |
58 |
||
59 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
60 |
* Gets a full site URL, given a site name. |
0 | 61 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* @since MU (3.0.0) |
0 | 63 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
64 |
* @param string $blogname Name of the subdomain or directory. |
0 | 65 |
* @return string |
66 |
*/ |
|
67 |
function get_blogaddress_by_name( $blogname ) { |
|
68 |
if ( is_subdomain_install() ) { |
|
9 | 69 |
if ( 'main' === $blogname ) { |
0 | 70 |
$blogname = 'www'; |
9 | 71 |
} |
0 | 72 |
$url = rtrim( network_home_url(), '/' ); |
9 | 73 |
if ( ! empty( $blogname ) ) { |
74 |
$url = preg_replace( '|^([^\.]+://)|', '${1}' . $blogname . '.', $url ); |
|
75 |
} |
|
0 | 76 |
} else { |
77 |
$url = network_home_url( $blogname ); |
|
78 |
} |
|
79 |
return esc_url( $url . '/' ); |
|
80 |
} |
|
81 |
||
82 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
83 |
* Retrieves a site's ID given its (subdomain or directory) slug. |
0 | 84 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* @since MU (3.0.0) |
9 | 86 |
* @since 4.7.0 Converted to use `get_sites()`. |
0 | 87 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* @param string $slug A site's slug. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* @return int|null The site ID, or null if no site is found for the given slug. |
0 | 90 |
*/ |
91 |
function get_id_from_blogname( $slug ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
$current_network = get_network(); |
9 | 93 |
$slug = trim( $slug, '/' ); |
0 | 94 |
|
95 |
if ( is_subdomain_install() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
$domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain ); |
9 | 97 |
$path = $current_network->path; |
0 | 98 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
$domain = $current_network->domain; |
9 | 100 |
$path = $current_network->path . $slug . '/'; |
0 | 101 |
} |
102 |
||
9 | 103 |
$site_ids = get_sites( |
104 |
array( |
|
105 |
'number' => 1, |
|
106 |
'fields' => 'ids', |
|
107 |
'domain' => $domain, |
|
108 |
'path' => $path, |
|
109 |
'update_site_meta_cache' => false, |
|
110 |
) |
|
111 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
if ( empty( $site_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
return null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
} |
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 |
return array_shift( $site_ids ); |
0 | 118 |
} |
119 |
||
120 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
121 |
* Retrieves the details for a blog from the blogs table and blog options. |
0 | 122 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 126 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
128 |
* Defaults to the current blog ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* @param bool $get_all Whether to retrieve all details or only the details in the blogs table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* Default is true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* @return WP_Site|false Blog details on success. False on failure. |
0 | 132 |
*/ |
133 |
function get_blog_details( $fields = null, $get_all = true ) { |
|
134 |
global $wpdb; |
|
135 |
||
9 | 136 |
if ( is_array( $fields ) ) { |
137 |
if ( isset( $fields['blog_id'] ) ) { |
|
0 | 138 |
$blog_id = $fields['blog_id']; |
9 | 139 |
} elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) { |
140 |
$key = md5( $fields['domain'] . $fields['path'] ); |
|
141 |
$blog = wp_cache_get( $key, 'blog-lookup' ); |
|
142 |
if ( false !== $blog ) { |
|
0 | 143 |
return $blog; |
9 | 144 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
145 |
if ( str_starts_with( $fields['domain'], 'www.' ) ) { |
0 | 146 |
$nowww = substr( $fields['domain'], 4 ); |
9 | 147 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); |
0 | 148 |
} else { |
149 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); |
|
150 |
} |
|
151 |
if ( $blog ) { |
|
9 | 152 |
wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' ); |
0 | 153 |
$blog_id = $blog->blog_id; |
154 |
} else { |
|
155 |
return false; |
|
156 |
} |
|
9 | 157 |
} elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) { |
158 |
$key = md5( $fields['domain'] ); |
|
159 |
$blog = wp_cache_get( $key, 'blog-lookup' ); |
|
160 |
if ( false !== $blog ) { |
|
0 | 161 |
return $blog; |
9 | 162 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
163 |
if ( str_starts_with( $fields['domain'], 'www.' ) ) { |
0 | 164 |
$nowww = substr( $fields['domain'], 4 ); |
9 | 165 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); |
0 | 166 |
} else { |
167 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); |
|
168 |
} |
|
169 |
if ( $blog ) { |
|
9 | 170 |
wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' ); |
0 | 171 |
$blog_id = $blog->blog_id; |
172 |
} else { |
|
173 |
return false; |
|
174 |
} |
|
175 |
} else { |
|
176 |
return false; |
|
177 |
} |
|
178 |
} else { |
|
9 | 179 |
if ( ! $fields ) { |
0 | 180 |
$blog_id = get_current_blog_id(); |
9 | 181 |
} elseif ( ! is_numeric( $fields ) ) { |
0 | 182 |
$blog_id = get_id_from_blogname( $fields ); |
9 | 183 |
} else { |
0 | 184 |
$blog_id = $fields; |
9 | 185 |
} |
0 | 186 |
} |
187 |
||
188 |
$blog_id = (int) $blog_id; |
|
189 |
||
9 | 190 |
$all = $get_all ? '' : 'short'; |
0 | 191 |
$details = wp_cache_get( $blog_id . $all, 'blog-details' ); |
192 |
||
193 |
if ( $details ) { |
|
194 |
if ( ! is_object( $details ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
195 |
if ( -1 === $details ) { |
0 | 196 |
return false; |
197 |
} else { |
|
198 |
// Clear old pre-serialized objects. Cache clients do better with that. |
|
199 |
wp_cache_delete( $blog_id . $all, 'blog-details' ); |
|
9 | 200 |
unset( $details ); |
0 | 201 |
} |
202 |
} else { |
|
203 |
return $details; |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
// Try the other cache. |
|
208 |
if ( $get_all ) { |
|
209 |
$details = wp_cache_get( $blog_id . 'short', 'blog-details' ); |
|
210 |
} else { |
|
211 |
$details = wp_cache_get( $blog_id, 'blog-details' ); |
|
212 |
// If short was requested and full cache is set, we can return. |
|
213 |
if ( $details ) { |
|
214 |
if ( ! is_object( $details ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
215 |
if ( -1 === $details ) { |
0 | 216 |
return false; |
217 |
} else { |
|
218 |
// Clear old pre-serialized objects. Cache clients do better with that. |
|
219 |
wp_cache_delete( $blog_id, 'blog-details' ); |
|
9 | 220 |
unset( $details ); |
0 | 221 |
} |
222 |
} else { |
|
223 |
return $details; |
|
224 |
} |
|
225 |
} |
|
226 |
} |
|
227 |
||
9 | 228 |
if ( empty( $details ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
$details = WP_Site::get_instance( $blog_id ); |
0 | 230 |
if ( ! $details ) { |
231 |
// Set the full cache. |
|
232 |
wp_cache_set( $blog_id, -1, 'blog-details' ); |
|
233 |
return false; |
|
234 |
} |
|
235 |
} |
|
236 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
if ( ! $details instanceof WP_Site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
$details = new WP_Site( $details ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
|
0 | 241 |
if ( ! $get_all ) { |
242 |
wp_cache_set( $blog_id . $all, $details, 'blog-details' ); |
|
243 |
return $details; |
|
244 |
} |
|
245 |
||
16 | 246 |
$switched_blog = false; |
247 |
||
248 |
if ( get_current_blog_id() !== $blog_id ) { |
|
249 |
switch_to_blog( $blog_id ); |
|
250 |
$switched_blog = true; |
|
251 |
} |
|
252 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
$details->blogname = get_option( 'blogname' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
$details->siteurl = get_option( 'siteurl' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
$details->post_count = get_option( 'post_count' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
$details->home = get_option( 'home' ); |
16 | 257 |
|
258 |
if ( $switched_blog ) { |
|
259 |
restore_current_blog(); |
|
260 |
} |
|
0 | 261 |
|
5 | 262 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
* Filters a blog's details. |
5 | 264 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* @since MU (3.0.0) |
16 | 266 |
* @deprecated 4.7.0 Use {@see 'site_details'} instead. |
5 | 267 |
* |
18 | 268 |
* @param WP_Site $details The blog details. |
5 | 269 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' ); |
0 | 271 |
|
272 |
wp_cache_set( $blog_id . $all, $details, 'blog-details' ); |
|
273 |
||
274 |
$key = md5( $details->domain . $details->path ); |
|
275 |
wp_cache_set( $key, $details, 'blog-lookup' ); |
|
276 |
||
277 |
return $details; |
|
278 |
} |
|
279 |
||
280 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
281 |
* Clears the blog details cache. |
0 | 282 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* @since MU (3.0.0) |
0 | 284 |
* |
5 | 285 |
* @param int $blog_id Optional. Blog ID. Defaults to current blog. |
0 | 286 |
*/ |
5 | 287 |
function refresh_blog_details( $blog_id = 0 ) { |
0 | 288 |
$blog_id = (int) $blog_id; |
5 | 289 |
if ( ! $blog_id ) { |
290 |
$blog_id = get_current_blog_id(); |
|
291 |
} |
|
292 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
clean_blog_cache( $blog_id ); |
0 | 294 |
} |
295 |
||
296 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
297 |
* Updates the details for a blog and the blogs table for a given blog ID. |
0 | 298 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @since MU (3.0.0) |
0 | 300 |
* |
16 | 301 |
* @param int $blog_id Blog ID. |
0 | 302 |
* @param array $details Array of details keyed by blogs table field names. |
303 |
* @return bool True if update succeeds, false otherwise. |
|
304 |
*/ |
|
305 |
function update_blog_details( $blog_id, $details = array() ) { |
|
9 | 306 |
if ( empty( $details ) ) { |
0 | 307 |
return false; |
5 | 308 |
} |
0 | 309 |
|
9 | 310 |
if ( is_object( $details ) ) { |
311 |
$details = get_object_vars( $details ); |
|
0 | 312 |
} |
313 |
||
9 | 314 |
$site = wp_update_site( $blog_id, $details ); |
0 | 315 |
|
9 | 316 |
if ( is_wp_error( $site ) ) { |
317 |
return false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
|
9 | 320 |
return true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
* Cleans the site details cache for a site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* @since 4.7.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* @param int $site_id Optional. Site ID. Default is the current site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
function clean_site_details_cache( $site_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
$site_id = (int) $site_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
if ( ! $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
$site_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
wp_cache_delete( $site_id, 'site-details' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
wp_cache_delete( $site_id, 'blog-details' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
341 |
* Retrieves option value for a given blog id based on name of option. |
0 | 342 |
* |
343 |
* If the option does not exist or does not have a value, then the return value |
|
344 |
* will be false. This is useful to check whether you need to install an option |
|
345 |
* and is commonly used during installation of plugin options and to test |
|
346 |
* whether upgrading is required. |
|
347 |
* |
|
348 |
* If the option was serialized then it will be unserialized when it is returned. |
|
349 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* @since MU (3.0.0) |
0 | 351 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
352 |
* @param int $id A blog ID. Can be null to refer to the current blog. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
353 |
* @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
354 |
* @param mixed $default_value Optional. Default value to return if the option does not exist. |
0 | 355 |
* @return mixed Value set for the option. |
356 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
357 |
function get_blog_option( $id, $option, $default_value = false ) { |
0 | 358 |
$id = (int) $id; |
359 |
||
9 | 360 |
if ( empty( $id ) ) { |
0 | 361 |
$id = get_current_blog_id(); |
9 | 362 |
} |
0 | 363 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
364 |
if ( get_current_blog_id() === $id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
365 |
return get_option( $option, $default_value ); |
9 | 366 |
} |
0 | 367 |
|
368 |
switch_to_blog( $id ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
369 |
$value = get_option( $option, $default_value ); |
0 | 370 |
restore_current_blog(); |
371 |
||
5 | 372 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* Filters a blog option value. |
5 | 374 |
* |
375 |
* The dynamic portion of the hook name, `$option`, refers to the blog option name. |
|
376 |
* |
|
377 |
* @since 3.5.0 |
|
378 |
* |
|
379 |
* @param string $value The option value. |
|
380 |
* @param int $id Blog ID. |
|
381 |
*/ |
|
382 |
return apply_filters( "blog_option_{$option}", $value, $id ); |
|
0 | 383 |
} |
384 |
||
385 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
386 |
* Adds a new option for a given blog ID. |
0 | 387 |
* |
388 |
* You do not need to serialize values. If the value needs to be serialized, then |
|
389 |
* it will be serialized before it is inserted into the database. Remember, |
|
390 |
* resources can not be serialized or added as an option. |
|
391 |
* |
|
392 |
* You can create options without values and then update the values later. |
|
393 |
* Existing options will not be updated and checks are performed to ensure that you |
|
394 |
* aren't adding a protected WordPress option. Care should be taken to not name |
|
395 |
* options the same as the ones which are protected. |
|
396 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* @since MU (3.0.0) |
0 | 398 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
* @param int $id A blog ID. Can be null to refer to the current blog. |
0 | 400 |
* @param string $option Name of option to add. Expected to not be SQL-escaped. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
401 |
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. |
16 | 402 |
* @return bool True if the option was added, false otherwise. |
0 | 403 |
*/ |
404 |
function add_blog_option( $id, $option, $value ) { |
|
405 |
$id = (int) $id; |
|
406 |
||
9 | 407 |
if ( empty( $id ) ) { |
0 | 408 |
$id = get_current_blog_id(); |
9 | 409 |
} |
0 | 410 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
411 |
if ( get_current_blog_id() === $id ) { |
0 | 412 |
return add_option( $option, $value ); |
9 | 413 |
} |
0 | 414 |
|
415 |
switch_to_blog( $id ); |
|
416 |
$return = add_option( $option, $value ); |
|
417 |
restore_current_blog(); |
|
418 |
||
419 |
return $return; |
|
420 |
} |
|
421 |
||
422 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
423 |
* Removes an option by name for a given blog ID. Prevents removal of protected WordPress options. |
0 | 424 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
* @since MU (3.0.0) |
0 | 426 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param int $id A blog ID. Can be null to refer to the current blog. |
0 | 428 |
* @param string $option Name of option to remove. Expected to not be SQL-escaped. |
16 | 429 |
* @return bool True if the option was deleted, false otherwise. |
0 | 430 |
*/ |
431 |
function delete_blog_option( $id, $option ) { |
|
432 |
$id = (int) $id; |
|
433 |
||
9 | 434 |
if ( empty( $id ) ) { |
0 | 435 |
$id = get_current_blog_id(); |
9 | 436 |
} |
0 | 437 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
438 |
if ( get_current_blog_id() === $id ) { |
0 | 439 |
return delete_option( $option ); |
9 | 440 |
} |
0 | 441 |
|
442 |
switch_to_blog( $id ); |
|
443 |
$return = delete_option( $option ); |
|
444 |
restore_current_blog(); |
|
445 |
||
446 |
return $return; |
|
447 |
} |
|
448 |
||
449 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
450 |
* Updates an option for a particular blog. |
0 | 451 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* @since MU (3.0.0) |
0 | 453 |
* |
16 | 454 |
* @param int $id The blog ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* @param string $option The option key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @param mixed $value The option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* @param mixed $deprecated Not used. |
16 | 458 |
* @return bool True if the value was updated, false otherwise. |
0 | 459 |
*/ |
460 |
function update_blog_option( $id, $option, $value, $deprecated = null ) { |
|
461 |
$id = (int) $id; |
|
462 |
||
9 | 463 |
if ( null !== $deprecated ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
_deprecated_argument( __FUNCTION__, '3.1.0' ); |
9 | 465 |
} |
0 | 466 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
467 |
if ( get_current_blog_id() === $id ) { |
0 | 468 |
return update_option( $option, $value ); |
9 | 469 |
} |
0 | 470 |
|
471 |
switch_to_blog( $id ); |
|
472 |
$return = update_option( $option, $value ); |
|
473 |
restore_current_blog(); |
|
474 |
||
475 |
return $return; |
|
476 |
} |
|
477 |
||
478 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
479 |
* Switches the current blog. |
0 | 480 |
* |
481 |
* This function is useful if you need to pull posts, or other information, |
|
482 |
* from other blogs. You can switch back afterwards using restore_current_blog(). |
|
483 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
484 |
* PHP code loaded with the originally requested site, such as code from a plugin or theme, does not switch. See #14941. |
0 | 485 |
* |
486 |
* @see restore_current_blog() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* @since MU (3.0.0) |
0 | 488 |
* |
16 | 489 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* @global int $blog_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* @global array $_wp_switched_stack |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @global bool $switched |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
493 |
* @global string $table_prefix The database table prefix. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* @global WP_Object_Cache $wp_object_cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
* |
16 | 496 |
* @param int $new_blog_id The ID of the blog to switch to. Default: current blog. |
497 |
* @param bool $deprecated Not used. |
|
498 |
* @return true Always returns true. |
|
0 | 499 |
*/ |
16 | 500 |
function switch_to_blog( $new_blog_id, $deprecated = null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
global $wpdb; |
0 | 502 |
|
16 | 503 |
$prev_blog_id = get_current_blog_id(); |
504 |
if ( empty( $new_blog_id ) ) { |
|
505 |
$new_blog_id = $prev_blog_id; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
} |
0 | 507 |
|
16 | 508 |
$GLOBALS['_wp_switched_stack'][] = $prev_blog_id; |
0 | 509 |
|
5 | 510 |
/* |
511 |
* If we're switching to the same blog id that we're on, |
|
512 |
* set the right vars, do the associated actions, but skip |
|
513 |
* the extra unnecessary work |
|
514 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
515 |
if ( $new_blog_id === $prev_blog_id ) { |
5 | 516 |
/** |
517 |
* Fires when the blog is switched. |
|
518 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* @since MU (3.0.0) |
16 | 520 |
* @since 5.4.0 The `$context` parameter was added. |
5 | 521 |
* |
16 | 522 |
* @param int $new_blog_id New blog ID. |
523 |
* @param int $prev_blog_id Previous blog ID. |
|
524 |
* @param string $context Additional context. Accepts 'switch' when called from switch_to_blog() |
|
525 |
* or 'restore' when called from restore_current_blog(). |
|
5 | 526 |
*/ |
16 | 527 |
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' ); |
528 |
||
0 | 529 |
$GLOBALS['switched'] = true; |
16 | 530 |
|
0 | 531 |
return true; |
532 |
} |
|
533 |
||
16 | 534 |
$wpdb->set_blog_id( $new_blog_id ); |
0 | 535 |
$GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
16 | 536 |
$GLOBALS['blog_id'] = $new_blog_id; |
0 | 537 |
|
538 |
if ( function_exists( 'wp_cache_switch_to_blog' ) ) { |
|
16 | 539 |
wp_cache_switch_to_blog( $new_blog_id ); |
0 | 540 |
} else { |
541 |
global $wp_object_cache; |
|
542 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { |
0 | 544 |
$global_groups = $wp_object_cache->global_groups; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
} else { |
0 | 546 |
$global_groups = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
} |
0 | 548 |
|
549 |
wp_cache_init(); |
|
550 |
||
551 |
if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
5 | 552 |
if ( is_array( $global_groups ) ) { |
0 | 553 |
wp_cache_add_global_groups( $global_groups ); |
5 | 554 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
555 |
wp_cache_add_global_groups( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
556 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
557 |
'blog-details', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
558 |
'blog-id-cache', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
559 |
'blog-lookup', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
560 |
'blog_meta', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
561 |
'global-posts', |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
562 |
'image_editor', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
563 |
'networks', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
564 |
'network-queries', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
565 |
'sites', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
566 |
'site-details', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
567 |
'site-options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
568 |
'site-queries', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
569 |
'site-transient', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
570 |
'theme_files', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
571 |
'rss', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
572 |
'users', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
573 |
'user-queries', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
574 |
'user_meta', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
575 |
'useremail', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
576 |
'userlogins', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
577 |
'userslugs', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
578 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
579 |
); |
5 | 580 |
} |
16 | 581 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
582 |
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); |
0 | 583 |
} |
584 |
} |
|
585 |
||
5 | 586 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
16 | 587 |
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' ); |
588 |
||
589 |
$GLOBALS['switched'] = true; |
|
590 |
||
591 |
return true; |
|
592 |
} |
|
593 |
||
594 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
595 |
* Restores the current blog, after calling switch_to_blog(). |
16 | 596 |
* |
597 |
* @see switch_to_blog() |
|
598 |
* @since MU (3.0.0) |
|
599 |
* |
|
600 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
601 |
* @global array $_wp_switched_stack |
|
602 |
* @global int $blog_id |
|
603 |
* @global bool $switched |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
604 |
* @global string $table_prefix The database table prefix. |
16 | 605 |
* @global WP_Object_Cache $wp_object_cache |
606 |
* |
|
607 |
* @return bool True on success, false if we're already on the current blog. |
|
608 |
*/ |
|
609 |
function restore_current_blog() { |
|
610 |
global $wpdb; |
|
611 |
||
612 |
if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { |
|
613 |
return false; |
|
614 |
} |
|
615 |
||
616 |
$new_blog_id = array_pop( $GLOBALS['_wp_switched_stack'] ); |
|
617 |
$prev_blog_id = get_current_blog_id(); |
|
618 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
619 |
if ( $new_blog_id === $prev_blog_id ) { |
16 | 620 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
621 |
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' ); |
|
0 | 622 |
|
16 | 623 |
// If we still have items in the switched stack, consider ourselves still 'switched'. |
624 |
$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
625 |
||
626 |
return true; |
|
627 |
} |
|
628 |
||
629 |
$wpdb->set_blog_id( $new_blog_id ); |
|
630 |
$GLOBALS['blog_id'] = $new_blog_id; |
|
631 |
$GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
|
632 |
||
633 |
if ( function_exists( 'wp_cache_switch_to_blog' ) ) { |
|
634 |
wp_cache_switch_to_blog( $new_blog_id ); |
|
635 |
} else { |
|
636 |
global $wp_object_cache; |
|
637 |
||
638 |
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { |
|
639 |
$global_groups = $wp_object_cache->global_groups; |
|
640 |
} else { |
|
641 |
$global_groups = false; |
|
642 |
} |
|
643 |
||
644 |
wp_cache_init(); |
|
645 |
||
646 |
if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
647 |
if ( is_array( $global_groups ) ) { |
|
648 |
wp_cache_add_global_groups( $global_groups ); |
|
649 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
650 |
wp_cache_add_global_groups( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
651 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
652 |
'blog-details', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
653 |
'blog-id-cache', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
654 |
'blog-lookup', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
655 |
'blog_meta', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
656 |
'global-posts', |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
657 |
'image_editor', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
658 |
'networks', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
659 |
'network-queries', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
660 |
'sites', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
661 |
'site-details', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
662 |
'site-options', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
663 |
'site-queries', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
664 |
'site-transient', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
665 |
'theme_files', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
666 |
'rss', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
667 |
'users', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
668 |
'user-queries', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
669 |
'user_meta', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
670 |
'useremail', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
671 |
'userlogins', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
672 |
'userslugs', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
673 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
674 |
); |
16 | 675 |
} |
676 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
677 |
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); |
16 | 678 |
} |
679 |
} |
|
680 |
||
681 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
682 |
do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' ); |
|
683 |
||
684 |
// If we still have items in the switched stack, consider ourselves still 'switched'. |
|
0 | 685 |
$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
686 |
||
687 |
return true; |
|
688 |
} |
|
689 |
||
690 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* Switches the initialized roles and current user capabilities to another site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
* @param int $new_site_id New site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
* @param int $old_site_id Old site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
function wp_switch_roles_and_user( $new_site_id, $old_site_id ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
699 |
if ( $new_site_id === $old_site_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
if ( ! did_action( 'init' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
wp_roles()->for_site( $new_site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
wp_get_current_user()->for_site( $new_site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
712 |
* Determines if switch_to_blog() is in effect. |
0 | 713 |
* |
714 |
* @since 3.5.0 |
|
715 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
* @global array $_wp_switched_stack |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* |
0 | 718 |
* @return bool True if switched, false otherwise. |
719 |
*/ |
|
720 |
function ms_is_switched() { |
|
721 |
return ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
722 |
} |
|
723 |
||
724 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
725 |
* Checks if a particular blog is archived. |
0 | 726 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
* @since MU (3.0.0) |
0 | 728 |
* |
16 | 729 |
* @param int $id Blog ID. |
730 |
* @return string Whether the blog is archived or not. |
|
0 | 731 |
*/ |
732 |
function is_archived( $id ) { |
|
9 | 733 |
return get_blog_status( $id, 'archived' ); |
0 | 734 |
} |
735 |
||
736 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
737 |
* Updates the 'archived' status of a particular blog. |
0 | 738 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* @since MU (3.0.0) |
0 | 740 |
* |
16 | 741 |
* @param int $id Blog ID. |
742 |
* @param string $archived The new status. |
|
0 | 743 |
* @return string $archived |
744 |
*/ |
|
745 |
function update_archived( $id, $archived ) { |
|
9 | 746 |
update_blog_status( $id, 'archived', $archived ); |
0 | 747 |
return $archived; |
748 |
} |
|
749 |
||
750 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
751 |
* Updates a blog details field. |
0 | 752 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
* @since MU (3.0.0) |
9 | 754 |
* @since 5.1.0 Use wp_update_site() internally. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 757 |
* |
16 | 758 |
* @param int $blog_id Blog ID. |
759 |
* @param string $pref Field name. |
|
760 |
* @param string $value Field value. |
|
761 |
* @param null $deprecated Not used. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
* @return string|false $value |
0 | 763 |
*/ |
764 |
function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { |
|
765 |
global $wpdb; |
|
766 |
||
9 | 767 |
if ( null !== $deprecated ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
_deprecated_argument( __FUNCTION__, '3.1.0' ); |
9 | 769 |
} |
0 | 770 |
|
16 | 771 |
$allowed_field_names = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); |
772 |
||
773 |
if ( ! in_array( $pref, $allowed_field_names, true ) ) { |
|
9 | 774 |
return $value; |
775 |
} |
|
0 | 776 |
|
9 | 777 |
$result = wp_update_site( |
778 |
$blog_id, |
|
779 |
array( |
|
780 |
$pref => $value, |
|
781 |
) |
|
782 |
); |
|
783 |
||
784 |
if ( is_wp_error( $result ) ) { |
|
785 |
return false; |
|
5 | 786 |
} |
0 | 787 |
|
788 |
return $value; |
|
789 |
} |
|
790 |
||
791 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
792 |
* Gets a blog details field. |
0 | 793 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 797 |
* |
16 | 798 |
* @param int $id Blog ID. |
799 |
* @param string $pref Field name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
* @return bool|string|null $value |
0 | 801 |
*/ |
802 |
function get_blog_status( $id, $pref ) { |
|
803 |
global $wpdb; |
|
804 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
$details = get_site( $id ); |
9 | 806 |
if ( $details ) { |
0 | 807 |
return $details->$pref; |
9 | 808 |
} |
0 | 809 |
|
9 | 810 |
return $wpdb->get_var( $wpdb->prepare( "SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id ) ); |
0 | 811 |
} |
812 |
||
813 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
814 |
* Gets a list of most recently updated blogs. |
0 | 815 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 819 |
* |
16 | 820 |
* @param mixed $deprecated Not used. |
821 |
* @param int $start Optional. Number of blogs to offset the query. Used to build LIMIT clause. |
|
822 |
* Can be used for pagination. Default 0. |
|
823 |
* @param int $quantity Optional. The maximum number of blogs to retrieve. Default 40. |
|
824 |
* @return array The list of blogs. |
|
0 | 825 |
*/ |
826 |
function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { |
|
827 |
global $wpdb; |
|
828 |
||
9 | 829 |
if ( ! empty( $deprecated ) ) { |
16 | 830 |
_deprecated_argument( __FUNCTION__, 'MU' ); // Never used. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
|
9 | 833 |
return $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", get_current_network_id(), $start, $quantity ), ARRAY_A ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* Handler for updating the site's last updated date when a post is published or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* an already published post is changed. |
0 | 839 |
* |
840 |
* @since 3.3.0 |
|
841 |
* |
|
16 | 842 |
* @param string $new_status The new post status. |
843 |
* @param string $old_status The old post status. |
|
844 |
* @param WP_Post $post Post object. |
|
0 | 845 |
*/ |
846 |
function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) { |
|
847 |
$post_type_obj = get_post_type_object( $post->post_type ); |
|
5 | 848 |
if ( ! $post_type_obj || ! $post_type_obj->public ) { |
0 | 849 |
return; |
5 | 850 |
} |
0 | 851 |
|
16 | 852 |
if ( 'publish' !== $new_status && 'publish' !== $old_status ) { |
0 | 853 |
return; |
5 | 854 |
} |
0 | 855 |
|
856 |
// Post was freshly published, published post was saved, or published post was unpublished. |
|
857 |
||
858 |
wpmu_update_blogs_date(); |
|
859 |
} |
|
860 |
||
861 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* Handler for updating the current site's last updated date when a published |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* post is deleted. |
0 | 864 |
* |
865 |
* @since 3.4.0 |
|
866 |
* |
|
867 |
* @param int $post_id Post ID |
|
868 |
*/ |
|
869 |
function _update_blog_date_on_post_delete( $post_id ) { |
|
870 |
$post = get_post( $post_id ); |
|
871 |
||
872 |
$post_type_obj = get_post_type_object( $post->post_type ); |
|
5 | 873 |
if ( ! $post_type_obj || ! $post_type_obj->public ) { |
0 | 874 |
return; |
5 | 875 |
} |
0 | 876 |
|
16 | 877 |
if ( 'publish' !== $post->post_status ) { |
0 | 878 |
return; |
5 | 879 |
} |
0 | 880 |
|
881 |
wpmu_update_blogs_date(); |
|
882 |
} |
|
883 |
||
5 | 884 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
* Handler for updating the current site's posts count when a post is deleted. |
5 | 886 |
* |
887 |
* @since 4.0.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
888 |
* @since 6.2.0 Added the `$post` parameter. |
5 | 889 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
890 |
* @param int $post_id Post ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
891 |
* @param WP_Post $post Post object. |
5 | 892 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
893 |
function _update_posts_count_on_delete( $post_id, $post ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { |
5 | 895 |
return; |
896 |
} |
|
897 |
||
898 |
update_posts_count(); |
|
899 |
} |
|
900 |
||
901 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
* Handler for updating the current site's posts count when a post status changes. |
5 | 903 |
* |
904 |
* @since 4.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
* @since 4.9.0 Added the `$post` parameter. |
5 | 906 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* @param string $new_status The status the post is changing to. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
* @param string $old_status The status the post is changing from. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
* @param WP_Post $post Post object |
5 | 910 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) { |
5 | 912 |
if ( $new_status === $old_status ) { |
913 |
return; |
|
914 |
} |
|
915 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
if ( 'post' !== get_post_type( $post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
|
5 | 920 |
if ( 'publish' !== $new_status && 'publish' !== $old_status ) { |
921 |
return; |
|
922 |
} |
|
923 |
||
924 |
update_posts_count(); |
|
925 |
} |
|
16 | 926 |
|
927 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
928 |
* Counts number of sites grouped by site status. |
16 | 929 |
* |
930 |
* @since 5.3.0 |
|
931 |
* |
|
932 |
* @param int $network_id Optional. The network to get counts for. Default is the current network ID. |
|
933 |
* @return int[] { |
|
934 |
* Numbers of sites grouped by site status. |
|
935 |
* |
|
936 |
* @type int $all The total number of sites. |
|
937 |
* @type int $public The number of public sites. |
|
938 |
* @type int $archived The number of archived sites. |
|
939 |
* @type int $mature The number of mature sites. |
|
940 |
* @type int $spam The number of spam sites. |
|
941 |
* @type int $deleted The number of deleted sites. |
|
942 |
* } |
|
943 |
*/ |
|
944 |
function wp_count_sites( $network_id = null ) { |
|
945 |
if ( empty( $network_id ) ) { |
|
946 |
$network_id = get_current_network_id(); |
|
947 |
} |
|
948 |
||
949 |
$counts = array(); |
|
950 |
$args = array( |
|
951 |
'network_id' => $network_id, |
|
952 |
'number' => 1, |
|
953 |
'fields' => 'ids', |
|
954 |
'no_found_rows' => false, |
|
955 |
); |
|
956 |
||
957 |
$q = new WP_Site_Query( $args ); |
|
958 |
$counts['all'] = $q->found_sites; |
|
959 |
||
960 |
$_args = $args; |
|
961 |
$statuses = array( 'public', 'archived', 'mature', 'spam', 'deleted' ); |
|
962 |
||
963 |
foreach ( $statuses as $status ) { |
|
964 |
$_args = $args; |
|
965 |
$_args[ $status ] = 1; |
|
966 |
||
967 |
$q = new WP_Site_Query( $_args ); |
|
968 |
$counts[ $status ] = $q->found_sites; |
|
969 |
} |
|
970 |
||
971 |
return $counts; |
|
972 |
} |