90 /** |
106 /** |
91 * Sets up the site query, based on the query vars passed. |
107 * Sets up the site query, based on the query vars passed. |
92 * |
108 * |
93 * @since 4.6.0 |
109 * @since 4.6.0 |
94 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. |
110 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. |
|
111 * @since 5.1.0 Introduced the 'update_site_meta_cache', 'meta_query', 'meta_key', |
|
112 * 'meta_value', 'meta_type' and 'meta_compare' parameters. |
95 * |
113 * |
96 * @param string|array $query { |
114 * @param string|array $query { |
97 * Optional. Array or query string of site query parameters. Default empty. |
115 * Optional. Array or query string of site query parameters. Default empty. |
98 * |
116 * |
99 * @type array $site__in Array of site IDs to include. Default empty. |
117 * @type array $site__in Array of site IDs to include. Default empty. |
100 * @type array $site__not_in Array of site IDs to exclude. Default empty. |
118 * @type array $site__not_in Array of site IDs to exclude. Default empty. |
101 * @type bool $count Whether to return a site count (true) or array of site objects. |
119 * @type bool $count Whether to return a site count (true) or array of site objects. |
102 * Default false. |
120 * Default false. |
103 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. |
121 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. |
104 * Default null. |
122 * Default null. |
105 * @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs) |
123 * @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs) |
106 * or empty (returns an array of complete site objects). Default empty. |
124 * or empty (returns an array of complete site objects). Default empty. |
107 * @type int $ID A site ID to only return that site. Default empty. |
125 * @type int $ID A site ID to only return that site. Default empty. |
108 * @type int $number Maximum number of sites to retrieve. Default 100. |
126 * @type int $number Maximum number of sites to retrieve. Default 100. |
109 * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. |
127 * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. |
110 * Default 0. |
128 * Default 0. |
111 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. |
129 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. |
112 * @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path', |
130 * @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path', |
113 * 'network_id', 'last_updated', 'registered', 'domain_length', |
131 * 'network_id', 'last_updated', 'registered', 'domain_length', |
114 * 'path_length', 'site__in' and 'network__in'. Also accepts false, |
132 * 'path_length', 'site__in' and 'network__in'. Also accepts false, |
115 * an empty array, or 'none' to disable `ORDER BY` clause. |
133 * an empty array, or 'none' to disable `ORDER BY` clause. |
116 * Default 'id'. |
134 * Default 'id'. |
117 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'. |
135 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'. |
118 * @type int $network_id Limit results to those affiliated with a given network ID. If 0, |
136 * @type int $network_id Limit results to those affiliated with a given network ID. If 0, |
119 * include all networks. Default 0. |
137 * include all networks. Default 0. |
120 * @type array $network__in Array of network IDs to include affiliated sites for. Default empty. |
138 * @type array $network__in Array of network IDs to include affiliated sites for. Default empty. |
121 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. |
139 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. |
122 * @type string $domain Limit results to those affiliated with a given domain. Default empty. |
140 * @type string $domain Limit results to those affiliated with a given domain. Default empty. |
123 * @type array $domain__in Array of domains to include affiliated sites for. Default empty. |
141 * @type array $domain__in Array of domains to include affiliated sites for. Default empty. |
124 * @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. |
142 * @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. |
125 * @type string $path Limit results to those affiliated with a given path. Default empty. |
143 * @type string $path Limit results to those affiliated with a given path. Default empty. |
126 * @type array $path__in Array of paths to include affiliated sites for. Default empty. |
144 * @type array $path__in Array of paths to include affiliated sites for. Default empty. |
127 * @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. |
145 * @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. |
128 * @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty. |
146 * @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty. |
129 * @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty. |
147 * @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty. |
130 * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. |
148 * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. |
131 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. |
149 * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. |
132 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. |
150 * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. |
133 * @type int $lang_id Limit results to a language ID. Default empty. |
151 * @type int $lang_id Limit results to a language ID. Default empty. |
134 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. |
152 * @type array $lang__in Array of language IDs to include affiliated sites for. Default empty. |
135 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. |
153 * @type array $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty. |
136 * @type string $search Search term(s) to retrieve matching sites for. Default empty. |
154 * @type string $search Search term(s) to retrieve matching sites for. Default empty. |
137 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. |
155 * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. |
138 * Default empty array. |
156 * Default empty array. |
139 * @type bool $update_site_cache Whether to prime the cache for found sites. Default true. |
157 * @type bool $update_site_cache Whether to prime the cache for found sites. Default true. |
|
158 * @type bool $update_site_meta_cache Whether to prime the metadata cache for found sites. Default true. |
|
159 * @type array $meta_query Meta query clauses to limit retrieved sites by. See `WP_Meta_Query`. |
|
160 * Default empty. |
|
161 * @type string $meta_key Limit sites to those matching a specific metadata key. |
|
162 * Can be used in conjunction with `$meta_value`. Default empty. |
|
163 * @type string $meta_value Limit sites to those matching a specific metadata value. |
|
164 * Usually used in conjunction with `$meta_key`. Default empty. |
|
165 * @type string $meta_type Data type that the `$meta_value` column will be CAST to for |
|
166 * comparisons. Default empty. |
|
167 * @type string $meta_compare Comparison operator to test the `$meta_value`. Default empty. |
140 * } |
168 * } |
141 */ |
169 */ |
142 public function __construct( $query = '' ) { |
170 public function __construct( $query = '' ) { |
143 $this->query_var_defaults = array( |
171 $this->query_var_defaults = array( |
144 'fields' => '', |
172 'fields' => '', |
145 'ID' => '', |
173 'ID' => '', |
146 'site__in' => '', |
174 'site__in' => '', |
147 'site__not_in' => '', |
175 'site__not_in' => '', |
148 'number' => 100, |
176 'number' => 100, |
149 'offset' => '', |
177 'offset' => '', |
150 'no_found_rows' => true, |
178 'no_found_rows' => true, |
151 'orderby' => 'id', |
179 'orderby' => 'id', |
152 'order' => 'ASC', |
180 'order' => 'ASC', |
153 'network_id' => 0, |
181 'network_id' => 0, |
154 'network__in' => '', |
182 'network__in' => '', |
155 'network__not_in' => '', |
183 'network__not_in' => '', |
156 'domain' => '', |
184 'domain' => '', |
157 'domain__in' => '', |
185 'domain__in' => '', |
158 'domain__not_in' => '', |
186 'domain__not_in' => '', |
159 'path' => '', |
187 'path' => '', |
160 'path__in' => '', |
188 'path__in' => '', |
161 'path__not_in' => '', |
189 'path__not_in' => '', |
162 'public' => null, |
190 'public' => null, |
163 'archived' => null, |
191 'archived' => null, |
164 'mature' => null, |
192 'mature' => null, |
165 'spam' => null, |
193 'spam' => null, |
166 'deleted' => null, |
194 'deleted' => null, |
167 'lang_id' => null, |
195 'lang_id' => null, |
168 'lang__in' => '', |
196 'lang__in' => '', |
169 'lang__not_in' => '', |
197 'lang__not_in' => '', |
170 'search' => '', |
198 'search' => '', |
171 'search_columns' => array(), |
199 'search_columns' => array(), |
172 'count' => false, |
200 'count' => false, |
173 'date_query' => null, // See WP_Date_Query |
201 'date_query' => null, // See WP_Date_Query |
174 'update_site_cache' => true, |
202 'update_site_cache' => true, |
|
203 'update_site_meta_cache' => true, |
|
204 'meta_query' => '', |
|
205 'meta_key' => '', |
|
206 'meta_value' => '', |
|
207 'meta_type' => '', |
|
208 'meta_compare' => '', |
175 ); |
209 ); |
176 |
210 |
177 if ( ! empty( $query ) ) { |
211 if ( ! empty( $query ) ) { |
178 $this->query( $query ); |
212 $this->query( $query ); |
179 } |
213 } |
223 /** |
257 /** |
224 * Retrieves a list of sites matching the query vars. |
258 * Retrieves a list of sites matching the query vars. |
225 * |
259 * |
226 * @since 4.6.0 |
260 * @since 4.6.0 |
227 * |
261 * |
|
262 * @global wpdb $wpdb WordPress database abstraction object. |
|
263 * |
228 * @return array|int List of WP_Site objects, a list of site ids when 'fields' is set to 'ids', |
264 * @return array|int List of WP_Site objects, a list of site ids when 'fields' is set to 'ids', |
229 * or the number of sites when 'count' is passed as a query var. |
265 * or the number of sites when 'count' is passed as a query var. |
230 */ |
266 */ |
231 public function get_sites() { |
267 public function get_sites() { |
|
268 global $wpdb; |
|
269 |
232 $this->parse_query(); |
270 $this->parse_query(); |
|
271 |
|
272 // Parse meta query. |
|
273 $this->meta_query = new WP_Meta_Query(); |
|
274 $this->meta_query->parse_query_vars( $this->query_vars ); |
233 |
275 |
234 /** |
276 /** |
235 * Fires before sites are retrieved. |
277 * Fires before sites are retrieved. |
236 * |
278 * |
237 * @since 4.6.0 |
279 * @since 4.6.0 |
238 * |
280 * |
239 * @param WP_Site_Query $this Current instance of WP_Site_Query (passed by reference). |
281 * @param WP_Site_Query $this Current instance of WP_Site_Query (passed by reference). |
240 */ |
282 */ |
241 do_action_ref_array( 'pre_get_sites', array( &$this ) ); |
283 do_action_ref_array( 'pre_get_sites', array( &$this ) ); |
242 |
284 |
243 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. |
285 // Reparse query vars, in case they were modified in a 'pre_get_sites' callback. |
244 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); |
286 $this->meta_query->parse_query_vars( $this->query_vars ); |
245 |
287 if ( ! empty( $this->meta_query->queries ) ) { |
246 // Ignore the $fields argument as the queried result will be the same regardless. |
288 $this->meta_query_clauses = $this->meta_query->get_sql( 'blog', $wpdb->blogs, 'blog_id', $this ); |
247 unset( $_args['fields'] ); |
289 } |
248 |
290 |
249 $key = md5( serialize( $_args ) ); |
291 $site_ids = null; |
250 $last_changed = wp_cache_get_last_changed( 'sites' ); |
292 |
251 |
293 /** |
252 $cache_key = "get_sites:$key:$last_changed"; |
294 * Filter the sites array before the query takes place. |
253 $cache_value = wp_cache_get( $cache_key, 'sites' ); |
295 * |
254 |
296 * Return a non-null value to bypass WordPress's default site queries. |
255 if ( false === $cache_value ) { |
297 * |
256 $site_ids = $this->get_site_ids(); |
298 * |
257 if ( $site_ids ) { |
299 * @since 5.2.0 |
258 $this->set_found_sites(); |
300 * |
|
301 * @param array|null $site_ids Return an array of site data to short-circuit WP's site query, |
|
302 * or null to allow WP to run its normal queries. |
|
303 * @param WP_Site_Query $this The WP_Site_Query instance, passed by reference. |
|
304 */ |
|
305 $site_ids = apply_filters_ref_array( 'sites_pre_query', array( $site_ids, &$this ) ); |
|
306 |
|
307 if ( null === $site_ids ) { |
|
308 |
|
309 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. |
|
310 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); |
|
311 |
|
312 // Ignore the $fields argument as the queried result will be the same regardless. |
|
313 unset( $_args['fields'] ); |
|
314 |
|
315 $key = md5( serialize( $_args ) ); |
|
316 $last_changed = wp_cache_get_last_changed( 'sites' ); |
|
317 |
|
318 $cache_key = "get_sites:$key:$last_changed"; |
|
319 $cache_value = wp_cache_get( $cache_key, 'sites' ); |
|
320 |
|
321 if ( false === $cache_value ) { |
|
322 $site_ids = $this->get_site_ids(); |
|
323 if ( $site_ids ) { |
|
324 $this->set_found_sites(); |
|
325 } |
|
326 |
|
327 $cache_value = array( |
|
328 'site_ids' => $site_ids, |
|
329 'found_sites' => $this->found_sites, |
|
330 ); |
|
331 wp_cache_add( $cache_key, $cache_value, 'sites' ); |
|
332 } else { |
|
333 $site_ids = $cache_value['site_ids']; |
|
334 $this->found_sites = $cache_value['found_sites']; |
259 } |
335 } |
260 |
|
261 $cache_value = array( |
|
262 'site_ids' => $site_ids, |
|
263 'found_sites' => $this->found_sites, |
|
264 ); |
|
265 wp_cache_add( $cache_key, $cache_value, 'sites' ); |
|
266 } else { |
|
267 $site_ids = $cache_value['site_ids']; |
|
268 $this->found_sites = $cache_value['found_sites']; |
|
269 } |
336 } |
270 |
337 |
271 if ( $this->found_sites && $this->query_vars['number'] ) { |
338 if ( $this->found_sites && $this->query_vars['number'] ) { |
272 $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); |
339 $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); |
273 } |
340 } |
382 } |
450 } |
383 |
451 |
384 if ( $this->query_vars['count'] ) { |
452 if ( $this->query_vars['count'] ) { |
385 $fields = 'COUNT(*)'; |
453 $fields = 'COUNT(*)'; |
386 } else { |
454 } else { |
387 $fields = 'blog_id'; |
455 $fields = "{$wpdb->blogs}.blog_id"; |
388 } |
456 } |
389 |
457 |
390 // Parse site IDs for an IN clause. |
458 // Parse site IDs for an IN clause. |
391 $site_id = absint( $this->query_vars['ID'] ); |
459 $site_id = absint( $this->query_vars['ID'] ); |
392 if ( ! empty( $site_id ) ) { |
460 if ( ! empty( $site_id ) ) { |
393 $this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id ); |
461 $this->sql_clauses['where']['ID'] = $wpdb->prepare( "{$wpdb->blogs}.blog_id = %d", $site_id ); |
394 } |
462 } |
395 |
463 |
396 // Parse site IDs for an IN clause. |
464 // Parse site IDs for an IN clause. |
397 if ( ! empty( $this->query_vars['site__in'] ) ) { |
465 if ( ! empty( $this->query_vars['site__in'] ) ) { |
398 $this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )'; |
466 $this->sql_clauses['where']['site__in'] = "{$wpdb->blogs}.blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )'; |
399 } |
467 } |
400 |
468 |
401 // Parse site IDs for a NOT IN clause. |
469 // Parse site IDs for a NOT IN clause. |
402 if ( ! empty( $this->query_vars['site__not_in'] ) ) { |
470 if ( ! empty( $this->query_vars['site__not_in'] ) ) { |
403 $this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )'; |
471 $this->sql_clauses['where']['site__not_in'] = "{$wpdb->blogs}.blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )'; |
404 } |
472 } |
405 |
473 |
406 $network_id = absint( $this->query_vars['network_id'] ); |
474 $network_id = absint( $this->query_vars['network_id'] ); |
407 |
475 |
408 if ( ! empty( $network_id ) ) { |
476 if ( ! empty( $network_id ) ) { |
446 if ( is_array( $this->query_vars['path__not_in'] ) ) { |
514 if ( is_array( $this->query_vars['path__not_in'] ) ) { |
447 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; |
515 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; |
448 } |
516 } |
449 |
517 |
450 if ( is_numeric( $this->query_vars['archived'] ) ) { |
518 if ( is_numeric( $this->query_vars['archived'] ) ) { |
451 $archived = absint( $this->query_vars['archived'] ); |
519 $archived = absint( $this->query_vars['archived'] ); |
452 $this->sql_clauses['where']['archived'] = $wpdb->prepare( "archived = %s ", absint( $archived ) ); |
520 $this->sql_clauses['where']['archived'] = $wpdb->prepare( 'archived = %s ', absint( $archived ) ); |
453 } |
521 } |
454 |
522 |
455 if ( is_numeric( $this->query_vars['mature'] ) ) { |
523 if ( is_numeric( $this->query_vars['mature'] ) ) { |
456 $mature = absint( $this->query_vars['mature'] ); |
524 $mature = absint( $this->query_vars['mature'] ); |
457 $this->sql_clauses['where']['mature'] = $wpdb->prepare( "mature = %d ", $mature ); |
525 $this->sql_clauses['where']['mature'] = $wpdb->prepare( 'mature = %d ', $mature ); |
458 } |
526 } |
459 |
527 |
460 if ( is_numeric( $this->query_vars['spam'] ) ) { |
528 if ( is_numeric( $this->query_vars['spam'] ) ) { |
461 $spam = absint( $this->query_vars['spam'] ); |
529 $spam = absint( $this->query_vars['spam'] ); |
462 $this->sql_clauses['where']['spam'] = $wpdb->prepare( "spam = %d ", $spam ); |
530 $this->sql_clauses['where']['spam'] = $wpdb->prepare( 'spam = %d ', $spam ); |
463 } |
531 } |
464 |
532 |
465 if ( is_numeric( $this->query_vars['deleted'] ) ) { |
533 if ( is_numeric( $this->query_vars['deleted'] ) ) { |
466 $deleted = absint( $this->query_vars['deleted'] ); |
534 $deleted = absint( $this->query_vars['deleted'] ); |
467 $this->sql_clauses['where']['deleted'] = $wpdb->prepare( "deleted = %d ", $deleted ); |
535 $this->sql_clauses['where']['deleted'] = $wpdb->prepare( 'deleted = %d ', $deleted ); |
468 } |
536 } |
469 |
537 |
470 if ( is_numeric( $this->query_vars['public'] ) ) { |
538 if ( is_numeric( $this->query_vars['public'] ) ) { |
471 $public = absint( $this->query_vars['public'] ); |
539 $public = absint( $this->query_vars['public'] ); |
472 $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public ); |
540 $this->sql_clauses['where']['public'] = $wpdb->prepare( 'public = %d ', $public ); |
473 } |
541 } |
474 |
542 |
475 if ( is_numeric( $this->query_vars['lang_id'] ) ) { |
543 if ( is_numeric( $this->query_vars['lang_id'] ) ) { |
476 $lang_id = absint( $this->query_vars['lang_id'] ); |
544 $lang_id = absint( $this->query_vars['lang_id'] ); |
477 $this->sql_clauses['where']['lang_id'] = $wpdb->prepare( "lang_id = %d ", $lang_id ); |
545 $this->sql_clauses['where']['lang_id'] = $wpdb->prepare( 'lang_id = %d ', $lang_id ); |
478 } |
546 } |
479 |
547 |
480 // Parse site language IDs for an IN clause. |
548 // Parse site language IDs for an IN clause. |
481 if ( ! empty( $this->query_vars['lang__in'] ) ) { |
549 if ( ! empty( $this->query_vars['lang__in'] ) ) { |
482 $this->sql_clauses['where']['lang__in'] = 'lang_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__in'] ) ) . ' )'; |
550 $this->sql_clauses['where']['lang__in'] = 'lang_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['lang__in'] ) ) . ' )'; |
504 * |
572 * |
505 * The default columns include 'domain' and 'path. |
573 * The default columns include 'domain' and 'path. |
506 * |
574 * |
507 * @since 4.6.0 |
575 * @since 4.6.0 |
508 * |
576 * |
509 * @param array $search_columns Array of column names to be searched. |
577 * @param string[] $search_columns Array of column names to be searched. |
510 * @param string $search Text being searched. |
578 * @param string $search Text being searched. |
511 * @param WP_Site_Query $this The current WP_Site_Query instance. |
579 * @param WP_Site_Query $this The current WP_Site_Query instance. |
512 */ |
580 */ |
513 $search_columns = apply_filters( 'site_search_columns', $search_columns, $this->query_vars['search'], $this ); |
581 $search_columns = apply_filters( 'site_search_columns', $search_columns, $this->query_vars['search'], $this ); |
514 |
582 |
515 $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search'], $search_columns ); |
583 $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search'], $search_columns ); |
516 } |
584 } |
517 |
585 |
518 $date_query = $this->query_vars['date_query']; |
586 $date_query = $this->query_vars['date_query']; |
519 if ( ! empty( $date_query ) && is_array( $date_query ) ) { |
587 if ( ! empty( $date_query ) && is_array( $date_query ) ) { |
520 $this->date_query = new WP_Date_Query( $date_query, 'registered' ); |
588 $this->date_query = new WP_Date_Query( $date_query, 'registered' ); |
521 $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() ); |
589 $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() ); |
522 } |
590 } |
523 |
591 |
524 $join = ''; |
592 $join = ''; |
|
593 $groupby = ''; |
|
594 |
|
595 if ( ! empty( $this->meta_query_clauses ) ) { |
|
596 $join .= $this->meta_query_clauses['join']; |
|
597 |
|
598 // Strip leading 'AND'. |
|
599 $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] ); |
|
600 |
|
601 if ( ! $this->query_vars['count'] ) { |
|
602 $groupby = "{$wpdb->blogs}.blog_id"; |
|
603 } |
|
604 } |
525 |
605 |
526 $where = implode( ' AND ', $this->sql_clauses['where'] ); |
606 $where = implode( ' AND ', $this->sql_clauses['where'] ); |
527 |
607 |
528 $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); |
608 $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); |
529 |
609 |
530 /** |
610 /** |
531 * Filters the site query clauses. |
611 * Filters the site query clauses. |
532 * |
612 * |
533 * @since 4.6.0 |
613 * @since 4.6.0 |
534 * |
614 * |
535 * @param array $pieces A compacted array of site query clauses. |
615 * @param string[] $pieces An associative array of site query clauses. |
536 * @param WP_Site_Query $this Current instance of WP_Site_Query (passed by reference). |
616 * @param WP_Site_Query $this Current instance of WP_Site_Query (passed by reference). |
537 */ |
617 */ |
538 $clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) ); |
618 $clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) ); |
539 |
619 |
540 $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; |
620 $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; |
541 $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; |
621 $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; |
542 $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; |
622 $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; |
543 $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; |
623 $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; |
544 $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; |
624 $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; |
545 $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; |
625 $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; |
546 |
626 |
547 if ( $where ) { |
627 if ( $where ) { |
548 $where = 'WHERE ' . $where; |
628 $where = 'WHERE ' . $where; |
549 } |
629 } |