Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: class-wp-site-query.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Site API: WP_Site_Query class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Sites
[5] Fix | Delete
* @since 4.6.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used for querying sites.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 4.6.0
[12] Fix | Delete
*
[13] Fix | Delete
* @see WP_Site_Query::__construct() for accepted arguments.
[14] Fix | Delete
*/
[15] Fix | Delete
#[AllowDynamicProperties]
[16] Fix | Delete
class WP_Site_Query {
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* SQL for database query.
[20] Fix | Delete
*
[21] Fix | Delete
* @since 4.6.0
[22] Fix | Delete
* @var string
[23] Fix | Delete
*/
[24] Fix | Delete
public $request;
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* SQL query clauses.
[28] Fix | Delete
*
[29] Fix | Delete
* @since 4.6.0
[30] Fix | Delete
* @var array
[31] Fix | Delete
*/
[32] Fix | Delete
protected $sql_clauses = array(
[33] Fix | Delete
'select' => '',
[34] Fix | Delete
'from' => '',
[35] Fix | Delete
'where' => array(),
[36] Fix | Delete
'groupby' => '',
[37] Fix | Delete
'orderby' => '',
[38] Fix | Delete
'limits' => '',
[39] Fix | Delete
);
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Metadata query container.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 5.1.0
[45] Fix | Delete
* @var WP_Meta_Query
[46] Fix | Delete
*/
[47] Fix | Delete
public $meta_query = false;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Metadata query clauses.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 5.1.0
[53] Fix | Delete
* @var array
[54] Fix | Delete
*/
[55] Fix | Delete
protected $meta_query_clauses;
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Date query container.
[59] Fix | Delete
*
[60] Fix | Delete
* @since 4.6.0
[61] Fix | Delete
* @var WP_Date_Query A date query instance.
[62] Fix | Delete
*/
[63] Fix | Delete
public $date_query = false;
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Query vars set by the user.
[67] Fix | Delete
*
[68] Fix | Delete
* @since 4.6.0
[69] Fix | Delete
* @var array
[70] Fix | Delete
*/
[71] Fix | Delete
public $query_vars;
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Default values for query vars.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 4.6.0
[77] Fix | Delete
* @var array
[78] Fix | Delete
*/
[79] Fix | Delete
public $query_var_defaults;
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* List of sites located by the query.
[83] Fix | Delete
*
[84] Fix | Delete
* @since 4.6.0
[85] Fix | Delete
* @var array
[86] Fix | Delete
*/
[87] Fix | Delete
public $sites;
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* The amount of found sites for the current query.
[91] Fix | Delete
*
[92] Fix | Delete
* @since 4.6.0
[93] Fix | Delete
* @var int
[94] Fix | Delete
*/
[95] Fix | Delete
public $found_sites = 0;
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* The number of pages.
[99] Fix | Delete
*
[100] Fix | Delete
* @since 4.6.0
[101] Fix | Delete
* @var int
[102] Fix | Delete
*/
[103] Fix | Delete
public $max_num_pages = 0;
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Sets up the site query, based on the query vars passed.
[107] Fix | Delete
*
[108] Fix | Delete
* @since 4.6.0
[109] Fix | Delete
* @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
[110] Fix | Delete
* @since 5.1.0 Introduced the 'update_site_meta_cache', 'meta_query', 'meta_key',
[111] Fix | Delete
* 'meta_compare_key', 'meta_value', 'meta_type', and 'meta_compare' parameters.
[112] Fix | Delete
* @since 5.3.0 Introduced the 'meta_type_key' parameter.
[113] Fix | Delete
*
[114] Fix | Delete
* @param string|array $query {
[115] Fix | Delete
* Optional. Array or query string of site query parameters. Default empty.
[116] Fix | Delete
*
[117] Fix | Delete
* @type int[] $site__in Array of site IDs to include. Default empty.
[118] Fix | Delete
* @type int[] $site__not_in Array of site IDs to exclude. Default empty.
[119] Fix | Delete
* @type bool $count Whether to return a site count (true) or array of site objects.
[120] Fix | Delete
* Default false.
[121] Fix | Delete
* @type array $date_query Date query clauses to limit sites by. See WP_Date_Query.
[122] Fix | Delete
* Default null.
[123] Fix | Delete
* @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs)
[124] Fix | Delete
* or empty (returns an array of complete site objects). Default empty.
[125] Fix | Delete
* @type int $ID A site ID to only return that site. Default empty.
[126] Fix | Delete
* @type int $number Maximum number of sites to retrieve. Default 100.
[127] Fix | Delete
* @type int $offset Number of sites to offset the query. Used to build LIMIT clause.
[128] Fix | Delete
* Default 0.
[129] Fix | Delete
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
[130] Fix | Delete
* @type string|array $orderby Site status or array of statuses. Accepts:
[131] Fix | Delete
* - 'id'
[132] Fix | Delete
* - 'domain'
[133] Fix | Delete
* - 'path'
[134] Fix | Delete
* - 'network_id'
[135] Fix | Delete
* - 'last_updated'
[136] Fix | Delete
* - 'registered'
[137] Fix | Delete
* - 'domain_length'
[138] Fix | Delete
* - 'path_length'
[139] Fix | Delete
* - 'site__in'
[140] Fix | Delete
* - 'network__in'
[141] Fix | Delete
* - 'deleted'
[142] Fix | Delete
* - 'mature'
[143] Fix | Delete
* - 'spam'
[144] Fix | Delete
* - 'archived'
[145] Fix | Delete
* - 'public'
[146] Fix | Delete
* - false, an empty array, or 'none' to disable `ORDER BY` clause.
[147] Fix | Delete
* Default 'id'.
[148] Fix | Delete
* @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
[149] Fix | Delete
* @type int $network_id Limit results to those affiliated with a given network ID. If 0,
[150] Fix | Delete
* include all networks. Default 0.
[151] Fix | Delete
* @type int[] $network__in Array of network IDs to include affiliated sites for. Default empty.
[152] Fix | Delete
* @type int[] $network__not_in Array of network IDs to exclude affiliated sites for. Default empty.
[153] Fix | Delete
* @type string $domain Limit results to those affiliated with a given domain. Default empty.
[154] Fix | Delete
* @type string[] $domain__in Array of domains to include affiliated sites for. Default empty.
[155] Fix | Delete
* @type string[] $domain__not_in Array of domains to exclude affiliated sites for. Default empty.
[156] Fix | Delete
* @type string $path Limit results to those affiliated with a given path. Default empty.
[157] Fix | Delete
* @type string[] $path__in Array of paths to include affiliated sites for. Default empty.
[158] Fix | Delete
* @type string[] $path__not_in Array of paths to exclude affiliated sites for. Default empty.
[159] Fix | Delete
* @type int $public Limit results to public sites. Accepts 1 or 0. Default empty.
[160] Fix | Delete
* @type int $archived Limit results to archived sites. Accepts 1 or 0. Default empty.
[161] Fix | Delete
* @type int $mature Limit results to mature sites. Accepts 1 or 0. Default empty.
[162] Fix | Delete
* @type int $spam Limit results to spam sites. Accepts 1 or 0. Default empty.
[163] Fix | Delete
* @type int $deleted Limit results to deleted sites. Accepts 1 or 0. Default empty.
[164] Fix | Delete
* @type int $lang_id Limit results to a language ID. Default empty.
[165] Fix | Delete
* @type string[] $lang__in Array of language IDs to include affiliated sites for. Default empty.
[166] Fix | Delete
* @type string[] $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty.
[167] Fix | Delete
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
[168] Fix | Delete
* @type string[] $search_columns Array of column names to be searched. Accepts 'domain' and 'path'.
[169] Fix | Delete
* Default empty array.
[170] Fix | Delete
* @type bool $update_site_cache Whether to prime the cache for found sites. Default true.
[171] Fix | Delete
* @type bool $update_site_meta_cache Whether to prime the metadata cache for found sites. Default true.
[172] Fix | Delete
* @type string|string[] $meta_key Meta key or keys to filter by.
[173] Fix | Delete
* @type string|string[] $meta_value Meta value or values to filter by.
[174] Fix | Delete
* @type string $meta_compare MySQL operator used for comparing the meta value.
[175] Fix | Delete
* See WP_Meta_Query::__construct() for accepted values and default value.
[176] Fix | Delete
* @type string $meta_compare_key MySQL operator used for comparing the meta key.
[177] Fix | Delete
* See WP_Meta_Query::__construct() for accepted values and default value.
[178] Fix | Delete
* @type string $meta_type MySQL data type that the meta_value column will be CAST to for comparisons.
[179] Fix | Delete
* See WP_Meta_Query::__construct() for accepted values and default value.
[180] Fix | Delete
* @type string $meta_type_key MySQL data type that the meta_key column will be CAST to for comparisons.
[181] Fix | Delete
* See WP_Meta_Query::__construct() for accepted values and default value.
[182] Fix | Delete
* @type array $meta_query An associative array of WP_Meta_Query arguments.
[183] Fix | Delete
* See WP_Meta_Query::__construct() for accepted values.
[184] Fix | Delete
* }
[185] Fix | Delete
*/
[186] Fix | Delete
public function __construct( $query = '' ) {
[187] Fix | Delete
$this->query_var_defaults = array(
[188] Fix | Delete
'fields' => '',
[189] Fix | Delete
'ID' => '',
[190] Fix | Delete
'site__in' => '',
[191] Fix | Delete
'site__not_in' => '',
[192] Fix | Delete
'number' => 100,
[193] Fix | Delete
'offset' => '',
[194] Fix | Delete
'no_found_rows' => true,
[195] Fix | Delete
'orderby' => 'id',
[196] Fix | Delete
'order' => 'ASC',
[197] Fix | Delete
'network_id' => 0,
[198] Fix | Delete
'network__in' => '',
[199] Fix | Delete
'network__not_in' => '',
[200] Fix | Delete
'domain' => '',
[201] Fix | Delete
'domain__in' => '',
[202] Fix | Delete
'domain__not_in' => '',
[203] Fix | Delete
'path' => '',
[204] Fix | Delete
'path__in' => '',
[205] Fix | Delete
'path__not_in' => '',
[206] Fix | Delete
'public' => null,
[207] Fix | Delete
'archived' => null,
[208] Fix | Delete
'mature' => null,
[209] Fix | Delete
'spam' => null,
[210] Fix | Delete
'deleted' => null,
[211] Fix | Delete
'lang_id' => null,
[212] Fix | Delete
'lang__in' => '',
[213] Fix | Delete
'lang__not_in' => '',
[214] Fix | Delete
'search' => '',
[215] Fix | Delete
'search_columns' => array(),
[216] Fix | Delete
'count' => false,
[217] Fix | Delete
'date_query' => null, // See WP_Date_Query.
[218] Fix | Delete
'update_site_cache' => true,
[219] Fix | Delete
'update_site_meta_cache' => true,
[220] Fix | Delete
'meta_query' => '',
[221] Fix | Delete
'meta_key' => '',
[222] Fix | Delete
'meta_value' => '',
[223] Fix | Delete
'meta_type' => '',
[224] Fix | Delete
'meta_compare' => '',
[225] Fix | Delete
);
[226] Fix | Delete
[227] Fix | Delete
if ( ! empty( $query ) ) {
[228] Fix | Delete
$this->query( $query );
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Parses arguments passed to the site query with default query parameters.
[234] Fix | Delete
*
[235] Fix | Delete
* @since 4.6.0
[236] Fix | Delete
*
[237] Fix | Delete
* @see WP_Site_Query::__construct()
[238] Fix | Delete
*
[239] Fix | Delete
* @param string|array $query Array or string of WP_Site_Query arguments. See WP_Site_Query::__construct().
[240] Fix | Delete
*/
[241] Fix | Delete
public function parse_query( $query = '' ) {
[242] Fix | Delete
if ( empty( $query ) ) {
[243] Fix | Delete
$query = $this->query_vars;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$this->query_vars = wp_parse_args( $query, $this->query_var_defaults );
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Fires after the site query vars have been parsed.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 4.6.0
[252] Fix | Delete
*
[253] Fix | Delete
* @param WP_Site_Query $query The WP_Site_Query instance (passed by reference).
[254] Fix | Delete
*/
[255] Fix | Delete
do_action_ref_array( 'parse_site_query', array( &$this ) );
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* Sets up the WordPress query for retrieving sites.
[260] Fix | Delete
*
[261] Fix | Delete
* @since 4.6.0
[262] Fix | Delete
*
[263] Fix | Delete
* @param string|array $query Array or URL query string of parameters.
[264] Fix | Delete
* @return array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids',
[265] Fix | Delete
* or the number of sites when 'count' is passed as a query var.
[266] Fix | Delete
*/
[267] Fix | Delete
public function query( $query ) {
[268] Fix | Delete
$this->query_vars = wp_parse_args( $query );
[269] Fix | Delete
[270] Fix | Delete
return $this->get_sites();
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Retrieves a list of sites matching the query vars.
[275] Fix | Delete
*
[276] Fix | Delete
* @since 4.6.0
[277] Fix | Delete
*
[278] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[279] Fix | Delete
*
[280] Fix | Delete
* @return array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids',
[281] Fix | Delete
* or the number of sites when 'count' is passed as a query var.
[282] Fix | Delete
*/
[283] Fix | Delete
public function get_sites() {
[284] Fix | Delete
global $wpdb;
[285] Fix | Delete
[286] Fix | Delete
$this->parse_query();
[287] Fix | Delete
[288] Fix | Delete
// Parse meta query.
[289] Fix | Delete
$this->meta_query = new WP_Meta_Query();
[290] Fix | Delete
$this->meta_query->parse_query_vars( $this->query_vars );
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Fires before sites are retrieved.
[294] Fix | Delete
*
[295] Fix | Delete
* @since 4.6.0
[296] Fix | Delete
*
[297] Fix | Delete
* @param WP_Site_Query $query Current instance of WP_Site_Query (passed by reference).
[298] Fix | Delete
*/
[299] Fix | Delete
do_action_ref_array( 'pre_get_sites', array( &$this ) );
[300] Fix | Delete
[301] Fix | Delete
// Reparse query vars, in case they were modified in a 'pre_get_sites' callback.
[302] Fix | Delete
$this->meta_query->parse_query_vars( $this->query_vars );
[303] Fix | Delete
if ( ! empty( $this->meta_query->queries ) ) {
[304] Fix | Delete
$this->meta_query_clauses = $this->meta_query->get_sql( 'blog', $wpdb->blogs, 'blog_id', $this );
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
$site_data = null;
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* Filters the site data before the get_sites query takes place.
[311] Fix | Delete
*
[312] Fix | Delete
* Return a non-null value to bypass WordPress' default site queries.
[313] Fix | Delete
*
[314] Fix | Delete
* The expected return type from this filter depends on the value passed
[315] Fix | Delete
* in the request query vars:
[316] Fix | Delete
* - When `$this->query_vars['count']` is set, the filter should return
[317] Fix | Delete
* the site count as an integer.
[318] Fix | Delete
* - When `'ids' === $this->query_vars['fields']`, the filter should return
[319] Fix | Delete
* an array of site IDs.
[320] Fix | Delete
* - Otherwise the filter should return an array of WP_Site objects.
[321] Fix | Delete
*
[322] Fix | Delete
* Note that if the filter returns an array of site data, it will be assigned
[323] Fix | Delete
* to the `sites` property of the current WP_Site_Query instance.
[324] Fix | Delete
*
[325] Fix | Delete
* Filtering functions that require pagination information are encouraged to set
[326] Fix | Delete
* the `found_sites` and `max_num_pages` properties of the WP_Site_Query object,
[327] Fix | Delete
* passed to the filter by reference. If WP_Site_Query does not perform a database
[328] Fix | Delete
* query, it will not have enough information to generate these values itself.
[329] Fix | Delete
*
[330] Fix | Delete
* @since 5.2.0
[331] Fix | Delete
* @since 5.6.0 The returned array of site data is assigned to the `sites` property
[332] Fix | Delete
* of the current WP_Site_Query instance.
[333] Fix | Delete
*
[334] Fix | Delete
* @param array|int|null $site_data Return an array of site data to short-circuit WP's site query,
[335] Fix | Delete
* the site count as an integer if `$this->query_vars['count']` is set,
[336] Fix | Delete
* or null to run the normal queries.
[337] Fix | Delete
* @param WP_Site_Query $query The WP_Site_Query instance, passed by reference.
[338] Fix | Delete
*/
[339] Fix | Delete
$site_data = apply_filters_ref_array( 'sites_pre_query', array( $site_data, &$this ) );
[340] Fix | Delete
[341] Fix | Delete
if ( null !== $site_data ) {
[342] Fix | Delete
if ( is_array( $site_data ) && ! $this->query_vars['count'] ) {
[343] Fix | Delete
$this->sites = $site_data;
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
return $site_data;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
[350] Fix | Delete
$_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
[351] Fix | Delete
[352] Fix | Delete
// Ignore the $fields, $update_site_cache, $update_site_meta_cache argument as the queried result will be the same regardless.
[353] Fix | Delete
unset( $_args['fields'], $_args['update_site_cache'], $_args['update_site_meta_cache'] );
[354] Fix | Delete
[355] Fix | Delete
$key = md5( serialize( $_args ) );
[356] Fix | Delete
$last_changed = wp_cache_get_last_changed( 'sites' );
[357] Fix | Delete
[358] Fix | Delete
$cache_key = "get_sites:$key:$last_changed";
[359] Fix | Delete
$cache_value = wp_cache_get( $cache_key, 'site-queries' );
[360] Fix | Delete
[361] Fix | Delete
if ( false === $cache_value ) {
[362] Fix | Delete
$site_ids = $this->get_site_ids();
[363] Fix | Delete
if ( $site_ids ) {
[364] Fix | Delete
$this->set_found_sites();
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
$cache_value = array(
[368] Fix | Delete
'site_ids' => $site_ids,
[369] Fix | Delete
'found_sites' => $this->found_sites,
[370] Fix | Delete
);
[371] Fix | Delete
wp_cache_add( $cache_key, $cache_value, 'site-queries' );
[372] Fix | Delete
} else {
[373] Fix | Delete
$site_ids = $cache_value['site_ids'];
[374] Fix | Delete
$this->found_sites = $cache_value['found_sites'];
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
if ( $this->found_sites && $this->query_vars['number'] ) {
[378] Fix | Delete
$this->max_num_pages = (int) ceil( $this->found_sites / $this->query_vars['number'] );
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
// If querying for a count only, there's nothing more to do.
[382] Fix | Delete
if ( $this->query_vars['count'] ) {
[383] Fix | Delete
// $site_ids is actually a count in this case.
[384] Fix | Delete
return (int) $site_ids;
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
$site_ids = array_map( 'intval', $site_ids );
[388] Fix | Delete
[389] Fix | Delete
if ( $this->query_vars['update_site_meta_cache'] ) {
[390] Fix | Delete
wp_lazyload_site_meta( $site_ids );
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
if ( 'ids' === $this->query_vars['fields'] ) {
[394] Fix | Delete
$this->sites = $site_ids;
[395] Fix | Delete
[396] Fix | Delete
return $this->sites;
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
// Prime site network caches.
[400] Fix | Delete
if ( $this->query_vars['update_site_cache'] ) {
[401] Fix | Delete
_prime_site_caches( $site_ids, false );
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
// Fetch full site objects from the primed cache.
[405] Fix | Delete
$_sites = array();
[406] Fix | Delete
foreach ( $site_ids as $site_id ) {
[407] Fix | Delete
$_site = get_site( $site_id );
[408] Fix | Delete
if ( $_site ) {
[409] Fix | Delete
$_sites[] = $_site;
[410] Fix | Delete
}
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
/**
[414] Fix | Delete
* Filters the site query results.
[415] Fix | Delete
*
[416] Fix | Delete
* @since 4.6.0
[417] Fix | Delete
*
[418] Fix | Delete
* @param WP_Site[] $_sites An array of WP_Site objects.
[419] Fix | Delete
* @param WP_Site_Query $query Current instance of WP_Site_Query (passed by reference).
[420] Fix | Delete
*/
[421] Fix | Delete
$_sites = apply_filters_ref_array( 'the_sites', array( $_sites, &$this ) );
[422] Fix | Delete
[423] Fix | Delete
// Convert to WP_Site instances.
[424] Fix | Delete
$this->sites = array_map( 'get_site', $_sites );
[425] Fix | Delete
[426] Fix | Delete
return $this->sites;
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
/**
[430] Fix | Delete
* Used internally to get a list of site IDs matching the query vars.
[431] Fix | Delete
*
[432] Fix | Delete
* @since 4.6.0
[433] Fix | Delete
*
[434] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[435] Fix | Delete
*
[436] Fix | Delete
* @return int|array A single count of site IDs if a count query. An array of site IDs if a full query.
[437] Fix | Delete
*/
[438] Fix | Delete
protected function get_site_ids() {
[439] Fix | Delete
global $wpdb;
[440] Fix | Delete
[441] Fix | Delete
$order = $this->parse_order( $this->query_vars['order'] );
[442] Fix | Delete
[443] Fix | Delete
// Disable ORDER BY with 'none', an empty array, or boolean false.
[444] Fix | Delete
if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) {
[445] Fix | Delete
$orderby = '';
[446] Fix | Delete
} elseif ( ! empty( $this->query_vars['orderby'] ) ) {
[447] Fix | Delete
$ordersby = is_array( $this->query_vars['orderby'] ) ?
[448] Fix | Delete
$this->query_vars['orderby'] :
[449] Fix | Delete
preg_split( '/[,\s]/', $this->query_vars['orderby'] );
[450] Fix | Delete
[451] Fix | Delete
$orderby_array = array();
[452] Fix | Delete
foreach ( $ordersby as $_key => $_value ) {
[453] Fix | Delete
if ( ! $_value ) {
[454] Fix | Delete
continue;
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
if ( is_int( $_key ) ) {
[458] Fix | Delete
$_orderby = $_value;
[459] Fix | Delete
$_order = $order;
[460] Fix | Delete
} else {
[461] Fix | Delete
$_orderby = $_key;
[462] Fix | Delete
$_order = $_value;
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
$parsed = $this->parse_orderby( $_orderby );
[466] Fix | Delete
[467] Fix | Delete
if ( ! $parsed ) {
[468] Fix | Delete
continue;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
if ( 'site__in' === $_orderby || 'network__in' === $_orderby ) {
[472] Fix | Delete
$orderby_array[] = $parsed;
[473] Fix | Delete
continue;
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
$orderby = implode( ', ', $orderby_array );
[480] Fix | Delete
} else {
[481] Fix | Delete
$orderby = "{$wpdb->blogs}.blog_id $order";
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
$number = absint( $this->query_vars['number'] );
[485] Fix | Delete
$offset = absint( $this->query_vars['offset'] );
[486] Fix | Delete
$limits = '';
[487] Fix | Delete
[488] Fix | Delete
if ( ! empty( $number ) ) {
[489] Fix | Delete
if ( $offset ) {
[490] Fix | Delete
$limits = 'LIMIT ' . $offset . ',' . $number;
[491] Fix | Delete
} else {
[492] Fix | Delete
$limits = 'LIMIT ' . $number;
[493] Fix | Delete
}
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
if ( $this->query_vars['count'] ) {
[497] Fix | Delete
$fields = 'COUNT(*)';
[498] Fix | Delete
} else {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function