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