Changeset 38768
- Timestamp:
- 10/10/2016 06:37:02 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r38639 r38768 141 141 return false; 142 142 } 143 144 /**145 * @since 4.7.0146 * @access protected147 * @var wpdb148 */149 protected $db;150 143 151 144 /** … … 268 261 */ 269 262 public function __construct( $query = '' ) { 270 $this->db = $GLOBALS['wpdb'];271 272 263 $this->query_var_defaults = array( 273 264 'author_email' => '', … … 373 364 * @access public 374 365 * 366 * @global wpdb $wpdb WordPress database abstraction object. 367 * 375 368 * @return int|array List of comments or number of found comments if `$count` argument is true. 376 369 */ 377 370 public function get_comments() { 371 global $wpdb; 372 378 373 $this->parse_query(); 379 374 … … 394 389 $this->meta_query->parse_query_vars( $this->query_vars ); 395 390 if ( ! empty( $this->meta_query->queries ) ) { 396 $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $ this->db->comments, 'comment_ID', $this );391 $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); 397 392 } 398 393 … … 486 481 * @since 4.4.0 487 482 * @access protected 483 * 484 * @global wpdb $wpdb WordPress database abstraction object. 488 485 */ 489 486 protected function get_comment_ids() { 487 global $wpdb; 488 490 489 // Assemble clauses related to 'comment_approved'. 491 490 $approved_clauses = array(); … … 516 515 517 516 default : 518 $status_clauses[] = $ this->db->prepare( "comment_approved = %s", $status );517 $status_clauses[] = $wpdb->prepare( "comment_approved = %s", $status ); 519 518 break; 520 519 } … … 539 538 // Numeric values are assumed to be user ids. 540 539 if ( is_numeric( $unapproved_identifier ) ) { 541 $approved_clauses[] = $ this->db->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );540 $approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier ); 542 541 543 542 // Otherwise we match against email addresses. 544 543 } else { 545 $approved_clauses[] = $ this->db->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );544 $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier ); 546 545 } 547 546 } … … 602 601 // If no valid clauses were found, order by comment_date_gmt. 603 602 if ( empty( $orderby_array ) ) { 604 $orderby_array[] = " {$this->db->comments}.comment_date_gmt $order";603 $orderby_array[] = "$wpdb->comments.comment_date_gmt $order"; 605 604 } 606 605 … … 635 634 } 636 635 637 $orderby_array[] = " {$this->db->comments}.comment_ID $comment_ID_order";636 $orderby_array[] = "$wpdb->comments.comment_ID $comment_ID_order"; 638 637 } 639 638 640 639 $orderby = implode( ', ', $orderby_array ); 641 640 } else { 642 $orderby = " {$this->db->comments}.comment_date_gmt $order";641 $orderby = "$wpdb->comments.comment_date_gmt $order"; 643 642 } 644 643 … … 657 656 $fields = 'COUNT(*)'; 658 657 } else { 659 $fields = " {$this->db->comments}.comment_ID";658 $fields = "$wpdb->comments.comment_ID"; 660 659 } 661 660 662 661 $post_id = absint( $this->query_vars['post_id'] ); 663 662 if ( ! empty( $post_id ) ) { 664 $this->sql_clauses['where']['post_id'] = $ this->db->prepare( 'comment_post_ID = %d', $post_id );663 $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id ); 665 664 } 666 665 667 666 // Parse comment IDs for an IN clause. 668 667 if ( ! empty( $this->query_vars['comment__in'] ) ) { 669 $this->sql_clauses['where']['comment__in'] = " {$this->db->comments}.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';668 $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )'; 670 669 } 671 670 672 671 // Parse comment IDs for a NOT IN clause. 673 672 if ( ! empty( $this->query_vars['comment__not_in'] ) ) { 674 $this->sql_clauses['where']['comment__not_in'] = " {$this->db->comments}.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';673 $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )'; 675 674 } 676 675 … … 696 695 697 696 if ( '' !== $this->query_vars['author_email'] ) { 698 $this->sql_clauses['where']['author_email'] = $ this->db->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );697 $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] ); 699 698 } 700 699 701 700 if ( '' !== $this->query_vars['author_url'] ) { 702 $this->sql_clauses['where']['author_url'] = $ this->db->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );701 $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] ); 703 702 } 704 703 705 704 if ( '' !== $this->query_vars['karma'] ) { 706 $this->sql_clauses['where']['karma'] = $ this->db->prepare( 'comment_karma = %d', $this->query_vars['karma'] );705 $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); 707 706 } 708 707 … … 735 734 736 735 default: 737 $comment_types[ $operator ][] = $ this->db->prepare( '%s', $type );736 $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type ); 738 737 break; 739 738 } … … 752 751 753 752 if ( '' !== $parent ) { 754 $this->sql_clauses['where']['parent'] = $ this->db->prepare( 'comment_parent = %d', $parent );753 $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $parent ); 755 754 } 756 755 … … 758 757 $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')'; 759 758 } elseif ( '' !== $this->query_vars['user_id'] ) { 760 $this->sql_clauses['where']['user_id'] = $ this->db->prepare( 'user_id = %d', $this->query_vars['user_id'] );759 $this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] ); 761 760 } 762 761 … … 782 781 // $field_value may be an array. 783 782 $esses = array_fill( 0, count( (array) $field_value ), '%s' ); 784 $this->sql_clauses['where'][ $field_name ] = $ this->db->prepare( " {$this->db->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );783 $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); 785 784 } 786 785 } … … 803 802 804 803 $esses = array_fill( 0, count( $q_values ), '%s' ); 805 $this->sql_clauses['where'][ $field_name ] = $ this->db->prepare( " {$this->db->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values );804 $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values ); 806 805 } 807 806 } … … 832 831 833 832 if ( $join_posts_table ) { 834 $join .= "JOIN {$this->db->posts} ON {$this->db->posts}.ID = {$this->db->comments}.comment_post_ID";833 $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; 835 834 } 836 835 … … 842 841 843 842 if ( ! $this->query_vars['count'] ) { 844 $groupby = "{$ this->db->comments}.comment_ID";843 $groupby = "{$wpdb->comments}.comment_ID"; 845 844 } 846 845 } … … 891 890 892 891 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 893 $this->sql_clauses['from'] = "FROM {$this->db->comments}$join";892 $this->sql_clauses['from'] = "FROM $wpdb->comments $join"; 894 893 $this->sql_clauses['groupby'] = $groupby; 895 894 $this->sql_clauses['orderby'] = $orderby; … … 899 898 900 899 if ( $this->query_vars['count'] ) { 901 return intval( $ this->db->get_var( $this->request ) );900 return intval( $wpdb->get_var( $this->request ) ); 902 901 } else { 903 $comment_ids = $ this->db->get_col( $this->request );902 $comment_ids = $wpdb->get_col( $this->request ); 904 903 return array_map( 'intval', $comment_ids ); 905 904 } … … 912 911 * @since 4.6.0 913 912 * @access private 913 * 914 * @global wpdb $wpdb WordPress database abstraction object. 914 915 */ 915 916 private function set_found_comments() { 917 global $wpdb; 918 916 919 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 917 920 /** … … 925 928 $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this ); 926 929 927 $this->found_comments = (int) $ this->db->get_var( $found_comments_query );930 $this->found_comments = (int) $wpdb->get_var( $found_comments_query ); 928 931 } 929 932 } … … 941 944 */ 942 945 protected function fill_descendants( $comments ) { 946 global $wpdb; 947 943 948 $levels = array( 944 949 0 => wp_list_pluck( $comments, 'comment_ID' ), … … 1071 1076 * @access protected 1072 1077 * 1078 * @global wpdb $wpdb WordPress database abstraction object. 1079 * 1073 1080 * @param string $string 1074 1081 * @param array $cols … … 1076 1083 */ 1077 1084 protected function get_search_sql( $string, $cols ) { 1078 $like = '%' . $this->db->esc_like( $string ) . '%'; 1085 global $wpdb; 1086 1087 $like = '%' . $wpdb->esc_like( $string ) . '%'; 1079 1088 1080 1089 $searches = array(); 1081 1090 foreach ( $cols as $col ) { 1082 $searches[] = $ this->db->prepare( "$col LIKE %s", $like );1091 $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); 1083 1092 } 1084 1093 … … 1092 1101 * @access protected 1093 1102 * 1103 * @global wpdb $wpdb WordPress database abstraction object. 1104 * 1094 1105 * @param string $orderby Alias for the field to order by. 1095 1106 * @return string|false Value to used in the ORDER clause. False otherwise. 1096 1107 */ 1097 1108 protected function parse_orderby( $orderby ) { 1109 global $wpdb; 1110 1098 1111 $allowed_keys = array( 1099 1112 'comment_agent', … … 1127 1140 $parsed = false; 1128 1141 if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) { 1129 $parsed = " {$this->db->commentmeta}.meta_value";1142 $parsed = "$wpdb->commentmeta.meta_value"; 1130 1143 } elseif ( $orderby == 'meta_value_num' ) { 1131 $parsed = " {$this->db->commentmeta}.meta_value+0";1144 $parsed = "$wpdb->commentmeta.meta_value+0"; 1132 1145 } elseif ( $orderby == 'comment__in' ) { 1133 1146 $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) ); 1134 $parsed = "FIELD( {$ this->db->comments}.comment_ID, $comment__in )";1147 $parsed = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )"; 1135 1148 } elseif ( in_array( $orderby, $allowed_keys ) ) { 1136 1149 … … 1139 1152 $parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); 1140 1153 } else { 1141 $parsed = " {$this->db->comments}.$orderby";1154 $parsed = "$wpdb->comments.$orderby"; 1142 1155 } 1143 1156 } -
trunk/src/wp-includes/class-wp-meta-query.php
r38275 r38768 107 107 108 108 /** 109 * @since 4.7.0110 * @access protected111 * @var wpdb112 */113 protected $db;114 115 /**116 109 * Constructor. 117 110 * … … 145 138 */ 146 139 public function __construct( $meta_query = false ) { 147 $this->db = $GLOBALS['wpdb']; 148 149 if ( ! $meta_query ) { 140 if ( !$meta_query ) 150 141 return; 151 }152 142 153 143 if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { … … 495 485 * @access public 496 486 * 487 * @global wpdb $wpdb WordPress database abstraction object. 488 * 497 489 * @param array $clause Query clause, passed by reference. 498 490 * @param array $parent_query Parent query array. … … 507 499 */ 508 500 public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) { 501 global $wpdb; 502 509 503 $sql_chunks = array( 510 504 'where' => array(), … … 544 538 $join .= " LEFT JOIN $this->meta_table"; 545 539 $join .= $i ? " AS $alias" : ''; 546 $join .= $ this->db->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] );540 $join .= $wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] ); 547 541 548 542 // All other JOIN clauses. … … 588 582 $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL'; 589 583 } else { 590 $sql_chunks['where'][] = $ this->db->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );584 $sql_chunks['where'][] = $wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) ); 591 585 } 592 586 } … … 608 602 case 'NOT IN' : 609 603 $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')'; 610 $where = $ this->db->prepare( $meta_compare_string, $meta_value );604 $where = $wpdb->prepare( $meta_compare_string, $meta_value ); 611 605 break; 612 606 … … 614 608 case 'NOT BETWEEN' : 615 609 $meta_value = array_slice( $meta_value, 0, 2 ); 616 $where = $ this->db->prepare( '%s AND %s', $meta_value );610 $where = $wpdb->prepare( '%s AND %s', $meta_value ); 617 611 break; 618 612 619 613 case 'LIKE' : 620 614 case 'NOT LIKE' : 621 $meta_value = '%' . $ this->db->esc_like( $meta_value ) . '%';622 $where = $ this->db->prepare( '%s', $meta_value );615 $meta_value = '%' . $wpdb->esc_like( $meta_value ) . '%'; 616 $where = $wpdb->prepare( '%s', $meta_value ); 623 617 break; 624 618 … … 626 620 case 'EXISTS' : 627 621 $meta_compare = '='; 628 $where = $ this->db->prepare( '%s', $meta_value );622 $where = $wpdb->prepare( '%s', $meta_value ); 629 623 break; 630 624 … … 635 629 636 630 default : 637 $where = $ this->db->prepare( '%s', $meta_value );631 $where = $wpdb->prepare( '%s', $meta_value ); 638 632 break; 639 633 -
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 -
trunk/src/wp-includes/class-wp-query.php
r38586 r38768 486 486 487 487 private $compat_methods = array( 'init_query_flags', 'parse_tax_query' ); 488 489 /**490 * @since 4.7.0491 * @access protected492 * @var wpdb493 */494 protected $db;495 488 496 489 /** … … 1298 1291 */ 1299 1292 protected function parse_search( &$q ) { 1293 global $wpdb; 1294 1300 1295 $search = ''; 1301 1296 … … 1337 1332 1338 1333 if ( $n && $include ) { 1339 $like = '%' . $ this->db->esc_like( $term ) . '%';1340 $q['search_orderby_title'][] = $ this->db->prepare( "{$this->db->posts}.post_title LIKE %s", $like );1341 } 1342 1343 $like = $n . $ this->db->esc_like( $term ) . $n;1344 $search .= $ this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like );1334 $like = '%' . $wpdb->esc_like( $term ) . '%'; 1335 $q['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like ); 1336 } 1337 1338 $like = $n . $wpdb->esc_like( $term ) . $n; 1339 $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like ); 1345 1340 $searchand = ' AND '; 1346 1341 } … … 1349 1344 $search = " AND ({$search}) "; 1350 1345 if ( ! is_user_logged_in() ) { 1351 $search .= " AND ({$ this->db->posts}.post_password = '') ";1346 $search .= " AND ({$wpdb->posts}.post_password = '') "; 1352 1347 } 1353 1348 } … … 1437 1432 */ 1438 1433 protected function parse_search_order( &$q ) { 1434 global $wpdb; 1435 1439 1436 if ( $q['search_terms_count'] > 1 ) { 1440 1437 $num_terms = count( $q['search_orderby_title'] ); … … 1443 1440 $like = ''; 1444 1441 if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) { 1445 $like = '%' . $ this->db->esc_like( $q['s'] ) . '%';1442 $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; 1446 1443 } 1447 1444 … … 1450 1447 // sentence match in 'post_title' 1451 1448 if ( $like ) { 1452 $search_orderby .= $ this->db->prepare( "WHEN {$this->db->posts}.post_title LIKE %s THEN 1 ", $like );1449 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like ); 1453 1450 } 1454 1451 … … 1465 1462 // Sentence match in 'post_content' and 'post_excerpt'. 1466 1463 if ( $like ) { 1467 $search_orderby .= $ this->db->prepare( "WHEN {$this->db->posts}.post_excerpt LIKE %s THEN 4 ", $like );1468 $search_orderby .= $ this->db->prepare( "WHEN {$this->db->posts}.post_content LIKE %s THEN 5 ", $like );1464 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_excerpt LIKE %s THEN 4 ", $like ); 1465 $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_content LIKE %s THEN 5 ", $like ); 1469 1466 } 1470 1467 … … 1491 1488 */ 1492 1489 protected function parse_orderby( $orderby ) { 1490 global $wpdb; 1491 1493 1492 // Used to filter values. 1494 1493 $allowed_keys = array( … … 1537 1536 case 'menu_order': 1538 1537 case 'comment_count': 1539 $orderby_clause = "{$ this->db->posts}.{$orderby}";1538 $orderby_clause = "{$wpdb->posts}.{$orderby}"; 1540 1539 break; 1541 1540 case 'rand': … … 1562 1561 } else { 1563 1562 // Default: order by post field. 1564 $orderby_clause = "{$ this->db->posts}.post_" . sanitize_key( $orderby );1563 $orderby_clause = "{$wpdb->posts}.post_" . sanitize_key( $orderby ); 1565 1564 } 1566 1565 … … 1652 1651 */ 1653 1652 public function get_posts() { 1653 global $wpdb; 1654 1654 1655 $this->parse_query(); 1655 1656 … … 1787 1788 switch ( $q['fields'] ) { 1788 1789 case 'ids': 1789 $fields = "{$ this->db->posts}.ID";1790 $fields = "{$wpdb->posts}.ID"; 1790 1791 break; 1791 1792 case 'id=>parent': 1792 $fields = "{$ this->db->posts}.ID, {$this->db->posts}.post_parent";1793 $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent"; 1793 1794 break; 1794 1795 default: 1795 $fields = "{$ this->db->posts}.*";1796 $fields = "{$wpdb->posts}.*"; 1796 1797 } 1797 1798 1798 1799 if ( '' !== $q['menu_order'] ) { 1799 $where .= " AND {$ this->db->posts}.menu_order = " . $q['menu_order'];1800 $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order']; 1800 1801 } 1801 1802 // The "m" parameter is meant for months but accepts datetimes of varying specificity 1802 1803 if ( $q['m'] ) { 1803 $where .= " AND YEAR({$ this->db->posts}.post_date)=" . substr($q['m'], 0, 4);1804 $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr($q['m'], 0, 4); 1804 1805 if ( strlen($q['m']) > 5 ) { 1805 $where .= " AND MONTH({$ this->db->posts}.post_date)=" . substr($q['m'], 4, 2);1806 $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 4, 2); 1806 1807 } 1807 1808 if ( strlen($q['m']) > 7 ) { 1808 $where .= " AND DAYOFMONTH({$ this->db->posts}.post_date)=" . substr($q['m'], 6, 2);1809 $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 6, 2); 1809 1810 } 1810 1811 if ( strlen($q['m']) > 9 ) { 1811 $where .= " AND HOUR({$ this->db->posts}.post_date)=" . substr($q['m'], 8, 2);1812 $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr($q['m'], 8, 2); 1812 1813 } 1813 1814 if ( strlen($q['m']) > 11 ) { 1814 $where .= " AND MINUTE({$ this->db->posts}.post_date)=" . substr($q['m'], 10, 2);1815 $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr($q['m'], 10, 2); 1815 1816 } 1816 1817 if ( strlen($q['m']) > 13 ) { 1817 $where .= " AND SECOND({$ this->db->posts}.post_date)=" . substr($q['m'], 12, 2);1818 $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr($q['m'], 12, 2); 1818 1819 } 1819 1820 } … … 1879 1880 1880 1881 if ( '' !== $q['title'] ) { 1881 $where .= $ this->db->prepare( " AND {$this->db->posts}.post_title = %s", stripslashes( $q['title'] ) );1882 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q['title'] ) ); 1882 1883 } 1883 1884 … … 1885 1886 if ( '' != $q['name'] ) { 1886 1887 $q['name'] = sanitize_title_for_query( $q['name'] ); 1887 $where .= " AND {$ this->db->posts}.post_name = '" . $q['name'] . "'";1888 $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'"; 1888 1889 } elseif ( '' != $q['pagename'] ) { 1889 1890 if ( isset($this->queried_object_id) ) { … … 1914 1915 $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); 1915 1916 $q['name'] = $q['pagename']; 1916 $where .= " AND ({$ this->db->posts}.ID = '$reqpage')";1917 $where .= " AND ({$wpdb->posts}.ID = '$reqpage')"; 1917 1918 $reqpage_obj = get_post( $reqpage ); 1918 1919 if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { … … 1926 1927 $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); 1927 1928 $q['name'] = $q['attachment']; 1928 $where .= " AND {$ this->db->posts}.post_name = '" . $q['attachment'] . "'";1929 $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'"; 1929 1930 } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { 1930 1931 $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); 1931 1932 $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'"; 1932 $where .= " AND {$ this->db->posts}.post_name IN ($post_name__in)";1933 $where .= " AND {$wpdb->posts}.post_name IN ($post_name__in)"; 1933 1934 } 1934 1935 … … 1939 1940 // If a post number is specified, load that post 1940 1941 if ( $q['p'] ) { 1941 $where .= " AND {$ this->db->posts}.ID = " . $q['p'];1942 $where .= " AND {$wpdb->posts}.ID = " . $q['p']; 1942 1943 } elseif ( $q['post__in'] ) { 1943 1944 $post__in = implode(',', array_map( 'absint', $q['post__in'] )); 1944 $where .= " AND {$ this->db->posts}.ID IN ($post__in)";1945 $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; 1945 1946 } elseif ( $q['post__not_in'] ) { 1946 1947 $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] )); 1947 $where .= " AND {$ this->db->posts}.ID NOT IN ($post__not_in)";1948 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; 1948 1949 } 1949 1950 1950 1951 if ( is_numeric( $q['post_parent'] ) ) { 1951 $where .= $ this->db->prepare( " AND {$this->db->posts}.post_parent = %d ", $q['post_parent'] );1952 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $q['post_parent'] ); 1952 1953 } elseif ( $q['post_parent__in'] ) { 1953 1954 $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); 1954 $where .= " AND {$ this->db->posts}.post_parent IN ($post_parent__in)";1955 $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; 1955 1956 } elseif ( $q['post_parent__not_in'] ) { 1956 1957 $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); 1957 $where .= " AND {$ this->db->posts}.post_parent NOT IN ($post_parent__not_in)";1958 $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; 1958 1959 } 1959 1960 … … 1961 1962 if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) { 1962 1963 $q['p'] = $q['page_id']; 1963 $where = " AND {$ this->db->posts}.ID = " . $q['page_id'];1964 $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; 1964 1965 } 1965 1966 } … … 1986 1987 $this->parse_tax_query( $q ); 1987 1988 1988 $clauses = $this->tax_query->get_sql( $ this->db->posts, 'ID' );1989 $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); 1989 1990 1990 1991 $join .= $clauses['join']; … … 2070 2071 2071 2072 if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { 2072 $groupby = "{$ this->db->posts}.ID";2073 $groupby = "{$wpdb->posts}.ID"; 2073 2074 } 2074 2075 … … 2087 2088 if ( ! empty( $q['author__not_in'] ) ) { 2088 2089 $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) ); 2089 $where .= " AND {$ this->db->posts}.post_author NOT IN ($author__not_in) ";2090 $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) "; 2090 2091 } elseif ( ! empty( $q['author__in'] ) ) { 2091 2092 $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) ); 2092 $where .= " AND {$ this->db->posts}.post_author IN ($author__in) ";2093 $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; 2093 2094 } 2094 2095 … … 2108 2109 if ( $q['author'] ) 2109 2110 $q['author'] = $q['author']->ID; 2110 $whichauthor .= " AND ({$ this->db->posts}.post_author = " . absint($q['author']) . ')';2111 $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint($q['author']) . ')'; 2111 2112 } 2112 2113 … … 2114 2115 2115 2116 if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { 2116 $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $ this->db->posts );2117 $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); 2117 2118 } 2118 2119 $where .= $search . $whichauthor . $whichmimetype; 2119 2120 2120 2121 if ( ! empty( $this->meta_query->queries ) ) { 2121 $clauses = $this->meta_query->get_sql( 'post', $ this->db->posts, 'ID', $this );2122 $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 2122 2123 $join .= $clauses['join']; 2123 2124 $where .= $clauses['where']; … … 2140 2141 $orderby = ''; 2141 2142 } else { 2142 $orderby = "{$ this->db->posts}.post_date " . $q['order'];2143 $orderby = "{$wpdb->posts}.post_date " . $q['order']; 2143 2144 } 2144 2145 } elseif ( 'none' == $q['orderby'] ) { 2145 2146 $orderby = ''; 2146 2147 } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { 2147 $orderby = "FIELD( {$ this->db->posts}.ID, $post__in )";2148 $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; 2148 2149 } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { 2149 $orderby = "FIELD( {$ this->db->posts}.post_parent, $post_parent__in )";2150 $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; 2150 2151 } elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) { 2151 $orderby = "FIELD( {$ this->db->posts}.post_name, $post_name__in )";2152 $orderby = "FIELD( {$wpdb->posts}.post_name, $post_name__in )"; 2152 2153 } else { 2153 2154 $orderby_array = array(); … … 2181 2182 2182 2183 if ( empty( $orderby ) ) { 2183 $orderby = "{$ this->db->posts}.post_date " . $q['order'];2184 $orderby = "{$wpdb->posts}.post_date " . $q['order']; 2184 2185 } elseif ( ! empty( $q['order'] ) ) { 2185 2186 $orderby .= " {$q['order']}"; … … 2221 2222 2222 2223 if ( isset( $q['post_password'] ) ) { 2223 $where .= $ this->db->prepare( " AND {$this->db->posts}.post_password = %s", $q['post_password'] );2224 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q['post_password'] ); 2224 2225 if ( empty( $q['perm'] ) ) { 2225 2226 $q['perm'] = 'readable'; 2226 2227 } 2227 2228 } elseif ( isset( $q['has_password'] ) ) { 2228 $where .= sprintf( " AND {$ this->db->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' );2229 $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' ); 2229 2230 } 2230 2231 2231 2232 if ( ! empty( $q['comment_status'] ) ) { 2232 $where .= $ this->db->prepare( " AND {$this->db->posts}.comment_status = %s ", $q['comment_status'] );2233 $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q['comment_status'] ); 2233 2234 } 2234 2235 2235 2236 if ( ! empty( $q['ping_status'] ) ) { 2236 $where .= $ this->db->prepare( " AND {$this->db->posts}.ping_status = %s ", $q['ping_status'] );2237 $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] ); 2237 2238 } 2238 2239 … … 2242 2243 $where .= ' AND 1=0 '; 2243 2244 } else { 2244 $where .= " AND {$ this->db->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')";2245 $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; 2245 2246 } 2246 2247 } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { 2247 $where .= " AND {$ this->db->posts}.post_type IN ('" . join("', '", $post_type) . "')";2248 $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", $post_type) . "')"; 2248 2249 } elseif ( ! empty( $post_type ) ) { 2249 $where .= " AND {$ this->db->posts}.post_type = '$post_type'";2250 $where .= " AND {$wpdb->posts}.post_type = '$post_type'"; 2250 2251 $post_type_object = get_post_type_object ( $post_type ); 2251 2252 } elseif ( $this->is_attachment ) { 2252 $where .= " AND {$ this->db->posts}.post_type = 'attachment'";2253 $where .= " AND {$wpdb->posts}.post_type = 'attachment'"; 2253 2254 $post_type_object = get_post_type_object ( 'attachment' ); 2254 2255 } elseif ( $this->is_page ) { 2255 $where .= " AND {$ this->db->posts}.post_type = 'page'";2256 $where .= " AND {$wpdb->posts}.post_type = 'page'"; 2256 2257 $post_type_object = get_post_type_object ( 'page' ); 2257 2258 } else { 2258 $where .= " AND {$ this->db->posts}.post_type = 'post'";2259 $where .= " AND {$wpdb->posts}.post_type = 'post'"; 2259 2260 $post_type_object = get_post_type_object ( 'post' ); 2260 2261 } … … 2285 2286 foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { 2286 2287 if ( ! in_array( $status, $q_status ) ) { 2287 $e_status[] = "{$ this->db->posts}.post_status <> '$status'";2288 $e_status[] = "{$wpdb->posts}.post_status <> '$status'"; 2288 2289 } 2289 2290 } … … 2292 2293 if ( in_array( $status, $q_status ) ) { 2293 2294 if ( 'private' == $status ) { 2294 $p_status[] = "{$ this->db->posts}.post_status = '$status'";2295 $p_status[] = "{$wpdb->posts}.post_status = '$status'"; 2295 2296 } else { 2296 $r_status[] = "{$ this->db->posts}.post_status = '$status'";2297 $r_status[] = "{$wpdb->posts}.post_status = '$status'"; 2297 2298 } 2298 2299 } … … 2310 2311 if ( !empty($r_status) ) { 2311 2312 if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) { 2312 $statuswheres[] = "({$ this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";2313 $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; 2313 2314 } else { 2314 2315 $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; … … 2317 2318 if ( !empty($p_status) ) { 2318 2319 if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) { 2319 $statuswheres[] = "({$ this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";2320 $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; 2320 2321 } else { 2321 2322 $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; … … 2323 2324 } 2324 2325 if ( $post_status_join ) { 2325 $join .= " LEFT JOIN {$ this->db->posts} AS p2 ON ({$this->db->posts}.post_parent = p2.ID) ";2326 $join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) "; 2326 2327 foreach ( $statuswheres as $index => $statuswhere ) { 2327 $statuswheres[$index] = "($statuswhere OR ({$ this->db->posts}.post_status = 'inherit' AND " . str_replace( $this->db->posts, 'p2', $statuswhere ) . "))";2328 $statuswheres[$index] = "($statuswhere OR ({$wpdb->posts}.post_status = 'inherit' AND " . str_replace( $wpdb->posts, 'p2', $statuswhere ) . "))"; 2328 2329 } 2329 2330 } … … 2333 2334 } 2334 2335 } elseif ( !$this->is_singular ) { 2335 $where .= " AND ({$ this->db->posts}.post_status = 'publish'";2336 $where .= " AND ({$wpdb->posts}.post_status = 'publish'"; 2336 2337 2337 2338 // Add public states. … … 2340 2341 if ( 'publish' == $state ) // Publish is hard-coded above. 2341 2342 continue; 2342 $where .= " OR {$ this->db->posts}.post_status = '$state'";2343 $where .= " OR {$wpdb->posts}.post_status = '$state'"; 2343 2344 } 2344 2345 … … 2347 2348 $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); 2348 2349 foreach ( (array) $admin_all_states as $state ) { 2349 $where .= " OR {$ this->db->posts}.post_status = '$state'";2350 $where .= " OR {$wpdb->posts}.post_status = '$state'"; 2350 2351 } 2351 2352 } … … 2355 2356 $private_states = get_post_stati( array('private' => true) ); 2356 2357 foreach ( (array) $private_states as $state ) { 2357 $where .= current_user_can( $read_private_cap ) ? " OR {$ this->db->posts}.post_status = '$state'" : " OR {$this->db->posts}.post_author = $user_id AND {$this->db->posts}.post_status = '$state'";2358 $where .= current_user_can( $read_private_cap ) ? " OR {$wpdb->posts}.post_status = '$state'" : " OR {$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$state'"; 2358 2359 } 2359 2360 } … … 2407 2408 if ( $this->is_comment_feed && ! $this->is_singular ) { 2408 2409 if ( $this->is_archive || $this->is_search ) { 2409 $cjoin = "JOIN {$ this->db->posts} ON ({$this->db->comments}.comment_post_ID = {$this->db->posts}.ID) $join ";2410 $cjoin = "JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) $join "; 2410 2411 $cwhere = "WHERE comment_approved = '1' $where"; 2411 $cgroupby = "{$ this->db->comments}.comment_id";2412 $cgroupby = "{$wpdb->comments}.comment_id"; 2412 2413 } else { // Other non singular e.g. front 2413 $cjoin = "JOIN {$ this->db->posts} ON ( {$this->db->comments}.comment_post_ID = {$this->db->posts}.ID )";2414 $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )"; 2414 2415 $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'"; 2415 2416 $cgroupby = ''; … … 2470 2471 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 2471 2472 2472 $comments = (array) $ this->db->get_results("SELECT $distinct {$this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits");2473 $comments = (array) $wpdb->get_results("SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"); 2473 2474 // Convert to WP_Comment 2474 2475 $this->comments = array_map( 'get_comment', $comments ); … … 2483 2484 $join = ''; 2484 2485 if ( $post_ids ) { 2485 $where = "AND {$ this->db->posts}.ID IN ($post_ids) ";2486 $where = "AND {$wpdb->posts}.ID IN ($post_ids) "; 2486 2487 } else { 2487 2488 $where = "AND 0"; … … 2725 2726 $found_rows = 'SQL_CALC_FOUND_ROWS'; 2726 2727 2727 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$ this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits";2728 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; 2728 2729 2729 2730 if ( !$q['suppress_filters'] ) { … … 2759 2760 if ( 'ids' == $q['fields'] ) { 2760 2761 if ( null === $this->posts ) { 2761 $this->posts = $ this->db->get_col( $this->request );2762 $this->posts = $wpdb->get_col( $this->request ); 2762 2763 } 2763 2764 … … 2771 2772 if ( 'id=>parent' == $q['fields'] ) { 2772 2773 if ( null === $this->posts ) { 2773 $this->posts = $ this->db->get_results( $this->request );2774 $this->posts = $wpdb->get_results( $this->request ); 2774 2775 } 2775 2776 … … 2789 2790 2790 2791 if ( null === $this->posts ) { 2791 $split_the_query = ( $old_request == $this->request && "{$ this->db->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );2792 $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 2792 2793 2793 2794 /** … … 2808 2809 // First get the IDs and then fill in the objects 2809 2810 2810 $this->request = "SELECT $found_rows $distinct {$ this->db->posts}.ID FROM {$this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits";2811 $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits"; 2811 2812 2812 2813 /** … … 2820 2821 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 2821 2822 2822 $ids = $ this->db->get_col( $this->request );2823 $ids = $wpdb->get_col( $this->request ); 2823 2824 2824 2825 if ( $ids ) { … … 2830 2831 } 2831 2832 } else { 2832 $this->posts = $ this->db->get_results( $this->request );2833 $this->posts = $wpdb->get_results( $this->request ); 2833 2834 $this->set_found_posts( $q, $limits ); 2834 2835 } … … 2870 2871 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 2871 2872 2872 $comments_request = "SELECT {$ this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits";2873 $comments = $ this->db->get_results($comments_request);2873 $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; 2874 $comments = $wpdb->get_results($comments_request); 2874 2875 // Convert to WP_Comment 2875 2876 $this->comments = array_map( 'get_comment', $comments ); … … 3018 3019 */ 3019 3020 private function set_found_posts( $q, $limits ) { 3021 global $wpdb; 3020 3022 // Bail if posts is an empty array. Continue if posts is an empty string, 3021 3023 // null, or false to accommodate caching plugins that fill posts later. … … 3032 3034 * @param WP_Query &$this The WP_Query instance (passed by reference). 3033 3035 */ 3034 $this->found_posts = $ this->db->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );3036 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 3035 3037 } else { 3036 3038 $this->found_posts = count( $this->posts ); … … 3329 3331 */ 3330 3332 public function __construct( $query = '' ) { 3331 $this->db = $GLOBALS['wpdb'];3332 3333 3333 if ( ! empty( $query ) ) { 3334 3334 $this->query( $query ); -
trunk/src/wp-includes/class-wp-roles.php
r38387 r38768 71 71 72 72 /** 73 * @since 4.7.074 * @access protected75 * @var wpdb76 */77 protected $db;78 79 /**80 73 * Constructor 81 74 * … … 83 76 */ 84 77 public function __construct() { 85 $this->db = $GLOBALS['wpdb'];86 87 78 $this->_init(); 88 79 } … … 118 109 */ 119 110 protected function _init() { 120 global $wp_user_roles; 121 $this->role_key = $this->db->get_blog_prefix() . 'user_roles'; 111 global $wp_user_roles, $wpdb; 112 113 $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; 122 114 if ( ! empty( $wp_user_roles ) ) { 123 115 $this->roles = $wp_user_roles; … … 148 140 */ 149 141 public function reinit() { 142 global $wpdb; 143 150 144 // There is no need to reinit if using the wp_user_roles global. 151 145 if ( ! $this->use_db ) { … … 154 148 155 149 // Duplicated from _init() to avoid an extra function call. 156 $this->role_key = $ this->db->get_blog_prefix() . 'user_roles';150 $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; 157 151 $this->roles = get_option( $this->role_key ); 158 152 if ( empty( $this->roles ) ) -
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': -
trunk/src/wp-includes/class-wp-tax-query.php
r38275 r38768 93 93 94 94 /** 95 * @since 4.7.096 * @access protected97 * @var wpdb98 */99 protected $db;100 101 /**102 95 * Constructor. 103 96 * … … 127 120 */ 128 121 public function __construct( $tax_query ) { 129 $this->db = $GLOBALS['wpdb'];130 131 122 if ( isset( $tax_query['relation'] ) ) { 132 123 $this->relation = $this->sanitize_relation( $tax_query['relation'] ); … … 397 388 * @access public 398 389 * 390 * @global wpdb $wpdb The WordPress database abstraction object. 391 * 399 392 * @param array $clause Query clause, passed by reference. 400 393 * @param array $parent_query Parent query array. … … 407 400 */ 408 401 public function get_sql_for_clause( &$clause, $parent_query ) { 402 global $wpdb; 403 409 404 $sql = array( 410 405 'where' => array(), … … 438 433 if ( false === $alias ) { 439 434 $i = count( $this->table_aliases ); 440 $alias = $i ? 'tt' . $i : $ this->db->term_relationships;435 $alias = $i ? 'tt' . $i : $wpdb->term_relationships; 441 436 442 437 // Store the alias as part of a flat array to build future iterators. … … 446 441 $clause['alias'] = $alias; 447 442 448 $join .= " LEFT JOIN {$this->db->term_relationships}";443 $join .= " LEFT JOIN $wpdb->term_relationships"; 449 444 $join .= $i ? " AS $alias" : ''; 450 445 $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)"; … … 464 459 $where = "$this->primary_table.$this->primary_id_column NOT IN ( 465 460 SELECT object_id 466 FROM {$this->db->term_relationships}461 FROM $wpdb->term_relationships 467 462 WHERE term_taxonomy_id IN ($terms) 468 463 )"; … … 480 475 $where = "( 481 476 SELECT COUNT(1) 482 FROM {$this->db->term_relationships}477 FROM $wpdb->term_relationships 483 478 WHERE term_taxonomy_id IN ($terms) 484 479 AND object_id = $this->primary_table.$this->primary_id_column … … 487 482 } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) { 488 483 489 $where = $ this->db->prepare( "$operator (484 $where = $wpdb->prepare( "$operator ( 490 485 SELECT 1 491 FROM {$this->db->term_relationships}492 INNER JOIN {$this->db->term_taxonomy}493 ON {$this->db->term_taxonomy}.term_taxonomy_id = {$this->db->term_relationships}.term_taxonomy_id494 WHERE {$this->db->term_taxonomy}.taxonomy = %s495 AND {$this->db->term_relationships}.object_id = $this->primary_table.$this->primary_id_column486 FROM $wpdb->term_relationships 487 INNER JOIN $wpdb->term_taxonomy 488 ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id 489 WHERE $wpdb->term_taxonomy.taxonomy = %s 490 AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column 496 491 )", $clause['taxonomy'] ); 497 492 … … 603 598 * @since 3.2.0 604 599 * 600 * @global wpdb $wpdb The WordPress database abstraction object. 601 * 605 602 * @param array $query The single query. Passed by reference. 606 603 * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', … … 608 605 */ 609 606 public function transform_query( &$query, $resulting_field ) { 607 global $wpdb; 608 610 609 if ( empty( $query['terms'] ) ) 611 610 return; … … 630 629 $terms = implode( ",", $query['terms'] ); 631 630 632 $terms = $ this->db->get_col( "633 SELECT {$this->db->term_taxonomy}.$resulting_field634 FROM {$this->db->term_taxonomy}635 INNER JOIN {$this->db->terms}USING (term_id)631 $terms = $wpdb->get_col( " 632 SELECT $wpdb->term_taxonomy.$resulting_field 633 FROM $wpdb->term_taxonomy 634 INNER JOIN $wpdb->terms USING (term_id) 636 635 WHERE taxonomy = '{$query['taxonomy']}' 637 AND {$this->db->terms}.{$query['field']} IN ($terms)636 AND $wpdb->terms.{$query['field']} IN ($terms) 638 637 " ); 639 638 break; 640 639 case 'term_taxonomy_id': 641 640 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 642 $terms = $ this->db->get_col( "641 $terms = $wpdb->get_col( " 643 642 SELECT $resulting_field 644 FROM {$this->db->term_taxonomy}643 FROM $wpdb->term_taxonomy 645 644 WHERE term_taxonomy_id IN ($terms) 646 645 " ); … … 648 647 default: 649 648 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 650 $terms = $ this->db->get_col( "649 $terms = $wpdb->get_col( " 651 650 SELECT $resulting_field 652 FROM {$this->db->term_taxonomy}651 FROM $wpdb->term_taxonomy 653 652 WHERE taxonomy = '{$query['taxonomy']}' 654 653 AND term_id IN ($terms) -
trunk/src/wp-includes/class-wp-term-query.php
r38667 r38768 86 86 */ 87 87 public $terms; 88 89 /**90 * @since 4.7.091 * @access protected92 * @var wpdb93 */94 protected $db;95 88 96 89 /** … … 187 180 */ 188 181 public function __construct( $query = '' ) { 189 $this->db = $GLOBALS['wpdb'];190 191 182 $this->query_var_defaults = array( 192 183 'taxonomy' => null, … … 315 306 * @access public 316 307 * 308 * @global wpdb $wpdb WordPress database abstraction object. 309 * 317 310 * @return array 318 311 */ 319 312 public function get_terms() { 313 global $wpdb; 314 320 315 $this->parse_query( $this->query_vars ); 321 316 $args = $this->query_vars; … … 510 505 $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})"; 511 506 } else { 512 $this->sql_clauses['where']['term_taxonomy_id'] = $ this->db->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );507 $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] ); 513 508 } 514 509 } 515 510 516 511 if ( ! empty( $args['name__like'] ) ) { 517 $this->sql_clauses['where']['name__like'] = $ this->db->prepare( "t.name LIKE %s", '%' . $this->db->esc_like( $args['name__like'] ) . '%' );512 $this->sql_clauses['where']['name__like'] = $wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' ); 518 513 } 519 514 520 515 if ( ! empty( $args['description__like'] ) ) { 521 $this->sql_clauses['where']['description__like'] = $ this->db->prepare( "tt.description LIKE %s", '%' . $this->db->esc_like( $args['description__like'] ) . '%' );516 $this->sql_clauses['where']['description__like'] = $wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' ); 522 517 } 523 518 … … 639 634 $fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) ); 640 635 641 $join .= " INNER JOIN {$this->db->term_taxonomy}AS tt ON t.term_id = tt.term_id";636 $join .= " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; 642 637 643 638 if ( ! empty( $this->query_vars['object_ids'] ) ) { 644 $join .= " INNER JOIN {$ this->db->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";639 $join .= " INNER JOIN {$wpdb->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id"; 645 640 } 646 641 … … 671 666 672 667 $this->sql_clauses['select'] = "SELECT $distinct $fields"; 673 $this->sql_clauses['from'] = "FROM {$this->db->terms}AS t $join";668 $this->sql_clauses['from'] = "FROM $wpdb->terms AS t $join"; 674 669 $this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : ''; 675 670 $this->sql_clauses['limits'] = $limits; … … 696 691 697 692 if ( 'count' == $_fields ) { 698 return $ this->db->get_var( $this->request );699 } 700 701 $terms = $ this->db->get_results( $this->request );693 return $wpdb->get_var( $this->request ); 694 } 695 696 $terms = $wpdb->get_results( $this->request ); 702 697 if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { 703 698 update_term_cache( $terms ); … … 830 825 * @since 4.6.0 831 826 * @access protected 827 * 828 * @global wpdb $wpdb WordPress database abstraction object. 832 829 * 833 830 * @param string $orderby_raw Alias for the field to order by. … … 967 964 * @access protected 968 965 * 966 * @global wpdb $wpdb WordPress database abstraction object. 967 * 969 968 * @param string $string 970 969 * @return string 971 970 */ 972 971 protected function get_search_sql( $string ) { 973 $like = '%' . $this->db->esc_like( $string ) . '%'; 974 975 return $this->db->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); 972 global $wpdb; 973 974 $like = '%' . $wpdb->esc_like( $string ) . '%'; 975 976 return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); 976 977 } 977 978 } -
trunk/src/wp-includes/class-wp-user-query.php
r38715 r38768 72 72 73 73 /** 74 * @since 4.7.075 * @access protected76 * @var wpdb77 */78 protected $db;79 80 /**81 74 * PHP5 constructor. 82 75 * … … 86 79 */ 87 80 public function __construct( $query = null ) { 88 $this->db = $GLOBALS['wpdb'];89 90 81 if ( ! empty( $query ) ) { 91 82 $this->prepare_query( $query ); … … 152 143 * @access public 153 144 * 145 * @global wpdb $wpdb WordPress database abstraction object. 154 146 * @global int $blog_id 155 147 * … … 225 217 */ 226 218 public function prepare_query( $query = array() ) { 219 global $wpdb; 220 227 221 if ( empty( $this->query_vars ) || ! empty( $query ) ) { 228 222 $this->query_limit = null; … … 253 247 foreach ( $qv['fields'] as $field ) { 254 248 $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); 255 $this->query_fields[] = " {$this->db->users}.$field";249 $this->query_fields[] = "$wpdb->users.$field"; 256 250 } 257 251 $this->query_fields = implode( ',', $this->query_fields ); 258 252 } elseif ( 'all' == $qv['fields'] ) { 259 $this->query_fields = " {$this->db->users}.*";253 $this->query_fields = "$wpdb->users.*"; 260 254 } else { 261 $this->query_fields = " {$this->db->users}.ID";255 $this->query_fields = "$wpdb->users.ID"; 262 256 } 263 257 … … 265 259 $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; 266 260 267 $this->query_from = "FROM {$this->db->users}";261 $this->query_from = "FROM $wpdb->users"; 268 262 $this->query_where = "WHERE 1=1"; 269 263 … … 288 282 289 283 foreach ( $post_types as &$post_type ) { 290 $post_type = $ this->db->prepare( '%s', $post_type );291 } 292 293 $posts_table = $ this->db->get_blog_prefix( $blog_id ) . 'posts';294 $this->query_where .= " AND {$this->db->users}.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )";284 $post_type = $wpdb->prepare( '%s', $post_type ); 285 } 286 287 $posts_table = $wpdb->get_blog_prefix( $blog_id ) . 'posts'; 288 $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )"; 295 289 } 296 290 297 291 // nicename 298 292 if ( '' !== $qv['nicename']) { 299 $this->query_where .= $ this->db->prepare( ' AND user_nicename = %s', $qv['nicename'] );293 $this->query_where .= $wpdb->prepare( ' AND user_nicename = %s', $qv['nicename'] ); 300 294 } 301 295 … … 314 308 // login 315 309 if ( '' !== $qv['login']) { 316 $this->query_where .= $ this->db->prepare( ' AND user_login = %s', $qv['login'] );310 $this->query_where .= $wpdb->prepare( ' AND user_login = %s', $qv['login'] ); 317 311 } 318 312 … … 335 329 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { 336 330 $who_query = array( 337 'key' => $ this->db->get_blog_prefix( $blog_id ) . 'user_level',331 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level', 338 332 'value' => 0, 339 333 'compare' => '!=', … … 382 376 foreach ( $roles as $role ) { 383 377 $roles_clauses[] = array( 384 'key' => $ this->db->get_blog_prefix( $blog_id ) . 'capabilities',378 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 385 379 'value' => '"' . $role . '"', 386 380 'compare' => 'LIKE', … … 395 389 foreach ( $role__in as $role ) { 396 390 $role__in_clauses[] = array( 397 'key' => $ this->db->get_blog_prefix( $blog_id ) . 'capabilities',391 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 398 392 'value' => '"' . $role . '"', 399 393 'compare' => 'LIKE', … … 408 402 foreach ( $role__not_in as $role ) { 409 403 $role__not_in_clauses[] = array( 410 'key' => $ this->db->get_blog_prefix( $blog_id ) . 'capabilities',404 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 411 405 'value' => '"' . $role . '"', 412 406 'compare' => 'NOT LIKE', … … 420 414 if ( empty( $role_queries ) ) { 421 415 $role_queries[] = array( 422 'key' => $ this->db->get_blog_prefix( $blog_id ) . 'capabilities',416 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 423 417 'compare' => 'EXISTS', 424 418 ); … … 442 436 443 437 if ( ! empty( $this->meta_query->queries ) ) { 444 $clauses = $this->meta_query->get_sql( 'user', $ this->db->users, 'ID', $this );438 $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this ); 445 439 $this->query_from .= $clauses['join']; 446 440 $this->query_where .= $clauses['where']; … … 504 498 if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { 505 499 if ( $qv['offset'] ) { 506 $this->query_limit = $ this->db->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);500 $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); 507 501 } else { 508 $this->query_limit = $ this->db->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );502 $this->query_limit = $wpdb->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); 509 503 } 510 504 } … … 562 556 // Sanitized earlier. 563 557 $ids = implode( ',', $include ); 564 $this->query_where .= " AND {$this->db->users}.ID IN ($ids)";558 $this->query_where .= " AND $wpdb->users.ID IN ($ids)"; 565 559 } elseif ( ! empty( $qv['exclude'] ) ) { 566 560 $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); 567 $this->query_where .= " AND {$this->db->users}.ID NOT IN ($ids)";561 $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)"; 568 562 } 569 563 … … 593 587 * 594 588 * @since 3.1.0 589 * 590 * @global wpdb $wpdb WordPress database abstraction object. 595 591 */ 596 592 public function query() { 593 global $wpdb; 594 597 595 $qv =& $this->query_vars; 598 596 … … 600 598 601 599 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { 602 $this->results = $ this->db->get_results( $this->request );600 $this->results = $wpdb->get_results( $this->request ); 603 601 } else { 604 $this->results = $ this->db->get_col( $this->request );602 $this->results = $wpdb->get_col( $this->request ); 605 603 } 606 604 … … 610 608 * @since 3.2.0 611 609 * 610 * @global wpdb $wpdb WordPress database abstraction object. 611 * 612 612 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. 613 613 */ 614 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { 615 $this->total_users = $this->db->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 616 } 617 618 if ( ! $this->results ) { 614 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 615 $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 616 617 if ( !$this->results ) 619 618 return; 620 }621 619 622 620 if ( 'all_with_meta' == $qv['fields'] ) { … … 669 667 * @access protected 670 668 * @since 3.1.0 669 * 670 * @global wpdb $wpdb WordPress database abstraction object. 671 671 * 672 672 * @param string $string … … 677 677 */ 678 678 protected function get_search_sql( $string, $cols, $wild = false ) { 679 global $wpdb; 680 679 681 $searches = array(); 680 682 $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; 681 683 $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; 682 $like = $leading_wild . $ this->db->esc_like( $string ) . $trailing_wild;684 $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild; 683 685 684 686 foreach ( $cols as $col ) { 685 687 if ( 'ID' == $col ) { 686 $searches[] = $ this->db->prepare( "$col = %s", $string );688 $searches[] = $wpdb->prepare( "$col = %s", $string ); 687 689 } else { 688 $searches[] = $ this->db->prepare( "$col LIKE %s", $like );690 $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); 689 691 } 690 692 } … … 723 725 * @access protected 724 726 * 727 * @global wpdb $wpdb WordPress database abstraction object. 728 * 725 729 * @param string $orderby Alias for the field to order by. 726 730 * @return string Value to used in the ORDER clause, if `$orderby` is valid. 727 731 */ 728 732 protected function parse_orderby( $orderby ) { 733 global $wpdb; 734 729 735 $meta_query_clauses = $this->meta_query->get_clauses(); 730 736 … … 741 747 $this->query_from .= " LEFT OUTER JOIN ( 742 748 SELECT post_author, COUNT(*) as post_count 743 FROM {$this->db->posts}749 FROM $wpdb->posts 744 750 $where 745 751 GROUP BY post_author 746 ) p ON ({$ this->db->users}.ID = p.post_author)752 ) p ON ({$wpdb->users}.ID = p.post_author) 747 753 "; 748 754 $_orderby = 'post_count'; … … 750 756 $_orderby = 'ID'; 751 757 } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) { 752 $_orderby = " {$this->db->usermeta}.meta_value";758 $_orderby = "$wpdb->usermeta.meta_value"; 753 759 } elseif ( 'meta_value_num' == $orderby ) { 754 $_orderby = " {$this->db->usermeta}.meta_value+0";760 $_orderby = "$wpdb->usermeta.meta_value+0"; 755 761 } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { 756 762 $include = wp_parse_id_list( $this->query_vars['include'] ); 757 763 $include_sql = implode( ',', $include ); 758 $_orderby = "FIELD( {$this->db->users}.ID, $include_sql )";764 $_orderby = "FIELD( $wpdb->users.ID, $include_sql )"; 759 765 } elseif ( 'nicename__in' === $orderby ) { 760 766 $sanitized_nicename__in = array_map( 'esc_sql', $this->query_vars['nicename__in'] ); -
trunk/src/wp-includes/class-wp-user.php
r38705 r38768 105 105 106 106 /** 107 * @since 4.7.0108 * @access protected109 * @var wpdb110 */111 protected $db;112 113 /**114 107 * Constructor. 115 108 * … … 118 111 * @since 2.0.0 119 112 * @access public 113 * 114 * @global wpdb $wpdb WordPress database abstraction object. 120 115 * 121 116 * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. … … 124 119 */ 125 120 public function __construct( $id = 0, $name = '', $blog_id = '' ) { 126 $this->db = $GLOBALS['wpdb'];127 128 121 if ( ! isset( self::$back_compat_keys ) ) { 129 $prefix = $ this->db->prefix;122 $prefix = $GLOBALS['wpdb']->prefix; 130 123 self::$back_compat_keys = array( 131 124 'user_firstname' => 'first_name', … … 242 235 243 236 if ( !$user = $wpdb->get_row( $wpdb->prepare( 244 "SELECT * FROM {$wpdb->users}WHERE $db_field = %s", $value245 ) ) ) {237 "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value 238 ) ) ) 246 239 return false; 247 } 240 248 241 update_user_caches( $user ); 249 242 … … 452 445 * @since 2.1.0 453 446 * 447 * @global wpdb $wpdb WordPress database abstraction object. 448 * 454 449 * @param string $cap_key Optional capability key 455 450 */ 456 451 protected function _init_caps( $cap_key = '' ) { 457 if ( empty( $cap_key ) ) { 458 $this->cap_key = $this->db->get_blog_prefix() . 'capabilities'; 459 } else { 452 global $wpdb; 453 454 if ( empty($cap_key) ) 455 $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; 456 else 460 457 $this->cap_key = $cap_key; 461 } 458 462 459 $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); 463 460 … … 637 634 * @since 2.0.0 638 635 * @access public 636 * 637 * @global wpdb $wpdb WordPress database abstraction object. 639 638 */ 640 639 public function update_user_level_from_caps() { 640 global $wpdb; 641 641 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); 642 update_user_meta( $this->ID, $ this->db->get_blog_prefix() . 'user_level', $this->user_level );642 update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level ); 643 643 } 644 644 … … 682 682 * @since 2.1.0 683 683 * @access public 684 * 685 * @global wpdb $wpdb WordPress database abstraction object. 684 686 */ 685 687 public function remove_all_caps() { 688 global $wpdb; 686 689 $this->caps = array(); 687 690 delete_user_meta( $this->ID, $this->cap_key ); 688 delete_user_meta( $this->ID, $ this->db->get_blog_prefix() . 'user_level' );691 delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' ); 689 692 $this->get_role_caps(); 690 693 } … … 772 775 * @since 3.0.0 773 776 * 777 * @global wpdb $wpdb WordPress database abstraction object. 778 * 774 779 * @param int $blog_id Optional. Site ID, defaults to current site. 775 780 */ 776 781 public function for_blog( $blog_id = '' ) { 777 if ( ! empty( $blog_id ) ) { 778 $cap_key = $this->db->get_blog_prefix( $blog_id ) . 'capabilities'; 779 } else { 782 global $wpdb; 783 if ( ! empty( $blog_id ) ) 784 $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; 785 else 780 786 $cap_key = ''; 781 }782 787 $this->_init_caps( $cap_key ); 783 788 } -
trunk/src/wp-includes/class-wp-xmlrpc-server.php
r38747 r38768 55 55 56 56 /** 57 * @since 4.7.058 * @access protected59 * @var wpdb60 */61 protected $db;62 63 /**64 57 * Registers all of the XMLRPC methods that XMLRPC server understands. 65 58 * … … 71 64 */ 72 65 public function __construct() { 73 $this->db = $GLOBALS['wpdb'];74 75 66 $this->methods = array( 76 67 // WordPress API … … 2895 2886 * @since 2.2.0 2896 2887 * 2888 * @global wpdb $wpdb WordPress database abstraction object. 2889 * 2897 2890 * @param array $args { 2898 2891 * Method arguments. Note: arguments must be ordered as documented. … … 2905 2898 */ 2906 2899 public function wp_getPageList( $args ) { 2900 global $wpdb; 2901 2907 2902 $this->escape( $args ); 2908 2903 … … 2920 2915 2921 2916 // Get list of pages ids and titles 2922 $page_list = $ this->db->get_results("2917 $page_list = $wpdb->get_results(" 2923 2918 SELECT ID page_id, 2924 2919 post_title page_title, … … 2927 2922 post_date, 2928 2923 post_status 2929 FROM {$ this->db->posts}2924 FROM {$wpdb->posts} 2930 2925 WHERE post_type = 'page' 2931 2926 ORDER BY ID … … 5144 5139 * @since 2.1.0 5145 5140 * 5141 * @global wpdb $wpdb WordPress database abstraction object. 5142 * 5146 5143 * @param int $post_ID Post ID. 5147 5144 * @param string $post_content Post Content for attachment. 5148 5145 */ 5149 5146 public function attach_uploads( $post_ID, $post_content ) { 5147 global $wpdb; 5148 5150 5149 // find any unattached files 5151 $attachments = $ this->db->get_results( "SELECT ID, guid FROM {$this->db->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );5150 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); 5152 5151 if ( is_array( $attachments ) ) { 5153 5152 foreach ( $attachments as $file ) { 5154 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { 5155 $this->db->update( $this->db->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); 5156 } 5153 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) 5154 $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) ); 5157 5155 } 5158 5156 } … … 5774 5772 * @since 1.5.0 5775 5773 * 5774 * @global wpdb $wpdb WordPress database abstraction object. 5775 * 5776 5776 * @param array $args { 5777 5777 * Method arguments. Note: arguments must be ordered as documented. … … 5785 5785 */ 5786 5786 public function mw_newMediaObject( $args ) { 5787 global $wpdb; 5788 5787 5789 $username = $this->escape( $args[1] ); 5788 5790 $password = $this->escape( $args[2] ); … … 6110 6112 * @since 1.5.0 6111 6113 * 6114 * @global wpdb $wpdb WordPress database abstraction object. 6115 * 6112 6116 * @param int $post_ID 6113 6117 * @return array|IXR_Error 6114 6118 */ 6115 6119 public function mt_getTrackbackPings( $post_ID ) { 6120 global $wpdb; 6121 6116 6122 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6117 6123 do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); … … 6122 6128 return new IXR_Error(404, __('Sorry, no such post.')); 6123 6129 6124 $comments = $ this->db->get_results( $this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments}WHERE comment_post_ID = %d", $post_ID) );6130 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); 6125 6131 6126 6132 if ( !$comments ) … … 6257 6263 // ...or a string #title, a little more complicated 6258 6264 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); 6259 $sql = $ this->db->prepare("SELECT ID FROM {$this->db->posts}WHERE post_title RLIKE %s", $title );6260 if (! ($post_ID = $ this->db->get_var($sql)) ) {6265 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); 6266 if (! ($post_ID = $wpdb->get_var($sql)) ) { 6261 6267 // returning unknown error '0' is better than die()ing 6262 6268 return $this->pingback_error( 0, '' ); … … 6282 6288 6283 6289 // Let's check that the remote site didn't already pingback this entry 6284 if ( $ this->db->get_results( $this->db->prepare("SELECT * FROM {$this->db->comments}WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )6290 if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) ) 6285 6291 return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); 6286 6292 … … 6409 6415 * @since 1.5.0 6410 6416 * 6417 * @global wpdb $wpdb WordPress database abstraction object. 6418 * 6411 6419 * @param string $url 6412 6420 * @return array|IXR_Error 6413 6421 */ 6414 6422 public function pingback_extensions_getPingbacks( $url ) { 6423 global $wpdb; 6424 6415 6425 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6416 6426 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); … … 6431 6441 } 6432 6442 6433 $comments = $ this->db->get_results( $this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments}WHERE comment_post_ID = %d", $post_ID) );6443 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); 6434 6444 6435 6445 if ( !$comments ) -
trunk/src/wp-includes/date.php
r38280 r38768 62 62 */ 63 63 public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' ); 64 65 /**66 * @since 4.7.067 * @access protected68 * @var wpdb69 */70 protected $db;71 64 72 65 /** … … 159 152 */ 160 153 public function __construct( $date_query, $default_column = 'post_date' ) { 161 $this->db = $GLOBALS['wpdb'];162 163 154 if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) { 164 155 $this->relation = 'OR'; … … 495 486 */ 496 487 public function validate_column( $column ) { 488 global $wpdb; 489 497 490 $valid_columns = array( 498 491 'post_date', 'post_date_gmt', 'post_modified', … … 519 512 520 513 $known_columns = array( 521 $ this->db->posts => array(514 $wpdb->posts => array( 522 515 'post_date', 523 516 'post_date_gmt', … … 525 518 'post_modified_gmt', 526 519 ), 527 $ this->db->comments => array(520 $wpdb->comments => array( 528 521 'comment_date', 529 522 'comment_date_gmt', 530 523 ), 531 $ this->db->users => array(524 $wpdb->users => array( 532 525 'user_registered', 533 526 ), 534 $ this->db->blogs => array(527 $wpdb->blogs => array( 535 528 'registered', 536 529 'last_updated', … … 724 717 */ 725 718 protected function get_sql_for_clause( $query, $parent_query ) { 719 global $wpdb; 720 726 721 // The sub-parts of a $where part. 727 722 $where_parts = array(); … … 746 741 // Range queries. 747 742 if ( ! empty( $query['after'] ) ) { 748 $where_parts[] = $ this->db->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );743 $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) ); 749 744 } 750 745 if ( ! empty( $query['before'] ) ) { 751 $where_parts[] = $ this->db->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );746 $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) ); 752 747 } 753 748 // Specific value queries. … … 963 958 */ 964 959 public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) { 960 global $wpdb; 961 965 962 // Have to have at least one 966 963 if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) … … 1016 1013 } 1017 1014 1018 return $ this->db->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );1015 return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time ); 1019 1016 } 1020 1017 } -
trunk/tests/phpunit/tests/user.php
r38398 r38768 182 182 183 183 foreach ( (array) $user as $key => $value ) { 184 if ( $value instanceof wpdb ) {185 continue;186 }187 184 $this->assertEquals( $value, $user->$key ); 188 185 }
Note: See TracChangeset
for help on using the changeset viewer.