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