Changeset 38275 for trunk/src/wp-includes/class-wp-site-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-site-query.php
r38103 r38275 95 95 */ 96 96 public $max_num_pages = 0; 97 98 /** 99 * @since 4.7.0 100 * @access protected 101 * @var wpdb 102 */ 103 protected $db; 97 104 98 105 /** … … 148 155 */ 149 156 public function __construct( $query = '' ) { 157 $this->db = $GLOBALS['wpdb']; 158 150 159 $this->query_var_defaults = array( 151 160 'fields' => '', … … 326 335 * @access protected 327 336 * 328 * @global wpdb $wpdb WordPress database abstraction object.329 *330 337 * @return int|array A single count of site IDs if a count query. An array of site IDs if a full query. 331 338 */ 332 339 protected function get_site_ids() { 333 global $wpdb;334 335 340 $order = $this->parse_order( $this->query_vars['order'] ); 336 341 … … 396 401 $site_id = absint( $this->query_vars['ID'] ); 397 402 if ( ! empty( $site_id ) ) { 398 $this->sql_clauses['where']['ID'] = $ wpdb->prepare( 'blog_id = %d', $site_id );403 $this->sql_clauses['where']['ID'] = $this->db->prepare( 'blog_id = %d', $site_id ); 399 404 } 400 405 … … 412 417 413 418 if ( ! empty( $network_id ) ) { 414 $this->sql_clauses['where']['network_id'] = $ wpdb->prepare( 'site_id = %d', $network_id );419 $this->sql_clauses['where']['network_id'] = $this->db->prepare( 'site_id = %d', $network_id ); 415 420 } 416 421 … … 426 431 427 432 if ( ! empty( $this->query_vars['domain'] ) ) { 428 $this->sql_clauses['where']['domain'] = $ wpdb->prepare( 'domain = %s', $this->query_vars['domain'] );433 $this->sql_clauses['where']['domain'] = $this->db->prepare( 'domain = %s', $this->query_vars['domain'] ); 429 434 } 430 435 431 436 // Parse site domain for an IN clause. 432 437 if ( is_array( $this->query_vars['domain__in'] ) ) { 433 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";438 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 434 439 } 435 440 436 441 // Parse site domain for a NOT IN clause. 437 442 if ( is_array( $this->query_vars['domain__not_in'] ) ) { 438 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";443 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 439 444 } 440 445 441 446 if ( ! empty( $this->query_vars['path'] ) ) { 442 $this->sql_clauses['where']['path'] = $ wpdb->prepare( 'path = %s', $this->query_vars['path'] );447 $this->sql_clauses['where']['path'] = $this->db->prepare( 'path = %s', $this->query_vars['path'] ); 443 448 } 444 449 445 450 // Parse site path for an IN clause. 446 451 if ( is_array( $this->query_vars['path__in'] ) ) { 447 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";452 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__in'] ) ) . "' )"; 448 453 } 449 454 450 455 // Parse site path for a NOT IN clause. 451 456 if ( is_array( $this->query_vars['path__not_in'] ) ) { 452 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";457 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 453 458 } 454 459 455 460 if ( is_numeric( $this->query_vars['archived'] ) ) { 456 461 $archived = absint( $this->query_vars['archived'] ); 457 $this->sql_clauses['where']['archived'] = $ wpdb->prepare( "archived = %d ", $archived );462 $this->sql_clauses['where']['archived'] = $this->db->prepare( "archived = %d ", $archived ); 458 463 } 459 464 460 465 if ( is_numeric( $this->query_vars['mature'] ) ) { 461 466 $mature = absint( $this->query_vars['mature'] ); 462 $this->sql_clauses['where']['mature'] = $ wpdb->prepare( "mature = %d ", $mature );467 $this->sql_clauses['where']['mature'] = $this->db->prepare( "mature = %d ", $mature ); 463 468 } 464 469 465 470 if ( is_numeric( $this->query_vars['spam'] ) ) { 466 471 $spam = absint( $this->query_vars['spam'] ); 467 $this->sql_clauses['where']['spam'] = $ wpdb->prepare( "spam = %d ", $spam );472 $this->sql_clauses['where']['spam'] = $this->db->prepare( "spam = %d ", $spam ); 468 473 } 469 474 470 475 if ( is_numeric( $this->query_vars['deleted'] ) ) { 471 476 $deleted = absint( $this->query_vars['deleted'] ); 472 $this->sql_clauses['where']['deleted'] = $ wpdb->prepare( "deleted = %d ", $deleted );477 $this->sql_clauses['where']['deleted'] = $this->db->prepare( "deleted = %d ", $deleted ); 473 478 } 474 479 475 480 if ( is_numeric( $this->query_vars['public'] ) ) { 476 481 $public = absint( $this->query_vars['public'] ); 477 $this->sql_clauses['where']['public'] = $ wpdb->prepare( "public = %d ", $public );482 $this->sql_clauses['where']['public'] = $this->db->prepare( "public = %d ", $public ); 478 483 } 479 484 … … 551 556 552 557 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 553 $this->sql_clauses['from'] = "FROM $wpdb->blogs$join";558 $this->sql_clauses['from'] = "FROM {$this->db->blogs} $join"; 554 559 $this->sql_clauses['groupby'] = $groupby; 555 560 $this->sql_clauses['orderby'] = $orderby; … … 559 564 560 565 if ( $this->query_vars['count'] ) { 561 return intval( $ wpdb->get_var( $this->request ) );562 } 563 564 $site_ids = $ wpdb->get_col( $this->request );566 return intval( $this->db->get_var( $this->request ) ); 567 } 568 569 $site_ids = $this->db->get_col( $this->request ); 565 570 566 571 return array_map( 'intval', $site_ids ); … … 573 578 * @since 4.6.0 574 579 * @access private 575 *576 * @global wpdb $wpdb WordPress database abstraction object.577 580 */ 578 581 private function set_found_sites() { 579 global $wpdb;580 581 582 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 582 583 /** … … 590 591 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 591 592 592 $this->found_sites = (int) $ wpdb->get_var( $found_sites_query );593 $this->found_sites = (int) $this->db->get_var( $found_sites_query ); 593 594 } 594 595 } … … 599 600 * @since 4.6.0 600 601 * @access protected 601 *602 * @global wpdb $wpdb WordPress database abstraction object.603 602 * 604 603 * @param string $string Search string. … … 607 606 */ 608 607 protected function get_search_sql( $string, $columns ) { 609 global $wpdb;610 611 608 if ( false !== strpos( $string, '*' ) ) { 612 $like = '%' . implode( '%', array_map( array( $ wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%';609 $like = '%' . implode( '%', array_map( array( $this->db, 'esc_like' ), explode( '*', $string ) ) ) . '%'; 613 610 } else { 614 $like = '%' . $ wpdb->esc_like( $string ) . '%';611 $like = '%' . $this->db->esc_like( $string ) . '%'; 615 612 } 616 613 617 614 $searches = array(); 618 615 foreach ( $columns as $column ) { 619 $searches[] = $ wpdb->prepare( "$column LIKE %s", $like );616 $searches[] = $this->db->prepare( "$column LIKE %s", $like ); 620 617 } 621 618 … … 628 625 * @since 4.6.0 629 626 * @access protected 630 *631 * @global wpdb $wpdb WordPress database abstraction object.632 627 * 633 628 * @param string $orderby Alias for the field to order by. … … 635 630 */ 636 631 protected function parse_orderby( $orderby ) { 637 global $wpdb;638 639 632 $parsed = false; 640 633 … … 642 635 case 'site__in': 643 636 $site__in = implode( ',', array_map( 'absint', $this->query_vars['site__in'] ) ); 644 $parsed = "FIELD( {$ wpdb->blogs}.blog_id, $site__in )";637 $parsed = "FIELD( {$this->db->blogs}.blog_id, $site__in )"; 645 638 break; 646 639 case 'network__in': 647 640 $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); 648 $parsed = "FIELD( {$ wpdb->blogs}.site_id, $network__in )";641 $parsed = "FIELD( {$this->db->blogs}.site_id, $network__in )"; 649 642 break; 650 643 case 'domain':
Note: See TracChangeset
for help on using the changeset viewer.