Changeset 38275 for trunk/src/wp-includes/class-wp-network-query.php
- Timestamp:
- 08/18/2016 06:20:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-network-query.php
r38104 r38275 86 86 */ 87 87 public $max_num_pages = 0; 88 89 /** 90 * @since 4.7.0 91 * @access protected 92 * @var wpdb 93 */ 94 protected $db; 88 95 89 96 /** … … 125 132 */ 126 133 public function __construct( $query = '' ) { 134 $this->db = $GLOBALS['wpdb']; 135 127 136 $this->query_var_defaults = array( 128 137 'network__in' => '', … … 291 300 */ 292 301 protected function get_network_ids() { 293 global $wpdb;294 295 302 $order = $this->parse_order( $this->query_vars['order'] ); 296 303 … … 333 340 $orderby = implode( ', ', $orderby_array ); 334 341 } else { 335 $orderby = " $wpdb->site.id $order";342 $orderby = "{$this->db->site}.id $order"; 336 343 } 337 344 … … 350 357 $fields = 'COUNT(*)'; 351 358 } else { 352 $fields = " $wpdb->site.id";359 $fields = "{$this->db->site}.id"; 353 360 } 354 361 355 362 // Parse network IDs for an IN clause. 356 363 if ( ! empty( $this->query_vars['network__in'] ) ) { 357 $this->sql_clauses['where']['network__in'] = " $wpdb->site.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )';364 $this->sql_clauses['where']['network__in'] = "{$this->db->site}.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; 358 365 } 359 366 360 367 // Parse network IDs for a NOT IN clause. 361 368 if ( ! empty( $this->query_vars['network__not_in'] ) ) { 362 $this->sql_clauses['where']['network__not_in'] = " $wpdb->site.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )';369 $this->sql_clauses['where']['network__not_in'] = "{$this->db->site}.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; 363 370 } 364 371 365 372 if ( ! empty( $this->query_vars['domain'] ) ) { 366 $this->sql_clauses['where']['domain'] = $ wpdb->prepare( "$wpdb->site.domain = %s", $this->query_vars['domain'] );373 $this->sql_clauses['where']['domain'] = $this->db->prepare( "{$this->db->site}.domain = %s", $this->query_vars['domain'] ); 367 374 } 368 375 369 376 // Parse network domain for an IN clause. 370 377 if ( is_array( $this->query_vars['domain__in'] ) ) { 371 $this->sql_clauses['where']['domain__in'] = " $wpdb->site.domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";378 $this->sql_clauses['where']['domain__in'] = "{$this->db->site}.domain IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 372 379 } 373 380 374 381 // Parse network domain for a NOT IN clause. 375 382 if ( is_array( $this->query_vars['domain__not_in'] ) ) { 376 $this->sql_clauses['where']['domain__not_in'] = " $wpdb->site.domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";383 $this->sql_clauses['where']['domain__not_in'] = "{$this->db->site}.domain NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 377 384 } 378 385 379 386 if ( ! empty( $this->query_vars['path'] ) ) { 380 $this->sql_clauses['where']['path'] = $ wpdb->prepare( "$wpdb->site.path = %s", $this->query_vars['path'] );387 $this->sql_clauses['where']['path'] = $this->db->prepare( "{$this->db->site}.path = %s", $this->query_vars['path'] ); 381 388 } 382 389 383 390 // Parse network path for an IN clause. 384 391 if ( is_array( $this->query_vars['path__in'] ) ) { 385 $this->sql_clauses['where']['path__in'] = " $wpdb->site.path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";392 $this->sql_clauses['where']['path__in'] = "{$this->db->site}.path IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__in'] ) ) . "' )"; 386 393 } 387 394 388 395 // Parse network path for a NOT IN clause. 389 396 if ( is_array( $this->query_vars['path__not_in'] ) ) { 390 $this->sql_clauses['where']['path__not_in'] = " $wpdb->site.path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";397 $this->sql_clauses['where']['path__not_in'] = "{$this->db->site}.path NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 391 398 } 392 399 … … 395 402 $this->sql_clauses['where']['search'] = $this->get_search_sql( 396 403 $this->query_vars['search'], 397 array( " $wpdb->site.domain", "$wpdb->site.path" )404 array( "{$this->db->site}.domain", "{$this->db->site}.path" ) 398 405 ); 399 406 } … … 440 447 441 448 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 442 $this->sql_clauses['from'] = "FROM $wpdb->site$join";449 $this->sql_clauses['from'] = "FROM {$this->db->site} $join"; 443 450 $this->sql_clauses['groupby'] = $groupby; 444 451 $this->sql_clauses['orderby'] = $orderby; … … 448 455 449 456 if ( $this->query_vars['count'] ) { 450 return intval( $ wpdb->get_var( $this->request ) );451 } 452 453 $network_ids = $ wpdb->get_col( $this->request );457 return intval( $this->db->get_var( $this->request ) ); 458 } 459 460 $network_ids = $this->db->get_col( $this->request ); 454 461 455 462 return array_map( 'intval', $network_ids ); … … 462 469 * @since 4.6.0 463 470 * @access private 464 *465 * @global wpdb $wpdb WordPress database abstraction object.466 471 */ 467 472 private function set_found_networks() { 468 global $wpdb;469 470 473 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 471 474 /** … … 479 482 $found_networks_query = apply_filters( 'found_networks_query', 'SELECT FOUND_ROWS()', $this ); 480 483 481 $this->found_networks = (int) $ wpdb->get_var( $found_networks_query );484 $this->found_networks = (int) $this->db->get_var( $found_networks_query ); 482 485 } 483 486 } … … 488 491 * @since 4.6.0 489 492 * @access protected 490 *491 * @global wpdb $wpdb WordPress database abstraction object.492 493 * 493 494 * @param string $string Search string. … … 497 498 */ 498 499 protected function get_search_sql( $string, $columns ) { 499 global $wpdb; 500 501 $like = '%' . $wpdb->esc_like( $string ) . '%'; 500 $like = '%' . $this->db->esc_like( $string ) . '%'; 502 501 503 502 $searches = array(); 504 503 foreach ( $columns as $column ) { 505 $searches[] = $ wpdb->prepare( "$column LIKE %s", $like );504 $searches[] = $this->db->prepare( "$column LIKE %s", $like ); 506 505 } 507 506 … … 514 513 * @since 4.6.0 515 514 * @access protected 516 *517 * @global wpdb $wpdb WordPress database abstraction object.518 515 * 519 516 * @param string $orderby Alias for the field to order by. … … 521 518 */ 522 519 protected function parse_orderby( $orderby ) { 523 global $wpdb;524 525 520 $allowed_keys = array( 526 521 'id', … … 532 527 if ( $orderby == 'network__in' ) { 533 528 $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); 534 $parsed = "FIELD( {$ wpdb->site}.id, $network__in )";529 $parsed = "FIELD( {$this->db->site}.id, $network__in )"; 535 530 } elseif ( $orderby == 'domain_length' || $orderby == 'path_length' ) { 536 531 $field = substr( $orderby, 0, -7 ); 537 $parsed = "CHAR_LENGTH( $wpdb->site.$field)";532 $parsed = "CHAR_LENGTH({$this->db->site}.$field)"; 538 533 } elseif ( in_array( $orderby, $allowed_keys ) ) { 539 $parsed = " $wpdb->site.$orderby";534 $parsed = "{$this->db->site}.$orderby"; 540 535 } 541 536
Note: See TracChangeset
for help on using the changeset viewer.