WP_Site_Query

Core class used for querying sites.

Defined (1)

The class is defined in the following location(s).

/wp-includes/class-wp-site-query.php  
  1. class WP_Site_Query { 
  2.  
  3. /** 
  4. * SQL for database query. 
  5. * @since 4.6.0 
  6. * @access public 
  7. * @var string 
  8. */ 
  9. public $request; 
  10.  
  11. /** 
  12. * SQL query clauses. 
  13. * @since 4.6.0 
  14. * @access protected 
  15. * @var array 
  16. */ 
  17. protected $sql_clauses = array( 
  18. 'select' => '',  
  19. 'from' => '',  
  20. 'where' => array(),  
  21. 'groupby' => '',  
  22. 'orderby' => '',  
  23. 'limits' => '',  
  24. ); 
  25.  
  26. /** 
  27. * Date query container. 
  28. * @since 4.6.0 
  29. * @access public 
  30. * @var object WP_Date_Query 
  31. */ 
  32. public $date_query = false; 
  33.  
  34. /** 
  35. * Query vars set by the user. 
  36. * @since 4.6.0 
  37. * @access public 
  38. * @var array 
  39. */ 
  40. public $query_vars; 
  41.  
  42. /** 
  43. * Default values for query vars. 
  44. * @since 4.6.0 
  45. * @access public 
  46. * @var array 
  47. */ 
  48. public $query_var_defaults; 
  49.  
  50. /** 
  51. * List of sites located by the query. 
  52. * @since 4.6.0 
  53. * @access public 
  54. * @var array 
  55. */ 
  56. public $sites; 
  57.  
  58. /** 
  59. * The amount of found sites for the current query. 
  60. * @since 4.6.0 
  61. * @access public 
  62. * @var int 
  63. */ 
  64. public $found_sites = 0; 
  65.  
  66. /** 
  67. * The number of pages. 
  68. * @since 4.6.0 
  69. * @access public 
  70. * @var int 
  71. */ 
  72. public $max_num_pages = 0; 
  73.  
  74. /** 
  75. * Sets up the site query, based on the query vars passed. 
  76. * @since 4.6.0 
  77. * @access public 
  78. * @param string|array $query { 
  79. * Optional. Array or query string of site query parameters. Default empty. 
  80. * @type array $site__in Array of site IDs to include. Default empty. 
  81. * @type array $site__not_in Array of site IDs to exclude. Default empty. 
  82. * @type bool $count Whether to return a site count (true) or array of site objects. 
  83. * Default false. 
  84. * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. 
  85. * Default null. 
  86. * @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs) 
  87. * or empty (returns an array of complete site objects). Default empty. 
  88. * @type int $ID A site ID to only return that site. Default empty. 
  89. * @type int $number Maximum number of sites to retrieve. Default 100. 
  90. * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. 
  91. * Default 0. 
  92. * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 
  93. * @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path',  
  94. * 'network_id', 'last_updated', 'registered', 'domain_length',  
  95. * 'path_length', 'site__in' and 'network__in'. Also accepts false,  
  96. * an empty array, or 'none' to disable `ORDER BY` clause. 
  97. * Default 'id'. 
  98. * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'. 
  99. * @type int $network_id Limit results to those affiliated with a given network ID. If 0,  
  100. * include all networks. Default 0. 
  101. * @type array $network__in Array of network IDs to include affiliated sites for. Default empty. 
  102. * @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty. 
  103. * @type string $domain Limit results to those affiliated with a given domain. Default empty. 
  104. * @type array $domain__in Array of domains to include affiliated sites for. Default empty. 
  105. * @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty. 
  106. * @type string $path Limit results to those affiliated with a given path. Default empty. 
  107. * @type array $path__in Array of paths to include affiliated sites for. Default empty. 
  108. * @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty. 
  109. * @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty. 
  110. * @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty. 
  111. * @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty. 
  112. * @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty. 
  113. * @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty. 
  114. * @type string $search Search term(s) to retrieve matching sites for. Default empty. 
  115. * @type array $search_columns Array of column names to be searched. Accepts 'domain' and 'path'. 
  116. * Default empty array. 
  117. * @type bool $update_site_cache Whether to prime the cache for found sites. Default false. 
  118. * } 
  119. */ 
  120. public function __construct( $query = '' ) { 
  121. $this->query_var_defaults = array( 
  122. 'fields' => '',  
  123. 'ID' => '',  
  124. 'site__in' => '',  
  125. 'site__not_in' => '',  
  126. 'number' => 100,  
  127. 'offset' => '',  
  128. 'no_found_rows' => true,  
  129. 'orderby' => 'id',  
  130. 'order' => 'ASC',  
  131. 'network_id' => 0,  
  132. 'network__in' => '',  
  133. 'network__not_in' => '',  
  134. 'domain' => '',  
  135. 'domain__in' => '',  
  136. 'domain__not_in' => '',  
  137. 'path' => '',  
  138. 'path__in' => '',  
  139. 'path__not_in' => '',  
  140. 'public' => null,  
  141. 'archived' => null,  
  142. 'mature' => null,  
  143. 'spam' => null,  
  144. 'deleted' => null,  
  145. 'search' => '',  
  146. 'search_columns' => array(),  
  147. 'count' => false,  
  148. 'date_query' => null, // See WP_Date_Query 
  149. 'update_site_cache' => true,  
  150. ); 
  151.  
  152. if ( ! empty( $query ) ) { 
  153. $this->query( $query ); 
  154.  
  155. /** 
  156. * Parses arguments passed to the site query with default query parameters. 
  157. * @since 4.6.0 
  158. * @access public 
  159. * @see WP_Site_Query::__construct() 
  160. * @param string|array $query Array or string of WP_Site_Query arguments. See WP_Site_Query::__construct(). 
  161. */ 
  162. public function parse_query( $query = '' ) { 
  163. if ( empty( $query ) ) { 
  164. $query = $this->query_vars; 
  165.  
  166. $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); 
  167.  
  168. /** 
  169. * Fires after the site query vars have been parsed. 
  170. * @since 4.6.0 
  171. * @param WP_Site_Query &$this The WP_Site_Query instance (passed by reference). 
  172. */ 
  173. do_action_ref_array( 'parse_site_query', array( &$this ) ); 
  174.  
  175. /** 
  176. * Sets up the WordPress query for retrieving sites. 
  177. * @since 4.6.0 
  178. * @access public 
  179. * @param string|array $query Array or URL query string of parameters. 
  180. * @return array|int List of sites, or number of sites when 'count' is passed as a query var. 
  181. */ 
  182. public function query( $query ) { 
  183. $this->query_vars = wp_parse_args( $query ); 
  184.  
  185. return $this->get_sites(); 
  186.  
  187. /** 
  188. * Retrieves a list of sites matching the query vars. 
  189. * @since 4.6.0 
  190. * @access public 
  191. * @return array|int List of sites, or number of sites when 'count' is passed as a query var. 
  192. */ 
  193. public function get_sites() { 
  194. $this->parse_query(); 
  195.  
  196. /** 
  197. * Fires before sites are retrieved. 
  198. * @since 4.6.0 
  199. * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 
  200. */ 
  201. do_action_ref_array( 'pre_get_sites', array( &$this ) ); 
  202.  
  203. // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 
  204. $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) ); 
  205. $last_changed = wp_cache_get_last_changed( 'sites' ); 
  206.  
  207. $cache_key = "get_sites:$key:$last_changed"; 
  208. $cache_value = wp_cache_get( $cache_key, 'sites' ); 
  209.  
  210. if ( false === $cache_value ) { 
  211. $site_ids = $this->get_site_ids(); 
  212. if ( $site_ids ) { 
  213. $this->set_found_sites(); 
  214.  
  215. $cache_value = array( 
  216. 'site_ids' => $site_ids,  
  217. 'found_sites' => $this->found_sites,  
  218. ); 
  219. wp_cache_add( $cache_key, $cache_value, 'sites' ); 
  220. } else { 
  221. $site_ids = $cache_value['site_ids']; 
  222. $this->found_sites = $cache_value['found_sites']; 
  223.  
  224. if ( $this->found_sites && $this->query_vars['number'] ) { 
  225. $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); 
  226.  
  227. // If querying for a count only, there's nothing more to do. 
  228. if ( $this->query_vars['count'] ) { 
  229. // $site_ids is actually a count in this case. 
  230. return intval( $site_ids ); 
  231.  
  232. $site_ids = array_map( 'intval', $site_ids ); 
  233.  
  234. if ( 'ids' == $this->query_vars['fields'] ) { 
  235. $this->sites = $site_ids; 
  236.  
  237. return $this->sites; 
  238.  
  239. // Prime site network caches. 
  240. if ( $this->query_vars['update_site_cache'] ) { 
  241. _prime_site_caches( $site_ids ); 
  242.  
  243. // Fetch full site objects from the primed cache. 
  244. $_sites = array(); 
  245. foreach ( $site_ids as $site_id ) { 
  246. if ( $_site = get_site( $site_id ) ) { 
  247. $_sites[] = $_site; 
  248.  
  249. /** 
  250. * Filters the site query results. 
  251. * @since 4.6.0 
  252. * @param array $results An array of sites. 
  253. * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 
  254. */ 
  255. $_sites = apply_filters_ref_array( 'the_sites', array( $_sites, &$this ) ); 
  256.  
  257. // Convert to WP_Site instances. 
  258. $this->sites = array_map( 'get_site', $_sites ); 
  259.  
  260. return $this->sites; 
  261.  
  262. /** 
  263. * Used internally to get a list of site IDs matching the query vars. 
  264. * @since 4.6.0 
  265. * @access protected 
  266. * @global wpdb $wpdb WordPress database abstraction object. 
  267. * @return int|array A single count of site IDs if a count query. An array of site IDs if a full query. 
  268. */ 
  269. protected function get_site_ids() { 
  270. global $wpdb; 
  271.  
  272. $order = $this->parse_order( $this->query_vars['order'] ); 
  273.  
  274. // Disable ORDER BY with 'none', an empty array, or boolean false. 
  275. if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) { 
  276. $orderby = ''; 
  277. } elseif ( ! empty( $this->query_vars['orderby'] ) ) { 
  278. $ordersby = is_array( $this->query_vars['orderby'] ) ? 
  279. $this->query_vars['orderby'] : 
  280. preg_split( '/[, \s]/', $this->query_vars['orderby'] ); 
  281.  
  282. $orderby_array = array(); 
  283. foreach ( $ordersby as $_key => $_value ) { 
  284. if ( ! $_value ) { 
  285. continue; 
  286.  
  287. if ( is_int( $_key ) ) { 
  288. $_orderby = $_value; 
  289. $_order = $order; 
  290. } else { 
  291. $_orderby = $_key; 
  292. $_order = $_value; 
  293.  
  294. $parsed = $this->parse_orderby( $_orderby ); 
  295.  
  296. if ( ! $parsed ) { 
  297. continue; 
  298.  
  299. if ( 'site__in' === $_orderby || 'network__in' === $_orderby ) { 
  300. $orderby_array[] = $parsed; 
  301. continue; 
  302.  
  303. $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); 
  304.  
  305. $orderby = implode( ', ', $orderby_array ); 
  306. } else { 
  307. $orderby = "blog_id $order"; 
  308.  
  309. $number = absint( $this->query_vars['number'] ); 
  310. $offset = absint( $this->query_vars['offset'] ); 
  311.  
  312. if ( ! empty( $number ) ) { 
  313. if ( $offset ) { 
  314. $limits = 'LIMIT ' . $offset . ', ' . $number; 
  315. } else { 
  316. $limits = 'LIMIT ' . $number; 
  317.  
  318. if ( $this->query_vars['count'] ) { 
  319. $fields = 'COUNT(*)'; 
  320. } else { 
  321. $fields = 'blog_id'; 
  322.  
  323. // Parse site IDs for an IN clause. 
  324. $site_id = absint( $this->query_vars['ID'] ); 
  325. if ( ! empty( $site_id ) ) { 
  326. $this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id ); 
  327.  
  328. // Parse site IDs for an IN clause. 
  329. if ( ! empty( $this->query_vars['site__in'] ) ) { 
  330. $this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode( ', ', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )'; 
  331.  
  332. // Parse site IDs for a NOT IN clause. 
  333. if ( ! empty( $this->query_vars['site__not_in'] ) ) { 
  334. $this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode( ', ', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )'; 
  335.  
  336. $network_id = absint( $this->query_vars['network_id'] ); 
  337.  
  338. if ( ! empty( $network_id ) ) { 
  339. $this->sql_clauses['where']['network_id'] = $wpdb->prepare( 'site_id = %d', $network_id ); 
  340.  
  341. // Parse site network IDs for an IN clause. 
  342. if ( ! empty( $this->query_vars['network__in'] ) ) { 
  343. $this->sql_clauses['where']['network__in'] = 'site_id IN ( ' . implode( ', ', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; 
  344.  
  345. // Parse site network IDs for a NOT IN clause. 
  346. if ( ! empty( $this->query_vars['network__not_in'] ) ) { 
  347. $this->sql_clauses['where']['network__not_in'] = 'site_id NOT IN ( ' . implode( ', ', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; 
  348.  
  349. if ( ! empty( $this->query_vars['domain'] ) ) { 
  350. $this->sql_clauses['where']['domain'] = $wpdb->prepare( 'domain = %s', $this->query_vars['domain'] ); 
  351.  
  352. // Parse site domain for an IN clause. 
  353. if ( is_array( $this->query_vars['domain__in'] ) ) { 
  354. $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 
  355.  
  356. // Parse site domain for a NOT IN clause. 
  357. if ( is_array( $this->query_vars['domain__not_in'] ) ) { 
  358. $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 
  359.  
  360. if ( ! empty( $this->query_vars['path'] ) ) { 
  361. $this->sql_clauses['where']['path'] = $wpdb->prepare( 'path = %s', $this->query_vars['path'] ); 
  362.  
  363. // Parse site path for an IN clause. 
  364. if ( is_array( $this->query_vars['path__in'] ) ) { 
  365. $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )"; 
  366.  
  367. // Parse site path for a NOT IN clause. 
  368. if ( is_array( $this->query_vars['path__not_in'] ) ) { 
  369. $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 
  370.  
  371. if ( is_numeric( $this->query_vars['archived'] ) ) { 
  372. $archived = absint( $this->query_vars['archived'] ); 
  373. $this->sql_clauses['where']['archived'] = $wpdb->prepare( "archived = %d ", $archived ); 
  374.  
  375. if ( is_numeric( $this->query_vars['mature'] ) ) { 
  376. $mature = absint( $this->query_vars['mature'] ); 
  377. $this->sql_clauses['where']['mature'] = $wpdb->prepare( "mature = %d ", $mature ); 
  378.  
  379. if ( is_numeric( $this->query_vars['spam'] ) ) { 
  380. $spam = absint( $this->query_vars['spam'] ); 
  381. $this->sql_clauses['where']['spam'] = $wpdb->prepare( "spam = %d ", $spam ); 
  382.  
  383. if ( is_numeric( $this->query_vars['deleted'] ) ) { 
  384. $deleted = absint( $this->query_vars['deleted'] ); 
  385. $this->sql_clauses['where']['deleted'] = $wpdb->prepare( "deleted = %d ", $deleted ); 
  386.  
  387. if ( is_numeric( $this->query_vars['public'] ) ) { 
  388. $public = absint( $this->query_vars['public'] ); 
  389. $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public ); 
  390.  
  391. // Falsey search strings are ignored. 
  392. if ( strlen( $this->query_vars['search'] ) ) { 
  393. $search_columns = array(); 
  394.  
  395. if ( $this->query_vars['search_columns'] ) { 
  396. $search_columns = array_intersect( $this->query_vars['search_columns'], array( 'domain', 'path' ) ); 
  397.  
  398. if ( ! $search_columns ) { 
  399. $search_columns = array( 'domain', 'path' ); 
  400.  
  401. /** 
  402. * Filters the columns to search in a WP_Site_Query search. 
  403. * The default columns include 'domain' and 'path. 
  404. * @since 4.6.0 
  405. * @param array $search_columns Array of column names to be searched. 
  406. * @param string $search Text being searched. 
  407. * @param WP_Site_Query $this The current WP_Site_Query instance. 
  408. */ 
  409. $search_columns = apply_filters( 'site_search_columns', $search_columns, $this->query_vars['search'], $this ); 
  410.  
  411. $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search'], $search_columns ); 
  412.  
  413. $date_query = $this->query_vars['date_query']; 
  414. if ( ! empty( $date_query ) && is_array( $date_query ) ) { 
  415. $this->date_query = new WP_Date_Query( $date_query, 'registered' ); 
  416. $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() ); 
  417.  
  418. $join = ''; 
  419.  
  420. $where = implode( ' AND ', $this->sql_clauses['where'] ); 
  421.  
  422. $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); 
  423.  
  424. /** 
  425. * Filters the site query clauses. 
  426. * @since 4.6.0 
  427. * @param array $pieces A compacted array of site query clauses. 
  428. * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 
  429. */ 
  430. $clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) ); 
  431.  
  432. $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; 
  433. $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; 
  434. $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; 
  435. $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; 
  436. $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; 
  437. $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; 
  438.  
  439. if ( $where ) { 
  440. $where = 'WHERE ' . $where; 
  441.  
  442. if ( $groupby ) { 
  443. $groupby = 'GROUP BY ' . $groupby; 
  444.  
  445. if ( $orderby ) { 
  446. $orderby = "ORDER BY $orderby"; 
  447.  
  448. $found_rows = ''; 
  449. if ( ! $this->query_vars['no_found_rows'] ) { 
  450. $found_rows = 'SQL_CALC_FOUND_ROWS'; 
  451.  
  452. $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 
  453. $this->sql_clauses['from'] = "FROM $wpdb->blogs $join"; 
  454. $this->sql_clauses['groupby'] = $groupby; 
  455. $this->sql_clauses['orderby'] = $orderby; 
  456. $this->sql_clauses['limits'] = $limits; 
  457.  
  458. $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; 
  459.  
  460. if ( $this->query_vars['count'] ) { 
  461. return intval( $wpdb->get_var( $this->request ) ); 
  462.  
  463. $site_ids = $wpdb->get_col( $this->request ); 
  464.  
  465. return array_map( 'intval', $site_ids ); 
  466.  
  467. /** 
  468. * Populates found_sites and max_num_pages properties for the current query 
  469. * if the limit clause was used. 
  470. * @since 4.6.0 
  471. * @access private 
  472. * @global wpdb $wpdb WordPress database abstraction object. 
  473. */ 
  474. private function set_found_sites() { 
  475. global $wpdb; 
  476.  
  477. if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 
  478. /** 
  479. * Filters the query used to retrieve found site count. 
  480. * @since 4.6.0 
  481. * @param string $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'. 
  482. * @param WP_Site_Query $site_query The `WP_Site_Query` instance. 
  483. */ 
  484. $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 
  485.  
  486. $this->found_sites = (int) $wpdb->get_var( $found_sites_query ); 
  487.  
  488. /** 
  489. * Used internally to generate an SQL string for searching across multiple columns. 
  490. * @since 4.6.0 
  491. * @access protected 
  492. * @global wpdb $wpdb WordPress database abstraction object. 
  493. * @param string $string Search string. 
  494. * @param array $columns Columns to search. 
  495. * @return string Search SQL. 
  496. */ 
  497. protected function get_search_sql( $string, $columns ) { 
  498. global $wpdb; 
  499.  
  500. if ( false !== strpos( $string, '*' ) ) { 
  501. $like = '%' . implode( '%', array_map( array( $wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%'; 
  502. } else { 
  503. $like = '%' . $wpdb->esc_like( $string ) . '%'; 
  504.  
  505. $searches = array(); 
  506. foreach ( $columns as $column ) { 
  507. $searches[] = $wpdb->prepare( "$column LIKE %s", $like ); 
  508.  
  509. return '(' . implode( ' OR ', $searches ) . ')'; 
  510.  
  511. /** 
  512. * Parses and sanitizes 'orderby' keys passed to the site query. 
  513. * @since 4.6.0 
  514. * @access protected 
  515. * @global wpdb $wpdb WordPress database abstraction object. 
  516. * @param string $orderby Alias for the field to order by. 
  517. * @return string|false Value to used in the ORDER clause. False otherwise. 
  518. */ 
  519. protected function parse_orderby( $orderby ) { 
  520. global $wpdb; 
  521.  
  522. $parsed = false; 
  523.  
  524. switch ( $orderby ) { 
  525. case 'site__in': 
  526. $site__in = implode( ', ', array_map( 'absint', $this->query_vars['site__in'] ) ); 
  527. $parsed = "FIELD( {$wpdb->blogs}.blog_id, $site__in )"; 
  528. break; 
  529. case 'network__in': 
  530. $network__in = implode( ', ', array_map( 'absint', $this->query_vars['network__in'] ) ); 
  531. $parsed = "FIELD( {$wpdb->blogs}.site_id, $network__in )"; 
  532. break; 
  533. case 'domain': 
  534. case 'last_updated': 
  535. case 'path': 
  536. case 'registered': 
  537. $parsed = $orderby; 
  538. break; 
  539. case 'network_id': 
  540. $parsed = 'site_id'; 
  541. break; 
  542. case 'domain_length': 
  543. $parsed = 'CHAR_LENGTH(domain)'; 
  544. break; 
  545. case 'path_length': 
  546. $parsed = 'CHAR_LENGTH(path)'; 
  547. break; 
  548. case 'id': 
  549. $parsed = 'blog_id'; 
  550. break; 
  551.  
  552. return $parsed; 
  553.  
  554. /** 
  555. * Parses an 'order' query variable and cast it to 'ASC' or 'DESC' as necessary. 
  556. * @since 4.6.0 
  557. * @access protected 
  558. * @param string $order The 'order' query variable. 
  559. * @return string The sanitized 'order' query variable. 
  560. */ 
  561. protected function parse_order( $order ) { 
  562. if ( ! is_string( $order ) || empty( $order ) ) { 
  563. return 'ASC'; 
  564.  
  565. if ( 'ASC' === strtoupper( $order ) ) { 
  566. return 'ASC'; 
  567. } else { 
  568. return 'DESC';