Changeset 38275
- Timestamp:
- 08/18/2016 06:20:55 PM (8 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r38121 r38275 141 141 return false; 142 142 } 143 144 /** 145 * @since 4.7.0 146 * @access protected 147 * @var wpdb 148 */ 149 protected $db; 143 150 144 151 /** … … 261 268 */ 262 269 public function __construct( $query = '' ) { 270 $this->db = $GLOBALS['wpdb']; 271 263 272 $this->query_var_defaults = array( 264 273 'author_email' => '', … … 364 373 * @access public 365 374 * 366 * @global wpdb $wpdb WordPress database abstraction object.367 *368 375 * @return int|array List of comments or number of found comments if `$count` argument is true. 369 376 */ 370 377 public function get_comments() { 371 global $wpdb;372 373 378 $this->parse_query(); 374 379 … … 389 394 $this->meta_query->parse_query_vars( $this->query_vars ); 390 395 if ( ! empty( $this->meta_query->queries ) ) { 391 $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $ wpdb->comments, 'comment_ID', $this );396 $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $this->db->comments, 'comment_ID', $this ); 392 397 } 393 398 … … 481 486 * @since 4.4.0 482 487 * @access protected 483 *484 * @global wpdb $wpdb WordPress database abstraction object.485 488 */ 486 489 protected function get_comment_ids() { 487 global $wpdb;488 489 490 // Assemble clauses related to 'comment_approved'. 490 491 $approved_clauses = array(); … … 515 516 516 517 default : 517 $status_clauses[] = $ wpdb->prepare( "comment_approved = %s", $status );518 $status_clauses[] = $this->db->prepare( "comment_approved = %s", $status ); 518 519 break; 519 520 } … … 538 539 // Numeric values are assumed to be user ids. 539 540 if ( is_numeric( $unapproved_identifier ) ) { 540 $approved_clauses[] = $ wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );541 $approved_clauses[] = $this->db->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier ); 541 542 542 543 // Otherwise we match against email addresses. 543 544 } else { 544 $approved_clauses[] = $ wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );545 $approved_clauses[] = $this->db->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier ); 545 546 } 546 547 } … … 601 602 // If no valid clauses were found, order by comment_date_gmt. 602 603 if ( empty( $orderby_array ) ) { 603 $orderby_array[] = " $wpdb->comments.comment_date_gmt $order";604 $orderby_array[] = "{$this->db->comments}.comment_date_gmt $order"; 604 605 } 605 606 … … 634 635 } 635 636 636 $orderby_array[] = " $wpdb->comments.comment_ID $comment_ID_order";637 $orderby_array[] = "{$this->db->comments}.comment_ID $comment_ID_order"; 637 638 } 638 639 639 640 $orderby = implode( ', ', $orderby_array ); 640 641 } else { 641 $orderby = " $wpdb->comments.comment_date_gmt $order";642 $orderby = "{$this->db->comments}.comment_date_gmt $order"; 642 643 } 643 644 … … 656 657 $fields = 'COUNT(*)'; 657 658 } else { 658 $fields = " $wpdb->comments.comment_ID";659 $fields = "{$this->db->comments}.comment_ID"; 659 660 } 660 661 661 662 $post_id = absint( $this->query_vars['post_id'] ); 662 663 if ( ! empty( $post_id ) ) { 663 $this->sql_clauses['where']['post_id'] = $ wpdb->prepare( 'comment_post_ID = %d', $post_id );664 $this->sql_clauses['where']['post_id'] = $this->db->prepare( 'comment_post_ID = %d', $post_id ); 664 665 } 665 666 666 667 // Parse comment IDs for an IN clause. 667 668 if ( ! empty( $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'] ) ) . ' )';669 $this->sql_clauses['where']['comment__in'] = "{$this->db->comments}.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )'; 669 670 } 670 671 671 672 // Parse comment IDs for a NOT IN clause. 672 673 if ( ! empty( $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'] ) ) . ' )';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'] ) ) . ' )'; 674 675 } 675 676 … … 695 696 696 697 if ( '' !== $this->query_vars['author_email'] ) { 697 $this->sql_clauses['where']['author_email'] = $ wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );698 $this->sql_clauses['where']['author_email'] = $this->db->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] ); 698 699 } 699 700 700 701 if ( '' !== $this->query_vars['author_url'] ) { 701 $this->sql_clauses['where']['author_url'] = $ wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );702 $this->sql_clauses['where']['author_url'] = $this->db->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] ); 702 703 } 703 704 704 705 if ( '' !== $this->query_vars['karma'] ) { 705 $this->sql_clauses['where']['karma'] = $ wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );706 $this->sql_clauses['where']['karma'] = $this->db->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); 706 707 } 707 708 … … 734 735 735 736 default: 736 $comment_types[ $operator ][] = $ wpdb->prepare( '%s', $type );737 $comment_types[ $operator ][] = $this->db->prepare( '%s', $type ); 737 738 break; 738 739 } … … 751 752 752 753 if ( '' !== $parent ) { 753 $this->sql_clauses['where']['parent'] = $ wpdb->prepare( 'comment_parent = %d', $parent );754 $this->sql_clauses['where']['parent'] = $this->db->prepare( 'comment_parent = %d', $parent ); 754 755 } 755 756 … … 757 758 $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')'; 758 759 } elseif ( '' !== $this->query_vars['user_id'] ) { 759 $this->sql_clauses['where']['user_id'] = $ wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );760 $this->sql_clauses['where']['user_id'] = $this->db->prepare( 'user_id = %d', $this->query_vars['user_id'] ); 760 761 } 761 762 … … 781 782 // $field_value may be an array. 782 783 $esses = array_fill( 0, count( (array) $field_value ), '%s' ); 783 $this->sql_clauses['where'][ $field_name ] = $ wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );784 $this->sql_clauses['where'][ $field_name ] = $this->db->prepare( " {$this->db->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); 784 785 } 785 786 } … … 802 803 803 804 $esses = array_fill( 0, count( $q_values ), '%s' ); 804 $this->sql_clauses['where'][ $field_name ] = $ wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values );805 $this->sql_clauses['where'][ $field_name ] = $this->db->prepare( " {$this->db->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values ); 805 806 } 806 807 } … … 831 832 832 833 if ( $join_posts_table ) { 833 $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";834 $join .= "JOIN {$this->db->posts} ON {$this->db->posts}.ID = {$this->db->comments}.comment_post_ID"; 834 835 } 835 836 … … 841 842 842 843 if ( ! $this->query_vars['count'] ) { 843 $groupby = "{$ wpdb->comments}.comment_ID";844 $groupby = "{$this->db->comments}.comment_ID"; 844 845 } 845 846 } … … 890 891 891 892 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 892 $this->sql_clauses['from'] = "FROM $wpdb->comments$join";893 $this->sql_clauses['from'] = "FROM {$this->db->comments} $join"; 893 894 $this->sql_clauses['groupby'] = $groupby; 894 895 $this->sql_clauses['orderby'] = $orderby; … … 898 899 899 900 if ( $this->query_vars['count'] ) { 900 return intval( $ wpdb->get_var( $this->request ) );901 return intval( $this->db->get_var( $this->request ) ); 901 902 } else { 902 $comment_ids = $ wpdb->get_col( $this->request );903 $comment_ids = $this->db->get_col( $this->request ); 903 904 return array_map( 'intval', $comment_ids ); 904 905 } … … 911 912 * @since 4.6.0 912 913 * @access private 913 *914 * @global wpdb $wpdb WordPress database abstraction object.915 914 */ 916 915 private function set_found_comments() { 917 global $wpdb;918 919 916 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 920 917 /** … … 928 925 $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this ); 929 926 930 $this->found_comments = (int) $ wpdb->get_var( $found_comments_query );927 $this->found_comments = (int) $this->db->get_var( $found_comments_query ); 931 928 } 932 929 } … … 944 941 */ 945 942 protected function fill_descendants( $comments ) { 946 global $wpdb;947 948 943 $levels = array( 949 944 0 => wp_list_pluck( $comments, 'comment_ID' ), … … 997 992 if ( $uncached_parent_ids ) { 998 993 $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $uncached_parent_ids ) ) . ')'; 999 $level_comments = $ wpdb->get_results( "SELECT $wpdb->comments.comment_ID, $wpdb->comments.comment_parent {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" );994 $level_comments = $this->db->get_results( "SELECT {$this->db->comments}.comment_ID, {$this->db->comments}.comment_parent {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" ); 1000 995 1001 996 // Cache parent-child relationships. … … 1068 1063 * @access protected 1069 1064 * 1070 * @global wpdb $wpdb WordPress database abstraction object.1071 *1072 1065 * @param string $string 1073 1066 * @param array $cols … … 1075 1068 */ 1076 1069 protected function get_search_sql( $string, $cols ) { 1077 global $wpdb; 1078 1079 $like = '%' . $wpdb->esc_like( $string ) . '%'; 1070 $like = '%' . $this->db->esc_like( $string ) . '%'; 1080 1071 1081 1072 $searches = array(); 1082 1073 foreach ( $cols as $col ) { 1083 $searches[] = $ wpdb->prepare( "$col LIKE %s", $like );1074 $searches[] = $this->db->prepare( "$col LIKE %s", $like ); 1084 1075 } 1085 1076 … … 1093 1084 * @access protected 1094 1085 * 1095 * @global wpdb $wpdb WordPress database abstraction object.1096 *1097 1086 * @param string $orderby Alias for the field to order by. 1098 1087 * @return string|false Value to used in the ORDER clause. False otherwise. 1099 1088 */ 1100 1089 protected function parse_orderby( $orderby ) { 1101 global $wpdb;1102 1103 1090 $allowed_keys = array( 1104 1091 'comment_agent', … … 1132 1119 $parsed = false; 1133 1120 if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) { 1134 $parsed = " $wpdb->commentmeta.meta_value";1121 $parsed = "{$this->db->commentmeta}.meta_value"; 1135 1122 } elseif ( $orderby == 'meta_value_num' ) { 1136 $parsed = " $wpdb->commentmeta.meta_value+0";1123 $parsed = "{$this->db->commentmeta}.meta_value+0"; 1137 1124 } elseif ( $orderby == 'comment__in' ) { 1138 1125 $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) ); 1139 $parsed = "FIELD( {$ wpdb->comments}.comment_ID, $comment__in )";1126 $parsed = "FIELD( {$this->db->comments}.comment_ID, $comment__in )"; 1140 1127 } elseif ( in_array( $orderby, $allowed_keys ) ) { 1141 1128 … … 1144 1131 $parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); 1145 1132 } else { 1146 $parsed = " $wpdb->comments.$orderby";1133 $parsed = "{$this->db->comments}.$orderby"; 1147 1134 } 1148 1135 } -
trunk/src/wp-includes/class-wp-meta-query.php
r37860 r38275 107 107 108 108 /** 109 * @since 4.7.0 110 * @access protected 111 * @var wpdb 112 */ 113 protected $db; 114 115 /** 109 116 * Constructor. 110 117 * … … 138 145 */ 139 146 public function __construct( $meta_query = false ) { 140 if ( !$meta_query ) 147 $this->db = $GLOBALS['wpdb']; 148 149 if ( ! $meta_query ) { 141 150 return; 151 } 142 152 143 153 if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { … … 485 495 * @access public 486 496 * 487 * @global wpdb $wpdb WordPress database abstraction object.488 *489 497 * @param array $clause Query clause, passed by reference. 490 498 * @param array $parent_query Parent query array. … … 499 507 */ 500 508 public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) { 501 global $wpdb;502 503 509 $sql_chunks = array( 504 510 'where' => array(), … … 538 544 $join .= " LEFT JOIN $this->meta_table"; 539 545 $join .= $i ? " AS $alias" : ''; 540 $join .= $ wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] );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'] ); 541 547 542 548 // All other JOIN clauses. … … 582 588 $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL'; 583 589 } else { 584 $sql_chunks['where'][] = $ wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );590 $sql_chunks['where'][] = $this->db->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) ); 585 591 } 586 592 } … … 602 608 case 'NOT IN' : 603 609 $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')'; 604 $where = $ wpdb->prepare( $meta_compare_string, $meta_value );610 $where = $this->db->prepare( $meta_compare_string, $meta_value ); 605 611 break; 606 612 … … 608 614 case 'NOT BETWEEN' : 609 615 $meta_value = array_slice( $meta_value, 0, 2 ); 610 $where = $ wpdb->prepare( '%s AND %s', $meta_value );616 $where = $this->db->prepare( '%s AND %s', $meta_value ); 611 617 break; 612 618 613 619 case 'LIKE' : 614 620 case 'NOT LIKE' : 615 $meta_value = '%' . $ wpdb->esc_like( $meta_value ) . '%';616 $where = $ wpdb->prepare( '%s', $meta_value );621 $meta_value = '%' . $this->db->esc_like( $meta_value ) . '%'; 622 $where = $this->db->prepare( '%s', $meta_value ); 617 623 break; 618 624 … … 620 626 case 'EXISTS' : 621 627 $meta_compare = '='; 622 $where = $ wpdb->prepare( '%s', $meta_value );628 $where = $this->db->prepare( '%s', $meta_value ); 623 629 break; 624 630 … … 629 635 630 636 default : 631 $where = $ wpdb->prepare( '%s', $meta_value );637 $where = $this->db->prepare( '%s', $meta_value ); 632 638 break; 633 639 -
trunk/src/wp-includes/class-wp-network-query.php
r38104 r38275 86 86 */ 87 87 public $max_num_pages = 0; 88 89 /** 90 * @since 4.7.0 91 * @access protected 92 * @var wpdb 93 */ 94 protected $db; 88 95 89 96 /** … … 125 132 */ 126 133 public function __construct( $query = '' ) { 134 $this->db = $GLOBALS['wpdb']; 135 127 136 $this->query_var_defaults = array( 128 137 'network__in' => '', … … 291 300 */ 292 301 protected function get_network_ids() { 293 global $wpdb;294 295 302 $order = $this->parse_order( $this->query_vars['order'] ); 296 303 … … 333 340 $orderby = implode( ', ', $orderby_array ); 334 341 } else { 335 $orderby = " $wpdb->site.id $order";342 $orderby = "{$this->db->site}.id $order"; 336 343 } 337 344 … … 350 357 $fields = 'COUNT(*)'; 351 358 } else { 352 $fields = " $wpdb->site.id";359 $fields = "{$this->db->site}.id"; 353 360 } 354 361 355 362 // Parse network IDs for an IN clause. 356 363 if ( ! empty( $this->query_vars['network__in'] ) ) { 357 $this->sql_clauses['where']['network__in'] = " $wpdb->site.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )';364 $this->sql_clauses['where']['network__in'] = "{$this->db->site}.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; 358 365 } 359 366 360 367 // Parse network IDs for a NOT IN clause. 361 368 if ( ! empty( $this->query_vars['network__not_in'] ) ) { 362 $this->sql_clauses['where']['network__not_in'] = " $wpdb->site.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )';369 $this->sql_clauses['where']['network__not_in'] = "{$this->db->site}.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; 363 370 } 364 371 365 372 if ( ! empty( $this->query_vars['domain'] ) ) { 366 $this->sql_clauses['where']['domain'] = $ wpdb->prepare( "$wpdb->site.domain = %s", $this->query_vars['domain'] );373 $this->sql_clauses['where']['domain'] = $this->db->prepare( "{$this->db->site}.domain = %s", $this->query_vars['domain'] ); 367 374 } 368 375 369 376 // Parse network domain for an IN clause. 370 377 if ( is_array( $this->query_vars['domain__in'] ) ) { 371 $this->sql_clauses['where']['domain__in'] = " $wpdb->site.domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";378 $this->sql_clauses['where']['domain__in'] = "{$this->db->site}.domain IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 372 379 } 373 380 374 381 // Parse network domain for a NOT IN clause. 375 382 if ( is_array( $this->query_vars['domain__not_in'] ) ) { 376 $this->sql_clauses['where']['domain__not_in'] = " $wpdb->site.domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";383 $this->sql_clauses['where']['domain__not_in'] = "{$this->db->site}.domain NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 377 384 } 378 385 379 386 if ( ! empty( $this->query_vars['path'] ) ) { 380 $this->sql_clauses['where']['path'] = $ wpdb->prepare( "$wpdb->site.path = %s", $this->query_vars['path'] );387 $this->sql_clauses['where']['path'] = $this->db->prepare( "{$this->db->site}.path = %s", $this->query_vars['path'] ); 381 388 } 382 389 383 390 // Parse network path for an IN clause. 384 391 if ( is_array( $this->query_vars['path__in'] ) ) { 385 $this->sql_clauses['where']['path__in'] = " $wpdb->site.path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";392 $this->sql_clauses['where']['path__in'] = "{$this->db->site}.path IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__in'] ) ) . "' )"; 386 393 } 387 394 388 395 // Parse network path for a NOT IN clause. 389 396 if ( is_array( $this->query_vars['path__not_in'] ) ) { 390 $this->sql_clauses['where']['path__not_in'] = " $wpdb->site.path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";397 $this->sql_clauses['where']['path__not_in'] = "{$this->db->site}.path NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 391 398 } 392 399 … … 395 402 $this->sql_clauses['where']['search'] = $this->get_search_sql( 396 403 $this->query_vars['search'], 397 array( " $wpdb->site.domain", "$wpdb->site.path" )404 array( "{$this->db->site}.domain", "{$this->db->site}.path" ) 398 405 ); 399 406 } … … 440 447 441 448 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 442 $this->sql_clauses['from'] = "FROM $wpdb->site$join";449 $this->sql_clauses['from'] = "FROM {$this->db->site} $join"; 443 450 $this->sql_clauses['groupby'] = $groupby; 444 451 $this->sql_clauses['orderby'] = $orderby; … … 448 455 449 456 if ( $this->query_vars['count'] ) { 450 return intval( $ wpdb->get_var( $this->request ) );451 } 452 453 $network_ids = $ wpdb->get_col( $this->request );457 return intval( $this->db->get_var( $this->request ) ); 458 } 459 460 $network_ids = $this->db->get_col( $this->request ); 454 461 455 462 return array_map( 'intval', $network_ids ); … … 462 469 * @since 4.6.0 463 470 * @access private 464 *465 * @global wpdb $wpdb WordPress database abstraction object.466 471 */ 467 472 private function set_found_networks() { 468 global $wpdb;469 470 473 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 471 474 /** … … 479 482 $found_networks_query = apply_filters( 'found_networks_query', 'SELECT FOUND_ROWS()', $this ); 480 483 481 $this->found_networks = (int) $ wpdb->get_var( $found_networks_query );484 $this->found_networks = (int) $this->db->get_var( $found_networks_query ); 482 485 } 483 486 } … … 488 491 * @since 4.6.0 489 492 * @access protected 490 *491 * @global wpdb $wpdb WordPress database abstraction object.492 493 * 493 494 * @param string $string Search string. … … 497 498 */ 498 499 protected function get_search_sql( $string, $columns ) { 499 global $wpdb; 500 501 $like = '%' . $wpdb->esc_like( $string ) . '%'; 500 $like = '%' . $this->db->esc_like( $string ) . '%'; 502 501 503 502 $searches = array(); 504 503 foreach ( $columns as $column ) { 505 $searches[] = $ wpdb->prepare( "$column LIKE %s", $like );504 $searches[] = $this->db->prepare( "$column LIKE %s", $like ); 506 505 } 507 506 … … 514 513 * @since 4.6.0 515 514 * @access protected 516 *517 * @global wpdb $wpdb WordPress database abstraction object.518 515 * 519 516 * @param string $orderby Alias for the field to order by. … … 521 518 */ 522 519 protected function parse_orderby( $orderby ) { 523 global $wpdb;524 525 520 $allowed_keys = array( 526 521 'id', … … 532 527 if ( $orderby == 'network__in' ) { 533 528 $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); 534 $parsed = "FIELD( {$ wpdb->site}.id, $network__in )";529 $parsed = "FIELD( {$this->db->site}.id, $network__in )"; 535 530 } elseif ( $orderby == 'domain_length' || $orderby == 'path_length' ) { 536 531 $field = substr( $orderby, 0, -7 ); 537 $parsed = "CHAR_LENGTH( $wpdb->site.$field)";532 $parsed = "CHAR_LENGTH({$this->db->site}.$field)"; 538 533 } elseif ( in_array( $orderby, $allowed_keys ) ) { 539 $parsed = " $wpdb->site.$orderby";534 $parsed = "{$this->db->site}.$orderby"; 540 535 } 541 536 -
trunk/src/wp-includes/class-wp-site-query.php
r38103 r38275 95 95 */ 96 96 public $max_num_pages = 0; 97 98 /** 99 * @since 4.7.0 100 * @access protected 101 * @var wpdb 102 */ 103 protected $db; 97 104 98 105 /** … … 148 155 */ 149 156 public function __construct( $query = '' ) { 157 $this->db = $GLOBALS['wpdb']; 158 150 159 $this->query_var_defaults = array( 151 160 'fields' => '', … … 326 335 * @access protected 327 336 * 328 * @global wpdb $wpdb WordPress database abstraction object.329 *330 337 * @return int|array A single count of site IDs if a count query. An array of site IDs if a full query. 331 338 */ 332 339 protected function get_site_ids() { 333 global $wpdb;334 335 340 $order = $this->parse_order( $this->query_vars['order'] ); 336 341 … … 396 401 $site_id = absint( $this->query_vars['ID'] ); 397 402 if ( ! empty( $site_id ) ) { 398 $this->sql_clauses['where']['ID'] = $ wpdb->prepare( 'blog_id = %d', $site_id );403 $this->sql_clauses['where']['ID'] = $this->db->prepare( 'blog_id = %d', $site_id ); 399 404 } 400 405 … … 412 417 413 418 if ( ! empty( $network_id ) ) { 414 $this->sql_clauses['where']['network_id'] = $ wpdb->prepare( 'site_id = %d', $network_id );419 $this->sql_clauses['where']['network_id'] = $this->db->prepare( 'site_id = %d', $network_id ); 415 420 } 416 421 … … 426 431 427 432 if ( ! empty( $this->query_vars['domain'] ) ) { 428 $this->sql_clauses['where']['domain'] = $ wpdb->prepare( 'domain = %s', $this->query_vars['domain'] );433 $this->sql_clauses['where']['domain'] = $this->db->prepare( 'domain = %s', $this->query_vars['domain'] ); 429 434 } 430 435 431 436 // Parse site domain for an IN clause. 432 437 if ( is_array( $this->query_vars['domain__in'] ) ) { 433 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";438 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 434 439 } 435 440 436 441 // Parse site domain for a NOT IN clause. 437 442 if ( is_array( $this->query_vars['domain__not_in'] ) ) { 438 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";443 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 439 444 } 440 445 441 446 if ( ! empty( $this->query_vars['path'] ) ) { 442 $this->sql_clauses['where']['path'] = $ wpdb->prepare( 'path = %s', $this->query_vars['path'] );447 $this->sql_clauses['where']['path'] = $this->db->prepare( 'path = %s', $this->query_vars['path'] ); 443 448 } 444 449 445 450 // Parse site path for an IN clause. 446 451 if ( is_array( $this->query_vars['path__in'] ) ) { 447 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";452 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__in'] ) ) . "' )"; 448 453 } 449 454 450 455 // Parse site path for a NOT IN clause. 451 456 if ( is_array( $this->query_vars['path__not_in'] ) ) { 452 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $ wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";457 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 453 458 } 454 459 455 460 if ( is_numeric( $this->query_vars['archived'] ) ) { 456 461 $archived = absint( $this->query_vars['archived'] ); 457 $this->sql_clauses['where']['archived'] = $ wpdb->prepare( "archived = %d ", $archived );462 $this->sql_clauses['where']['archived'] = $this->db->prepare( "archived = %d ", $archived ); 458 463 } 459 464 460 465 if ( is_numeric( $this->query_vars['mature'] ) ) { 461 466 $mature = absint( $this->query_vars['mature'] ); 462 $this->sql_clauses['where']['mature'] = $ wpdb->prepare( "mature = %d ", $mature );467 $this->sql_clauses['where']['mature'] = $this->db->prepare( "mature = %d ", $mature ); 463 468 } 464 469 465 470 if ( is_numeric( $this->query_vars['spam'] ) ) { 466 471 $spam = absint( $this->query_vars['spam'] ); 467 $this->sql_clauses['where']['spam'] = $ wpdb->prepare( "spam = %d ", $spam );472 $this->sql_clauses['where']['spam'] = $this->db->prepare( "spam = %d ", $spam ); 468 473 } 469 474 470 475 if ( is_numeric( $this->query_vars['deleted'] ) ) { 471 476 $deleted = absint( $this->query_vars['deleted'] ); 472 $this->sql_clauses['where']['deleted'] = $ wpdb->prepare( "deleted = %d ", $deleted );477 $this->sql_clauses['where']['deleted'] = $this->db->prepare( "deleted = %d ", $deleted ); 473 478 } 474 479 475 480 if ( is_numeric( $this->query_vars['public'] ) ) { 476 481 $public = absint( $this->query_vars['public'] ); 477 $this->sql_clauses['where']['public'] = $ wpdb->prepare( "public = %d ", $public );482 $this->sql_clauses['where']['public'] = $this->db->prepare( "public = %d ", $public ); 478 483 } 479 484 … … 551 556 552 557 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 553 $this->sql_clauses['from'] = "FROM $wpdb->blogs$join";558 $this->sql_clauses['from'] = "FROM {$this->db->blogs} $join"; 554 559 $this->sql_clauses['groupby'] = $groupby; 555 560 $this->sql_clauses['orderby'] = $orderby; … … 559 564 560 565 if ( $this->query_vars['count'] ) { 561 return intval( $ wpdb->get_var( $this->request ) );562 } 563 564 $site_ids = $ wpdb->get_col( $this->request );566 return intval( $this->db->get_var( $this->request ) ); 567 } 568 569 $site_ids = $this->db->get_col( $this->request ); 565 570 566 571 return array_map( 'intval', $site_ids ); … … 573 578 * @since 4.6.0 574 579 * @access private 575 *576 * @global wpdb $wpdb WordPress database abstraction object.577 580 */ 578 581 private function set_found_sites() { 579 global $wpdb;580 581 582 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 582 583 /** … … 590 591 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 591 592 592 $this->found_sites = (int) $ wpdb->get_var( $found_sites_query );593 $this->found_sites = (int) $this->db->get_var( $found_sites_query ); 593 594 } 594 595 } … … 599 600 * @since 4.6.0 600 601 * @access protected 601 *602 * @global wpdb $wpdb WordPress database abstraction object.603 602 * 604 603 * @param string $string Search string. … … 607 606 */ 608 607 protected function get_search_sql( $string, $columns ) { 609 global $wpdb;610 611 608 if ( false !== strpos( $string, '*' ) ) { 612 $like = '%' . implode( '%', array_map( array( $ wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%';609 $like = '%' . implode( '%', array_map( array( $this->db, 'esc_like' ), explode( '*', $string ) ) ) . '%'; 613 610 } else { 614 $like = '%' . $ wpdb->esc_like( $string ) . '%';611 $like = '%' . $this->db->esc_like( $string ) . '%'; 615 612 } 616 613 617 614 $searches = array(); 618 615 foreach ( $columns as $column ) { 619 $searches[] = $ wpdb->prepare( "$column LIKE %s", $like );616 $searches[] = $this->db->prepare( "$column LIKE %s", $like ); 620 617 } 621 618 … … 628 625 * @since 4.6.0 629 626 * @access protected 630 *631 * @global wpdb $wpdb WordPress database abstraction object.632 627 * 633 628 * @param string $orderby Alias for the field to order by. … … 635 630 */ 636 631 protected function parse_orderby( $orderby ) { 637 global $wpdb;638 639 632 $parsed = false; 640 633 … … 642 635 case 'site__in': 643 636 $site__in = implode( ',', array_map( 'absint', $this->query_vars['site__in'] ) ); 644 $parsed = "FIELD( {$ wpdb->blogs}.blog_id, $site__in )";637 $parsed = "FIELD( {$this->db->blogs}.blog_id, $site__in )"; 645 638 break; 646 639 case 'network__in': 647 640 $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); 648 $parsed = "FIELD( {$ wpdb->blogs}.site_id, $network__in )";641 $parsed = "FIELD( {$this->db->blogs}.site_id, $network__in )"; 649 642 break; 650 643 case 'domain': -
trunk/src/wp-includes/class-wp-tax-query.php
r38079 r38275 93 93 94 94 /** 95 * @since 4.7.0 96 * @access protected 97 * @var wpdb 98 */ 99 protected $db; 100 101 /** 95 102 * Constructor. 96 103 * … … 120 127 */ 121 128 public function __construct( $tax_query ) { 129 $this->db = $GLOBALS['wpdb']; 130 122 131 if ( isset( $tax_query['relation'] ) ) { 123 132 $this->relation = $this->sanitize_relation( $tax_query['relation'] ); … … 388 397 * @access public 389 398 * 390 * @global wpdb $wpdb The WordPress database abstraction object.391 *392 399 * @param array $clause Query clause, passed by reference. 393 400 * @param array $parent_query Parent query array. … … 400 407 */ 401 408 public function get_sql_for_clause( &$clause, $parent_query ) { 402 global $wpdb;403 404 409 $sql = array( 405 410 'where' => array(), … … 433 438 if ( false === $alias ) { 434 439 $i = count( $this->table_aliases ); 435 $alias = $i ? 'tt' . $i : $ wpdb->term_relationships;440 $alias = $i ? 'tt' . $i : $this->db->term_relationships; 436 441 437 442 // Store the alias as part of a flat array to build future iterators. … … 441 446 $clause['alias'] = $alias; 442 447 443 $join .= " LEFT JOIN $wpdb->term_relationships";448 $join .= " LEFT JOIN {$this->db->term_relationships}"; 444 449 $join .= $i ? " AS $alias" : ''; 445 450 $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)"; … … 459 464 $where = "$this->primary_table.$this->primary_id_column NOT IN ( 460 465 SELECT object_id 461 FROM $wpdb->term_relationships466 FROM {$this->db->term_relationships} 462 467 WHERE term_taxonomy_id IN ($terms) 463 468 )"; … … 475 480 $where = "( 476 481 SELECT COUNT(1) 477 FROM $wpdb->term_relationships482 FROM {$this->db->term_relationships} 478 483 WHERE term_taxonomy_id IN ($terms) 479 484 AND object_id = $this->primary_table.$this->primary_id_column … … 482 487 } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) { 483 488 484 $where = $ wpdb->prepare( "$operator (489 $where = $this->db->prepare( "$operator ( 485 490 SELECT 1 486 FROM $wpdb->term_relationships487 INNER JOIN $wpdb->term_taxonomy488 ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id489 WHERE $wpdb->term_taxonomy.taxonomy = %s490 AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column491 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_id 494 WHERE {$this->db->term_taxonomy}.taxonomy = %s 495 AND {$this->db->term_relationships}.object_id = $this->primary_table.$this->primary_id_column 491 496 )", $clause['taxonomy'] ); 492 497 … … 598 603 * @since 3.2.0 599 604 * 600 * @global wpdb $wpdb The WordPress database abstraction object.601 *602 605 * @param array $query The single query. Passed by reference. 603 606 * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', … … 605 608 */ 606 609 public function transform_query( &$query, $resulting_field ) { 607 global $wpdb;608 609 610 if ( empty( $query['terms'] ) ) 610 611 return; … … 629 630 $terms = implode( ",", $query['terms'] ); 630 631 631 $terms = $ wpdb->get_col( "632 SELECT $wpdb->term_taxonomy.$resulting_field633 FROM $wpdb->term_taxonomy634 INNER JOIN $wpdb->termsUSING (term_id)632 $terms = $this->db->get_col( " 633 SELECT {$this->db->term_taxonomy}.$resulting_field 634 FROM {$this->db->term_taxonomy} 635 INNER JOIN {$this->db->terms} USING (term_id) 635 636 WHERE taxonomy = '{$query['taxonomy']}' 636 AND $wpdb->terms.{$query['field']} IN ($terms)637 AND {$this->db->terms}.{$query['field']} IN ($terms) 637 638 " ); 638 639 break; 639 640 case 'term_taxonomy_id': 640 641 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 641 $terms = $ wpdb->get_col( "642 $terms = $this->db->get_col( " 642 643 SELECT $resulting_field 643 FROM $wpdb->term_taxonomy644 FROM {$this->db->term_taxonomy} 644 645 WHERE term_taxonomy_id IN ($terms) 645 646 " ); … … 647 648 default: 648 649 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 649 $terms = $ wpdb->get_col( "650 $terms = $this->db->get_col( " 650 651 SELECT $resulting_field 651 FROM $wpdb->term_taxonomy652 FROM {$this->db->term_taxonomy} 652 653 WHERE taxonomy = '{$query['taxonomy']}' 653 654 AND term_id IN ($terms) -
trunk/src/wp-includes/class-wp-term-query.php
r38212 r38275 86 86 */ 87 87 public $terms; 88 89 /** 90 * @since 4.7.0 91 * @access protected 92 * @var wpdb 93 */ 94 protected $db; 88 95 89 96 /** … … 173 180 */ 174 181 public function __construct( $query = '' ) { 182 $this->db = $GLOBALS['wpdb']; 183 175 184 $this->query_var_defaults = array( 176 185 'taxonomy' => null, … … 294 303 * @access public 295 304 * 296 * @global wpdb $wpdb WordPress database abstraction object.297 *298 305 * @return array 299 306 */ 300 307 public function get_terms() { 301 global $wpdb;302 303 308 $this->parse_query( $this->query_vars ); 304 309 $args = $this->query_vars; … … 487 492 $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})"; 488 493 } else { 489 $this->sql_clauses['where']['term_taxonomy_id'] = $ wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );494 $this->sql_clauses['where']['term_taxonomy_id'] = $this->db->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] ); 490 495 } 491 496 } 492 497 493 498 if ( ! empty( $args['name__like'] ) ) { 494 $this->sql_clauses['where']['name__like'] = $ wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );499 $this->sql_clauses['where']['name__like'] = $this->db->prepare( "t.name LIKE %s", '%' . $this->db->esc_like( $args['name__like'] ) . '%' ); 495 500 } 496 501 497 502 if ( ! empty( $args['description__like'] ) ) { 498 $this->sql_clauses['where']['description__like'] = $ wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );503 $this->sql_clauses['where']['description__like'] = $this->db->prepare( "tt.description LIKE %s", '%' . $this->db->esc_like( $args['description__like'] ) . '%' ); 499 504 } 500 505 … … 592 597 $fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) ); 593 598 594 $join .= " INNER JOIN $wpdb->term_taxonomyAS tt ON t.term_id = tt.term_id";599 $join .= " INNER JOIN {$this->db->term_taxonomy} AS tt ON t.term_id = tt.term_id"; 595 600 596 601 $where = implode( ' AND ', $this->sql_clauses['where'] ); … … 622 627 623 628 $this->sql_clauses['select'] = "SELECT $distinct $fields"; 624 $this->sql_clauses['from'] = "FROM $wpdb->termsAS t $join";629 $this->sql_clauses['from'] = "FROM {$this->db->terms} AS t $join"; 625 630 $this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : ''; 626 631 $this->sql_clauses['limits'] = $limits; … … 647 652 648 653 if ( 'count' == $_fields ) { 649 return $ wpdb->get_var( $this->request );650 } 651 652 $terms = $ wpdb->get_results( $this->request );654 return $this->db->get_var( $this->request ); 655 } 656 657 $terms = $this->db->get_results( $this->request ); 653 658 if ( 'all' == $_fields ) { 654 659 update_term_cache( $terms ); … … 753 758 * @since 4.6.0 754 759 * @access protected 755 *756 * @global wpdb $wpdb WordPress database abstraction object.757 760 * 758 761 * @param string $orderby_raw Alias for the field to order by. … … 895 898 * @access protected 896 899 * 897 * @global wpdb $wpdb WordPress database abstraction object.898 *899 900 * @param string $string 900 901 * @return string 901 902 */ 902 903 protected function get_search_sql( $string ) { 903 global $wpdb; 904 905 $like = '%' . $wpdb->esc_like( $string ) . '%'; 906 907 return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); 904 $like = '%' . $this->db->esc_like( $string ) . '%'; 905 906 return $this->db->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); 908 907 } 909 908 } -
trunk/src/wp-includes/class-wp-user-query.php
r37492 r38275 72 72 73 73 /** 74 * @since 4.7.0 75 * @access protected 76 * @var wpdb 77 */ 78 protected $db; 79 80 /** 74 81 * PHP5 constructor. 75 82 * … … 79 86 */ 80 87 public function __construct( $query = null ) { 88 $this->db = $GLOBALS['wpdb']; 89 81 90 if ( ! empty( $query ) ) { 82 91 $this->prepare_query( $query ); … … 135 144 * @access public 136 145 * 137 * @global wpdb $wpdb WordPress database abstraction object.138 146 * @global int $blog_id 139 147 * … … 199 207 */ 200 208 public function prepare_query( $query = array() ) { 201 global $wpdb;202 203 209 if ( empty( $this->query_vars ) || ! empty( $query ) ) { 204 210 $this->query_limit = null; … … 229 235 foreach ( $qv['fields'] as $field ) { 230 236 $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); 231 $this->query_fields[] = " $wpdb->users.$field";237 $this->query_fields[] = "{$this->db->users}.$field"; 232 238 } 233 239 $this->query_fields = implode( ',', $this->query_fields ); 234 240 } elseif ( 'all' == $qv['fields'] ) { 235 $this->query_fields = " $wpdb->users.*";241 $this->query_fields = "{$this->db->users}.*"; 236 242 } else { 237 $this->query_fields = " $wpdb->users.ID";243 $this->query_fields = "{$this->db->users}.ID"; 238 244 } 239 245 … … 241 247 $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; 242 248 243 $this->query_from = "FROM $wpdb->users";249 $this->query_from = "FROM {$this->db->users}"; 244 250 $this->query_where = "WHERE 1=1"; 245 251 … … 264 270 265 271 foreach ( $post_types as &$post_type ) { 266 $post_type = $ wpdb->prepare( '%s', $post_type );267 } 268 269 $posts_table = $ wpdb->get_blog_prefix( $blog_id ) . 'posts';270 $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 ) . " ) )";272 $post_type = $this->db->prepare( '%s', $post_type ); 273 } 274 275 $posts_table = $this->db->get_blog_prefix( $blog_id ) . 'posts'; 276 $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 ) . " ) )"; 271 277 } 272 278 … … 277 283 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { 278 284 $who_query = array( 279 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'user_level',285 'key' => $this->db->get_blog_prefix( $blog_id ) . 'user_level', 280 286 'value' => 0, 281 287 'compare' => '!=', … … 324 330 foreach ( $roles as $role ) { 325 331 $roles_clauses[] = array( 326 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',332 'key' => $this->db->get_blog_prefix( $blog_id ) . 'capabilities', 327 333 'value' => '"' . $role . '"', 328 334 'compare' => 'LIKE', … … 337 343 foreach ( $role__in as $role ) { 338 344 $role__in_clauses[] = array( 339 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',345 'key' => $this->db->get_blog_prefix( $blog_id ) . 'capabilities', 340 346 'value' => '"' . $role . '"', 341 347 'compare' => 'LIKE', … … 350 356 foreach ( $role__not_in as $role ) { 351 357 $role__not_in_clauses[] = array( 352 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',358 'key' => $this->db->get_blog_prefix( $blog_id ) . 'capabilities', 353 359 'value' => '"' . $role . '"', 354 360 'compare' => 'NOT LIKE', … … 362 368 if ( empty( $role_queries ) ) { 363 369 $role_queries[] = array( 364 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',370 'key' => $this->db->get_blog_prefix( $blog_id ) . 'capabilities', 365 371 'compare' => 'EXISTS', 366 372 ); … … 384 390 385 391 if ( ! empty( $this->meta_query->queries ) ) { 386 $clauses = $this->meta_query->get_sql( 'user', $ wpdb->users, 'ID', $this );392 $clauses = $this->meta_query->get_sql( 'user', $this->db->users, 'ID', $this ); 387 393 $this->query_from .= $clauses['join']; 388 394 $this->query_where .= $clauses['where']; … … 442 448 if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { 443 449 if ( $qv['offset'] ) { 444 $this->query_limit = $ wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);450 $this->query_limit = $this->db->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); 445 451 } else { 446 $this->query_limit = $ wpdb->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );452 $this->query_limit = $this->db->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); 447 453 } 448 454 } … … 500 506 // Sanitized earlier. 501 507 $ids = implode( ',', $include ); 502 $this->query_where .= " AND $wpdb->users.ID IN ($ids)";508 $this->query_where .= " AND {$this->db->users}.ID IN ($ids)"; 503 509 } elseif ( ! empty( $qv['exclude'] ) ) { 504 510 $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); 505 $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";511 $this->query_where .= " AND {$this->db->users}.ID NOT IN ($ids)"; 506 512 } 507 513 … … 531 537 * 532 538 * @since 3.1.0 533 *534 * @global wpdb $wpdb WordPress database abstraction object.535 539 */ 536 540 public function query() { 537 global $wpdb;538 539 541 $qv =& $this->query_vars; 540 542 … … 542 544 543 545 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { 544 $this->results = $ wpdb->get_results( $this->request );546 $this->results = $this->db->get_results( $this->request ); 545 547 } else { 546 $this->results = $ wpdb->get_col( $this->request );548 $this->results = $this->db->get_col( $this->request ); 547 549 } 548 550 … … 552 554 * @since 3.2.0 553 555 * 554 * @global wpdb $wpdb WordPress database abstraction object.555 *556 556 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. 557 557 */ 558 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 559 $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 560 561 if ( !$this->results ) 558 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { 559 $this->total_users = $this->db->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 560 } 561 562 if ( ! $this->results ) { 562 563 return; 564 } 563 565 564 566 if ( 'all_with_meta' == $qv['fields'] ) { … … 611 613 * @access protected 612 614 * @since 3.1.0 613 *614 * @global wpdb $wpdb WordPress database abstraction object.615 615 * 616 616 * @param string $string … … 621 621 */ 622 622 protected function get_search_sql( $string, $cols, $wild = false ) { 623 global $wpdb;624 625 623 $searches = array(); 626 624 $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; 627 625 $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; 628 $like = $leading_wild . $ wpdb->esc_like( $string ) . $trailing_wild;626 $like = $leading_wild . $this->db->esc_like( $string ) . $trailing_wild; 629 627 630 628 foreach ( $cols as $col ) { 631 629 if ( 'ID' == $col ) { 632 $searches[] = $ wpdb->prepare( "$col = %s", $string );630 $searches[] = $this->db->prepare( "$col = %s", $string ); 633 631 } else { 634 $searches[] = $ wpdb->prepare( "$col LIKE %s", $like );632 $searches[] = $this->db->prepare( "$col LIKE %s", $like ); 635 633 } 636 634 } … … 669 667 * @access protected 670 668 * 671 * @global wpdb $wpdb WordPress database abstraction object.672 *673 669 * @param string $orderby Alias for the field to order by. 674 670 * @return string Value to used in the ORDER clause, if `$orderby` is valid. 675 671 */ 676 672 protected function parse_orderby( $orderby ) { 677 global $wpdb;678 679 673 $meta_query_clauses = $this->meta_query->get_clauses(); 680 674 … … 691 685 $this->query_from .= " LEFT OUTER JOIN ( 692 686 SELECT post_author, COUNT(*) as post_count 693 FROM $wpdb->posts687 FROM {$this->db->posts} 694 688 $where 695 689 GROUP BY post_author 696 ) p ON ({$ wpdb->users}.ID = p.post_author)690 ) p ON ({$this->db->users}.ID = p.post_author) 697 691 "; 698 692 $_orderby = 'post_count'; … … 700 694 $_orderby = 'ID'; 701 695 } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) { 702 $_orderby = " $wpdb->usermeta.meta_value";696 $_orderby = "{$this->db->usermeta}.meta_value"; 703 697 } elseif ( 'meta_value_num' == $orderby ) { 704 $_orderby = " $wpdb->usermeta.meta_value+0";698 $_orderby = "{$this->db->usermeta}.meta_value+0"; 705 699 } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { 706 700 $include = wp_parse_id_list( $this->query_vars['include'] ); 707 701 $include_sql = implode( ',', $include ); 708 $_orderby = "FIELD( $wpdb->users.ID, $include_sql )";702 $_orderby = "FIELD( {$this->db->users}.ID, $include_sql )"; 709 703 } elseif ( isset( $meta_query_clauses[ $orderby ] ) ) { 710 704 $meta_clause = $meta_query_clauses[ $orderby ]; -
trunk/src/wp-includes/class-wp-user.php
r37985 r38275 103 103 104 104 /** 105 * @since 4.7.0 106 * @access protected 107 * @var wpdb 108 */ 109 protected $db; 110 111 /** 105 112 * Constructor. 106 113 * … … 109 116 * @since 2.0.0 110 117 * @access public 111 *112 * @global wpdb $wpdb WordPress database abstraction object.113 118 * 114 119 * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. … … 117 122 */ 118 123 public function __construct( $id = 0, $name = '', $blog_id = '' ) { 124 $this->db = $GLOBALS['wpdb']; 125 119 126 if ( ! isset( self::$back_compat_keys ) ) { 120 $prefix = $ GLOBALS['wpdb']->prefix;127 $prefix = $this->db->prefix; 121 128 self::$back_compat_keys = array( 122 129 'user_firstname' => 'first_name', … … 233 240 234 241 if ( !$user = $wpdb->get_row( $wpdb->prepare( 235 "SELECT * FROM $wpdb->usersWHERE $db_field = %s", $value236 ) ) ) 242 "SELECT * FROM {$wpdb->users} WHERE $db_field = %s", $value 243 ) ) ) { 237 244 return false; 238 245 } 239 246 update_user_caches( $user ); 240 247 … … 443 450 * @since 2.1.0 444 451 * 445 * @global wpdb $wpdb WordPress database abstraction object.446 *447 452 * @param string $cap_key Optional capability key 448 453 */ 449 454 protected function _init_caps( $cap_key = '' ) { 450 global $wpdb; 451 452 if ( empty($cap_key) ) 453 $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; 454 else 455 if ( empty( $cap_key ) ) { 456 $this->cap_key = $this->db->get_blog_prefix() . 'capabilities'; 457 } else { 455 458 $this->cap_key = $cap_key; 456 459 } 457 460 $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); 458 461 … … 632 635 * @since 2.0.0 633 636 * @access public 634 *635 * @global wpdb $wpdb WordPress database abstraction object.636 637 */ 637 638 public function update_user_level_from_caps() { 638 global $wpdb;639 639 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); 640 update_user_meta( $this->ID, $ wpdb->get_blog_prefix() . 'user_level', $this->user_level );640 update_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level', $this->user_level ); 641 641 } 642 642 … … 680 680 * @since 2.1.0 681 681 * @access public 682 *683 * @global wpdb $wpdb WordPress database abstraction object.684 682 */ 685 683 public function remove_all_caps() { 686 global $wpdb;687 684 $this->caps = array(); 688 685 delete_user_meta( $this->ID, $this->cap_key ); 689 delete_user_meta( $this->ID, $ wpdb->get_blog_prefix() . 'user_level' );686 delete_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level' ); 690 687 $this->get_role_caps(); 691 688 } … … 773 770 * @since 3.0.0 774 771 * 775 * @global wpdb $wpdb WordPress database abstraction object.776 *777 772 * @param int $blog_id Optional. Site ID, defaults to current site. 778 773 */ 779 774 public function for_blog( $blog_id = '' ) { 780 global $wpdb; 781 if ( ! empty( $blog_id ) ) 782 $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; 783 else 775 if ( ! empty( $blog_id ) ) { 776 $cap_key = $this->db->get_blog_prefix( $blog_id ) . 'capabilities'; 777 } else { 784 778 $cap_key = ''; 779 } 785 780 $this->_init_caps( $cap_key ); 786 781 } -
trunk/src/wp-includes/class-wp-xmlrpc-server.php
r38077 r38275 55 55 56 56 /** 57 * @since 4.7.0 58 * @access protected 59 * @var wpdb 60 */ 61 protected $db; 62 63 /** 57 64 * Registers all of the XMLRPC methods that XMLRPC server understands. 58 65 * … … 64 71 */ 65 72 public function __construct() { 73 $this->db = $GLOBALS['wpdb']; 74 66 75 $this->methods = array( 67 76 // WordPress API … … 2883 2892 * @since 2.2.0 2884 2893 * 2885 * @global wpdb $wpdb WordPress database abstraction object.2886 *2887 2894 * @param array $args { 2888 2895 * Method arguments. Note: arguments must be ordered as documented. … … 2895 2902 */ 2896 2903 public function wp_getPageList( $args ) { 2897 global $wpdb;2898 2899 2904 $this->escape( $args ); 2900 2905 … … 2912 2917 2913 2918 // Get list of pages ids and titles 2914 $page_list = $ wpdb->get_results("2919 $page_list = $this->db->get_results(" 2915 2920 SELECT ID page_id, 2916 2921 post_title page_title, … … 2919 2924 post_date, 2920 2925 post_status 2921 FROM {$ wpdb->posts}2926 FROM {$this->db->posts} 2922 2927 WHERE post_type = 'page' 2923 2928 ORDER BY ID … … 5131 5136 * @since 2.1.0 5132 5137 * 5133 * @global wpdb $wpdb WordPress database abstraction object.5134 *5135 5138 * @param int $post_ID Post ID. 5136 5139 * @param string $post_content Post Content for attachment. 5137 5140 */ 5138 5141 public function attach_uploads( $post_ID, $post_content ) { 5139 global $wpdb;5140 5141 5142 // find any unattached files 5142 $attachments = $ wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );5143 $attachments = $this->db->get_results( "SELECT ID, guid FROM {$this->db->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); 5143 5144 if ( is_array( $attachments ) ) { 5144 5145 foreach ( $attachments as $file ) { 5145 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) 5146 $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) ); 5146 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { 5147 $this->db->update( $this->db->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); 5148 } 5147 5149 } 5148 5150 } … … 5764 5766 * @since 1.5.0 5765 5767 * 5766 * @global wpdb $wpdb WordPress database abstraction object.5767 *5768 5768 * @param array $args { 5769 5769 * Method arguments. Note: arguments must be ordered as documented. … … 5777 5777 */ 5778 5778 public function mw_newMediaObject( $args ) { 5779 global $wpdb;5780 5781 5779 $username = $this->escape( $args[1] ); 5782 5780 $password = $this->escape( $args[2] ); … … 6103 6101 * @since 1.5.0 6104 6102 * 6105 * @global wpdb $wpdb WordPress database abstraction object.6106 *6107 6103 * @param int $post_ID 6108 6104 * @return array|IXR_Error 6109 6105 */ 6110 6106 public function mt_getTrackbackPings( $post_ID ) { 6111 global $wpdb;6112 6113 6107 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6114 6108 do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); … … 6119 6113 return new IXR_Error(404, __('Sorry, no such post.')); 6120 6114 6121 $comments = $ wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->commentsWHERE comment_post_ID = %d", $post_ID) );6115 $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) ); 6122 6116 6123 6117 if ( !$comments ) … … 6193 6187 * @since 1.5.0 6194 6188 * 6195 * @global wpdb $wpdb WordPress database abstraction object.6196 6189 * @global string $wp_version 6197 6190 * … … 6205 6198 */ 6206 6199 public function pingback_ping( $args ) { 6207 global $wp db, $wp_version;6200 global $wp_version; 6208 6201 6209 6202 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ … … 6259 6252 // ...or a string #title, a little more complicated 6260 6253 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); 6261 $sql = $ wpdb->prepare("SELECT ID FROM $wpdb->postsWHERE post_title RLIKE %s", $title );6262 if (! ($post_ID = $ wpdb->get_var($sql)) ) {6254 $sql = $this->db->prepare("SELECT ID FROM {$this->db->posts} WHERE post_title RLIKE %s", $title ); 6255 if (! ($post_ID = $this->db->get_var($sql)) ) { 6263 6256 // returning unknown error '0' is better than die()ing 6264 6257 return $this->pingback_error( 0, '' ); … … 6284 6277 6285 6278 // Let's check that the remote site didn't already pingback this entry 6286 if ( $ wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->commentsWHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )6279 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) ) ) 6287 6280 return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); 6288 6281 … … 6409 6402 * @since 1.5.0 6410 6403 * 6411 * @global wpdb $wpdb WordPress database abstraction object.6412 *6413 6404 * @param string $url 6414 6405 * @return array|IXR_Error 6415 6406 */ 6416 6407 public function pingback_extensions_getPingbacks( $url ) { 6417 global $wpdb;6418 6419 6408 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6420 6409 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); … … 6435 6424 } 6436 6425 6437 $comments = $ wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->commentsWHERE comment_post_ID = %d", $post_ID) );6426 $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) ); 6438 6427 6439 6428 if ( !$comments )
Note: See TracChangeset
for help on using the changeset viewer.