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