Changeset 37868
- Timestamp:
- 06/26/2016 12:45:29 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-site-query.php
r37735 r37868 232 232 * @access public 233 233 * 234 * @global wpdb $wpdb WordPress database abstraction object.235 *236 234 * @return array|int List of sites, or number of sites when 'count' is passed as a query var. 237 235 */ 238 236 public function get_sites() { 239 global $wpdb;240 241 237 $this->parse_query(); 242 238 … … 257 253 wp_cache_set( 'last_changed', $last_changed, 'sites' ); 258 254 } 259 $cache_key = "get_site_ids:$key:$last_changed"; 260 261 $site_ids = wp_cache_get( $cache_key, 'sites' ); 262 if ( false === $site_ids ) { 255 256 $cache_key = "get_sites:$key:$last_changed"; 257 $cache_value = wp_cache_get( $cache_key, 'sites' ); 258 259 if ( false === $cache_value ) { 263 260 $site_ids = $this->get_site_ids(); 264 wp_cache_add( $cache_key, $site_ids, 'sites' ); 261 if ( $site_ids ) { 262 $this->set_found_sites(); 263 } 264 265 $cache_value = array( 266 'site_ids' => $site_ids, 267 'found_sites' => $this->found_sites, 268 'max_num_pages' => $this->max_num_pages, 269 ); 270 wp_cache_add( $cache_key, $cache_value, 'sites' ); 271 } else { 272 $site_ids = $cache_value['site_ids']; 273 $this->found_sites = $cache_value['found_sites']; 274 $this->max_num_pages = $cache_value['max_num_pages']; 265 275 } 266 276 … … 274 284 275 285 $this->site_count = count( $this->sites ); 276 277 if ( $site_ids && $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {278 /**279 * Filters the query used to retrieve found site count.280 *281 * @since 4.6.0282 *283 * @param string $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'.284 * @param WP_Site_Query $site_query The `WP_Site_Query` instance.285 */286 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this );287 288 $this->found_sites = (int) $wpdb->get_var( $found_sites_query );289 $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] );290 }291 286 292 287 if ( 'ids' == $this->query_vars['fields'] ) { … … 570 565 571 566 return array_map( 'intval', $site_ids ); 567 } 568 569 /** 570 * Populates found_sites and max_num_pages properties for the current query 571 * if the limit clause was used. 572 * 573 * @since 4.6.0 574 * @access private 575 * 576 * @global wpdb $wpdb WordPress database abstraction object. 577 */ 578 private function set_found_sites() { 579 global $wpdb; 580 581 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 582 /** 583 * Filters the query used to retrieve found site count. 584 * 585 * @since 4.6.0 586 * 587 * @param string $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'. 588 * @param WP_Site_Query $site_query The `WP_Site_Query` instance. 589 */ 590 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 591 592 $this->found_sites = (int) $wpdb->get_var( $found_sites_query ); 593 $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); 594 } 572 595 } 573 596
Note: See TracChangeset
for help on using the changeset viewer.