author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:06:33 +0200 | |
changeset 8 | c7c34916027a |
parent 7 | cf61fcea0001 |
child 9 | 177826044cd9 |
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 |
||
11 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* Update the last_updated field for the current site. |
0 | 13 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* @since MU (3.0.0) |
0 | 15 |
*/ |
16 |
function wpmu_update_blogs_date() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
$site_id = get_current_blog_id(); |
0 | 18 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) ); |
5 | 20 |
/** |
21 |
* Fires after the blog details are updated. |
|
22 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @since MU (3.0.0) |
5 | 24 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @param int $blog_id Site ID. |
5 | 26 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
do_action( 'wpmu_blog_updated', $site_id ); |
0 | 28 |
} |
29 |
||
30 |
/** |
|
31 |
* Get a full blog URL, given a blog id. |
|
32 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @since MU (3.0.0) |
0 | 34 |
* |
35 |
* @param int $blog_id Blog ID |
|
5 | 36 |
* @return string Full URL of the blog if found. Empty string if not. |
0 | 37 |
*/ |
38 |
function get_blogaddress_by_id( $blog_id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
$bloginfo = get_site( (int) $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
if ( empty( $bloginfo ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
} |
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 |
$scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
$scheme = empty( $scheme ) ? 'http' : $scheme; |
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 |
return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path ); |
0 | 49 |
} |
50 |
||
51 |
/** |
|
52 |
* Get a full blog URL, given a blog name. |
|
53 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* @since MU (3.0.0) |
0 | 55 |
* |
56 |
* @param string $blogname The (subdomain or directory) name |
|
57 |
* @return string |
|
58 |
*/ |
|
59 |
function get_blogaddress_by_name( $blogname ) { |
|
60 |
if ( is_subdomain_install() ) { |
|
61 |
if ( $blogname == 'main' ) |
|
62 |
$blogname = 'www'; |
|
63 |
$url = rtrim( network_home_url(), '/' ); |
|
64 |
if ( !empty( $blogname ) ) |
|
65 |
$url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url ); |
|
66 |
} else { |
|
67 |
$url = network_home_url( $blogname ); |
|
68 |
} |
|
69 |
return esc_url( $url . '/' ); |
|
70 |
} |
|
71 |
||
72 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* Retrieves a sites ID given its (subdomain or directory) slug. |
0 | 74 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
* @since 4.7.0 Converted to use get_sites(). |
0 | 77 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
* @param string $slug A site's slug. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* @return int|null The site ID, or null if no site is found for the given slug. |
0 | 80 |
*/ |
81 |
function get_id_from_blogname( $slug ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
$current_network = get_network(); |
0 | 83 |
$slug = trim( $slug, '/' ); |
84 |
||
85 |
if ( is_subdomain_install() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
$domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
$path = $current_network->path; |
0 | 88 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
$domain = $current_network->domain; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
$path = $current_network->path . $slug . '/'; |
0 | 91 |
} |
92 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
$site_ids = get_sites( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
'number' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
'fields' => 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
'domain' => $domain, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
'path' => $path, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
if ( empty( $site_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
return null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
return array_shift( $site_ids ); |
0 | 105 |
} |
106 |
||
107 |
/** |
|
108 |
* Retrieve the details for a blog from the blogs table and blog options. |
|
109 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 113 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
* @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
* If not specified the current blog ID is used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* @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
|
117 |
* Default is true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* @return WP_Site|false Blog details on success. False on failure. |
0 | 119 |
*/ |
120 |
function get_blog_details( $fields = null, $get_all = true ) { |
|
121 |
global $wpdb; |
|
122 |
||
123 |
if ( is_array($fields ) ) { |
|
124 |
if ( isset($fields['blog_id']) ) { |
|
125 |
$blog_id = $fields['blog_id']; |
|
126 |
} elseif ( isset($fields['domain']) && isset($fields['path']) ) { |
|
127 |
$key = md5( $fields['domain'] . $fields['path'] ); |
|
128 |
$blog = wp_cache_get($key, 'blog-lookup'); |
|
129 |
if ( false !== $blog ) |
|
130 |
return $blog; |
|
131 |
if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { |
|
132 |
$nowww = substr( $fields['domain'], 4 ); |
|
133 |
$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'] ) ); |
|
134 |
} else { |
|
135 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); |
|
136 |
} |
|
137 |
if ( $blog ) { |
|
138 |
wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); |
|
139 |
$blog_id = $blog->blog_id; |
|
140 |
} else { |
|
141 |
return false; |
|
142 |
} |
|
143 |
} elseif ( isset($fields['domain']) && is_subdomain_install() ) { |
|
144 |
$key = md5( $fields['domain'] ); |
|
145 |
$blog = wp_cache_get($key, 'blog-lookup'); |
|
146 |
if ( false !== $blog ) |
|
147 |
return $blog; |
|
148 |
if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { |
|
149 |
$nowww = substr( $fields['domain'], 4 ); |
|
150 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); |
|
151 |
} else { |
|
152 |
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); |
|
153 |
} |
|
154 |
if ( $blog ) { |
|
155 |
wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); |
|
156 |
$blog_id = $blog->blog_id; |
|
157 |
} else { |
|
158 |
return false; |
|
159 |
} |
|
160 |
} else { |
|
161 |
return false; |
|
162 |
} |
|
163 |
} else { |
|
164 |
if ( ! $fields ) |
|
165 |
$blog_id = get_current_blog_id(); |
|
166 |
elseif ( ! is_numeric( $fields ) ) |
|
167 |
$blog_id = get_id_from_blogname( $fields ); |
|
168 |
else |
|
169 |
$blog_id = $fields; |
|
170 |
} |
|
171 |
||
172 |
$blog_id = (int) $blog_id; |
|
173 |
||
174 |
$all = $get_all == true ? '' : 'short'; |
|
175 |
$details = wp_cache_get( $blog_id . $all, 'blog-details' ); |
|
176 |
||
177 |
if ( $details ) { |
|
178 |
if ( ! is_object( $details ) ) { |
|
179 |
if ( $details == -1 ) { |
|
180 |
return false; |
|
181 |
} else { |
|
182 |
// Clear old pre-serialized objects. Cache clients do better with that. |
|
183 |
wp_cache_delete( $blog_id . $all, 'blog-details' ); |
|
184 |
unset($details); |
|
185 |
} |
|
186 |
} else { |
|
187 |
return $details; |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
// Try the other cache. |
|
192 |
if ( $get_all ) { |
|
193 |
$details = wp_cache_get( $blog_id . 'short', 'blog-details' ); |
|
194 |
} else { |
|
195 |
$details = wp_cache_get( $blog_id, 'blog-details' ); |
|
196 |
// If short was requested and full cache is set, we can return. |
|
197 |
if ( $details ) { |
|
198 |
if ( ! is_object( $details ) ) { |
|
199 |
if ( $details == -1 ) { |
|
200 |
return false; |
|
201 |
} else { |
|
202 |
// Clear old pre-serialized objects. Cache clients do better with that. |
|
203 |
wp_cache_delete( $blog_id, 'blog-details' ); |
|
204 |
unset($details); |
|
205 |
} |
|
206 |
} else { |
|
207 |
return $details; |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
||
212 |
if ( empty($details) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
$details = WP_Site::get_instance( $blog_id ); |
0 | 214 |
if ( ! $details ) { |
215 |
// Set the full cache. |
|
216 |
wp_cache_set( $blog_id, -1, 'blog-details' ); |
|
217 |
return false; |
|
218 |
} |
|
219 |
} |
|
220 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
if ( ! $details instanceof WP_Site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
$details = new WP_Site( $details ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
|
0 | 225 |
if ( ! $get_all ) { |
226 |
wp_cache_set( $blog_id . $all, $details, 'blog-details' ); |
|
227 |
return $details; |
|
228 |
} |
|
229 |
||
230 |
switch_to_blog( $blog_id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
$details->blogname = get_option( 'blogname' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
$details->siteurl = get_option( 'siteurl' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
$details->post_count = get_option( 'post_count' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
$details->home = get_option( 'home' ); |
0 | 235 |
restore_current_blog(); |
236 |
||
5 | 237 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* Filters a blog's details. |
5 | 239 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* @deprecated 4.7.0 Use site_details |
5 | 242 |
* |
243 |
* @param object $details The blog details. |
|
244 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' ); |
0 | 246 |
|
247 |
wp_cache_set( $blog_id . $all, $details, 'blog-details' ); |
|
248 |
||
249 |
$key = md5( $details->domain . $details->path ); |
|
250 |
wp_cache_set( $key, $details, 'blog-lookup' ); |
|
251 |
||
252 |
return $details; |
|
253 |
} |
|
254 |
||
255 |
/** |
|
256 |
* Clear the blog details cache. |
|
257 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* @since MU (3.0.0) |
0 | 259 |
* |
5 | 260 |
* @param int $blog_id Optional. Blog ID. Defaults to current blog. |
0 | 261 |
*/ |
5 | 262 |
function refresh_blog_details( $blog_id = 0 ) { |
0 | 263 |
$blog_id = (int) $blog_id; |
5 | 264 |
if ( ! $blog_id ) { |
265 |
$blog_id = get_current_blog_id(); |
|
266 |
} |
|
267 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
clean_blog_cache( $blog_id ); |
0 | 269 |
} |
270 |
||
271 |
/** |
|
272 |
* Update the details for a blog. Updates the blogs table for a given blog id. |
|
273 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
* @since MU (3.0.0) |
0 | 275 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* @param int $blog_id Blog ID |
0 | 279 |
* @param array $details Array of details keyed by blogs table field names. |
280 |
* @return bool True if update succeeds, false otherwise. |
|
281 |
*/ |
|
282 |
function update_blog_details( $blog_id, $details = array() ) { |
|
283 |
global $wpdb; |
|
284 |
||
285 |
if ( empty($details) ) |
|
286 |
return false; |
|
287 |
||
288 |
if ( is_object($details) ) |
|
289 |
$details = get_object_vars($details); |
|
290 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
$current_details = get_site( $blog_id ); |
0 | 292 |
if ( empty($current_details) ) |
293 |
return false; |
|
294 |
||
295 |
$current_details = get_object_vars($current_details); |
|
296 |
||
297 |
$details = array_merge($current_details, $details); |
|
298 |
$details['last_updated'] = current_time('mysql', true); |
|
299 |
||
300 |
$update_details = array(); |
|
301 |
$fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); |
|
5 | 302 |
foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) { |
303 |
if ( 'path' === $field ) { |
|
304 |
$details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) ); |
|
305 |
} |
|
306 |
||
307 |
$update_details[ $field ] = $details[ $field ]; |
|
308 |
} |
|
0 | 309 |
|
310 |
$result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); |
|
311 |
||
312 |
if ( false === $result ) |
|
313 |
return false; |
|
314 |
||
315 |
// If spam status changed, issue actions. |
|
5 | 316 |
if ( $details['spam'] != $current_details['spam'] ) { |
317 |
if ( $details['spam'] == 1 ) { |
|
318 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* Fires when the 'spam' status is added to a blog. |
5 | 320 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* @since MU (3.0.0) |
5 | 322 |
* |
323 |
* @param int $blog_id Blog ID. |
|
324 |
*/ |
|
0 | 325 |
do_action( 'make_spam_blog', $blog_id ); |
5 | 326 |
} else { |
327 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* Fires when the 'spam' status is removed from a blog. |
5 | 329 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
* @since MU (3.0.0) |
5 | 331 |
* |
332 |
* @param int $blog_id Blog ID. |
|
333 |
*/ |
|
0 | 334 |
do_action( 'make_ham_blog', $blog_id ); |
5 | 335 |
} |
0 | 336 |
} |
337 |
||
338 |
// If mature status changed, issue actions. |
|
5 | 339 |
if ( $details['mature'] != $current_details['mature'] ) { |
340 |
if ( $details['mature'] == 1 ) { |
|
341 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
* Fires when the 'mature' status is added to a blog. |
5 | 343 |
* |
344 |
* @since 3.1.0 |
|
345 |
* |
|
346 |
* @param int $blog_id Blog ID. |
|
347 |
*/ |
|
0 | 348 |
do_action( 'mature_blog', $blog_id ); |
5 | 349 |
} else { |
350 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
* Fires when the 'mature' status is removed from a blog. |
5 | 352 |
* |
353 |
* @since 3.1.0 |
|
354 |
* |
|
355 |
* @param int $blog_id Blog ID. |
|
356 |
*/ |
|
0 | 357 |
do_action( 'unmature_blog', $blog_id ); |
5 | 358 |
} |
0 | 359 |
} |
360 |
||
361 |
// If archived status changed, issue actions. |
|
5 | 362 |
if ( $details['archived'] != $current_details['archived'] ) { |
363 |
if ( $details['archived'] == 1 ) { |
|
364 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* Fires when the 'archived' status is added to a blog. |
5 | 366 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
* @since MU (3.0.0) |
5 | 368 |
* |
369 |
* @param int $blog_id Blog ID. |
|
370 |
*/ |
|
0 | 371 |
do_action( 'archive_blog', $blog_id ); |
5 | 372 |
} else { |
373 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* Fires when the 'archived' status is removed from a blog. |
5 | 375 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* @since MU (3.0.0) |
5 | 377 |
* |
378 |
* @param int $blog_id Blog ID. |
|
379 |
*/ |
|
0 | 380 |
do_action( 'unarchive_blog', $blog_id ); |
5 | 381 |
} |
0 | 382 |
} |
383 |
||
384 |
// If deleted status changed, issue actions. |
|
5 | 385 |
if ( $details['deleted'] != $current_details['deleted'] ) { |
386 |
if ( $details['deleted'] == 1 ) { |
|
387 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* Fires when the 'deleted' status is added to a blog. |
5 | 389 |
* |
390 |
* @since 3.5.0 |
|
391 |
* |
|
392 |
* @param int $blog_id Blog ID. |
|
393 |
*/ |
|
0 | 394 |
do_action( 'make_delete_blog', $blog_id ); |
5 | 395 |
} else { |
396 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* Fires when the 'deleted' status is removed from a blog. |
5 | 398 |
* |
399 |
* @since 3.5.0 |
|
400 |
* |
|
401 |
* @param int $blog_id Blog ID. |
|
402 |
*/ |
|
0 | 403 |
do_action( 'make_undelete_blog', $blog_id ); |
5 | 404 |
} |
0 | 405 |
} |
406 |
||
5 | 407 |
if ( isset( $details['public'] ) ) { |
0 | 408 |
switch_to_blog( $blog_id ); |
5 | 409 |
update_option( 'blog_public', $details['public'] ); |
0 | 410 |
restore_current_blog(); |
411 |
} |
|
412 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
clean_blog_cache( $blog_id ); |
0 | 414 |
|
415 |
return true; |
|
416 |
} |
|
417 |
||
418 |
/** |
|
419 |
* Clean the blog cache |
|
420 |
* |
|
421 |
* @since 3.5.0 |
|
422 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* @global bool $_wp_suspend_cache_invalidation |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
* @param WP_Site|int $blog The site object or ID to be cleared from cache. |
0 | 426 |
*/ |
427 |
function clean_blog_cache( $blog ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
global $_wp_suspend_cache_invalidation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
if ( ! empty( $_wp_suspend_cache_invalidation ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
if ( empty( $blog ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
$blog_id = $blog; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
$blog = get_site( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
if ( ! $blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
if ( ! is_numeric( $blog_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
// Make sure a WP_Site object exists even when the site has been deleted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
$blog = new WP_Site( (object) array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
'blog_id' => $blog_id, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
'domain' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
'path' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
|
0 | 453 |
$blog_id = $blog->blog_id; |
454 |
$domain_path_key = md5( $blog->domain . $blog->path ); |
|
455 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
wp_cache_delete( $blog_id, 'sites' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
wp_cache_delete( $blog_id, 'site-details' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
wp_cache_delete( $blog_id, 'blog-details' ); |
0 | 459 |
wp_cache_delete( $blog_id . 'short' , 'blog-details' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
wp_cache_delete( $domain_path_key, 'blog-lookup' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
wp_cache_delete( $domain_path_key, 'blog-id-cache' ); |
0 | 462 |
wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); |
463 |
wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* Fires immediately after a site has been removed from the object cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* @param int $id Blog ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
* @param WP_Site $blog Site object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
* @param string $domain_path_key md5 hash of domain and path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
wp_cache_set( 'last_changed', microtime(), 'sites' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
* Fires after the blog details cache is cleared. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* @deprecated 4.9.0 Use clean_site_cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
* @param int $blog_id Blog ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
do_action_deprecated( 'refresh_blog_details', array( $blog_id ), '4.9.0', 'clean_site_cache' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* Cleans the site details cache for a site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @since 4.7.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* @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
|
495 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
function clean_site_details_cache( $site_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
$site_id = (int) $site_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
if ( ! $site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
$site_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
wp_cache_delete( $site_id, 'site-details' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
wp_cache_delete( $site_id, 'blog-details' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
* Retrieves site data given a site ID or site object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
* Site data will be cached and returned after being passed through a filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
* If the provided site is empty, the current site global will be used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
* @param WP_Site|int|null $site Optional. Site to retrieve. Default is the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* @return WP_Site|null The site object or null if not found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
function get_site( $site = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
if ( empty( $site ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
$site = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
if ( $site instanceof WP_Site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
$_site = $site; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
} elseif ( is_object( $site ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
$_site = new WP_Site( $site ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
$_site = WP_Site::get_instance( $site ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
if ( ! $_site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
return null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
* Fires after a site is retrieved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
* @param WP_Site $_site Site data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
$_site = apply_filters( 'get_site', $_site ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
return $_site; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
* Adds any sites from the given ids to the cache that do not already exist in cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
* @see update_site_cache() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
* @param array $ids ID list. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
function _prime_site_caches( $ids ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
$non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
if ( ! empty( $non_cached_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
update_site_cache( $fresh_sites ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* Updates sites in cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* @param array $sites Array of site objects. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
function update_site_cache( $sites ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
if ( ! $sites ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
foreach ( $sites as $site ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
wp_cache_add( $site->blog_id, $site, 'sites' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* Retrieves a list of sites matching requested arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* @see WP_Site_Query::parse_query() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
* @param string|array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
* Optional. Array or query string of site query parameters. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
* @type array $site__in Array of site IDs to include. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
* @type array $site__not_in Array of site IDs to exclude. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
* @type bool $count Whether to return a site count (true) or array of site objects. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
* @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
* Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
* @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* or empty (returns an array of complete site objects). Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* @type int $ID A site ID to only return that site. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* @type int $number Maximum number of sites to retrieve. Default 100. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* @type int $offset Number of sites to offset the query. Used to build LIMIT clause. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
* Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
* @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
* 'network_id', 'last_updated', 'registered', 'domain_length', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
* 'path_length', 'site__in' and 'network__in'. Also accepts false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* an empty array, or 'none' to disable `ORDER BY` clause. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
* Default 'id'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* @type int $network_id Limit results to those affiliated with a given network ID. If 0, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* include all networks. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* @type array $network__in Array of network IDs to include affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* @type string $domain Limit results to those affiliated with a given domain. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* @type array $domain__in Array of domains to include affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* @type string $path Limit results to those affiliated with a given path. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* @type array $path__in Array of paths to include affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
* @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* @type int $lang_id Limit results to a language ID. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* @type string $search Search term(s) to retrieve matching sites for. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* @type bool $update_site_cache Whether to prime the cache for found sites. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* @return array|int List of WP_Site objects, a list of site ids when 'fields' is set to 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* or the number of sites when 'count' is passed as a query var. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
function get_sites( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
$query = new WP_Site_Query(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
return $query->query( $args ); |
0 | 646 |
} |
647 |
||
648 |
/** |
|
649 |
* Retrieve option value for a given blog id based on name of option. |
|
650 |
* |
|
651 |
* If the option does not exist or does not have a value, then the return value |
|
652 |
* will be false. This is useful to check whether you need to install an option |
|
653 |
* and is commonly used during installation of plugin options and to test |
|
654 |
* whether upgrading is required. |
|
655 |
* |
|
656 |
* If the option was serialized then it will be unserialized when it is returned. |
|
657 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
* @since MU (3.0.0) |
0 | 659 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
* @param int $id A blog ID. Can be null to refer to the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
* @param string $option Name of option to retrieve. Expected to not be SQL-escaped. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
* @param mixed $default Optional. Default value to return if the option does not exist. |
0 | 663 |
* @return mixed Value set for the option. |
664 |
*/ |
|
665 |
function get_blog_option( $id, $option, $default = false ) { |
|
666 |
$id = (int) $id; |
|
667 |
||
668 |
if ( empty( $id ) ) |
|
669 |
$id = get_current_blog_id(); |
|
670 |
||
671 |
if ( get_current_blog_id() == $id ) |
|
672 |
return get_option( $option, $default ); |
|
673 |
||
674 |
switch_to_blog( $id ); |
|
675 |
$value = get_option( $option, $default ); |
|
676 |
restore_current_blog(); |
|
677 |
||
5 | 678 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
* Filters a blog option value. |
5 | 680 |
* |
681 |
* The dynamic portion of the hook name, `$option`, refers to the blog option name. |
|
682 |
* |
|
683 |
* @since 3.5.0 |
|
684 |
* |
|
685 |
* @param string $value The option value. |
|
686 |
* @param int $id Blog ID. |
|
687 |
*/ |
|
688 |
return apply_filters( "blog_option_{$option}", $value, $id ); |
|
0 | 689 |
} |
690 |
||
691 |
/** |
|
692 |
* Add a new option for a given blog id. |
|
693 |
* |
|
694 |
* You do not need to serialize values. If the value needs to be serialized, then |
|
695 |
* it will be serialized before it is inserted into the database. Remember, |
|
696 |
* resources can not be serialized or added as an option. |
|
697 |
* |
|
698 |
* You can create options without values and then update the values later. |
|
699 |
* Existing options will not be updated and checks are performed to ensure that you |
|
700 |
* aren't adding a protected WordPress option. Care should be taken to not name |
|
701 |
* options the same as the ones which are protected. |
|
702 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* @since MU (3.0.0) |
0 | 704 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
* @param int $id A blog ID. Can be null to refer to the current blog. |
0 | 706 |
* @param string $option Name of option to add. Expected to not be SQL-escaped. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. |
0 | 708 |
* @return bool False if option was not added and true if option was added. |
709 |
*/ |
|
710 |
function add_blog_option( $id, $option, $value ) { |
|
711 |
$id = (int) $id; |
|
712 |
||
713 |
if ( empty( $id ) ) |
|
714 |
$id = get_current_blog_id(); |
|
715 |
||
716 |
if ( get_current_blog_id() == $id ) |
|
717 |
return add_option( $option, $value ); |
|
718 |
||
719 |
switch_to_blog( $id ); |
|
720 |
$return = add_option( $option, $value ); |
|
721 |
restore_current_blog(); |
|
722 |
||
723 |
return $return; |
|
724 |
} |
|
725 |
||
726 |
/** |
|
727 |
* Removes option by name for a given blog id. Prevents removal of protected WordPress options. |
|
728 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
* @since MU (3.0.0) |
0 | 730 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* @param int $id A blog ID. Can be null to refer to the current blog. |
0 | 732 |
* @param string $option Name of option to remove. Expected to not be SQL-escaped. |
733 |
* @return bool True, if option is successfully deleted. False on failure. |
|
734 |
*/ |
|
735 |
function delete_blog_option( $id, $option ) { |
|
736 |
$id = (int) $id; |
|
737 |
||
738 |
if ( empty( $id ) ) |
|
739 |
$id = get_current_blog_id(); |
|
740 |
||
741 |
if ( get_current_blog_id() == $id ) |
|
742 |
return delete_option( $option ); |
|
743 |
||
744 |
switch_to_blog( $id ); |
|
745 |
$return = delete_option( $option ); |
|
746 |
restore_current_blog(); |
|
747 |
||
748 |
return $return; |
|
749 |
} |
|
750 |
||
751 |
/** |
|
752 |
* Update an option for a particular blog. |
|
753 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
* @since MU (3.0.0) |
0 | 755 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
* @param int $id The blog id. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
* @param string $option The option key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
* @param mixed $value The option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
* @param mixed $deprecated Not used. |
0 | 760 |
* @return bool True on success, false on failure. |
761 |
*/ |
|
762 |
function update_blog_option( $id, $option, $value, $deprecated = null ) { |
|
763 |
$id = (int) $id; |
|
764 |
||
765 |
if ( null !== $deprecated ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
_deprecated_argument( __FUNCTION__, '3.1.0' ); |
0 | 767 |
|
768 |
if ( get_current_blog_id() == $id ) |
|
769 |
return update_option( $option, $value ); |
|
770 |
||
771 |
switch_to_blog( $id ); |
|
772 |
$return = update_option( $option, $value ); |
|
773 |
restore_current_blog(); |
|
774 |
||
775 |
return $return; |
|
776 |
} |
|
777 |
||
778 |
/** |
|
779 |
* Switch the current blog. |
|
780 |
* |
|
781 |
* This function is useful if you need to pull posts, or other information, |
|
782 |
* from other blogs. You can switch back afterwards using restore_current_blog(). |
|
783 |
* |
|
784 |
* Things that aren't switched: |
|
785 |
* - plugins. See #14941 |
|
786 |
* |
|
787 |
* @see restore_current_blog() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
* @since MU (3.0.0) |
0 | 789 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
* @global int $blog_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
* @global array $_wp_switched_stack |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
* @global bool $switched |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
* @global string $table_prefix |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* @global WP_Object_Cache $wp_object_cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
* @param int $new_blog The id of the blog you want to switch to. Default: current blog |
0 | 798 |
* @param bool $deprecated Deprecated argument |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
* @return true Always returns True. |
0 | 800 |
*/ |
801 |
function switch_to_blog( $new_blog, $deprecated = null ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
global $wpdb; |
0 | 803 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
$blog_id = get_current_blog_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
if ( empty( $new_blog ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
$new_blog = $blog_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
} |
0 | 808 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
$GLOBALS['_wp_switched_stack'][] = $blog_id; |
0 | 810 |
|
5 | 811 |
/* |
812 |
* If we're switching to the same blog id that we're on, |
|
813 |
* set the right vars, do the associated actions, but skip |
|
814 |
* the extra unnecessary work |
|
815 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
if ( $new_blog == $blog_id ) { |
5 | 817 |
/** |
818 |
* Fires when the blog is switched. |
|
819 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
* @since MU (3.0.0) |
5 | 821 |
* |
822 |
* @param int $new_blog New blog ID. |
|
823 |
* @param int $new_blog Blog ID. |
|
824 |
*/ |
|
0 | 825 |
do_action( 'switch_blog', $new_blog, $new_blog ); |
826 |
$GLOBALS['switched'] = true; |
|
827 |
return true; |
|
828 |
} |
|
829 |
||
830 |
$wpdb->set_blog_id( $new_blog ); |
|
831 |
$GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
$prev_blog_id = $blog_id; |
0 | 833 |
$GLOBALS['blog_id'] = $new_blog; |
834 |
||
835 |
if ( function_exists( 'wp_cache_switch_to_blog' ) ) { |
|
836 |
wp_cache_switch_to_blog( $new_blog ); |
|
837 |
} else { |
|
838 |
global $wp_object_cache; |
|
839 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { |
0 | 841 |
$global_groups = $wp_object_cache->global_groups; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
} else { |
0 | 843 |
$global_groups = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
} |
0 | 845 |
wp_cache_init(); |
846 |
||
847 |
if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
5 | 848 |
if ( is_array( $global_groups ) ) { |
0 | 849 |
wp_cache_add_global_groups( $global_groups ); |
5 | 850 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); |
5 | 852 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
0 | 854 |
} |
855 |
} |
|
856 |
||
5 | 857 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
0 | 858 |
do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
859 |
$GLOBALS['switched'] = true; |
|
860 |
||
861 |
return true; |
|
862 |
} |
|
863 |
||
864 |
/** |
|
865 |
* Restore the current blog, after calling switch_to_blog() |
|
866 |
* |
|
867 |
* @see switch_to_blog() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
* @global array $_wp_switched_stack |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
* @global int $blog_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
* @global bool $switched |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
* @global string $table_prefix |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
* @global WP_Object_Cache $wp_object_cache |
0 | 876 |
* |
877 |
* @return bool True on success, false if we're already on the current blog |
|
878 |
*/ |
|
879 |
function restore_current_blog() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
global $wpdb; |
0 | 881 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { |
0 | 883 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
} |
0 | 885 |
|
886 |
$blog = array_pop( $GLOBALS['_wp_switched_stack'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
$blog_id = get_current_blog_id(); |
0 | 888 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
if ( $blog_id == $blog ) { |
5 | 890 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
0 | 891 |
do_action( 'switch_blog', $blog, $blog ); |
892 |
// If we still have items in the switched stack, consider ourselves still 'switched' |
|
893 |
$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
894 |
return true; |
|
895 |
} |
|
896 |
||
897 |
$wpdb->set_blog_id( $blog ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
$prev_blog_id = $blog_id; |
0 | 899 |
$GLOBALS['blog_id'] = $blog; |
900 |
$GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
|
901 |
||
902 |
if ( function_exists( 'wp_cache_switch_to_blog' ) ) { |
|
903 |
wp_cache_switch_to_blog( $blog ); |
|
904 |
} else { |
|
905 |
global $wp_object_cache; |
|
906 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { |
0 | 908 |
$global_groups = $wp_object_cache->global_groups; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
} else { |
0 | 910 |
$global_groups = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
} |
0 | 912 |
|
913 |
wp_cache_init(); |
|
914 |
||
915 |
if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
5 | 916 |
if ( is_array( $global_groups ) ) { |
0 | 917 |
wp_cache_add_global_groups( $global_groups ); |
5 | 918 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); |
5 | 920 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
0 | 922 |
} |
923 |
} |
|
924 |
||
5 | 925 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
0 | 926 |
do_action( 'switch_blog', $blog, $prev_blog_id ); |
927 |
||
928 |
// If we still have items in the switched stack, consider ourselves still 'switched' |
|
929 |
$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
930 |
||
931 |
return true; |
|
932 |
} |
|
933 |
||
934 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
* 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
|
936 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
* @param int $new_site_id New site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
* @param int $old_site_id Old site ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
function wp_switch_roles_and_user( $new_site_id, $old_site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
if ( $new_site_id == $old_site_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
if ( ! did_action( 'init' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
wp_roles()->for_site( $new_site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
wp_get_current_user()->for_site( $new_site_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
/** |
0 | 956 |
* Determines if switch_to_blog() is in effect |
957 |
* |
|
958 |
* @since 3.5.0 |
|
959 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
* @global array $_wp_switched_stack |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
* |
0 | 962 |
* @return bool True if switched, false otherwise. |
963 |
*/ |
|
964 |
function ms_is_switched() { |
|
965 |
return ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
966 |
} |
|
967 |
||
968 |
/** |
|
969 |
* Check if a particular blog is archived. |
|
970 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
* @since MU (3.0.0) |
0 | 972 |
* |
973 |
* @param int $id The blog id |
|
974 |
* @return string Whether the blog is archived or not |
|
975 |
*/ |
|
976 |
function is_archived( $id ) { |
|
977 |
return get_blog_status($id, 'archived'); |
|
978 |
} |
|
979 |
||
980 |
/** |
|
981 |
* Update the 'archived' status of a particular blog. |
|
982 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
* @since MU (3.0.0) |
0 | 984 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
* @param int $id The blog id |
0 | 986 |
* @param string $archived The new status |
987 |
* @return string $archived |
|
988 |
*/ |
|
989 |
function update_archived( $id, $archived ) { |
|
990 |
update_blog_status($id, 'archived', $archived); |
|
991 |
return $archived; |
|
992 |
} |
|
993 |
||
994 |
/** |
|
995 |
* Update a blog details field. |
|
996 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1000 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
* @param int $blog_id BLog ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
* @param string $pref A field name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
* @param string $value Value for $pref |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
* @param null $deprecated |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
* @return string|false $value |
0 | 1006 |
*/ |
1007 |
function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { |
|
1008 |
global $wpdb; |
|
1009 |
||
1010 |
if ( null !== $deprecated ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
_deprecated_argument( __FUNCTION__, '3.1.0' ); |
0 | 1012 |
|
1013 |
if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) |
|
1014 |
return $value; |
|
1015 |
||
1016 |
$result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); |
|
1017 |
||
1018 |
if ( false === $result ) |
|
1019 |
return false; |
|
1020 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
clean_blog_cache( $blog_id ); |
0 | 1022 |
|
5 | 1023 |
if ( 'spam' == $pref ) { |
1024 |
if ( $value == 1 ) { |
|
1025 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1026 |
do_action( 'make_spam_blog', $blog_id ); |
|
1027 |
} else { |
|
1028 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1029 |
do_action( 'make_ham_blog', $blog_id ); |
|
1030 |
} |
|
1031 |
} elseif ( 'mature' == $pref ) { |
|
1032 |
if ( $value == 1 ) { |
|
1033 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1034 |
do_action( 'mature_blog', $blog_id ); |
|
1035 |
} else { |
|
1036 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1037 |
do_action( 'unmature_blog', $blog_id ); |
|
1038 |
} |
|
1039 |
} elseif ( 'archived' == $pref ) { |
|
1040 |
if ( $value == 1 ) { |
|
1041 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1042 |
do_action( 'archive_blog', $blog_id ); |
|
1043 |
} else { |
|
1044 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1045 |
do_action( 'unarchive_blog', $blog_id ); |
|
1046 |
} |
|
1047 |
} elseif ( 'deleted' == $pref ) { |
|
1048 |
if ( $value == 1 ) { |
|
1049 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1050 |
do_action( 'make_delete_blog', $blog_id ); |
|
1051 |
} else { |
|
1052 |
/** This filter is documented in wp-includes/ms-blogs.php */ |
|
1053 |
do_action( 'make_undelete_blog', $blog_id ); |
|
1054 |
} |
|
1055 |
} elseif ( 'public' == $pref ) { |
|
1056 |
/** |
|
1057 |
* Fires after the current blog's 'public' setting is updated. |
|
1058 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
* @since MU (3.0.0) |
5 | 1060 |
* |
1061 |
* @param int $blog_id Blog ID. |
|
1062 |
* @param string $value The value of blog status. |
|
1063 |
*/ |
|
0 | 1064 |
do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public(). |
5 | 1065 |
} |
0 | 1066 |
|
1067 |
return $value; |
|
1068 |
} |
|
1069 |
||
1070 |
/** |
|
1071 |
* Get a blog details field. |
|
1072 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1076 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
* @param int $id The blog id |
0 | 1078 |
* @param string $pref A field name |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
* @return bool|string|null $value |
0 | 1080 |
*/ |
1081 |
function get_blog_status( $id, $pref ) { |
|
1082 |
global $wpdb; |
|
1083 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
$details = get_site( $id ); |
0 | 1085 |
if ( $details ) |
1086 |
return $details->$pref; |
|
1087 |
||
1088 |
return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) ); |
|
1089 |
} |
|
1090 |
||
1091 |
/** |
|
1092 |
* Get a list of most recently updated blogs. |
|
1093 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 1097 |
* |
1098 |
* @param mixed $deprecated Not used |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* @param int $start The offset |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
* @param int $quantity The maximum number of blogs to retrieve. Default is 40. |
0 | 1101 |
* @return array The list of blogs |
1102 |
*/ |
|
1103 |
function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { |
|
1104 |
global $wpdb; |
|
1105 |
||
1106 |
if ( ! empty( $deprecated ) ) |
|
1107 |
_deprecated_argument( __FUNCTION__, 'MU' ); // never used |
|
1108 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
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 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
* Retrieves a list of networks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
* @param string|array $args Optional. Array or string of arguments. See WP_Network_Query::parse_query() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
* for information on accepted arguments. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
* @return array|int List of WP_Network objects, a list of network ids when 'fields' is set to 'ids', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* or the number of networks when 'count' is passed as a query var. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
function get_networks( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
$query = new WP_Network_Query(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
return $query->query( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* Retrieves network data given a network ID or network object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
* Network data will be cached and returned after being passed through a filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
* If the provided network is empty, the current network global will be used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
* @global WP_Network $current_site |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
* @param WP_Network|int|null $network Optional. Network to retrieve. Default is the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
* @return WP_Network|null The network object or null if not found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
function get_network( $network = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
global $current_site; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
if ( empty( $network ) && isset( $current_site ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
$network = $current_site; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
if ( $network instanceof WP_Network ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
$_network = $network; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
} elseif ( is_object( $network ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
$_network = new WP_Network( $network ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
$_network = WP_Network::get_instance( $network ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
if ( ! $_network ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
return null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
* Fires after a network is retrieved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* @param WP_Network $_network Network data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
$_network = apply_filters( 'get_network', $_network ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
return $_network; |
0 | 1169 |
} |
1170 |
||
1171 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* Removes a network from the object cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* @global bool $_wp_suspend_cache_invalidation |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
* @param int|array $ids Network ID or an array of network IDs to remove from cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
function clean_network_cache( $ids ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
global $_wp_suspend_cache_invalidation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
if ( ! empty( $_wp_suspend_cache_invalidation ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
foreach ( (array) $ids as $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
wp_cache_delete( $id, 'networks' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
* Fires immediately after a network has been removed from the object cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
* @param int $id Network ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
do_action( 'clean_network_cache', $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
wp_cache_set( 'last_changed', microtime(), 'networks' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
* Updates the network cache of given networks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
* Will add the networks in $networks to the cache. If network ID already exists |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
* in the network cache then it will not be updated. The network is added to the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
* cache using the network group with the key using the ID of the networks. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
* @param array $networks Array of network row objects. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
function update_network_cache( $networks ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
foreach ( (array) $networks as $network ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
wp_cache_add( $network->id, $network, 'networks' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
* Adds any networks from the given IDs to the cache that do not already exist in cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @see update_network_cache() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
* @param array $network_ids Array of network IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
function _prime_network_caches( $network_ids ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
$non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
if ( !empty( $non_cached_ids ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
$fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
update_network_cache( $fresh_networks ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
* 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
|
1244 |
* an already published post is changed. |
0 | 1245 |
* |
1246 |
* @since 3.3.0 |
|
1247 |
* |
|
1248 |
* @param string $new_status The new post status |
|
1249 |
* @param string $old_status The old post status |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
* @param object $post Post object |
0 | 1251 |
*/ |
1252 |
function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) { |
|
1253 |
$post_type_obj = get_post_type_object( $post->post_type ); |
|
5 | 1254 |
if ( ! $post_type_obj || ! $post_type_obj->public ) { |
0 | 1255 |
return; |
5 | 1256 |
} |
0 | 1257 |
|
5 | 1258 |
if ( 'publish' != $new_status && 'publish' != $old_status ) { |
0 | 1259 |
return; |
5 | 1260 |
} |
0 | 1261 |
|
1262 |
// Post was freshly published, published post was saved, or published post was unpublished. |
|
1263 |
||
1264 |
wpmu_update_blogs_date(); |
|
1265 |
} |
|
1266 |
||
1267 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
* 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
|
1269 |
* post is deleted. |
0 | 1270 |
* |
1271 |
* @since 3.4.0 |
|
1272 |
* |
|
1273 |
* @param int $post_id Post ID |
|
1274 |
*/ |
|
1275 |
function _update_blog_date_on_post_delete( $post_id ) { |
|
1276 |
$post = get_post( $post_id ); |
|
1277 |
||
1278 |
$post_type_obj = get_post_type_object( $post->post_type ); |
|
5 | 1279 |
if ( ! $post_type_obj || ! $post_type_obj->public ) { |
0 | 1280 |
return; |
5 | 1281 |
} |
0 | 1282 |
|
5 | 1283 |
if ( 'publish' != $post->post_status ) { |
0 | 1284 |
return; |
5 | 1285 |
} |
0 | 1286 |
|
1287 |
wpmu_update_blogs_date(); |
|
1288 |
} |
|
1289 |
||
5 | 1290 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
* Handler for updating the current site's posts count when a post is deleted. |
5 | 1292 |
* |
1293 |
* @since 4.0.0 |
|
1294 |
* |
|
1295 |
* @param int $post_id Post ID. |
|
1296 |
*/ |
|
1297 |
function _update_posts_count_on_delete( $post_id ) { |
|
1298 |
$post = get_post( $post_id ); |
|
1299 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) { |
5 | 1301 |
return; |
1302 |
} |
|
1303 |
||
1304 |
update_posts_count(); |
|
1305 |
} |
|
1306 |
||
1307 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
* Handler for updating the current site's posts count when a post status changes. |
5 | 1309 |
* |
1310 |
* @since 4.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* @since 4.9.0 Added the `$post` parameter. |
5 | 1312 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
* @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
|
1314 |
* @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
|
1315 |
* @param WP_Post $post Post object |
5 | 1316 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) { |
5 | 1318 |
if ( $new_status === $old_status ) { |
1319 |
return; |
|
1320 |
} |
|
1321 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
if ( 'post' !== get_post_type( $post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
|
5 | 1326 |
if ( 'publish' !== $new_status && 'publish' !== $old_status ) { |
1327 |
return; |
|
1328 |
} |
|
1329 |
||
1330 |
update_posts_count(); |
|
1331 |
} |