Ticket #37699: 37699.diff
File 37699.diff, 216.8 KB (added by , 8 years ago) |
---|
-
src/wp-includes/author-template.php
332 332 * 333 333 * @since 1.2.0 334 334 * 335 * @global wpdb $wpdb WordPress database abstraction object.336 *337 335 * @param string|array $args { 338 336 * Optional. Array or string of default arguments. 339 337 * … … 361 359 * @return string|void The output, if echo is set to false. 362 360 */ 363 361 function wp_list_authors( $args = '' ) { 364 global $wpdb;365 366 362 $defaults = array( 367 363 'orderby' => 'name', 'order' => 'ASC', 'number' => '', 368 364 'optioncount' => false, 'exclude_admin' => true, … … 379 375 $query_args['fields'] = 'ids'; 380 376 $authors = get_users( $query_args ); 381 377 378 $wpdb = WP::get( 'wpdb' ); 382 379 $author_count = array(); 383 380 foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) { 384 381 $author_count[$row->post_author] = $row->count; … … 466 463 * 467 464 * @since 3.2.0 468 465 * 469 * @global wpdb $wpdb WordPress database abstraction object.470 *471 466 * @return bool Whether or not we have more than one author 472 467 */ 473 468 function is_multi_author() { 474 global $wpdb;475 476 469 if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) { 470 $wpdb = WP::get( 'wpdb' ); 477 471 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2"); 478 472 $is_multi_author = 1 < count( $rows ) ? 1 : 0; 479 473 set_transient( 'is_multi_author', $is_multi_author ); -
src/wp-includes/bookmark.php
11 11 * 12 12 * @since 2.1.0 13 13 * 14 * @global wpdb $wpdb WordPress database abstraction object.15 *16 14 * @param int|stdClass $bookmark 17 15 * @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant 18 16 * @param string $filter Optional, default is 'raw'. … … 19 17 * @return array|object|null Type returned depends on $output value. 20 18 */ 21 19 function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') { 22 global $wpdb;23 24 20 if ( empty($bookmark) ) { 25 21 if ( isset($GLOBALS['link']) ) 26 22 $_bookmark = & $GLOBALS['link']; … … 33 29 if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) { 34 30 $_bookmark = & $GLOBALS['link']; 35 31 } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) { 32 $wpdb = WP::get( 'wpdb' ); 36 33 $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark)); 37 34 if ( $_bookmark ) { 38 35 $_bookmark->link_category = array_unique( wp_get_object_terms( $_bookmark->link_id, 'link_category', array( 'fields' => 'ids' ) ) ); … … 92 89 * 93 90 * @since 2.1.0 94 91 * 95 * @global wpdb $wpdb WordPress database abstraction object.96 *97 92 * @param string|array $args { 98 93 * Optional. String or array of arguments to retrieve bookmarks. 99 94 * … … 115 110 * @return array List of bookmark row objects. 116 111 */ 117 112 function get_bookmarks( $args = '' ) { 118 global $wpdb;119 120 113 $defaults = array( 121 114 'orderby' => 'name', 'order' => 'ASC', 122 115 'limit' => -1, 'category' => '', … … 203 196 } 204 197 } 205 198 199 $wpdb = WP::get( 'wpdb' ); 206 200 $search = ''; 207 201 if ( ! empty( $r['search'] ) ) { 208 202 $like = '%' . $wpdb->esc_like( $r['search'] ) . '%'; -
src/wp-includes/canonical.php
31 31 * @global WP_Rewrite $wp_rewrite 32 32 * @global bool $is_IIS 33 33 * @global WP_Query $wp_query 34 * @global wpdb $wpdb WordPress database abstraction object.35 34 * 36 35 * @param string $requested_url Optional. The URL that was requested, used to 37 36 * figure if redirect is needed. … … 39 38 * @return string|void The string of the URL, if redirect needed. 40 39 */ 41 40 function redirect_canonical( $requested_url = null, $do_redirect = true ) { 42 global $wp_rewrite, $is_IIS, $wp_query, $wp db, $wp;41 global $wp_rewrite, $is_IIS, $wp_query, $wp; 43 42 44 43 if ( isset( $_SERVER['REQUEST_METHOD'] ) && ! in_array( strtoupper( $_SERVER['REQUEST_METHOD'] ), array( 'GET', 'HEAD' ) ) ) { 45 44 return; … … 98 97 } 99 98 100 99 if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) { 101 100 $wpdb = WP::get( 'wpdb' ); 102 101 $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) ); 103 102 104 103 if ( isset($vars[0]) && $vars = $vars[0] ) { … … 204 203 $redirect['query'] = remove_query_arg('year', $redirect['query']); 205 204 } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { 206 205 $author = get_userdata(get_query_var('author')); 206 $wpdb = WP::get( 'wpdb' ); 207 207 if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) { 208 208 if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) 209 209 $redirect['query'] = remove_query_arg('author', $redirect['query']); … … 581 581 * 582 582 * @since 2.3.0 583 583 * 584 * @global wpdb $wpdb WordPress database abstraction object.585 *586 584 * @return false|string The correct URL if one is found. False on failure. 587 585 */ 588 586 function redirect_guess_404_permalink() { 589 global $wpdb;590 591 587 if ( get_query_var('name') ) { 588 $wpdb = WP::get( 'wpdb' ); 592 589 $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like( get_query_var('name') ) . '%'); 593 590 594 591 // if any of post_type, year, monthnum, or day are set, use them to refine the query -
src/wp-includes/class-wp-comment-query.php
141 141 return false; 142 142 } 143 143 144 protected $dbh; 145 144 146 /** 145 147 * Constructor. 146 148 * … … 260 262 * } 261 263 */ 262 264 public function __construct( $query = '' ) { 265 $this->dbh = WP::get( 'wpdb' ); 266 263 267 $this->query_var_defaults = array( 264 268 'author_email' => '', 265 269 'author_url' => '', … … 363 367 * @since 4.2.0 364 368 * @access public 365 369 * 366 * @global wpdb $wpdb WordPress database abstraction object.367 *368 370 * @return int|array List of comments or number of found comments if `$count` argument is true. 369 371 */ 370 372 public function get_comments() { 371 global $wpdb;372 373 373 $this->parse_query(); 374 374 375 375 // Parse meta query … … 388 388 // Reparse query vars, in case they were modified in a 'pre_get_comments' callback. 389 389 $this->meta_query->parse_query_vars( $this->query_vars ); 390 390 if ( ! empty( $this->meta_query->queries ) ) { 391 $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $ wpdb->comments, 'comment_ID', $this );391 $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $this->dbh->comments, 'comment_ID', $this ); 392 392 } 393 393 394 394 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. … … 480 480 * 481 481 * @since 4.4.0 482 482 * @access protected 483 *484 * @global wpdb $wpdb WordPress database abstraction object.485 483 */ 486 484 protected function get_comment_ids() { 487 global $wpdb;488 489 485 // Assemble clauses related to 'comment_approved'. 490 486 $approved_clauses = array(); 491 487 … … 514 510 break; 515 511 516 512 default : 517 $status_clauses[] = $ wpdb->prepare( "comment_approved = %s", $status );513 $status_clauses[] = $this->dbh->prepare( "comment_approved = %s", $status ); 518 514 break; 519 515 } 520 516 } … … 537 533 foreach ( $include_unapproved as $unapproved_identifier ) { 538 534 // Numeric values are assumed to be user ids. 539 535 if ( is_numeric( $unapproved_identifier ) ) { 540 $approved_clauses[] = $ wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );536 $approved_clauses[] = $this->dbh->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier ); 541 537 542 538 // Otherwise we match against email addresses. 543 539 } else { 544 $approved_clauses[] = $ wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );540 $approved_clauses[] = $this->dbh->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier ); 545 541 } 546 542 } 547 543 } … … 600 596 601 597 // If no valid clauses were found, order by comment_date_gmt. 602 598 if ( empty( $orderby_array ) ) { 603 $orderby_array[] = " $wpdb->comments.comment_date_gmt $order";599 $orderby_array[] = "{$this->dbh->comments}.comment_date_gmt $order"; 604 600 } 605 601 606 602 // To ensure determinate sorting, always include a comment_ID clause. … … 633 629 $comment_ID_order = 'DESC'; 634 630 } 635 631 636 $orderby_array[] = " $wpdb->comments.comment_ID $comment_ID_order";632 $orderby_array[] = "{$this->dbh->comments}.comment_ID $comment_ID_order"; 637 633 } 638 634 639 635 $orderby = implode( ', ', $orderby_array ); 640 636 } else { 641 $orderby = " $wpdb->comments.comment_date_gmt $order";637 $orderby = "{$this->dbh->comments}.comment_date_gmt $order"; 642 638 } 643 639 644 640 $number = absint( $this->query_vars['number'] ); … … 655 651 if ( $this->query_vars['count'] ) { 656 652 $fields = 'COUNT(*)'; 657 653 } else { 658 $fields = " $wpdb->comments.comment_ID";654 $fields = "{$this->dbh->comments}.comment_ID"; 659 655 } 660 656 661 657 $post_id = absint( $this->query_vars['post_id'] ); 662 658 if ( ! empty( $post_id ) ) { 663 $this->sql_clauses['where']['post_id'] = $ wpdb->prepare( 'comment_post_ID = %d', $post_id );659 $this->sql_clauses['where']['post_id'] = $this->dbh->prepare( 'comment_post_ID = %d', $post_id ); 664 660 } 665 661 666 662 // Parse comment IDs for an IN clause. 667 663 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'] ) ) . ' )';664 $this->sql_clauses['where']['comment__in'] = "{$this->dbh->comments}.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )'; 669 665 } 670 666 671 667 // Parse comment IDs for a NOT IN clause. 672 668 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'] ) ) . ' )';669 $this->sql_clauses['where']['comment__not_in'] = "{$this->dbh->comments}.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )'; 674 670 } 675 671 676 672 // Parse comment parent IDs for an IN clause. … … 694 690 } 695 691 696 692 if ( '' !== $this->query_vars['author_email'] ) { 697 $this->sql_clauses['where']['author_email'] = $ wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );693 $this->sql_clauses['where']['author_email'] = $this->dbh->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] ); 698 694 } 699 695 700 696 if ( '' !== $this->query_vars['author_url'] ) { 701 $this->sql_clauses['where']['author_url'] = $ wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );697 $this->sql_clauses['where']['author_url'] = $this->dbh->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] ); 702 698 } 703 699 704 700 if ( '' !== $this->query_vars['karma'] ) { 705 $this->sql_clauses['where']['karma'] = $ wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );701 $this->sql_clauses['where']['karma'] = $this->dbh->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); 706 702 } 707 703 708 704 // Filtering by comment_type: 'type', 'type__in', 'type__not_in'. … … 733 729 break; 734 730 735 731 default: 736 $comment_types[ $operator ][] = $ wpdb->prepare( '%s', $type );732 $comment_types[ $operator ][] = $this->dbh->prepare( '%s', $type ); 737 733 break; 738 734 } 739 735 } … … 750 746 } 751 747 752 748 if ( '' !== $parent ) { 753 $this->sql_clauses['where']['parent'] = $ wpdb->prepare( 'comment_parent = %d', $parent );749 $this->sql_clauses['where']['parent'] = $this->dbh->prepare( 'comment_parent = %d', $parent ); 754 750 } 755 751 756 752 if ( is_array( $this->query_vars['user_id'] ) ) { 757 753 $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')'; 758 754 } elseif ( '' !== $this->query_vars['user_id'] ) { 759 $this->sql_clauses['where']['user_id'] = $ wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );755 $this->sql_clauses['where']['user_id'] = $this->dbh->prepare( 'user_id = %d', $this->query_vars['user_id'] ); 760 756 } 761 757 762 758 // Falsy search strings are ignored. … … 780 776 foreach ( $post_fields as $field_name => $field_value ) { 781 777 // $field_value may be an array. 782 778 $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 );779 $this->sql_clauses['where'][ $field_name ] = $this->dbh->prepare( " {$this->dbh->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); 784 780 } 785 781 } 786 782 … … 801 797 $join_posts_table = true; 802 798 803 799 $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 );800 $this->sql_clauses['where'][ $field_name ] = $this->dbh->prepare( " {$this->dbh->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values ); 805 801 } 806 802 } 807 803 … … 830 826 $join = ''; 831 827 832 828 if ( $join_posts_table ) { 833 $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";829 $join .= "JOIN {$this->dbh->posts} ON {$this->dbh->posts}.ID = {$this->dbh->comments}.comment_post_ID"; 834 830 } 835 831 836 832 if ( ! empty( $this->meta_query_clauses ) ) { … … 840 836 $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] ); 841 837 842 838 if ( ! $this->query_vars['count'] ) { 843 $groupby = "{$ wpdb->comments}.comment_ID";839 $groupby = "{$this->dbh->comments}.comment_ID"; 844 840 } 845 841 } 846 842 … … 889 885 } 890 886 891 887 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 892 $this->sql_clauses['from'] = "FROM $wpdb->comments$join";888 $this->sql_clauses['from'] = "FROM {$this->dbh->comments} $join"; 893 889 $this->sql_clauses['groupby'] = $groupby; 894 890 $this->sql_clauses['orderby'] = $orderby; 895 891 $this->sql_clauses['limits'] = $limits; … … 897 893 $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; 898 894 899 895 if ( $this->query_vars['count'] ) { 900 return intval( $ wpdb->get_var( $this->request ) );896 return intval( $this->dbh->get_var( $this->request ) ); 901 897 } else { 902 $comment_ids = $ wpdb->get_col( $this->request );898 $comment_ids = $this->dbh->get_col( $this->request ); 903 899 return array_map( 'intval', $comment_ids ); 904 900 } 905 901 } … … 910 906 * 911 907 * @since 4.6.0 912 908 * @access private 913 *914 * @global wpdb $wpdb WordPress database abstraction object.915 909 */ 916 910 private function set_found_comments() { 917 global $wpdb;918 919 911 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 920 912 /** 921 913 * Filters the query used to retrieve found comment count. … … 927 919 */ 928 920 $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this ); 929 921 930 $this->found_comments = (int) $ wpdb->get_var( $found_comments_query );922 $this->found_comments = (int) $this->dbh->get_var( $found_comments_query ); 931 923 } 932 924 } 933 925 … … 943 935 * @return array 944 936 */ 945 937 protected function fill_descendants( $comments ) { 946 global $wpdb;947 948 938 $levels = array( 949 939 0 => wp_list_pluck( $comments, 'comment_ID' ), 950 940 ); … … 996 986 997 987 if ( $uncached_parent_ids ) { 998 988 $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" );989 $level_comments = $this->dbh->get_results( "SELECT {$this->dbh->comments}.comment_ID, {$this->dbh->comments}.comment_parent {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" ); 1000 990 1001 991 // Cache parent-child relationships. 1002 992 $parent_map = array_fill_keys( $uncached_parent_ids, array() ); … … 1067 1057 * @since 3.1.0 1068 1058 * @access protected 1069 1059 * 1070 * @global wpdb $wpdb WordPress database abstraction object.1071 *1072 1060 * @param string $string 1073 1061 * @param array $cols 1074 1062 * @return string 1075 1063 */ 1076 1064 protected function get_search_sql( $string, $cols ) { 1077 global $wpdb;1065 $like = '%' . $this->dbh->esc_like( $string ) . '%'; 1078 1066 1079 $like = '%' . $wpdb->esc_like( $string ) . '%';1080 1081 1067 $searches = array(); 1082 1068 foreach ( $cols as $col ) { 1083 $searches[] = $ wpdb->prepare( "$col LIKE %s", $like );1069 $searches[] = $this->dbh->prepare( "$col LIKE %s", $like ); 1084 1070 } 1085 1071 1086 1072 return ' AND (' . implode(' OR ', $searches) . ')'; … … 1092 1078 * @since 4.2.0 1093 1079 * @access protected 1094 1080 * 1095 * @global wpdb $wpdb WordPress database abstraction object.1096 *1097 1081 * @param string $orderby Alias for the field to order by. 1098 1082 * @return string|false Value to used in the ORDER clause. False otherwise. 1099 1083 */ 1100 1084 protected function parse_orderby( $orderby ) { 1101 global $wpdb;1102 1103 1085 $allowed_keys = array( 1104 1086 'comment_agent', 1105 1087 'comment_approved', … … 1131 1113 1132 1114 $parsed = false; 1133 1115 if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) { 1134 $parsed = " $wpdb->commentmeta.meta_value";1116 $parsed = "{$this->dbh->commentmeta}.meta_value"; 1135 1117 } elseif ( $orderby == 'meta_value_num' ) { 1136 $parsed = " $wpdb->commentmeta.meta_value+0";1118 $parsed = "{$this->dbh->commentmeta}.meta_value+0"; 1137 1119 } elseif ( $orderby == 'comment__in' ) { 1138 1120 $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) ); 1139 $parsed = "FIELD( {$ wpdb->comments}.comment_ID, $comment__in )";1121 $parsed = "FIELD( {$this->dbh->comments}.comment_ID, $comment__in )"; 1140 1122 } elseif ( in_array( $orderby, $allowed_keys ) ) { 1141 1123 1142 1124 if ( isset( $meta_query_clauses[ $orderby ] ) ) { … … 1143 1125 $meta_clause = $meta_query_clauses[ $orderby ]; 1144 1126 $parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); 1145 1127 } else { 1146 $parsed = " $wpdb->comments.$orderby";1128 $parsed = "{$this->dbh->comments}.$orderby"; 1147 1129 } 1148 1130 } 1149 1131 -
src/wp-includes/class-wp-comment.php
183 183 * @access public 184 184 * @static 185 185 * 186 * @global wpdb $wpdb WordPress database abstraction object.187 *188 186 * @param int $id Comment ID. 189 187 * @return WP_Comment|false Comment object, otherwise false. 190 188 */ 191 189 public static function get_instance( $id ) { 192 global $wpdb;193 194 190 $comment_id = (int) $id; 195 191 if ( ! $comment_id ) { 196 192 return false; … … 199 195 $_comment = wp_cache_get( $comment_id, 'comment' ); 200 196 201 197 if ( ! $_comment ) { 198 $wpdb = WP::get( 'wpdb' ); 202 199 $_comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id ) ); 203 200 204 201 if ( ! $_comment ) { -
src/wp-includes/class-wp-meta-query.php
105 105 */ 106 106 protected $has_or_relation = false; 107 107 108 protected $dbh; 109 108 110 /** 109 111 * Constructor. 110 112 * … … 137 139 * } 138 140 */ 139 141 public function __construct( $meta_query = false ) { 142 $this->dbh = WP::get( 'wpdb' ); 143 140 144 if ( !$meta_query ) 141 145 return; 142 146 … … 484 488 * @since 4.1.0 485 489 * @access public 486 490 * 487 * @global wpdb $wpdb WordPress database abstraction object.488 *489 491 * @param array $clause Query clause, passed by reference. 490 492 * @param array $parent_query Parent query array. 491 493 * @param string $clause_key Optional. The array key used to name the clause in the original `$meta_query` … … 498 500 * } 499 501 */ 500 502 public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) { 501 global $wpdb;502 503 503 $sql_chunks = array( 504 504 'where' => array(), 505 505 'join' => array(), … … 537 537 if ( 'NOT EXISTS' === $meta_compare ) { 538 538 $join .= " LEFT JOIN $this->meta_table"; 539 539 $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'] );540 $join .= $this->dbh->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] ); 541 541 542 542 // All other JOIN clauses. 543 543 } else { … … 581 581 if ( 'NOT EXISTS' === $meta_compare ) { 582 582 $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL'; 583 583 } else { 584 $sql_chunks['where'][] = $ wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );584 $sql_chunks['where'][] = $this->dbh->prepare( "{$alias}.meta_key = %s", trim( $clause['key'] ) ); 585 585 } 586 586 } 587 587 … … 601 601 case 'IN' : 602 602 case 'NOT IN' : 603 603 $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')'; 604 $where = $ wpdb->prepare( $meta_compare_string, $meta_value );604 $where = $this->dbh->prepare( $meta_compare_string, $meta_value ); 605 605 break; 606 606 607 607 case 'BETWEEN' : 608 608 case 'NOT BETWEEN' : 609 609 $meta_value = array_slice( $meta_value, 0, 2 ); 610 $where = $ wpdb->prepare( '%s AND %s', $meta_value );610 $where = $this->dbh->prepare( '%s AND %s', $meta_value ); 611 611 break; 612 612 613 613 case 'LIKE' : 614 614 case 'NOT LIKE' : 615 $meta_value = '%' . $ wpdb->esc_like( $meta_value ) . '%';616 $where = $ wpdb->prepare( '%s', $meta_value );615 $meta_value = '%' . $this->dbh->esc_like( $meta_value ) . '%'; 616 $where = $this->dbh->prepare( '%s', $meta_value ); 617 617 break; 618 618 619 619 // EXISTS with a value is interpreted as '='. 620 620 case 'EXISTS' : 621 621 $meta_compare = '='; 622 $where = $ wpdb->prepare( '%s', $meta_value );622 $where = $this->dbh->prepare( '%s', $meta_value ); 623 623 break; 624 624 625 625 // 'value' is ignored for NOT EXISTS. … … 628 628 break; 629 629 630 630 default : 631 $where = $ wpdb->prepare( '%s', $meta_value );631 $where = $this->dbh->prepare( '%s', $meta_value ); 632 632 break; 633 633 634 634 } -
src/wp-includes/class-wp-network-query.php
86 86 */ 87 87 public $max_num_pages = 0; 88 88 89 protected $dbh; 90 89 91 /** 90 92 * Constructor. 91 93 * … … 124 126 * } 125 127 */ 126 128 public function __construct( $query = '' ) { 129 $this->dbh = WP::get( 'wpdb' ); 130 127 131 $this->query_var_defaults = array( 128 132 'network__in' => '', 129 133 'network__not_in' => '', … … 290 294 * @return int|array A single count of network IDs if a count query. An array of network IDs if a full query. 291 295 */ 292 296 protected function get_network_ids() { 293 global $wpdb;294 295 297 $order = $this->parse_order( $this->query_vars['order'] ); 296 298 297 299 // Disable ORDER BY with 'none', an empty array, or boolean false. … … 332 334 333 335 $orderby = implode( ', ', $orderby_array ); 334 336 } else { 335 $orderby = " $wpdb->site.id $order";337 $orderby = "{$this->dbh->site}.id $order"; 336 338 } 337 339 338 340 $number = absint( $this->query_vars['number'] ); … … 349 351 if ( $this->query_vars['count'] ) { 350 352 $fields = 'COUNT(*)'; 351 353 } else { 352 $fields = " $wpdb->site.id";354 $fields = "{$this->dbh->site}.id"; 353 355 } 354 356 355 357 // Parse network IDs for an IN clause. 356 358 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'] ) ) . ' )';359 $this->sql_clauses['where']['network__in'] = "{$this->dbh->site}.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; 358 360 } 359 361 360 362 // Parse network IDs for a NOT IN clause. 361 363 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'] ) ) . ' )';364 $this->sql_clauses['where']['network__not_in'] = "{$this->dbh->site}.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; 363 365 } 364 366 365 367 if ( ! empty( $this->query_vars['domain'] ) ) { 366 $this->sql_clauses['where']['domain'] = $ wpdb->prepare( "$wpdb->site.domain = %s", $this->query_vars['domain'] );368 $this->sql_clauses['where']['domain'] = $this->dbh->prepare( "{$this->dbh->site}.domain = %s", $this->query_vars['domain'] ); 367 369 } 368 370 369 371 // Parse network domain for an IN clause. 370 372 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'] ) ) . "' )";373 $this->sql_clauses['where']['domain__in'] = "{$this->dbh->site}.domain IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 372 374 } 373 375 374 376 // Parse network domain for a NOT IN clause. 375 377 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'] ) ) . "' )";378 $this->sql_clauses['where']['domain__not_in'] = "{$this->dbh->site}.domain NOT IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 377 379 } 378 380 379 381 if ( ! empty( $this->query_vars['path'] ) ) { 380 $this->sql_clauses['where']['path'] = $ wpdb->prepare( "$wpdb->site.path = %s", $this->query_vars['path'] );382 $this->sql_clauses['where']['path'] = $this->dbh->prepare( "{$this->dbh->site}.path = %s", $this->query_vars['path'] ); 381 383 } 382 384 383 385 // Parse network path for an IN clause. 384 386 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'] ) ) . "' )";387 $this->sql_clauses['where']['path__in'] = "{$this->dbh->site}.path IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['path__in'] ) ) . "' )"; 386 388 } 387 389 388 390 // Parse network path for a NOT IN clause. 389 391 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'] ) ) . "' )";392 $this->sql_clauses['where']['path__not_in'] = "{$this->dbh->site}.path NOT IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 391 393 } 392 394 393 395 // Falsey search strings are ignored. … … 394 396 if ( strlen( $this->query_vars['search'] ) ) { 395 397 $this->sql_clauses['where']['search'] = $this->get_search_sql( 396 398 $this->query_vars['search'], 397 array( " $wpdb->site.domain", "$wpdb->site.path" )399 array( "{$this->dbh->site}.domain", "{$this->dbh->site}.path" ) 398 400 ); 399 401 } 400 402 … … 439 441 } 440 442 441 443 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 442 $this->sql_clauses['from'] = "FROM $wpdb->site$join";444 $this->sql_clauses['from'] = "FROM {$this->dbh->site} $join"; 443 445 $this->sql_clauses['groupby'] = $groupby; 444 446 $this->sql_clauses['orderby'] = $orderby; 445 447 $this->sql_clauses['limits'] = $limits; … … 447 449 $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; 448 450 449 451 if ( $this->query_vars['count'] ) { 450 return intval( $ wpdb->get_var( $this->request ) );452 return intval( $this->dbh->get_var( $this->request ) ); 451 453 } 452 454 453 $network_ids = $ wpdb->get_col( $this->request );455 $network_ids = $this->dbh->get_col( $this->request ); 454 456 455 457 return array_map( 'intval', $network_ids ); 456 458 } … … 461 463 * 462 464 * @since 4.6.0 463 465 * @access private 464 *465 * @global wpdb $wpdb WordPress database abstraction object.466 466 */ 467 467 private function set_found_networks() { 468 global $wpdb;469 470 468 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 471 469 /** 472 470 * Filters the query used to retrieve found network count. … … 478 476 */ 479 477 $found_networks_query = apply_filters( 'found_networks_query', 'SELECT FOUND_ROWS()', $this ); 480 478 481 $this->found_networks = (int) $ wpdb->get_var( $found_networks_query );479 $this->found_networks = (int) $this->dbh->get_var( $found_networks_query ); 482 480 } 483 481 } 484 482 … … 488 486 * @since 4.6.0 489 487 * @access protected 490 488 * 491 * @global wpdb $wpdb WordPress database abstraction object.492 *493 489 * @param string $string Search string. 494 490 * @param array $columns Columns to search. 495 491 * … … 496 492 * @return string Search SQL. 497 493 */ 498 494 protected function get_search_sql( $string, $columns ) { 499 global $wpdb;495 $like = '%' . $this->dbh->esc_like( $string ) . '%'; 500 496 501 $like = '%' . $wpdb->esc_like( $string ) . '%';502 503 497 $searches = array(); 504 498 foreach ( $columns as $column ) { 505 $searches[] = $ wpdb->prepare( "$column LIKE %s", $like );499 $searches[] = $this->dbh->prepare( "$column LIKE %s", $like ); 506 500 } 507 501 508 502 return '(' . implode( ' OR ', $searches ) . ')'; … … 514 508 * @since 4.6.0 515 509 * @access protected 516 510 * 517 * @global wpdb $wpdb WordPress database abstraction object.518 *519 511 * @param string $orderby Alias for the field to order by. 520 512 * @return string|false Value to used in the ORDER clause. False otherwise. 521 513 */ 522 514 protected function parse_orderby( $orderby ) { 523 global $wpdb;524 525 515 $allowed_keys = array( 526 516 'id', 527 517 'domain', … … 531 521 $parsed = false; 532 522 if ( $orderby == 'network__in' ) { 533 523 $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); 534 $parsed = "FIELD( {$ wpdb->site}.id, $network__in )";524 $parsed = "FIELD( {$this->dbh->site}.id, $network__in )"; 535 525 } elseif ( $orderby == 'domain_length' || $orderby == 'path_length' ) { 536 526 $field = substr( $orderby, 0, -7 ); 537 $parsed = "CHAR_LENGTH( $wpdb->site.$field)";527 $parsed = "CHAR_LENGTH({$this->dbh->site}.$field)"; 538 528 } elseif ( in_array( $orderby, $allowed_keys ) ) { 539 $parsed = " $wpdb->site.$orderby";529 $parsed = "{$this->dbh->site}.$orderby"; 540 530 } 541 531 542 532 return $parsed; -
src/wp-includes/class-wp-network.php
87 87 */ 88 88 public $site_name = ''; 89 89 90 protected $dbh; 91 90 92 /** 91 93 * Retrieve a network from the database by its ID. 92 94 * … … 93 95 * @since 4.4.0 94 96 * @access public 95 97 * 96 * @global wpdb $wpdb WordPress database abstraction object.97 *98 98 * @param int $network_id The ID of the network to retrieve. 99 99 * @return WP_Network|bool The network's object if found. False if not. 100 100 */ 101 101 public static function get_instance( $network_id ) { 102 global $wpdb;103 104 102 $network_id = (int) $network_id; 105 103 if ( ! $network_id ) { 106 104 return false; … … 109 107 $_network = wp_cache_get( $network_id, 'networks' ); 110 108 111 109 if ( ! $_network ) { 110 $wpdb = WP::get( 'wpdb' ); 112 111 $_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) ); 113 112 114 113 if ( empty( $_network ) || is_wp_error( $_network ) ) { … … 137 136 $this->$key = $value; 138 137 } 139 138 139 $this->dbh = WP::get( 'wpdb' ); 140 140 141 $this->_set_site_name(); 141 142 $this->_set_cookie_domain(); 142 143 } … … 267 268 * @return WP_Network|bool Network object if successful. False when no network is found. 268 269 */ 269 270 public static function get_by_path( $domain = '', $path = '', $segments = null ) { 270 global $wpdb;271 272 271 $domains = array( $domain ); 273 272 $pieces = explode( '.', $domain ); 274 273 … … 295 294 if ( wp_using_ext_object_cache() ) { 296 295 $using_paths = wp_cache_get( 'networks_have_paths', 'site-options' ); 297 296 if ( false === $using_paths ) { 298 $using_paths = (int) $ wpdb->get_var( "SELECT id FROM {$wpdb->site} WHERE path <> '/' LIMIT 1" );297 $using_paths = (int) $this->dbh->get_var( "SELECT id FROM {$this->dbh->site} WHERE path <> '/' LIMIT 1" ); 299 298 wp_cache_add( 'networks_have_paths', $using_paths, 'site-options' ); 300 299 } 301 300 } … … 356 355 // @todo Consider additional optimization routes, perhaps as an opt-in for plugins. 357 356 // We already have paths covered. What about how far domains should be drilled down (including www)? 358 357 359 $search_domains = "'" . implode( "', '", $ wpdb->_escape( $domains ) ) . "'";358 $search_domains = "'" . implode( "', '", $this->dbh->_escape( $domains ) ) . "'"; 360 359 361 360 if ( ! $using_paths ) { 362 $network = $ wpdb->get_row( "363 SELECT * FROM {$ wpdb->site}361 $network = $this->dbh->get_row( " 362 SELECT * FROM {$this->dbh->site} 364 363 WHERE domain IN ({$search_domains}) 365 364 ORDER BY CHAR_LENGTH(domain) 366 365 DESC LIMIT 1 … … 373 372 return false; 374 373 375 374 } else { 376 $search_paths = "'" . implode( "', '", $ wpdb->_escape( $paths ) ) . "'";377 $networks = $ wpdb->get_results( "378 SELECT * FROM {$ wpdb->site}375 $search_paths = "'" . implode( "', '", $this->dbh->_escape( $paths ) ) . "'"; 376 $networks = $this->dbh->get_results( " 377 SELECT * FROM {$this->dbh->site} 379 378 WHERE domain IN ({$search_domains}) 380 379 AND path IN ({$search_paths}) 381 380 ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC -
src/wp-includes/class-wp-post.php
202 202 * @static 203 203 * @access public 204 204 * 205 * @global wpdb $wpdb WordPress database abstraction object.206 *207 205 * @param int $post_id Post ID. 208 206 * @return WP_Post|false Post object, false otherwise. 209 207 */ 210 208 public static function get_instance( $post_id ) { 211 global $wpdb;212 213 209 $post_id = (int) $post_id; 214 210 if ( ! $post_id ) 215 211 return false; … … 217 213 $_post = wp_cache_get( $post_id, 'posts' ); 218 214 219 215 if ( ! $_post ) { 216 $wpdb = WP::get( 'wpdb' ); 220 217 $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); 221 218 222 219 if ( ! $_post ) -
src/wp-includes/class-wp-registry.php
1 <?php 2 3 class WP_Registry { 4 private $data = array(); 5 private static $instance; 6 7 public static function instance() { 8 if ( ! self::$instance ) { 9 self::$instance = new self; 10 } 11 return self::$instance; 12 } 13 14 private function __construct() {} 15 16 private function __clone() {} 17 18 public function get( $key, $global = true ) { 19 if ( $global && array_key_exists( $key, $GLOBALS ) ) { 20 return $GLOBALS[ $key ]; 21 } elseif ( array_key_exists( $key, $this->data ) ) { 22 return $this->data[ $key ]; 23 } 24 25 return $this->set( $key, null, $global ); 26 } 27 28 public function set( $key, $value = null, $global = false ) { 29 if ( null === $value ) { 30 switch ( $key ) { 31 case 'wp_hasher': 32 require_once ABSPATH . WPINC . '/class-phpass.php'; 33 $value = new PasswordHash( 8, true ); 34 break; 35 } 36 } 37 $this->data[ $key ] = $value; 38 if ( $global ) { 39 $GLOBALS[ $key ] = $this->data[ $key ]; 40 } 41 return $value; 42 } 43 } 44 No newline at end of file -
src/wp-includes/class-wp-rewrite.php
450 450 * @since 2.5.0 451 451 * @access public 452 452 * 453 * @global wpdb $wpdb WordPress database abstraction object.454 *455 453 * @return array Array of page URIs as first element and attachment URIs as second element. 456 454 */ 457 455 public function page_uri_index() { 458 global $wpdb;456 $wpdb = WP::get( 'wpdb' ); 459 457 460 458 // Get pages in order of hierarchy, i.e. children after parents. 461 459 $pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'"); -
src/wp-includes/class-wp-roles.php
105 105 * @since 2.1.0 106 106 * @access protected 107 107 * 108 * @global wpdb $wpdb WordPress database abstraction object.109 108 * @global array $wp_user_roles Used to set the 'roles' property value. 110 109 */ 111 110 protected function _init() { 112 global $wpdb, $wp_user_roles; 111 global $wp_user_roles; 112 $wpdb = WP::get( 'wpdb' ); 113 113 $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; 114 114 if ( ! empty( $wp_user_roles ) ) { 115 115 $this->roles = $wp_user_roles; … … 137 137 * 138 138 * @since 3.5.0 139 139 * @access public 140 *141 * @global wpdb $wpdb WordPress database abstraction object.142 140 */ 143 141 public function reinit() { 144 142 // There is no need to reinit if using the wp_user_roles global. … … 145 143 if ( ! $this->use_db ) 146 144 return; 147 145 148 global $wpdb;146 $wpdb = WP::get( 'wpdb' ); 149 147 150 148 // Duplicated from _init() to avoid an extra function call. 151 149 $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; -
src/wp-includes/class-wp-site-query.php
95 95 */ 96 96 public $max_num_pages = 0; 97 97 98 protected $dbh; 99 98 100 /** 99 101 * Sets up the site query, based on the query vars passed. 100 102 * … … 147 149 * } 148 150 */ 149 151 public function __construct( $query = '' ) { 152 $this->dbh = WP::get( 'wpdb' ); 153 150 154 $this->query_var_defaults = array( 151 155 'fields' => '', 152 156 'ID' => '', … … 325 329 * @since 4.6.0 326 330 * @access protected 327 331 * 328 * @global wpdb $wpdb WordPress database abstraction object.329 *330 332 * @return int|array A single count of site IDs if a count query. An array of site IDs if a full query. 331 333 */ 332 334 protected function get_site_ids() { 333 global $wpdb;334 335 335 $order = $this->parse_order( $this->query_vars['order'] ); 336 336 337 337 // Disable ORDER BY with 'none', an empty array, or boolean false. … … 395 395 // Parse site IDs for an IN clause. 396 396 $site_id = absint( $this->query_vars['ID'] ); 397 397 if ( ! empty( $site_id ) ) { 398 $this->sql_clauses['where']['ID'] = $ wpdb->prepare( 'blog_id = %d', $site_id );398 $this->sql_clauses['where']['ID'] = $this->dbh->prepare( 'blog_id = %d', $site_id ); 399 399 } 400 400 401 401 // Parse site IDs for an IN clause. … … 411 411 $network_id = absint( $this->query_vars['network_id'] ); 412 412 413 413 if ( ! empty( $network_id ) ) { 414 $this->sql_clauses['where']['network_id'] = $ wpdb->prepare( 'site_id = %d', $network_id );414 $this->sql_clauses['where']['network_id'] = $this->dbh->prepare( 'site_id = %d', $network_id ); 415 415 } 416 416 417 417 // Parse site network IDs for an IN clause. … … 425 425 } 426 426 427 427 if ( ! empty( $this->query_vars['domain'] ) ) { 428 $this->sql_clauses['where']['domain'] = $ wpdb->prepare( 'domain = %s', $this->query_vars['domain'] );428 $this->sql_clauses['where']['domain'] = $this->dbh->prepare( 'domain = %s', $this->query_vars['domain'] ); 429 429 } 430 430 431 431 // Parse site domain for an IN clause. 432 432 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'] ) ) . "' )";433 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 434 434 } 435 435 436 436 // Parse site domain for a NOT IN clause. 437 437 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'] ) ) . "' )";438 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 439 439 } 440 440 441 441 if ( ! empty( $this->query_vars['path'] ) ) { 442 $this->sql_clauses['where']['path'] = $ wpdb->prepare( 'path = %s', $this->query_vars['path'] );442 $this->sql_clauses['where']['path'] = $this->dbh->prepare( 'path = %s', $this->query_vars['path'] ); 443 443 } 444 444 445 445 // Parse site path for an IN clause. 446 446 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'] ) ) . "' )";447 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['path__in'] ) ) . "' )"; 448 448 } 449 449 450 450 // Parse site path for a NOT IN clause. 451 451 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'] ) ) . "' )";452 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $this->dbh->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 453 453 } 454 454 455 455 if ( is_numeric( $this->query_vars['archived'] ) ) { 456 456 $archived = absint( $this->query_vars['archived'] ); 457 $this->sql_clauses['where']['archived'] = $ wpdb->prepare( "archived = %d ", $archived );457 $this->sql_clauses['where']['archived'] = $this->dbh->prepare( "archived = %d ", $archived ); 458 458 } 459 459 460 460 if ( is_numeric( $this->query_vars['mature'] ) ) { 461 461 $mature = absint( $this->query_vars['mature'] ); 462 $this->sql_clauses['where']['mature'] = $ wpdb->prepare( "mature = %d ", $mature );462 $this->sql_clauses['where']['mature'] = $this->dbh->prepare( "mature = %d ", $mature ); 463 463 } 464 464 465 465 if ( is_numeric( $this->query_vars['spam'] ) ) { 466 466 $spam = absint( $this->query_vars['spam'] ); 467 $this->sql_clauses['where']['spam'] = $ wpdb->prepare( "spam = %d ", $spam );467 $this->sql_clauses['where']['spam'] = $this->dbh->prepare( "spam = %d ", $spam ); 468 468 } 469 469 470 470 if ( is_numeric( $this->query_vars['deleted'] ) ) { 471 471 $deleted = absint( $this->query_vars['deleted'] ); 472 $this->sql_clauses['where']['deleted'] = $ wpdb->prepare( "deleted = %d ", $deleted );472 $this->sql_clauses['where']['deleted'] = $this->dbh->prepare( "deleted = %d ", $deleted ); 473 473 } 474 474 475 475 if ( is_numeric( $this->query_vars['public'] ) ) { 476 476 $public = absint( $this->query_vars['public'] ); 477 $this->sql_clauses['where']['public'] = $ wpdb->prepare( "public = %d ", $public );477 $this->sql_clauses['where']['public'] = $this->dbh->prepare( "public = %d ", $public ); 478 478 } 479 479 480 480 // Falsey search strings are ignored. … … 550 550 } 551 551 552 552 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 553 $this->sql_clauses['from'] = "FROM $wpdb->blogs$join";553 $this->sql_clauses['from'] = "FROM {$this->dbh->blogs} $join"; 554 554 $this->sql_clauses['groupby'] = $groupby; 555 555 $this->sql_clauses['orderby'] = $orderby; 556 556 $this->sql_clauses['limits'] = $limits; … … 558 558 $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; 559 559 560 560 if ( $this->query_vars['count'] ) { 561 return intval( $ wpdb->get_var( $this->request ) );561 return intval( $this->dbh->get_var( $this->request ) ); 562 562 } 563 563 564 $site_ids = $ wpdb->get_col( $this->request );564 $site_ids = $this->dbh->get_col( $this->request ); 565 565 566 566 return array_map( 'intval', $site_ids ); 567 567 } … … 572 572 * 573 573 * @since 4.6.0 574 574 * @access private 575 *576 * @global wpdb $wpdb WordPress database abstraction object.577 575 */ 578 576 private function set_found_sites() { 579 global $wpdb;580 581 577 if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 582 578 /** 583 579 * Filters the query used to retrieve found site count. … … 589 585 */ 590 586 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 591 587 592 $this->found_sites = (int) $ wpdb->get_var( $found_sites_query );588 $this->found_sites = (int) $this->dbh->get_var( $found_sites_query ); 593 589 } 594 590 } 595 591 … … 599 595 * @since 4.6.0 600 596 * @access protected 601 597 * 602 * @global wpdb $wpdb WordPress database abstraction object.603 *604 598 * @param string $string Search string. 605 599 * @param array $columns Columns to search. 606 600 * @return string Search SQL. 607 601 */ 608 602 protected function get_search_sql( $string, $columns ) { 609 global $wpdb;610 611 603 if ( false !== strpos( $string, '*' ) ) { 612 $like = '%' . implode( '%', array_map( array( $ wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%';604 $like = '%' . implode( '%', array_map( array( $this->dbh, 'esc_like' ), explode( '*', $string ) ) ) . '%'; 613 605 } else { 614 $like = '%' . $ wpdb->esc_like( $string ) . '%';606 $like = '%' . $this->dbh->esc_like( $string ) . '%'; 615 607 } 616 608 617 609 $searches = array(); 618 610 foreach ( $columns as $column ) { 619 $searches[] = $ wpdb->prepare( "$column LIKE %s", $like );611 $searches[] = $this->dbh->prepare( "$column LIKE %s", $like ); 620 612 } 621 613 622 614 return '(' . implode( ' OR ', $searches ) . ')'; … … 628 620 * @since 4.6.0 629 621 * @access protected 630 622 * 631 * @global wpdb $wpdb WordPress database abstraction object.632 *633 623 * @param string $orderby Alias for the field to order by. 634 624 * @return string|false Value to used in the ORDER clause. False otherwise. 635 625 */ 636 626 protected function parse_orderby( $orderby ) { 637 global $wpdb;638 639 627 $parsed = false; 640 628 641 629 switch ( $orderby ) { 642 630 case 'site__in': 643 631 $site__in = implode( ',', array_map( 'absint', $this->query_vars['site__in'] ) ); 644 $parsed = "FIELD( {$ wpdb->blogs}.blog_id, $site__in )";632 $parsed = "FIELD( {$this->dbh->blogs}.blog_id, $site__in )"; 645 633 break; 646 634 case 'network__in': 647 635 $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); 648 $parsed = "FIELD( {$ wpdb->blogs}.site_id, $network__in )";636 $parsed = "FIELD( {$this->dbh->blogs}.site_id, $network__in )"; 649 637 break; 650 638 case 'domain': 651 639 case 'last_updated': -
src/wp-includes/class-wp-site.php
157 157 * @since 4.5.0 158 158 * @access public 159 159 * 160 * @global wpdb $wpdb WordPress database abstraction object.161 *162 160 * @param int $site_id The ID of the site to retrieve. 163 161 * @return WP_Site|false The site's object if found. False if not. 164 162 */ 165 163 public static function get_instance( $site_id ) { 166 global $wpdb;167 168 164 $site_id = (int) $site_id; 169 165 if ( ! $site_id ) { 170 166 return false; … … 173 169 $_site = wp_cache_get( $site_id, 'sites' ); 174 170 175 171 if ( ! $_site ) { 172 $wpdb = WP::get( 'wpdb' ); 176 173 $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) ); 177 174 178 175 if ( empty( $_site ) || is_wp_error( $_site ) ) { -
src/wp-includes/class-wp-tax-query.php
91 91 */ 92 92 public $primary_id_column; 93 93 94 protected $dbh; 95 94 96 /** 95 97 * Constructor. 96 98 * … … 125 127 $this->relation = 'AND'; 126 128 } 127 129 130 $this->dbh = WP::get( 'wpdb' ); 131 128 132 $this->queries = $this->sanitize_query( $tax_query ); 129 133 } 130 134 … … 387 391 * @since 4.1.0 388 392 * @access public 389 393 * 390 * @global wpdb $wpdb The WordPress database abstraction object.391 *392 394 * @param array $clause Query clause, passed by reference. 393 395 * @param array $parent_query Parent query array. 394 396 * @return array { … … 399 401 * } 400 402 */ 401 403 public function get_sql_for_clause( &$clause, $parent_query ) { 402 global $wpdb;403 404 404 $sql = array( 405 405 'where' => array(), 406 406 'join' => array(), … … 432 432 $alias = $this->find_compatible_table_alias( $clause, $parent_query ); 433 433 if ( false === $alias ) { 434 434 $i = count( $this->table_aliases ); 435 $alias = $i ? 'tt' . $i : $ wpdb->term_relationships;435 $alias = $i ? 'tt' . $i : $this->dbh->term_relationships; 436 436 437 437 // Store the alias as part of a flat array to build future iterators. 438 438 $this->table_aliases[] = $alias; … … 440 440 // Store the alias with this clause, so later siblings can use it. 441 441 $clause['alias'] = $alias; 442 442 443 $join .= " LEFT JOIN $wpdb->term_relationships";443 $join .= " LEFT JOIN {$this->dbh->term_relationships}"; 444 444 $join .= $i ? " AS $alias" : ''; 445 445 $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)"; 446 446 } … … 458 458 459 459 $where = "$this->primary_table.$this->primary_id_column NOT IN ( 460 460 SELECT object_id 461 FROM $wpdb->term_relationships461 FROM {$this->dbh->term_relationships} 462 462 WHERE term_taxonomy_id IN ($terms) 463 463 )"; 464 464 … … 474 474 475 475 $where = "( 476 476 SELECT COUNT(1) 477 FROM $wpdb->term_relationships477 FROM {$this->dbh->term_relationships} 478 478 WHERE term_taxonomy_id IN ($terms) 479 479 AND object_id = $this->primary_table.$this->primary_id_column 480 480 ) = $num_terms"; … … 481 481 482 482 } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) { 483 483 484 $where = $ wpdb->prepare( "$operator (484 $where = $this->dbh->prepare( "$operator ( 485 485 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_column486 FROM {$this->dbh->term_relationships} 487 INNER JOIN {$this->dbh->term_taxonomy} 488 ON {$this->dbh->term_taxonomy}.term_taxonomy_id = {$this->dbh->term_relationships}.term_taxonomy_id 489 WHERE {$this->dbh->term_taxonomy}.taxonomy = %s 490 AND {$this->dbh->term_relationships}.object_id = {$this->primary_table}.{$this->primary_id_column} 491 491 )", $clause['taxonomy'] ); 492 492 493 493 } … … 597 597 * 598 598 * @since 3.2.0 599 599 * 600 * @global wpdb $wpdb The WordPress database abstraction object.601 *602 600 * @param array $query The single query. Passed by reference. 603 601 * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', 604 602 * or 'term_id'. Default 'term_id'. 605 603 */ 606 604 public function transform_query( &$query, $resulting_field ) { 607 global $wpdb;608 609 605 if ( empty( $query['terms'] ) ) 610 606 return; 611 607 … … 628 624 629 625 $terms = implode( ",", $query['terms'] ); 630 626 631 $terms = $ wpdb->get_col( "632 SELECT $wpdb->term_taxonomy.$resulting_field633 FROM $wpdb->term_taxonomy634 INNER JOIN $wpdb->termsUSING (term_id)627 $terms = $this->dbh->get_col( " 628 SELECT {$this->dbh->term_taxonomy}.$resulting_field 629 FROM {$this->dbh->term_taxonomy} 630 INNER JOIN {$this->dbh->terms} USING (term_id) 635 631 WHERE taxonomy = '{$query['taxonomy']}' 636 AND $wpdb->terms.{$query['field']} IN ($terms)632 AND {$this->dbh->terms}.{$query['field']} IN ($terms) 637 633 " ); 638 634 break; 639 635 case 'term_taxonomy_id': 640 636 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 641 $terms = $ wpdb->get_col( "637 $terms = $this->dbh->get_col( " 642 638 SELECT $resulting_field 643 FROM $wpdb->term_taxonomy639 FROM {$this->dbh->term_taxonomy} 644 640 WHERE term_taxonomy_id IN ($terms) 645 641 " ); 646 642 break; 647 643 default: 648 644 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 649 $terms = $ wpdb->get_col( "645 $terms = $this->dbh->get_col( " 650 646 SELECT $resulting_field 651 FROM $wpdb->term_taxonomy647 FROM {$this->dbh->term_taxonomy} 652 648 WHERE taxonomy = '{$query['taxonomy']}' 653 649 AND term_id IN ($terms) 654 650 " ); -
src/wp-includes/class-wp-term-query.php
86 86 */ 87 87 public $terms; 88 88 89 protected $dbh; 90 89 91 /** 90 92 * Constructor. 91 93 * … … 201 203 'meta_query' => '', 202 204 ); 203 205 206 $this->dbh = WP::get( 'wpdb' ); 207 204 208 if ( ! empty( $query ) ) { 205 209 $this->query( $query ); 206 210 } … … 293 297 * @param 4.6.0 294 298 * @access public 295 299 * 296 * @global wpdb $wpdb WordPress database abstraction object.297 *298 300 * @return array 299 301 */ 300 302 public function get_terms() { 301 global $wpdb;302 303 303 $this->parse_query( $this->query_vars ); 304 304 $args = $this->query_vars; 305 305 … … 486 486 $tt_ids = implode( ',', array_map( 'intval', $args['term_taxonomy_id'] ) ); 487 487 $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})"; 488 488 } else { 489 $this->sql_clauses['where']['term_taxonomy_id'] = $ wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );489 $this->sql_clauses['where']['term_taxonomy_id'] = $this->dbh->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] ); 490 490 } 491 491 } 492 492 493 493 if ( ! empty( $args['name__like'] ) ) { 494 $this->sql_clauses['where']['name__like'] = $ wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );494 $this->sql_clauses['where']['name__like'] = $this->dbh->prepare( "t.name LIKE %s", '%' . $this->dbh->esc_like( $args['name__like'] ) . '%' ); 495 495 } 496 496 497 497 if ( ! empty( $args['description__like'] ) ) { 498 $this->sql_clauses['where']['description__like'] = $ wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );498 $this->sql_clauses['where']['description__like'] = $this->dbh->prepare( "tt.description LIKE %s", '%' . $this->dbh->esc_like( $args['description__like'] ) . '%' ); 499 499 } 500 500 501 501 if ( '' !== $parent ) { … … 591 591 */ 592 592 $fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) ); 593 593 594 $join .= " INNER JOIN $wpdb->term_taxonomyAS tt ON t.term_id = tt.term_id";594 $join .= " INNER JOIN {$this->dbh->term_taxonomy} AS tt ON t.term_id = tt.term_id"; 595 595 596 596 $where = implode( ' AND ', $this->sql_clauses['where'] ); 597 597 … … 621 621 } 622 622 623 623 $this->sql_clauses['select'] = "SELECT $distinct $fields"; 624 $this->sql_clauses['from'] = "FROM $wpdb->termsAS t $join";624 $this->sql_clauses['from'] = "FROM {$this->dbh->terms} AS t $join"; 625 625 $this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : ''; 626 626 $this->sql_clauses['limits'] = $limits; 627 627 … … 646 646 } 647 647 648 648 if ( 'count' == $_fields ) { 649 return $ wpdb->get_var( $this->request );649 return $this->dbh->get_var( $this->request ); 650 650 } 651 651 652 $terms = $ wpdb->get_results( $this->request );652 $terms = $this->dbh->get_results( $this->request ); 653 653 if ( 'all' == $_fields ) { 654 654 update_term_cache( $terms ); 655 655 } … … 753 753 * @since 4.6.0 754 754 * @access protected 755 755 * 756 * @global wpdb $wpdb WordPress database abstraction object.757 *758 756 * @param string $orderby_raw Alias for the field to order by. 759 757 * @return string|false Value to used in the ORDER clause. False otherwise. 760 758 */ … … 894 892 * @since 4.6.0 895 893 * @access protected 896 894 * 897 * @global wpdb $wpdb WordPress database abstraction object.898 *899 895 * @param string $string 900 896 * @return string 901 897 */ 902 898 protected function get_search_sql( $string ) { 903 global $wpdb;899 $like = '%' . $this->dbh->esc_like( $string ) . '%'; 904 900 905 $like = '%' . $wpdb->esc_like( $string ) . '%'; 906 907 return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); 901 return $this->dbh->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); 908 902 } 909 903 } -
src/wp-includes/class-wp-term.php
113 113 * @access public 114 114 * @static 115 115 * 116 * @global wpdb $wpdb WordPress database abstraction object.117 *118 116 * @param int $term_id Term ID. 119 117 * @param string $taxonomy Optional. Limit matched terms to those matching `$taxonomy`. Only used for 120 118 * disambiguating potentially shared terms. … … 123 121 * False for other failures. 124 122 */ 125 123 public static function get_instance( $term_id, $taxonomy = null ) { 126 global $wpdb;127 128 124 $term_id = (int) $term_id; 129 125 if ( ! $term_id ) { 130 126 return false; … … 134 130 135 131 // If there isn't a cached version, hit the database. 136 132 if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) { 133 $wpdb = WP::get( 'wpdb' ); 137 134 // Grab all matching terms, in case any are shared between taxonomies. 138 135 $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) ); 139 136 if ( ! $terms ) { -
src/wp-includes/class-wp-user-query.php
70 70 public $query_orderby; 71 71 public $query_limit; 72 72 73 protected $dbh; 74 73 75 /** 74 76 * PHP5 constructor. 75 77 * … … 78 80 * @param null|string|array $query Optional. The query variables. 79 81 */ 80 82 public function __construct( $query = null ) { 83 $this->dbh = WP::get( 'wpdb' ); 84 81 85 if ( ! empty( $query ) ) { 82 86 $this->prepare_query( $query ); 83 87 $this->query(); … … 134 138 * 135 139 * @access public 136 140 * 137 * @global wpdb $wpdb WordPress database abstraction object.138 141 * @global int $blog_id 139 142 * 140 143 * @param string|array $query { … … 198 201 * } 199 202 */ 200 203 public function prepare_query( $query = array() ) { 201 global $wpdb;202 203 204 if ( empty( $this->query_vars ) || ! empty( $query ) ) { 204 205 $this->query_limit = null; 205 206 $this->query_vars = $this->fill_query_vars( $query ); … … 228 229 $this->query_fields = array(); 229 230 foreach ( $qv['fields'] as $field ) { 230 231 $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); 231 $this->query_fields[] = " $wpdb->users.$field";232 $this->query_fields[] = "{$this->dbh->users}.$field"; 232 233 } 233 234 $this->query_fields = implode( ',', $this->query_fields ); 234 235 } elseif ( 'all' == $qv['fields'] ) { 235 $this->query_fields = " $wpdb->users.*";236 $this->query_fields = "{$this->dbh->users}.*"; 236 237 } else { 237 $this->query_fields = " $wpdb->users.ID";238 $this->query_fields = "{$this->dbh->users}.ID"; 238 239 } 239 240 240 241 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 241 242 $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; 242 243 243 $this->query_from = "FROM $wpdb->users";244 $this->query_from = "FROM {$this->dbh->users}"; 244 245 $this->query_where = "WHERE 1=1"; 245 246 246 247 // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below. … … 263 264 } 264 265 265 266 foreach ( $post_types as &$post_type ) { 266 $post_type = $ wpdb->prepare( '%s', $post_type );267 $post_type = $this->dbh->prepare( '%s', $post_type ); 267 268 } 268 269 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 ) . " ) )";270 $posts_table = $this->dbh->get_blog_prefix( $blog_id ) . 'posts'; 271 $this->query_where .= " AND {$this->dbh->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 272 } 272 273 273 274 // Meta query. … … 276 277 277 278 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) { 278 279 $who_query = array( 279 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'user_level',280 'key' => $this->dbh->get_blog_prefix( $blog_id ) . 'user_level', 280 281 'value' => 0, 281 282 'compare' => '!=', 282 283 ); … … 323 324 if ( ! empty( $roles ) ) { 324 325 foreach ( $roles as $role ) { 325 326 $roles_clauses[] = array( 326 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',327 'key' => $this->dbh->get_blog_prefix( $blog_id ) . 'capabilities', 327 328 'value' => '"' . $role . '"', 328 329 'compare' => 'LIKE', 329 330 ); … … 336 337 if ( ! empty( $role__in ) ) { 337 338 foreach ( $role__in as $role ) { 338 339 $role__in_clauses[] = array( 339 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',340 'key' => $this->dbh->get_blog_prefix( $blog_id ) . 'capabilities', 340 341 'value' => '"' . $role . '"', 341 342 'compare' => 'LIKE', 342 343 ); … … 349 350 if ( ! empty( $role__not_in ) ) { 350 351 foreach ( $role__not_in as $role ) { 351 352 $role__not_in_clauses[] = array( 352 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',353 'key' => $this->dbh->get_blog_prefix( $blog_id ) . 'capabilities', 353 354 'value' => '"' . $role . '"', 354 355 'compare' => 'NOT LIKE', 355 356 ); … … 361 362 // If there are no specific roles named, make sure the user is a member of the site. 362 363 if ( empty( $role_queries ) ) { 363 364 $role_queries[] = array( 364 'key' => $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities',365 'key' => $this->dbh->get_blog_prefix( $blog_id ) . 'capabilities', 365 366 'compare' => 'EXISTS', 366 367 ); 367 368 } … … 383 384 } 384 385 385 386 if ( ! empty( $this->meta_query->queries ) ) { 386 $clauses = $this->meta_query->get_sql( 'user', $ wpdb->users, 'ID', $this );387 $clauses = $this->meta_query->get_sql( 'user', $this->dbh->users, 'ID', $this ); 387 388 $this->query_from .= $clauses['join']; 388 389 $this->query_where .= $clauses['where']; 389 390 … … 441 442 // limit 442 443 if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { 443 444 if ( $qv['offset'] ) { 444 $this->query_limit = $ wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);445 $this->query_limit = $this->dbh->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); 445 446 } else { 446 $this->query_limit = $ wpdb->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );447 $this->query_limit = $this->dbh->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); 447 448 } 448 449 } 449 450 … … 499 500 if ( ! empty( $include ) ) { 500 501 // Sanitized earlier. 501 502 $ids = implode( ',', $include ); 502 $this->query_where .= " AND $wpdb->users.ID IN ($ids)";503 $this->query_where .= " AND {$this->dbh->users}.ID IN ($ids)"; 503 504 } elseif ( ! empty( $qv['exclude'] ) ) { 504 505 $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); 505 $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";506 $this->query_where .= " AND {$this->dbh->users}.ID NOT IN ($ids)"; 506 507 } 507 508 508 509 // Date queries are allowed for the user_registered field. … … 530 531 * Execute the query, with the current variables. 531 532 * 532 533 * @since 3.1.0 533 *534 * @global wpdb $wpdb WordPress database abstraction object.535 534 */ 536 535 public function query() { 537 global $wpdb;538 539 536 $qv =& $this->query_vars; 540 537 541 538 $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; 542 539 543 540 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { 544 $this->results = $ wpdb->get_results( $this->request );541 $this->results = $this->dbh->get_results( $this->request ); 545 542 } else { 546 $this->results = $ wpdb->get_col( $this->request );543 $this->results = $this->dbh->get_col( $this->request ); 547 544 } 548 545 549 546 /** … … 551 548 * 552 549 * @since 3.2.0 553 550 * 554 * @global wpdb $wpdb WordPress database abstraction object.555 *556 551 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. 557 552 */ 558 553 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 559 $this->total_users = $ wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );554 $this->total_users = $this->dbh->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 560 555 561 556 if ( !$this->results ) 562 557 return; … … 611 606 * @access protected 612 607 * @since 3.1.0 613 608 * 614 * @global wpdb $wpdb WordPress database abstraction object.615 *616 609 * @param string $string 617 610 * @param array $cols 618 611 * @param bool $wild Whether to allow wildcard searches. Default is false for Network Admin, true for single site. … … 620 613 * @return string 621 614 */ 622 615 protected function get_search_sql( $string, $cols, $wild = false ) { 623 global $wpdb;624 625 616 $searches = array(); 626 617 $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; 627 618 $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; 628 $like = $leading_wild . $ wpdb->esc_like( $string ) . $trailing_wild;619 $like = $leading_wild . $this->dbh->esc_like( $string ) . $trailing_wild; 629 620 630 621 foreach ( $cols as $col ) { 631 622 if ( 'ID' == $col ) { 632 $searches[] = $ wpdb->prepare( "$col = %s", $string );623 $searches[] = $this->dbh->prepare( "$col = %s", $string ); 633 624 } else { 634 $searches[] = $ wpdb->prepare( "$col LIKE %s", $like );625 $searches[] = $this->dbh->prepare( "$col LIKE %s", $like ); 635 626 } 636 627 } 637 628 … … 668 659 * @since 4.2.0 669 660 * @access protected 670 661 * 671 * @global wpdb $wpdb WordPress database abstraction object.672 *673 662 * @param string $orderby Alias for the field to order by. 674 663 * @return string Value to used in the ORDER clause, if `$orderby` is valid. 675 664 */ 676 665 protected function parse_orderby( $orderby ) { 677 global $wpdb;678 679 666 $meta_query_clauses = $this->meta_query->get_clauses(); 680 667 681 668 $_orderby = ''; … … 690 677 $where = get_posts_by_author_sql( 'post' ); 691 678 $this->query_from .= " LEFT OUTER JOIN ( 692 679 SELECT post_author, COUNT(*) as post_count 693 FROM $wpdb->posts680 FROM {$this->dbh->posts} 694 681 $where 695 682 GROUP BY post_author 696 ) p ON ({$ wpdb->users}.ID = p.post_author)683 ) p ON ({$this->dbh->users}.ID = p.post_author) 697 684 "; 698 685 $_orderby = 'post_count'; 699 686 } elseif ( 'ID' == $orderby || 'id' == $orderby ) { 700 687 $_orderby = 'ID'; 701 688 } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) { 702 $_orderby = " $wpdb->usermeta.meta_value";689 $_orderby = "{$this->dbh->usermeta}.meta_value"; 703 690 } elseif ( 'meta_value_num' == $orderby ) { 704 $_orderby = " $wpdb->usermeta.meta_value+0";691 $_orderby = "{$this->dbh->usermeta}.meta_value+0"; 705 692 } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { 706 693 $include = wp_parse_id_list( $this->query_vars['include'] ); 707 694 $include_sql = implode( ',', $include ); 708 $_orderby = "FIELD( $wpdb->users.ID, $include_sql )";695 $_orderby = "FIELD( {$this->dbh->users}.ID, $include_sql )"; 709 696 } elseif ( isset( $meta_query_clauses[ $orderby ] ) ) { 710 697 $meta_clause = $meta_query_clauses[ $orderby ]; 711 698 $_orderby = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); -
src/wp-includes/class-wp-user.php
101 101 */ 102 102 private static $back_compat_keys; 103 103 104 protected $dbh; 105 104 106 /** 105 107 * Constructor. 106 108 * … … 109 111 * @since 2.0.0 110 112 * @access public 111 113 * 112 * @global wpdb $wpdb WordPress database abstraction object.113 *114 114 * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. 115 115 * @param string $name Optional. User's username 116 116 * @param int $blog_id Optional Site ID, defaults to current site. 117 117 */ 118 118 public function __construct( $id = 0, $name = '', $blog_id = '' ) { 119 $this->dbh = WP::get( 'wpdb' ); 120 119 121 if ( ! isset( self::$back_compat_keys ) ) { 120 $prefix = $ GLOBALS['wpdb']->prefix;122 $prefix = $this->dbh->prefix; 121 123 self::$back_compat_keys = array( 122 124 'user_firstname' => 'first_name', 123 125 'user_lastname' => 'last_name', … … 175 177 * 176 178 * @static 177 179 * 178 * @global wpdb $wpdb WordPress database abstraction object.179 *180 180 * @param string $field The field to query against: 'id', 'ID', 'slug', 'email' or 'login'. 181 181 * @param string|int $value The field value 182 182 * @return object|false Raw user object 183 183 */ 184 184 public static function get_data_by( $field, $value ) { 185 global $wpdb;186 187 185 // 'ID' is an alias of 'id'. 188 186 if ( 'ID' === $field ) { 189 187 $field = 'id'; … … 231 229 return $user; 232 230 } 233 231 232 $wpdb = WP::get( 'wpdb' ); 234 233 if ( !$user = $wpdb->get_row( $wpdb->prepare( 235 234 "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value 236 235 ) ) ) … … 442 441 * @access protected 443 442 * @since 2.1.0 444 443 * 445 * @global wpdb $wpdb WordPress database abstraction object.446 *447 444 * @param string $cap_key Optional capability key 448 445 */ 449 446 protected function _init_caps( $cap_key = '' ) { 450 global $wpdb;451 452 447 if ( empty($cap_key) ) 453 $this->cap_key = $ wpdb->get_blog_prefix() . 'capabilities';448 $this->cap_key = $this->dbh->get_blog_prefix() . 'capabilities'; 454 449 else 455 450 $this->cap_key = $cap_key; 456 451 … … 631 626 * 632 627 * @since 2.0.0 633 628 * @access public 634 *635 * @global wpdb $wpdb WordPress database abstraction object.636 629 */ 637 630 public function update_user_level_from_caps() { 638 global $wpdb;639 631 $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 );632 update_user_meta( $this->ID, $this->dbh->get_blog_prefix() . 'user_level', $this->user_level ); 641 633 } 642 634 643 635 /** … … 679 671 * 680 672 * @since 2.1.0 681 673 * @access public 682 *683 * @global wpdb $wpdb WordPress database abstraction object.684 674 */ 685 675 public function remove_all_caps() { 686 global $wpdb;687 676 $this->caps = array(); 688 677 delete_user_meta( $this->ID, $this->cap_key ); 689 delete_user_meta( $this->ID, $ wpdb->get_blog_prefix() . 'user_level' );678 delete_user_meta( $this->ID, $this->dbh->get_blog_prefix() . 'user_level' ); 690 679 $this->get_role_caps(); 691 680 } 692 681 … … 772 761 * 773 762 * @since 3.0.0 774 763 * 775 * @global wpdb $wpdb WordPress database abstraction object.776 *777 764 * @param int $blog_id Optional. Site ID, defaults to current site. 778 765 */ 779 766 public function for_blog( $blog_id = '' ) { 780 global $wpdb;781 767 if ( ! empty( $blog_id ) ) 782 $cap_key = $ wpdb->get_blog_prefix( $blog_id ) . 'capabilities';768 $cap_key = $this->dbh->get_blog_prefix( $blog_id ) . 'capabilities'; 783 769 else 784 770 $cap_key = ''; 785 771 $this->_init_caps( $cap_key ); -
src/wp-includes/class-wp-xmlrpc-server.php
53 53 */ 54 54 protected $auth_failed = false; 55 55 56 protected $dbh; 57 56 58 /** 57 59 * Registers all of the XMLRPC methods that XMLRPC server understands. 58 60 * … … 63 65 * @since 1.5.0 64 66 */ 65 67 public function __construct() { 68 $this->dbh = WP::get( 'wpdb' ); 69 66 70 $this->methods = array( 67 71 // WordPress API 68 72 'wp.getUsersBlogs' => 'this:wp_getUsersBlogs', … … 2882 2886 * 2883 2887 * @since 2.2.0 2884 2888 * 2885 * @global wpdb $wpdb WordPress database abstraction object.2886 *2887 2889 * @param array $args { 2888 2890 * Method arguments. Note: arguments must be ordered as documented. 2889 2891 * … … 2894 2896 * @return array|IXR_Error 2895 2897 */ 2896 2898 public function wp_getPageList( $args ) { 2897 global $wpdb;2898 2899 2899 $this->escape( $args ); 2900 2900 2901 2901 $username = $args[1]; … … 2911 2911 do_action( 'xmlrpc_call', 'wp.getPageList' ); 2912 2912 2913 2913 // Get list of pages ids and titles 2914 $page_list = $ wpdb->get_results("2914 $page_list = $this->dbh->get_results(" 2915 2915 SELECT ID page_id, 2916 2916 post_title page_title, 2917 2917 post_parent page_parent_id, … … 2918 2918 post_date_gmt, 2919 2919 post_date, 2920 2920 post_status 2921 FROM {$ wpdb->posts}2921 FROM {$this->dbh->posts} 2922 2922 WHERE post_type = 'page' 2923 2923 ORDER BY ID 2924 2924 "); … … 5130 5130 * 5131 5131 * @since 2.1.0 5132 5132 * 5133 * @global wpdb $wpdb WordPress database abstraction object.5134 *5135 5133 * @param int $post_ID Post ID. 5136 5134 * @param string $post_content Post Content for attachment. 5137 5135 */ 5138 5136 public function attach_uploads( $post_ID, $post_content ) { 5139 global $wpdb;5140 5141 5137 // find any unattached files 5142 $attachments = $ wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );5138 $attachments = $this->dbh->get_results( "SELECT ID, guid FROM {$this->dbh->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); 5143 5139 if ( is_array( $attachments ) ) { 5144 5140 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) ); 5141 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { 5142 $this->dbh->update($this->dbh->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) ); 5143 } 5147 5144 } 5148 5145 } 5149 5146 } … … 5763 5760 * 5764 5761 * @since 1.5.0 5765 5762 * 5766 * @global wpdb $wpdb WordPress database abstraction object.5767 *5768 5763 * @param array $args { 5769 5764 * Method arguments. Note: arguments must be ordered as documented. 5770 5765 * … … 5776 5771 * @return array|IXR_Error 5777 5772 */ 5778 5773 public function mw_newMediaObject( $args ) { 5779 global $wpdb;5780 5781 5774 $username = $this->escape( $args[1] ); 5782 5775 $password = $this->escape( $args[2] ); 5783 5776 $data = $args[3]; … … 6102 6095 * 6103 6096 * @since 1.5.0 6104 6097 * 6105 * @global wpdb $wpdb WordPress database abstraction object.6106 *6107 6098 * @param int $post_ID 6108 6099 * @return array|IXR_Error 6109 6100 */ 6110 6101 public function mt_getTrackbackPings( $post_ID ) { 6111 global $wpdb;6112 6113 6102 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6114 6103 do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); 6115 6104 … … 6118 6107 if ( !$actual_post ) 6119 6108 return new IXR_Error(404, __('Sorry, no such post.')); 6120 6109 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) );6110 $comments = $this->dbh->get_results( $this->dbh->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->dbh->comments} WHERE comment_post_ID = %d", $post_ID) ); 6122 6111 6123 6112 if ( !$comments ) 6124 6113 return array(); … … 6192 6181 * 6193 6182 * @since 1.5.0 6194 6183 * 6195 * @global wpdb $wpdb WordPress database abstraction object.6196 6184 * @global string $wp_version 6197 6185 * 6198 6186 * @param array $args { … … 6204 6192 * @return string|IXR_Error 6205 6193 */ 6206 6194 public function pingback_ping( $args ) { 6207 global $wp db, $wp_version;6195 global $wp_version; 6208 6196 6209 6197 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6210 6198 do_action( 'xmlrpc_call', 'pingback.ping' ); … … 6258 6246 } elseif ( is_string($urltest['fragment']) ) { 6259 6247 // ...or a string #title, a little more complicated 6260 6248 $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)) ) {6249 $sql = $this->dbh->prepare("SELECT ID FROM {$this->dbh->posts} WHERE post_title RLIKE %s", $title ); 6250 if (! ($post_ID = $this->dbh->get_var($sql)) ) { 6263 6251 // returning unknown error '0' is better than die()ing 6264 6252 return $this->pingback_error( 0, '' ); 6265 6253 } … … 6283 6271 return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); 6284 6272 6285 6273 // 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) ) )6274 if ( $this->dbh->get_results( $this->dbh->prepare("SELECT * FROM {$this->dbh->comments} WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) ) 6287 6275 return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); 6288 6276 6289 6277 // very stupid, but gives time to the 'from' server to publish ! … … 6408 6396 * 6409 6397 * @since 1.5.0 6410 6398 * 6411 * @global wpdb $wpdb WordPress database abstraction object.6412 *6413 6399 * @param string $url 6414 6400 * @return array|IXR_Error 6415 6401 */ 6416 6402 public function pingback_extensions_getPingbacks( $url ) { 6417 global $wpdb;6418 6419 6403 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 6420 6404 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); 6421 6405 … … 6434 6418 return $this->pingback_error( 32, __('The specified target URL does not exist.' ) ); 6435 6419 } 6436 6420 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) );6421 $comments = $this->dbh->get_results( $this->dbh->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->dbh->comments} WHERE comment_post_ID = %d", $post_ID) ); 6438 6422 6439 6423 if ( !$comments ) 6440 6424 return array(); -
src/wp-includes/class-wp.php
91 91 */ 92 92 public $did_permalink = false; 93 93 94 public static function get( $key, $global = false ) { 95 return WP_Registry::instance()->get( $key, $global ); 96 } 97 98 public static function set( $key, $value = null, $global = false ) { 99 return WP_Registry::instance()->set( $key, $value, $global ); 100 } 101 94 102 /** 95 103 * Add name to list of public query variables. 96 104 * -
src/wp-includes/comment-template.php
1275 1275 * 1276 1276 * @global WP_Query $wp_query 1277 1277 * @global WP_Post $post 1278 * @global wpdb $wpdb1279 1278 * @global int $id 1280 1279 * @global WP_Comment $comment 1281 1280 * @global string $user_login … … 1289 1288 * Default false. 1290 1289 */ 1291 1290 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1292 global $wp_query, $withcomments, $post, $ wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;1291 global $wp_query, $withcomments, $post, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; 1293 1292 1293 $wpdb = WP::get( 'wpdb' ); 1294 1294 1295 if ( !(is_single() || is_page() || $withcomments) || empty($post) ) 1295 1296 return; 1296 1297 -
src/wp-includes/comment.php
24 24 * 25 25 * @since 1.2.0 26 26 * 27 * @global wpdb $wpdb WordPress database abstraction object.28 *29 27 * @param string $author Comment author name. 30 28 * @param string $email Comment author email. 31 29 * @param string $url Comment author URL. … … 37 35 * @return bool If all checks pass, true, otherwise false. 38 36 */ 39 37 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) { 40 global $wpdb;41 42 38 // If manual moderation is enabled, skip all checks and return false. 43 39 if ( 1 == get_option('comment_moderation') ) 44 40 return false; … … 110 106 */ 111 107 if ( 1 == get_option('comment_whitelist')) { 112 108 if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) { 109 $wpdb = WP::get( 'wpdb' ); 113 110 // expected_slashed ($author, $email) 114 111 $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1"); 115 112 if ( ( 1 == $ok_to_comment ) && … … 287 284 * 288 285 * @since 1.5.0 289 286 * 290 * @global wpdb $wpdb WordPress database abstraction object.291 287 * @staticvar array $cache_lastcommentmodified 292 288 * 293 289 * @param string $timezone Which timezone to use in reference to 'gmt', 'blog', … … 295 291 * @return string Last comment modified date. 296 292 */ 297 293 function get_lastcommentmodified($timezone = 'server') { 298 global $wpdb;299 294 static $cache_lastcommentmodified = array(); 300 295 301 296 if ( isset($cache_lastcommentmodified[$timezone]) ) … … 303 298 304 299 $add_seconds_server = date('Z'); 305 300 301 $wpdb = WP::get( 'wpdb' ); 306 302 switch ( strtolower($timezone)) { 307 303 case 'gmt': 308 304 $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); … … 328 324 * 329 325 * @since 2.0.0 330 326 * 331 * @global wpdb $wpdb WordPress database abstraction object.332 *333 327 * @param int $post_id Optional. Comment amount in post if > 0, else total comments blog wide. 334 328 * @return array The amount of spam, approved, awaiting moderation, and total comments. 335 329 */ 336 330 function get_comment_count( $post_id = 0 ) { 337 global $wpdb; 338 331 $wpdb = WP::get( 'wpdb' ); 339 332 $post_id = (int) $post_id; 340 333 341 334 $where = ''; … … 582 575 * 583 576 * @since 2.0.0 584 577 * 585 * @global wpdb $wpdb WordPress database abstraction object.586 *587 578 * @param array $commentdata Contains information on the comment 588 579 * @return int|string Signifies the approval status (0|1|'spam') 589 580 */ 590 581 function wp_allow_comment( $commentdata ) { 591 global $wpdb;582 $wpdb = WP::get( 'wpdb' ); 592 583 593 584 // Simple duplicate check 594 585 // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) … … 715 706 * 716 707 * @since 2.3.0 717 708 * 718 * @global wpdb $wpdb WordPress database abstraction object.719 *720 709 * @param string $ip Comment IP. 721 710 * @param string $email Comment author email address. 722 711 * @param string $date MySQL time string. 723 712 */ 724 713 function check_comment_flood_db( $ip, $email, $date ) { 725 global $wpdb;726 714 // don't throttle admins or moderators 727 715 if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) { 728 716 return; … … 737 725 $check_column = '`comment_author_IP`'; 738 726 } 739 727 728 $wpdb = WP::get( 'wpdb' ); 740 729 $sql = $wpdb->prepare( 741 730 "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", 742 731 $hour_ago, … … 854 843 * 855 844 * @since 2.7.0 856 845 * 857 * @global wpdb $wpdb WordPress database abstraction object.858 *859 846 * @param int $comment_ID Comment ID. 860 847 * @param array $args { 861 848 * Array of optional arguments. … … 870 857 * @return int|null Comment page number or null on error. 871 858 */ 872 859 function get_page_of_comment( $comment_ID, $args = array() ) { 873 global $wpdb;874 875 860 $page = null; 876 861 877 862 if ( !$comment = get_comment( $comment_ID ) ) … … 913 898 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) 914 899 return get_page_of_comment( $comment->comment_parent, $args ); 915 900 901 $wpdb = WP::get( 'wpdb' ); 916 902 $comment_args = array( 917 903 'type' => $args['type'], 918 904 'post_id' => $comment->comment_post_ID, … … 974 960 * 975 961 * @since 4.5.0 976 962 * 977 * @global wpdb $wpdb WordPress database abstraction object.978 *979 963 * @return array Maximum character length for the comment form fields. 980 964 */ 981 965 function wp_get_comment_fields_max_lengths() { 982 global $wpdb; 983 966 $wpdb = WP::get( 'wpdb' ); 984 967 $lengths = array( 985 968 'comment_author' => 245, 986 969 'comment_author_email' => 100, … … 1144 1127 * 1145 1128 * @since 2.0.0 1146 1129 * 1147 * @global wpdb $wpdb WordPress database abstraction object.1148 *1149 1130 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. 1150 1131 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false. 1151 1132 * @return bool True on success, false on failure. 1152 1133 */ 1153 1134 function wp_delete_comment($comment_id, $force_delete = false) { 1154 global $wpdb;1155 1135 if (!$comment = get_comment($comment_id)) 1156 1136 return false; 1157 1137 … … 1167 1147 */ 1168 1148 do_action( 'delete_comment', $comment->comment_ID ); 1169 1149 1150 $wpdb = WP::get( 'wpdb' ); 1170 1151 // Move children up a level. 1171 1152 $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) ); 1172 1153 if ( !empty($children) ) { … … 1532 1513 * @since 2.0.0 1533 1514 * @since 4.4.0 Introduced `$comment_meta` argument. 1534 1515 * 1535 * @global wpdb $wpdb WordPress database abstraction object.1536 *1537 1516 * @param array $commentdata { 1538 1517 * Array of arguments for inserting a new comment. 1539 1518 * … … 1562 1541 * @return int|false The new comment's ID on success, false on failure. 1563 1542 */ 1564 1543 function wp_insert_comment( $commentdata ) { 1565 global $wpdb;1566 1544 $data = wp_unslash( $commentdata ); 1567 1545 1568 1546 $comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; … … 1584 1562 $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; 1585 1563 1586 1564 $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' ); 1565 $wpdb = WP::get( 'wpdb' ); 1587 1566 if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { 1588 1567 return false; 1589 1568 } … … 1717 1696 * @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`. 1718 1697 * 1719 1698 * @see wp_insert_comment() 1720 * @global wpdb $wpdb WordPress database abstraction object.1721 1699 * 1722 1700 * @param array $commentdata { 1723 1701 * Comment data. … … 1741 1719 * @return int|false The ID of the comment on success, false on failure. 1742 1720 */ 1743 1721 function wp_new_comment( $commentdata ) { 1744 global $wpdb;1745 1746 1722 if ( isset( $commentdata['user_ID'] ) ) { 1747 1723 $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; 1748 1724 } … … 1797 1773 1798 1774 foreach ( $fields as $field ) { 1799 1775 if ( isset( $commentdata[ $field ] ) ) { 1776 $wpdb = WP::get( 'wpdb' ); 1800 1777 $commentdata[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $commentdata[ $field ] ); 1801 1778 } 1802 1779 } … … 1901 1878 * 1902 1879 * @since 1.0.0 1903 1880 * 1904 * @global wpdb $wpdb WordPress database abstraction object.1905 *1906 1881 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. 1907 1882 * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'. 1908 1883 * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false. … … 1909 1884 * @return bool|WP_Error True on success, false or WP_Error on failure. 1910 1885 */ 1911 1886 function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { 1912 global $wpdb;1913 1914 1887 switch ( $comment_status ) { 1915 1888 case 'hold': 1916 1889 case '0': … … 1933 1906 1934 1907 $comment_old = clone get_comment($comment_id); 1935 1908 1909 $wpdb = WP::get( 'wpdb' ); 1936 1910 if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { 1937 if ( $wp_error ) 1911 if ( $wp_error ) { 1938 1912 return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); 1939 else1913 } else { 1940 1914 return false; 1915 } 1941 1916 } 1942 1917 1943 1918 clean_comment_cache( $comment_old->comment_ID ); … … 1970 1945 * 1971 1946 * @since 2.0.0 1972 1947 * 1973 * @global wpdb $wpdb WordPress database abstraction object.1974 *1975 1948 * @param array $commentarr Contains information on the comment. 1976 1949 * @return int Comment was updated if value is 1, or was not updated if value is 0. 1977 1950 */ 1978 1951 function wp_update_comment($commentarr) { 1979 global $wpdb;1980 1981 1952 // First, get all of the original fields 1982 1953 $comment = get_comment($commentarr['comment_ID'], ARRAY_A); 1983 1954 if ( empty( $comment ) ) { … … 2025 1996 $comment_post_ID = $data['comment_post_ID']; 2026 1997 $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' ); 2027 1998 $data = wp_array_slice_assoc( $data, $keys ); 1999 $wpdb = WP::get( 'wpdb' ); 2028 2000 $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); 2029 2001 2030 2002 clean_comment_cache( $comment_ID ); … … 2125 2097 * 2126 2098 * @since 2.5.0 2127 2099 * 2128 * @global wpdb $wpdb WordPress database abstraction object.2129 *2130 2100 * @param int $post_id Post ID 2131 2101 * @return bool True on success, false on '0' $post_id or if post with ID does not exist. 2132 2102 */ 2133 2103 function wp_update_comment_count_now($post_id) { 2134 global $wpdb;2135 2104 $post_id = (int) $post_id; 2136 2105 if ( !$post_id ) 2137 2106 return false; … … 2155 2124 */ 2156 2125 $new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id ); 2157 2126 2127 $wpdb = WP::get( 'wpdb' ); 2158 2128 if ( is_null( $new ) ) { 2159 2129 $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) ); 2160 2130 } else { … … 2260 2230 * Perform all pingbacks, enclosures, trackbacks, and send to pingback services. 2261 2231 * 2262 2232 * @since 2.1.0 2263 *2264 * @global wpdb $wpdb WordPress database abstraction object.2265 2233 */ 2266 2234 function do_all_pings() { 2267 global $wpdb;2235 $wpdb = WP::get( 'wpdb' ); 2268 2236 2269 2237 // Do pingbacks 2270 2238 while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { … … 2293 2261 * 2294 2262 * @since 1.5.0 2295 2263 * 2296 * @global wpdb $wpdb WordPress database abstraction object.2297 *2298 2264 * @param int $post_id Post ID to do trackbacks on. 2299 2265 */ 2300 2266 function do_trackbacks($post_id) { 2301 global $wpdb;2302 2303 2267 $post = get_post( $post_id ); 2304 2268 $to_ping = get_to_ping($post_id); 2305 2269 $pinged = get_pung($post_id); 2306 2270 if ( empty($to_ping) ) { 2271 $wpdb = WP::get( 'wpdb' ); 2307 2272 $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id) ); 2308 2273 return; 2309 2274 } … … 2330 2295 trackback($tb_ping, $post_title, $excerpt, $post_id); 2331 2296 $pinged[] = $tb_ping; 2332 2297 } else { 2298 $wpdb = WP::get( 'wpdb' ); 2333 2299 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping, $post_id) ); 2334 2300 } 2335 2301 } … … 2469 2435 * 2470 2436 * @since 0.71 2471 2437 * 2472 * @global wpdb $wpdb WordPress database abstraction object.2473 *2474 2438 * @param string $trackback_url URL to send trackbacks. 2475 2439 * @param string $title Title of post. 2476 2440 * @param string $excerpt Excerpt of post. … … 2478 2442 * @return int|false|void Database query from update. 2479 2443 */ 2480 2444 function trackback($trackback_url, $title, $excerpt, $ID) { 2481 global $wpdb;2482 2483 2445 if ( empty($trackback_url) ) 2484 2446 return; 2485 2447 … … 2497 2459 if ( is_wp_error( $response ) ) 2498 2460 return; 2499 2461 2462 $wpdb = WP::get( 'wpdb' ); 2500 2463 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID) ); 2501 2464 return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID) ); 2502 2465 } … … 2621 2584 * @access private 2622 2585 * 2623 2586 * @see update_comment_cache() 2624 * @global wpdb $wpdb WordPress database abstraction object.2625 2587 * 2626 2588 * @param array $comment_ids Array of comment IDs. 2627 2589 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 2628 2590 */ 2629 2591 function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) { 2630 global $wpdb;2631 2632 2592 $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); 2633 2593 if ( !empty( $non_cached_ids ) ) { 2594 $wpdb = WP::get( 'wpdb' ); 2634 2595 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 2635 2596 2636 2597 update_comment_cache( $fresh_comments, $update_meta_cache ); -
src/wp-includes/date.php
62 62 */ 63 63 public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' ); 64 64 65 protected $dbh; 66 65 67 /** 66 68 * Constructor. 67 69 * … … 158 160 $this->relation = 'AND'; 159 161 } 160 162 163 $this->dbh = WP::get( 'wpdb' ); 164 161 165 if ( ! is_array( $date_query ) ) { 162 166 return; 163 167 } … … 486 490 * @return string A validated column name value. 487 491 */ 488 492 public function validate_column( $column ) { 489 global $wpdb;490 491 493 $valid_columns = array( 492 494 'post_date', 'post_date_gmt', 'post_modified', 493 495 'post_modified_gmt', 'comment_date', 'comment_date_gmt', … … 512 514 } 513 515 514 516 $known_columns = array( 515 $ wpdb->posts => array(517 $this->dbh->posts => array( 516 518 'post_date', 517 519 'post_date_gmt', 518 520 'post_modified', 519 521 'post_modified_gmt', 520 522 ), 521 $ wpdb->comments => array(523 $this->dbh->comments => array( 522 524 'comment_date', 523 525 'comment_date_gmt', 524 526 ), 525 $ wpdb->users => array(527 $this->dbh->users => array( 526 528 'user_registered', 527 529 ), 528 $ wpdb->blogs => array(530 $this->dbh->blogs => array( 529 531 'registered', 530 532 'last_updated', 531 533 ), … … 717 719 * } 718 720 */ 719 721 protected function get_sql_for_clause( $query, $parent_query ) { 720 global $wpdb;721 722 722 // The sub-parts of a $where part. 723 723 $where_parts = array(); 724 724 … … 741 741 742 742 // Range queries. 743 743 if ( ! empty( $query['after'] ) ) 744 $where_parts[] = $ wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );744 $where_parts[] = $this->dbh->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) ); 745 745 746 746 if ( ! empty( $query['before'] ) ) 747 $where_parts[] = $ wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );747 $where_parts[] = $this->dbh->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) ); 748 748 749 749 // Specific value queries. 750 750 … … 958 958 * @return string|false A query part or false on failure. 959 959 */ 960 960 public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) { 961 global $wpdb;962 963 961 // Have to have at least one 964 962 if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) 965 963 return false; … … 1013 1011 $time .= sprintf( '%02d', $second ); 1014 1012 } 1015 1013 1016 return $ wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );1014 return $this->dbh->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time ); 1017 1015 } 1018 1016 } -
src/wp-includes/deprecated.php
2210 2210 */ 2211 2211 function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { 2212 2212 _deprecated_function( __FUNCTION__, '3.0.0', 'delete_user_meta()' ); 2213 global $wpdb; 2213 2214 2214 if ( !is_numeric( $user_id ) ) 2215 2215 return false; 2216 2216 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); … … 2219 2219 $meta_value = serialize($meta_value); 2220 2220 $meta_value = trim( $meta_value ); 2221 2221 2222 $wpdb = WP::get( 'wpdb' ); 2222 2223 $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); 2223 2224 2224 2225 if ( $cur && $cur->umeta_id ) … … 2256 2257 */ 2257 2258 function get_usermeta( $user_id, $meta_key = '' ) { 2258 2259 _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_meta()' ); 2259 global $wpdb; 2260 2260 2261 $user_id = (int) $user_id; 2261 2262 2262 2263 if ( !$user_id ) 2263 2264 return false; 2264 2265 2266 $wpdb = WP::get( 'wpdb' ); 2267 2265 2268 if ( !empty($meta_key) ) { 2266 2269 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); 2267 2270 $user = wp_cache_get($user_id, 'users'); … … 2309 2312 */ 2310 2313 function update_usermeta( $user_id, $meta_key, $meta_value ) { 2311 2314 _deprecated_function( __FUNCTION__, '3.0.0', 'update_user_meta()' ); 2312 global $wpdb; 2315 2313 2316 if ( !is_numeric( $user_id ) ) 2314 2317 return false; 2315 2318 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); … … 2323 2326 return delete_usermeta($user_id, $meta_key); 2324 2327 } 2325 2328 2329 $wpdb = WP::get( 'wpdb' ); 2326 2330 $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); 2327 2331 2328 2332 if ( $cur ) … … 2356 2360 * @deprecated 3.1.0 Use get_users() 2357 2361 * @see get_users() 2358 2362 * 2359 * @global wpdb $wpdb WordPress database abstraction object.2360 2363 * @global int $blog_id The site ID of the site for those that use more than one site. 2361 2364 * 2362 2365 * @param int $id Site ID. … … 2365 2368 function get_users_of_blog( $id = '' ) { 2366 2369 _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' ); 2367 2370 2368 global $ wpdb, $blog_id;2369 if ( empty( $id) )2371 global $blog_id; 2372 if ( empty( $id ) ) { 2370 2373 $id = (int) $blog_id; 2374 } 2375 $wpdb = WP::get( 'wpdb' ); 2371 2376 $blog_prefix = $wpdb->get_blog_prefix($id); 2372 2377 $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ); 2373 2378 return $users; -
src/wp-includes/formatting.php
3717 3717 * 3718 3718 * @since 2.8.0 3719 3719 * 3720 * @global wpdb $wpdb WordPress database abstraction object.3721 *3722 3720 * @param string|array $data Unescaped data 3723 3721 * @return string|array Escaped data 3724 3722 */ 3725 3723 function esc_sql( $data ) { 3726 global $wpdb; 3727 return $wpdb->_escape( $data ); 3724 return WP::get( 'wpdb' )->_escape( $data ); 3728 3725 } 3729 3726 3730 3727 /** … … 4012 4009 * 4013 4010 * @since 2.0.5 4014 4011 * 4015 * @global wpdb $wpdb WordPress database abstraction object.4016 *4017 4012 * @param string $option The name of the option. 4018 4013 * @param string $value The unsanitised value. 4019 4014 * @return string Sanitized value. 4020 4015 */ 4021 4016 function sanitize_option( $option, $value ) { 4022 global $wpdb;4023 4024 4017 $original_value = $value; 4025 4018 $error = ''; 4026 4019 4020 $wpdb = WP::get( 'wpdb' ); 4021 4027 4022 switch ( $option ) { 4028 4023 case 'admin_email' : 4029 4024 case 'new_admin_email' : -
src/wp-includes/functions.php
554 554 * 555 555 * @since 1.5.0 556 556 * 557 * @global wpdb $wpdb WordPress database abstraction object.558 *559 557 * @param string $content Post Content. 560 558 * @param int $post_ID Post ID. 561 559 */ 562 560 function do_enclose( $content, $post_ID ) { 563 global $wpdb;561 $wpdb = WP::get( 'wpdb' ); 564 562 565 563 //TODO: Tidy this ghetto code up and make the debug code optional 566 564 include_once( ABSPATH . WPINC . '/class-IXR.php' ); … … 1183 1181 * 1184 1182 * @since 2.0.0 1185 1183 * 1186 * @global wpdb $wpdb WordPress database abstraction object.1187 *1188 1184 * @return int Number of database queries. 1189 1185 */ 1190 1186 function get_num_queries() { 1191 global $wpdb; 1192 return $wpdb->num_queries; 1187 return WP::get( 'wpdb' )->num_queries; 1193 1188 } 1194 1189 1195 1190 /** … … 1353 1348 * 1354 1349 * @since 2.1.0 1355 1350 * 1356 * @global wpdb $wpdb WordPress database abstraction object.1357 *1358 1351 * @return bool Whether the site is already installed. 1359 1352 */ 1360 1353 function is_blog_installed() { 1361 global $wpdb;1362 1363 1354 /* 1364 1355 * Check cache first. If options table goes away and we have true 1365 1356 * cached, oh well. … … 1367 1358 if ( wp_cache_get( 'is_blog_installed' ) ) 1368 1359 return true; 1369 1360 1361 $wpdb = WP::get( 'wpdb' ); 1370 1362 $suppress = $wpdb->suppress_errors(); 1371 1363 if ( ! wp_installing() ) { 1372 1364 $alloptions = wp_load_alloptions(); … … 3612 3604 * in WordPress 2.5.0. 3613 3605 * 3614 3606 * @since 2.3.2 3615 *3616 * @global wpdb $wpdb WordPress database abstraction object.3617 3607 */ 3618 3608 function dead_db() { 3619 global $wpdb;3609 $wpdb = WP::get( 'wpdb' ); 3620 3610 3621 3611 wp_load_translations_early(); 3622 3612 … … 4285 4275 * 4286 4276 * @since 4.3.0 4287 4277 * 4288 * @global wpdb $wpdb WordPress database abstraction object.4289 *4290 4278 * @return int The ID of the main network. 4291 4279 */ 4292 4280 function get_main_network_id() { 4293 global $wpdb;4294 4295 4281 if ( ! is_multisite() ) { 4296 4282 return 1; 4297 4283 } … … 4307 4293 $main_network_id = wp_cache_get( 'primary_network_id', 'site-options' ); 4308 4294 4309 4295 if ( false === $main_network_id ) { 4296 $wpdb = WP::get( 'wpdb' ); 4310 4297 $main_network_id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->site} ORDER BY id LIMIT 1" ); 4311 4298 wp_cache_add( 'primary_network_id', $main_network_id, 'site-options' ); 4312 4299 } … … 4580 4567 * The default value of `EMPTY_TRASH_DAYS` is 30 (days). 4581 4568 * 4582 4569 * @since 2.9.0 4583 *4584 * @global wpdb $wpdb WordPress database abstraction object.4585 4570 */ 4586 4571 function wp_scheduled_delete() { 4587 global $wpdb;4572 $wpdb = WP::get( 'wpdb' ); 4588 4573 4589 4574 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); 4590 4575 -
src/wp-includes/general-template.php
1611 1611 * 1612 1612 * @see get_archives_link() 1613 1613 * 1614 * @global wpdb $wpdb1615 1614 * @global WP_Locale $wp_locale 1616 1615 * 1617 1616 * @param string|array $args { … … 1639 1638 * @return string|void String when retrieving. 1640 1639 */ 1641 1640 function wp_get_archives( $args = '' ) { 1642 global $wp db, $wp_locale;1641 global $wp_locale; 1643 1642 1644 1643 $defaults = array( 1645 1644 'type' => 'monthly', 'limit' => '', … … 1674 1673 // this is what will separate dates on weekly archive links 1675 1674 $archive_week_separator = '–'; 1676 1675 1676 $wpdb = WP::get( 'wpdb' ); 1677 1677 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] ); 1678 1678 1679 1679 /** … … 1857 1857 * 1858 1858 * @since 1.0.0 1859 1859 * 1860 * @global wpdb $wpdb1861 1860 * @global int $m 1862 1861 * @global int $monthnum 1863 1862 * @global int $year … … 1869 1868 * @return string|void String when retrieving. 1870 1869 */ 1871 1870 function get_calendar( $initial = true, $echo = true ) { 1872 global $ wpdb, $m, $monthnum, $year, $wp_locale, $posts;1871 global $m, $monthnum, $year, $wp_locale, $posts; 1873 1872 1873 $wpdb = WP::get( 'wpdb' ); 1874 1874 1875 $key = md5( $m . $monthnum . $year ); 1875 1876 $cache = wp_cache_get( 'get_calendar', 'calendar' ); 1876 1877 -
src/wp-includes/http.php
602 602 * 603 603 * @since 3.6.0 604 604 * 605 * @global wpdb $wpdb WordPress database abstraction object.606 605 * @staticvar array $queried 607 606 * 608 607 * @param bool $is_external … … 610 609 * @return bool 611 610 */ 612 611 function ms_allowed_http_request_hosts( $is_external, $host ) { 613 global $wpdb;614 612 static $queried = array(); 615 613 if ( $is_external ) 616 614 return $is_external; … … 618 616 return true; 619 617 if ( isset( $queried[ $host ] ) ) 620 618 return $queried[ $host ]; 619 620 $wpdb = WP::get( 'wpdb' ); 621 621 $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); 622 622 return $queried[ $host ]; 623 623 } -
src/wp-includes/link-template.php
1576 1576 * 1577 1577 * @since 2.5.0 1578 1578 * 1579 * @global wpdb $wpdb WordPress database abstraction object.1580 *1581 1579 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. 1582 1580 * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. 1583 1581 * @param bool $previous Optional. Whether to retrieve previous post. Default true … … 1586 1584 * corresponding post exists. 1587 1585 */ 1588 1586 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { 1589 global $wpdb;1590 1591 1587 if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) 1592 1588 return null; 1593 1589 1590 $wpdb = WP::get( 'wpdb' ); 1591 1594 1592 $current_post_date = $post->post_date; 1595 1593 1596 1594 $join = ''; -
src/wp-includes/load.php
388 388 * Load the database class file and instantiate the `$wpdb` global. 389 389 * 390 390 * @since 2.5.0 391 *392 * @global wpdb $wpdb The WordPress database class.393 391 */ 394 392 function require_wp_db() { 395 global $wpdb;393 $wpdb = null; 396 394 397 395 require_once( ABSPATH . WPINC . '/wp-db.php' ); 398 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) 396 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { 399 397 require_once( WP_CONTENT_DIR . '/db.php' ); 398 } 400 399 401 if ( isset( $wpdb ) ) 400 if ( isset( $wpdb ) ) { 401 WP::set( 'wpdb', $wpdb, true ); 402 402 return; 403 } 403 404 404 $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); 405 $db = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); 406 407 WP::set( 'wpdb', $db, true ); 405 408 } 406 409 407 410 /** -
src/wp-includes/media.php
3216 3216 * @since 3.5.0 3217 3217 * 3218 3218 * @global int $content_width 3219 * @global wpdb $wpdb3220 3219 * @global WP_Locale $wp_locale 3221 3220 * 3222 3221 * @param array $args { … … 3230 3229 if ( did_action( 'wp_enqueue_media' ) ) 3231 3230 return; 3232 3231 3233 global $content_width, $wp db, $wp_locale;3232 global $content_width, $wp_locale; 3234 3233 3235 3234 $defaults = array( 3236 3235 'post' => null, … … 3269 3268 } 3270 3269 } 3271 3270 3271 $wpdb = WP::get( 'wpdb' ); 3272 3272 3273 $has_audio = $wpdb->get_var( " 3273 3274 SELECT ID 3274 3275 FROM $wpdb->posts … … 3743 3744 * 3744 3745 * @since 4.0.0 3745 3746 * 3746 * @global wpdb $wpdb WordPress database abstraction object.3747 *3748 3747 * @param string $url The URL to resolve. 3749 3748 * @return int The found post ID, or 0 on failure. 3750 3749 */ 3751 3750 function attachment_url_to_postid( $url ) { 3752 global $wpdb;3753 3754 3751 $dir = wp_get_upload_dir(); 3755 3752 $path = $url; 3756 3753 … … 3766 3763 $path = substr( $path, strlen( $dir['baseurl'] . '/' ) ); 3767 3764 } 3768 3765 3766 $wpdb = WP::get( 'wpdb' ); 3769 3767 $sql = $wpdb->prepare( 3770 3768 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 3771 3769 $path -
src/wp-includes/meta.php
15 15 * 16 16 * @since 2.9.0 17 17 * 18 * @global wpdb $wpdb WordPress database abstraction object.19 *20 18 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 21 19 * @param int $object_id ID of the object metadata is for 22 20 * @param string $meta_key Metadata key … … 28 26 * @return int|false The meta ID on success, false on failure. 29 27 */ 30 28 function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) { 31 global $wpdb;32 33 29 if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) { 34 30 return false; 35 31 } … … 71 67 if ( null !== $check ) 72 68 return $check; 73 69 70 $wpdb = WP::get( 'wpdb' ); 74 71 if ( $unique && $wpdb->get_var( $wpdb->prepare( 75 72 "SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d", 76 73 $meta_key, $object_id ) ) ) … … 130 127 * 131 128 * @since 2.9.0 132 129 * 133 * @global wpdb $wpdb WordPress database abstraction object.134 *135 130 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 136 131 * @param int $object_id ID of the object metadata is for 137 132 * @param string $meta_key Metadata key … … 141 136 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 142 137 */ 143 138 function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '') { 144 global $wpdb;145 146 139 if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) { 147 140 return false; 148 141 } … … 197 190 } 198 191 } 199 192 193 $wpdb = WP::get( 'wpdb' ); 200 194 $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ); 201 195 if ( empty( $meta_ids ) ) { 202 196 return add_metadata( $meta_type, $object_id, $raw_meta_key, $passed_value ); … … 289 283 * 290 284 * @since 2.9.0 291 285 * 292 * @global wpdb $wpdb WordPress database abstraction object.293 *294 286 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 295 287 * @param int $object_id ID of the object metadata is for 296 288 * @param string $meta_key Metadata key … … 305 297 * @return bool True on successful delete, false on failure. 306 298 */ 307 299 function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) { 308 global $wpdb;309 310 300 if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) { 311 301 return false; 312 302 } … … 351 341 $_meta_value = $meta_value; 352 342 $meta_value = maybe_serialize( $meta_value ); 353 343 344 $wpdb = WP::get( 'wpdb' ); 345 354 346 $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); 355 347 356 348 if ( !$delete_all ) … … 558 550 * 559 551 * @since 3.3.0 560 552 * 561 * @global wpdb $wpdb WordPress database abstraction object.562 *563 553 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 564 554 * @param int $meta_id ID for a specific meta row 565 555 * @return object|false Meta object or false. 566 556 */ 567 557 function get_metadata_by_mid( $meta_type, $meta_id ) { 568 global $wpdb;569 570 558 if ( ! $meta_type || ! is_numeric( $meta_id ) ) { 571 559 return false; 572 560 } … … 583 571 584 572 $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; 585 573 574 $wpdb = WP::get( 'wpdb' ); 586 575 $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); 587 576 588 577 if ( empty( $meta ) ) … … 599 588 * 600 589 * @since 3.3.0 601 590 * 602 * @global wpdb $wpdb WordPress database abstraction object.603 *604 591 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 605 592 * @param int $meta_id ID for a specific meta row 606 593 * @param string $meta_value Metadata value … … 608 595 * @return bool True on successful update, false on failure. 609 596 */ 610 597 function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) { 611 global $wpdb;612 613 598 // Make sure everything is valid. 614 599 if ( ! $meta_type || ! is_numeric( $meta_id ) ) { 615 600 return false; … … 664 649 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 665 650 } 666 651 652 $wpdb = WP::get( 'wpdb' ); 667 653 // Run the update query, all fields in $data are %s, $where is a %d. 668 654 $result = $wpdb->update( $table, $data, $where, '%s', '%d' ); 669 655 if ( ! $result ) … … 692 678 * 693 679 * @since 3.3.0 694 680 * 695 * @global wpdb $wpdb WordPress database abstraction object.696 *697 681 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user). 698 682 * @param int $meta_id ID for a specific meta row 699 683 * @return bool True on successful delete, false on failure. 700 684 */ 701 685 function delete_metadata_by_mid( $meta_type, $meta_id ) { 702 global $wpdb;703 704 686 // Make sure everything is valid. 705 687 if ( ! $meta_type || ! is_numeric( $meta_id ) ) { 706 688 return false; … … 742 724 do_action( "delete_{$meta_type}meta", $meta_id ); 743 725 } 744 726 727 $wpdb = WP::get( 'wpdb' ); 745 728 // Run the query, will return true if deleted, false otherwise 746 729 $result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) ); 747 730 … … 779 762 * 780 763 * @since 2.9.0 781 764 * 782 * @global wpdb $wpdb WordPress database abstraction object.783 *784 765 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 785 766 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for 786 767 * @return array|false Metadata cache for the specified objects, or false on failure. 787 768 */ 788 769 function update_meta_cache($meta_type, $object_ids) { 789 global $wpdb;790 791 770 if ( ! $meta_type || ! $object_ids ) { 792 771 return false; 793 772 } … … 823 802 // Get meta info 824 803 $id_list = join( ',', $ids ); 825 804 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 805 806 $wpdb = WP::get( 'wpdb' ); 826 807 $meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A ); 827 808 828 809 if ( !empty($meta_list) ) { … … 892 873 * 893 874 * @since 2.9.0 894 875 * 895 * @global wpdb $wpdb WordPress database abstraction object.896 *897 876 * @param string $type Type of object to get metadata table for (e.g., comment, post, or user) 898 877 * @return string|false Metadata table name, or false if no metadata table exists 899 878 */ 900 879 function _get_meta_table($type) { 901 global $wpdb;880 $wpdb = WP::get( 'wpdb' ); 902 881 903 882 $table_name = $type . 'meta'; 904 883 -
src/wp-includes/ms-blogs.php
12 12 * Update the last_updated field for the current site. 13 13 * 14 14 * @since MU 15 *16 * @global wpdb $wpdb WordPress database abstraction object.17 15 */ 18 16 function wpmu_update_blogs_date() { 19 global $wpdb;17 $wpdb = WP::get( 'wpdb' ); 20 18 21 19 update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) ); 22 20 /** … … 76 74 * 77 75 * @since MU 78 76 * 79 * @global wpdb $wpdb WordPress database abstraction object.80 *81 77 * @param string $slug 82 78 * @return int A blog id 83 79 */ 84 80 function get_id_from_blogname( $slug ) { 85 global $wpdb;86 87 81 $current_site = get_current_site(); 88 82 $slug = trim( $slug, '/' ); 89 83 … … 99 93 $path = $current_site->path . $slug . '/'; 100 94 } 101 95 96 $wpdb = WP::get( 'wpdb' ); 102 97 $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) ); 103 98 wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' ); 104 99 return $blog_id; … … 109 104 * 110 105 * @since MU 111 106 * 112 * @global wpdb $wpdb WordPress database abstraction object.113 *114 107 * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. 115 108 * If not specified the current blog ID is used. 116 109 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. … … 118 111 * @return WP_Site|false Blog details on success. False on failure. 119 112 */ 120 113 function get_blog_details( $fields = null, $get_all = true ) { 121 global $wpdb;114 $wpdb = WP::get( 'wpdb' ); 122 115 123 116 if ( is_array($fields ) ) { 124 117 if ( isset($fields['blog_id']) ) { … … 293 286 * 294 287 * @since MU 295 288 * 296 * @global wpdb $wpdb WordPress database abstraction object.297 *298 289 * @param int $blog_id Blog ID 299 290 * @param array $details Array of details keyed by blogs table field names. 300 291 * @return bool True if update succeeds, false otherwise. 301 292 */ 302 293 function update_blog_details( $blog_id, $details = array() ) { 303 global $wpdb;304 305 294 if ( empty($details) ) 306 295 return false; 307 296 … … 327 316 $update_details[ $field ] = $details[ $field ]; 328 317 } 329 318 319 $wpdb = WP::get( 'wpdb' ); 330 320 $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); 331 321 332 322 if ( false === $result ) … … 517 507 * @access private 518 508 * 519 509 * @see update_site_cache() 520 * @global wpdb $wpdb WordPress database abstraction object.521 510 * 522 511 * @param array $ids ID list. 523 512 */ 524 513 function _prime_site_caches( $ids ) { 525 global $wpdb;526 527 514 $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); 528 515 if ( ! empty( $non_cached_ids ) ) { 516 $wpdb = WP::get( 'wpdb' ); 529 517 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 530 518 531 519 update_site_cache( $fresh_sites ); … … 752 740 * @see restore_current_blog() 753 741 * @since MU 754 742 * 755 * @global wpdb $wpdb756 743 * @global int $blog_id 757 744 * @global array $_wp_switched_stack 758 745 * @global bool $switched … … 764 751 * @return true Always returns True. 765 752 */ 766 753 function switch_to_blog( $new_blog, $deprecated = null ) { 767 global $wpdb;768 769 754 if ( empty( $new_blog ) ) 770 755 $new_blog = $GLOBALS['blog_id']; 771 756 … … 790 775 return true; 791 776 } 792 777 778 $wpdb = WP::get( 'wpdb' ); 793 779 $wpdb->set_blog_id( $new_blog ); 794 780 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); 795 781 $prev_blog_id = $GLOBALS['blog_id']; … … 836 822 * @see switch_to_blog() 837 823 * @since MU 838 824 * 839 * @global wpdb $wpdb840 825 * @global array $_wp_switched_stack 841 826 * @global int $blog_id 842 827 * @global bool $switched … … 846 831 * @return bool True on success, false if we're already on the current blog 847 832 */ 848 833 function restore_current_blog() { 849 global $wpdb;850 851 834 if ( empty( $GLOBALS['_wp_switched_stack'] ) ) 852 835 return false; 853 836 … … 861 844 return true; 862 845 } 863 846 847 $wpdb = WP::get( 'wpdb' ); 864 848 $wpdb->set_blog_id( $blog ); 865 849 $prev_blog_id = $GLOBALS['blog_id']; 866 850 $GLOBALS['blog_id'] = $blog; … … 947 931 * 948 932 * @since MU 949 933 * 950 * @global wpdb $wpdb WordPress database abstraction object.951 *952 934 * @param int $blog_id BLog ID 953 935 * @param string $pref A field name 954 936 * @param string $value Value for $pref … … 956 938 * @return string|false $value 957 939 */ 958 940 function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { 959 global $wpdb;960 961 941 if ( null !== $deprecated ) 962 942 _deprecated_argument( __FUNCTION__, '3.1.0' ); 963 943 … … 964 944 if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) 965 945 return $value; 966 946 947 $wpdb = WP::get( 'wpdb' ); 967 948 $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); 968 949 969 950 if ( false === $result ) … … 1023 1004 * 1024 1005 * @since MU 1025 1006 * 1026 * @global wpdb $wpdb WordPress database abstraction object.1027 *1028 1007 * @param int $id The blog id 1029 1008 * @param string $pref A field name 1030 1009 * @return bool|string|null $value 1031 1010 */ 1032 1011 function get_blog_status( $id, $pref ) { 1033 global $wpdb;1034 1035 1012 $details = get_blog_details( $id, false ); 1036 1013 if ( $details ) 1037 1014 return $details->$pref; 1038 1015 1016 $wpdb = WP::get( 'wpdb' ); 1039 1017 return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) ); 1040 1018 } 1041 1019 … … 1044 1022 * 1045 1023 * @since MU 1046 1024 * 1047 * @global wpdb $wpdb WordPress database abstraction object.1048 *1049 1025 * @param mixed $deprecated Not used 1050 1026 * @param int $start The offset 1051 1027 * @param int $quantity The maximum number of blogs to retrieve. Default is 40. … … 1052 1028 * @return array The list of blogs 1053 1029 */ 1054 1030 function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { 1055 global $wpdb;1056 1057 1031 if ( ! empty( $deprecated ) ) 1058 1032 _deprecated_argument( __FUNCTION__, 'MU' ); // never used 1059 1033 1034 $wpdb = WP::get( 'wpdb' ); 1060 1035 return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A ); 1061 1036 } 1062 1037 … … 1166 1141 * @access private 1167 1142 * 1168 1143 * @see update_network_cache() 1169 * @global wpdb $wpdb WordPress database abstraction object.1170 1144 * 1171 1145 * @param array $network_ids Array of network IDs. 1172 1146 */ 1173 1147 function _prime_network_caches( $network_ids ) { 1174 global $wpdb;1175 1176 1148 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1177 1149 if ( !empty( $non_cached_ids ) ) { 1150 $wpdb = WP::get( 'wpdb' ); 1178 1151 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); 1179 1152 1180 1153 update_network_cache( $fresh_networks ); -
src/wp-includes/ms-default-constants.php
14 14 * wp-includes/ms-files.php (wp-content/blogs.php in MU). 15 15 * 16 16 * @since 3.0.0 17 *18 * @global wpdb $wpdb WordPress database abstraction object.19 17 */ 20 18 function ms_upload_constants() { 21 global $wpdb;22 23 19 // This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT. 24 20 add_filter( 'default_site_option_ms_files_rewriting', '__return_true' ); 25 21 … … 33 29 // Note, the main site in a post-MU network uses wp-content/uploads. 34 30 // This is handled in wp_upload_dir() by ignoring UPLOADS for this case. 35 31 if ( ! defined( 'UPLOADS' ) ) { 32 $wpdb = WP::get( 'wpdb' ); 36 33 define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" ); 37 34 38 35 // Uploads dir relative to ABSPATH -
src/wp-includes/ms-deprecated.php
185 185 function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) { 186 186 _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' ); 187 187 188 global $wpdb;188 $wpdb = WP::get( 'wpdb' ); 189 189 $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A ); 190 190 191 191 $blog_list = array(); … … 417 417 * @since MU 1.0 418 418 * @deprecated 4.4.0 419 419 * 420 * @global wpdb $wpdb WordPress database abstraction object.421 *422 420 * @param string $sitedomain Optional. Site domain. 423 421 * @param string $path Optional. Site path. 424 422 * @return array|false The network admins … … 426 424 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { 427 425 _deprecated_function( __FUNCTION__, '4.4.0' ); 428 426 429 global $wpdb;427 $wpdb = WP::get( 'wpdb' ); 430 428 431 429 if ( ! $sitedomain ) 432 430 $site_id = $wpdb->siteid; … … 446 444 * @deprecated 4.6.0 447 445 * @see get_sites() 448 446 * 449 * @global wpdb $wpdb WordPress database abstraction object.450 *451 447 * @param array $args { 452 448 * Array of default arguments. Optional. 453 449 * … … 467 463 * values for whether the site is public, archived, mature, spam, and/or deleted. 468 464 */ 469 465 function wp_get_sites( $args = array() ) { 470 global $wpdb;471 472 466 _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); 473 467 474 468 if ( wp_is_large_network() ) 475 469 return array(); 476 470 471 $wpdb = WP::get( 'wpdb' ); 472 477 473 $defaults = array( 478 474 'network_id' => $wpdb->siteid, 479 475 'public' => null, -
src/wp-includes/ms-functions.php
34 34 * 35 35 * @since MU 1.0 36 36 * 37 * @global wpdb $wpdb WordPress database abstraction object.38 *39 37 * @param int $user_id The unique ID of the user 40 38 * @return WP_Site|void The blog object 41 39 */ 42 40 function get_active_blog_for_user( $user_id ) { 43 global $wpdb;44 41 $blogs = get_blogs_of_user( $user_id ); 45 42 if ( empty( $blogs ) ) 46 43 return; 47 44 45 $wpdb = WP::get( 'wpdb' ); 48 46 if ( !is_multisite() ) 49 47 return $blogs[$wpdb->blogid]; 50 48 … … 194 192 * 195 193 * @since MU 1.0 196 194 * 197 * @global wpdb $wpdb WordPress database abstraction object.198 *199 195 * @param int $user_id ID of the user you're removing. 200 196 * @param int $blog_id ID of the blog you're removing the user from. 201 197 * @param string $reassign Optional. A user to whom to reassign posts. … … 202 198 * @return true|WP_Error 203 199 */ 204 200 function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') { 205 global $wpdb;206 201 switch_to_blog($blog_id); 207 202 $user_id = (int) $user_id; 208 203 /** … … 250 245 } 251 246 252 247 if ( $reassign != '' ) { 248 $wpdb = WP::get( 'wpdb' ); 253 249 $reassign = (int) $reassign; 254 250 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); 255 251 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) ); … … 297 293 * 298 294 * @since MU 2.6.5 299 295 * 300 * @global wpdb $wpdb WordPress database abstraction object.301 *302 296 * @param string $domain 303 297 * @param string $path Optional. Not required for subdomain installations. 304 298 * @return int 0 if no blog found, otherwise the ID of the matching blog … … 401 395 * 402 396 * @since MU 403 397 * 404 * @global wpdb $wpdb WordPress database abstraction object.405 *406 398 * @param string $user_name The login name provided by the user. 407 399 * @param string $user_email The email provided by the user. 408 400 * @return array Contains username, email, and error messages. 409 401 */ 410 402 function wpmu_validate_user_signup($user_name, $user_email) { 411 global $wpdb;412 413 403 $errors = new WP_Error(); 414 404 415 405 $orig_username = $user_name; … … 474 464 if ( email_exists($user_email) ) 475 465 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); 476 466 467 $wpdb = WP::get( 'wpdb' ); 477 468 // Has someone already signed up for this username? 478 469 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) ); 479 470 if ( $signup != null ) { … … 535 526 * 536 527 * @since MU 537 528 * 538 * @global wpdb $wpdb539 529 * @global string $domain 540 530 * 541 531 * @param string $blogname The blog name provided by the user. Must be unique. … … 544 534 * @return array Contains the new site data and error messages. 545 535 */ 546 536 function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { 547 global $ wpdb, $domain;537 global $domain; 548 538 549 539 $current_site = get_current_site(); 550 540 $base = $current_site->path; … … 579 569 if ( strlen( $blogname ) < 4 && !is_super_admin() ) 580 570 $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); 581 571 572 $wpdb = WP::get( 'wpdb' ); 582 573 // do not allow users to create a blog that conflicts with a page on the main blog. 583 574 if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) 584 575 $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); … … 657 648 * 658 649 * @since MU 659 650 * 660 * @global wpdb $wpdb WordPress database abstraction object.661 *662 651 * @param string $domain The requested domain. 663 652 * @param string $path The requested path. 664 653 * @param string $title The requested site title. … … 667 656 * @param array $meta By default, contains the requested privacy setting and lang_id. 668 657 */ 669 658 function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) { 670 global $wpdb;671 672 659 $key = substr( md5( time() . rand() . $domain ), 0, 16 ); 673 660 $meta = serialize($meta); 674 661 662 $wpdb = WP::get( 'wpdb' ); 675 663 $wpdb->insert( $wpdb->signups, array( 676 664 'domain' => $domain, 677 665 'path' => $path, … … 707 695 * 708 696 * @since MU 709 697 * 710 * @global wpdb $wpdb WordPress database abstraction object.711 *712 698 * @param string $user The user's requested login name. 713 699 * @param string $user_email The user's email address. 714 700 * @param array $meta By default, this is an empty array. 715 701 */ 716 702 function wpmu_signup_user( $user, $user_email, $meta = array() ) { 717 global $wpdb;718 719 703 // Format data 720 704 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) ); 721 705 $user_email = sanitize_email( $user_email ); … … 722 706 $key = substr( md5( time() . rand() . $user_email ), 0, 16 ); 723 707 $meta = serialize($meta); 724 708 709 $wpdb = WP::get( 'wpdb' ); 725 710 $wpdb->insert( $wpdb->signups, array( 726 711 'domain' => '', 727 712 'path' => '', … … 947 932 * 948 933 * @since MU 949 934 * 950 * @global wpdb $wpdb WordPress database abstraction object.951 *952 935 * @param string $key The activation key provided to the user. 953 936 * @return array|WP_Error An array containing information about the activated user and/or blog 954 937 */ 955 938 function wpmu_activate_signup($key) { 956 global $wpdb;939 $wpdb = WP::get( 'wpdb' ); 957 940 958 941 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) ); 959 942 … … 1252 1235 * 1253 1236 * @since MU 1254 1237 * 1255 * @global wpdb $wpdb WordPress database abstraction object.1256 *1257 1238 * @param string $domain The domain to be checked. 1258 1239 * @param string $path The path to be checked. 1259 1240 * @param int $site_id Optional. Relevant only on multi-network installs. … … 1291 1272 * 1292 1273 * @since MU 1293 1274 * 1294 * @global wpdb $wpdb WordPress database abstraction object.1295 *1296 1275 * @param string $domain The domain of the new site. 1297 1276 * @param string $path The path of the new site. 1298 1277 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. … … 1299 1278 * @return int|false The ID of the new row 1300 1279 */ 1301 1280 function insert_blog($domain, $path, $site_id) { 1302 global $wpdb;1281 $wpdb = WP::get( 'wpdb' ); 1303 1282 1304 1283 $path = trailingslashit($path); 1305 1284 $site_id = (int) $site_id; … … 1325 1304 * 1326 1305 * @since MU 1327 1306 * 1328 * @global wpdb $wpdb1329 1307 * @global WP_Roles $wp_roles 1330 1308 * 1331 1309 * @param int $blog_id The value returned by insert_blog(). … … 1332 1310 * @param string $blog_title The title of the new site. 1333 1311 */ 1334 1312 function install_blog( $blog_id, $blog_title = '' ) { 1335 global $wp db, $wp_roles, $current_site;1313 global $wp_roles, $current_site; 1336 1314 1315 $wpdb = WP::get( 'wpdb' ); 1316 1337 1317 // Cast for security 1338 1318 $blog_id = (int) $blog_id; 1339 1319 … … 1393 1373 * @deprecated MU 1394 1374 * @deprecated Use wp_install_defaults() 1395 1375 * 1396 * @global wpdb $wpdb WordPress database abstraction object.1397 *1398 1376 * @param int $blog_id Ignored in this function. 1399 1377 * @param int $user_id 1400 1378 */ 1401 1379 function install_blog_defaults($blog_id, $user_id) { 1402 global $wpdb;1380 $wpdb = WP::get( 'wpdb' ); 1403 1381 1404 1382 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 1405 1383 … … 1618 1596 * 1619 1597 * @since MU 1620 1598 * 1621 * @global wpdb $wpdb WordPress database abstraction object.1622 *1623 1599 * @param int $user_id 1624 1600 * @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts 1625 1601 */ 1626 1602 function get_most_recent_post_of_user( $user_id ) { 1627 global $wpdb;1603 $wpdb = WP::get( 'wpdb' ); 1628 1604 1629 1605 $user_blogs = get_blogs_of_user( (int) $user_id ); 1630 1606 $most_recent_post = array(); … … 1765 1741 * 1766 1742 * @since MU 1767 1743 * 1768 * @global wpdb $wpdb WordPress database abstraction object.1769 *1770 1744 * @param string $deprecated Not used. 1771 1745 */ 1772 1746 function update_posts_count( $deprecated = '' ) { 1773 global $wpdb;1747 $wpdb = WP::get( 'wpdb' ); 1774 1748 update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); 1775 1749 } 1776 1750 … … 1779 1753 * 1780 1754 * @since MU 1781 1755 * 1782 * @global wpdb $wpdb WordPress database abstraction object.1783 *1784 1756 * @param int $blog_id 1785 1757 * @param int $user_id 1786 1758 */ 1787 1759 function wpmu_log_new_registrations( $blog_id, $user_id ) { 1788 global $wpdb;1789 1760 $user = get_userdata( (int) $user_id ); 1790 if ( $user ) 1761 if ( $user ) { 1762 $wpdb = WP::get( 'wpdb' ); 1791 1763 $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); 1764 } 1792 1765 } 1793 1766 1794 1767 /** … … 1798 1771 * 1799 1772 * @see term_id_filter 1800 1773 * 1801 * @global wpdb $wpdb WordPress database abstraction object.1802 1774 * @staticvar int $global_terms_recurse 1803 1775 * 1804 1776 * @param int $term_id An ID for a term on the current blog. … … 1806 1778 * @return int An ID from the global terms table mapped from $term_id. 1807 1779 */ 1808 1780 function global_terms( $term_id, $deprecated = '' ) { 1809 global $wpdb;1810 1781 static $global_terms_recurse = null; 1811 1782 1812 1783 if ( !global_terms_enabled() ) … … 1822 1793 } 1823 1794 1824 1795 $term_id = intval( $term_id ); 1796 $wpdb = WP::get( 'wpdb' ); 1825 1797 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); 1826 1798 1827 1799 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); … … 2082 2054 * 2083 2055 * @since MU 2084 2056 * 2085 * @global wpdb $wpdb WordPress database abstraction object.2086 *2087 2057 * @param string $key 2088 2058 * @param int $user_id Optional. Defaults to current user. 2089 2059 * @param int $blog_id Optional. Defaults to current blog. … … 2090 2060 * @return bool 2091 2061 */ 2092 2062 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 2093 global $wpdb; 2094 2063 $wpdb = WP::get( 'wpdb' ); 2095 2064 $current_user = wp_get_current_user(); 2096 2065 if ( $blog_id == 0 ) { 2097 2066 $blog_id = $wpdb->blogid; … … 2257 2226 * Update the network-wide site count. 2258 2227 * 2259 2228 * @since 3.7.0 2260 *2261 * @global wpdb $wpdb WordPress database abstraction object.2262 2229 */ 2263 2230 function wp_update_network_site_counts() { 2264 global $wpdb;2231 $wpdb = WP::get( 'wpdb' ); 2265 2232 2266 2233 $count = get_sites( array( 2267 2234 'network_id' => $wpdb->siteid, … … 2278 2245 * Update the network-wide user count. 2279 2246 * 2280 2247 * @since 3.7.0 2281 *2282 * @global wpdb $wpdb WordPress database abstraction object.2283 2248 */ 2284 2249 function wp_update_network_user_counts() { 2285 global $wpdb;2250 $wpdb = WP::get( 'wpdb' ); 2286 2251 2287 2252 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); 2288 2253 update_site_option( 'user_count', $count ); -
src/wp-includes/ms-load.php
157 157 * 158 158 * @since 3.9.0 159 159 * 160 * @global wpdb $wpdb WordPress database abstraction object.161 *162 160 * @param string $domain Domain to check. 163 161 * @param string $path Path to check. 164 162 * @param int|null $segments Path segments to use. Defaults to null, or the full path. … … 277 275 * @since 4.6.0 278 276 * @access private 279 277 * 280 * @global wpdb $wpdb WordPress database abstraction object.281 278 * @global WP_Network $current_site The current network. 282 279 * @global WP_Site $current_blog The current site. 283 280 * … … 290 287 * Redirect URL if parts exist, but the request as a whole can not be fulfilled. 291 288 */ 292 289 function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) { 293 global $ wpdb, $current_site, $current_blog;290 global $current_site, $current_blog; 294 291 292 $wpdb = WP::get( 'wpdb' ); 293 295 294 // If the network is defined in wp-config.php, we can simply use that. 296 295 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { 297 296 $current_site = new stdClass; … … 454 453 * @since 3.0.0 455 454 * @since 4.4.0 The `$domain` and `$path` parameters were added. 456 455 * 457 * @global wpdb $wpdb WordPress database abstraction object.458 *459 456 * @param string $domain The requested domain for the error to reference. 460 457 * @param string $path The requested path for the error to reference. 461 458 */ 462 459 function ms_not_installed( $domain, $path ) { 463 global $wpdb;464 465 460 if ( ! is_admin() ) { 466 461 dead_db(); 467 462 } … … 473 468 $msg = '<h1>' . $title . '</h1>'; 474 469 $msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . ''; 475 470 $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>'; 471 472 $wpdb = WP::get( 'wpdb' ); 476 473 $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) ); 477 474 if ( ! $wpdb->get_var( $query ) ) { 478 475 $msg .= '<p>' . sprintf( -
src/wp-includes/ms-settings.php
85 85 wp_load_core_site_options( $site_id ); 86 86 } 87 87 88 $wpdb = WP::get( 'wpdb' ); 89 88 90 $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php 89 91 $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id ); 90 92 $table_prefix = $wpdb->get_blog_prefix(); -
src/wp-includes/option.php
21 21 * 22 22 * @since 1.5.0 23 23 * 24 * @global wpdb $wpdb WordPress database abstraction object.25 *26 24 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. 27 25 * @param mixed $default Optional. Default value to return if the option does not exist. 28 26 * @return mixed Value set for the option. 29 27 */ 30 28 function get_option( $option, $default = false ) { 31 global $wpdb;32 33 29 $option = trim( $option ); 34 30 if ( empty( $option ) ) 35 31 return false; … … 83 79 $value = wp_cache_get( $option, 'options' ); 84 80 85 81 if ( false === $value ) { 82 $wpdb = WP::get( 'wpdb' ); 86 83 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); 87 84 88 85 // Has to be get_row instead of get_var because of funkiness with 0, false, null values … … 102 99 } 103 100 } 104 101 } else { 102 $wpdb = WP::get( 'wpdb' ); 105 103 $suppress = $wpdb->suppress_errors(); 106 104 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); 107 105 $wpdb->suppress_errors( $suppress ); … … 167 165 * 168 166 * @since 2.2.0 169 167 * 170 * @global wpdb $wpdb WordPress database abstraction object.171 *172 168 * @return array List of all options. 173 169 */ 174 170 function wp_load_alloptions() { 175 global $wpdb;176 177 171 if ( ! wp_installing() || ! is_multisite() ) 178 172 $alloptions = wp_cache_get( 'alloptions', 'options' ); 179 173 else … … 180 174 $alloptions = false; 181 175 182 176 if ( !$alloptions ) { 177 $wpdb = WP::get( 'wpdb' ); 183 178 $suppress = $wpdb->suppress_errors(); 184 179 if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) 185 180 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); … … 200 195 * 201 196 * @since 3.0.0 202 197 * 203 * @global wpdb $wpdb WordPress database abstraction object.204 *205 198 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site. 206 199 */ 207 200 function wp_load_core_site_options( $site_id = null ) { 208 global $wpdb;209 210 201 if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) 211 202 return; 212 203 204 $wpdb = WP::get( 'wpdb' ); 213 205 if ( empty($site_id) ) 214 206 $site_id = $wpdb->siteid; 215 207 … … 240 232 * @since 1.0.0 241 233 * @since 4.2.0 The `$autoload` parameter was added. 242 234 * 243 * @global wpdb $wpdb WordPress database abstraction object.244 *245 235 * @param string $option Option name. Expected to not be SQL-escaped. 246 236 * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 247 237 * @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, … … 251 241 * @return bool False if value was not updated and true if value was updated. 252 242 */ 253 243 function update_option( $option, $value, $autoload = null ) { 254 global $wpdb;255 256 244 $option = trim($option); 257 245 if ( empty($option) ) 258 246 return false; … … 325 313 $update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; 326 314 } 327 315 316 $wpdb = WP::get( 'wpdb' ); 328 317 $result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) ); 329 318 if ( ! $result ) 330 319 return false; … … 386 375 * 387 376 * @since 1.0.0 388 377 * 389 * @global wpdb $wpdb WordPress database abstraction object.390 *391 378 * @param string $option Name of option to add. Expected to not be SQL-escaped. 392 379 * @param mixed $value Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. 393 380 * @param string $deprecated Optional. Description. Not used anymore. … … 396 383 * @return bool False if option was not added and true if option was added. 397 384 */ 398 385 function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { 399 global $wpdb;400 401 386 if ( !empty( $deprecated ) ) 402 387 _deprecated_argument( __FUNCTION__, '2.3.0' ); 403 388 … … 432 417 */ 433 418 do_action( 'add_option', $option, $value ); 434 419 420 $wpdb = WP::get( 'wpdb' ); 435 421 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); 436 422 if ( ! $result ) 437 423 return false; … … 483 469 * 484 470 * @since 1.2.0 485 471 * 486 * @global wpdb $wpdb WordPress database abstraction object.487 *488 472 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 489 473 * @return bool True, if option is successfully deleted. False on failure. 490 474 */ 491 475 function delete_option( $option ) { 492 global $wpdb;493 494 476 $option = trim( $option ); 495 477 if ( empty( $option ) ) 496 478 return false; … … 497 479 498 480 wp_protect_special_option( $option ); 499 481 482 $wpdb = WP::get( 'wpdb' ); 500 483 // Get the ID, if no ID then return 501 484 $row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ); 502 485 if ( is_null( $row ) ) … … 1069 1052 * 1070 1053 * @see get_option() 1071 1054 * 1072 * @global wpdb $wpdb1073 1055 * @global object $current_site 1074 1056 * 1075 1057 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1078 1060 * @return mixed Value set for the option. 1079 1061 */ 1080 1062 function get_network_option( $network_id, $option, $default = false ) { 1081 global $ wpdb, $current_site;1063 global $current_site; 1082 1064 1083 1065 if ( $network_id && ! is_numeric( $network_id ) ) { 1084 1066 return false; … … 1142 1124 $value = wp_cache_get( $cache_key, 'site-options' ); 1143 1125 1144 1126 if ( ! isset( $value ) || false === $value ) { 1127 $wpdb = WP::get( 'wpdb' ); 1145 1128 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1146 1129 1147 1130 // Has to be get_row instead of get_var because of funkiness with 0, false, null values … … 1186 1169 * 1187 1170 * @see add_option() 1188 1171 * 1189 * @global wpdb $wpdb1190 1172 * @global object $current_site 1191 1173 * 1192 1174 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1195 1177 * @return bool False if option was not added and true if option was added. 1196 1178 */ 1197 1179 function add_network_option( $network_id, $option, $value ) { 1198 global $ wpdb, $current_site;1180 global $current_site; 1199 1181 1200 1182 if ( $network_id && ! is_numeric( $network_id ) ) { 1201 1183 return false; … … 1242 1224 $value = sanitize_option( $option, $value ); 1243 1225 1244 1226 $serialized_value = maybe_serialize( $value ); 1227 $wpdb = WP::get( 'wpdb' ); 1245 1228 $result = $wpdb->insert( $wpdb->sitemeta, array( 'site_id' => $network_id, 'meta_key' => $option, 'meta_value' => $serialized_value ) ); 1246 1229 1247 1230 if ( ! $result ) { … … 1296 1279 * 1297 1280 * @see delete_option() 1298 1281 * 1299 * @global wpdb $wpdb1300 1282 * @global object $current_site 1301 1283 * 1302 1284 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1304 1286 * @return bool True, if succeed. False, if failure. 1305 1287 */ 1306 1288 function delete_network_option( $network_id, $option ) { 1307 global $ wpdb, $current_site;1289 global $current_site; 1308 1290 1309 1291 if ( $network_id && ! is_numeric( $network_id ) ) { 1310 1292 return false; … … 1332 1314 if ( ! is_multisite() ) { 1333 1315 $result = delete_option( $option ); 1334 1316 } else { 1317 $wpdb = WP::get( 'wpdb' ); 1335 1318 $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 1336 1319 if ( is_null( $row ) || ! $row->meta_id ) { 1337 1320 return false; … … 1378 1361 * 1379 1362 * @see update_option() 1380 1363 * 1381 * @global wpdb $wpdb1382 1364 * @global object $current_site 1383 1365 * 1384 1366 * @param int $network_id ID of the network. Can be null to default to the current network ID. … … 1387 1369 * @return bool False if value was not updated and true if value was updated. 1388 1370 */ 1389 1371 function update_network_option( $network_id, $option, $value ) { 1390 global $ wpdb, $current_site;1372 global $current_site; 1391 1373 1392 1374 if ( $network_id && ! is_numeric( $network_id ) ) { 1393 1375 return false; … … 1440 1422 $value = sanitize_option( $option, $value ); 1441 1423 1442 1424 $serialized_value = maybe_serialize( $value ); 1425 $wpdb = WP::get( 'wpdb' ); 1443 1426 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $network_id, 'meta_key' => $option ) ); 1444 1427 1445 1428 if ( $result ) { -
src/wp-includes/pluggable.php
114 114 * 115 115 * @since 3.0.0 116 116 * 117 * @global wpdb $wpdb WordPress database abstraction object.118 *119 117 * @param array $user_ids User ID numbers list 120 118 */ 121 119 function cache_users( $user_ids ) { 122 global $wpdb;123 124 120 $clean = _get_non_cached_ids( $user_ids, 'users' ); 125 121 126 122 if ( empty( $clean ) ) … … 128 124 129 125 $list = implode( ',', $clean ); 130 126 127 $wpdb = WP::get( 'wpdb' ); 131 128 $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); 132 129 133 130 $ids = array(); … … 1528 1525 * 1529 1526 * @since 1.0.0 1530 1527 * 1531 * @global wpdb $wpdb WordPress database abstraction object.1532 *1533 1528 * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator 1534 1529 * should be notified, overriding the site setting. 1535 1530 * … … 1537 1532 * @return true Always returns true. 1538 1533 */ 1539 1534 function wp_notify_moderator($comment_id) { 1540 global $wpdb;1541 1542 1535 $maybe_notify = get_option( 'moderation_notify' ); 1543 1536 1544 1537 /** … … 1566 1559 } 1567 1560 1568 1561 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 1562 $wpdb = WP::get( 'wpdb' ); 1569 1563 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 1570 1564 1571 1565 // The blogname option is escaped with esc_html on the way into the database in sanitize_option … … 1698 1692 * @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter. 1699 1693 * @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created. 1700 1694 * 1701 * @global wpdb $wpdb WordPress database object for queries.1702 1695 * @global PasswordHash $wp_hasher Portable PHP password hashing framework instance. 1703 1696 * 1704 1697 * @param int $user_id User ID. … … 1711 1704 _deprecated_argument( __FUNCTION__, '4.3.1' ); 1712 1705 } 1713 1706 1714 global $wp db, $wp_hasher;1707 global $wp_hasher; 1715 1708 $user = get_userdata( $user_id ); 1716 1709 1717 1710 // The blogname option is escaped with esc_html on the way into the database in sanitize_option … … 1743 1736 $wp_hasher = new PasswordHash( 8, true ); 1744 1737 } 1745 1738 $hashed = time() . ':' . $wp_hasher->HashPassword( $key ); 1739 $wpdb = WP::get( 'wpdb' ); 1746 1740 $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); 1747 1741 1748 1742 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n"; … … 2213 2207 * 2214 2208 * @since 2.5.0 2215 2209 * 2216 * @global wpdb $wpdb WordPress database abstraction object.2217 *2218 2210 * @param string $password The plaintext new user password 2219 2211 * @param int $user_id User ID 2220 2212 */ 2221 2213 function wp_set_password( $password, $user_id ) { 2222 global $wpdb;2214 $wpdb = WP::get( 'wpdb' ); 2223 2215 2224 2216 $hash = wp_hash_password( $password ); 2225 2217 $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) ); -
src/wp-includes/post.php
1498 1498 * 1499 1499 * @since 2.5.0 1500 1500 * 1501 * @global wpdb $wpdb WordPress database abstraction object.1502 *1503 1501 * @param int $post_id Optional. Post ID to change post type. Default 0. 1504 1502 * @param string $post_type Optional. Post type. Accepts 'post' or 'page' to 1505 1503 * name a few. Default 'post'. … … 1506 1504 * @return int|false Amount of rows changed. Should be 1 for success and 0 for failure. 1507 1505 */ 1508 1506 function set_post_type( $post_id = 0, $post_type = 'post' ) { 1509 global $wpdb;1507 $wpdb = WP::get( 'wpdb' ); 1510 1508 1511 1509 $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db'); 1512 1510 $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) ); … … 2085 2083 * 2086 2084 * @since 2.5.0 2087 2085 * 2088 * @global wpdb $wpdb WordPress database abstraction object.2089 *2090 2086 * @param string $type Optional. Post type to retrieve count. Default 'post'. 2091 2087 * @param string $perm Optional. 'readable' or empty. Default empty. 2092 2088 * @return object Number of posts for each status. 2093 2089 */ 2094 2090 function wp_count_posts( $type = 'post', $perm = '' ) { 2095 global $wpdb;2096 2097 2091 if ( ! post_type_exists( $type ) ) 2098 2092 return new stdClass; 2099 2093 … … 2105 2099 return apply_filters( 'wp_count_posts', $counts, $type, $perm ); 2106 2100 } 2107 2101 2102 $wpdb = WP::get( 'wpdb' ); 2108 2103 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2109 2104 if ( 'readable' == $perm && is_user_logged_in() ) { 2110 2105 $post_type_object = get_post_type_object($type); … … 2150 2145 * 2151 2146 * @since 2.5.0 2152 2147 * 2153 * @global wpdb $wpdb WordPress database abstraction object.2154 *2155 2148 * @param string|array $mime_type Optional. Array or comma-separated list of 2156 2149 * MIME patterns. Default empty. 2157 2150 * @return object An object containing the attachment counts by mime type. 2158 2151 */ 2159 2152 function wp_count_attachments( $mime_type = '' ) { 2160 global $wpdb;2153 $wpdb = WP::get( 'wpdb' ); 2161 2154 2162 2155 $and = wp_post_mime_type_where( $mime_type ); 2163 2156 $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); … … 2319 2312 * 2320 2313 * @since 1.0.0 2321 2314 * 2322 * @global wpdb $wpdb WordPress database abstraction object.2323 2315 * @see wp_delete_attachment() 2324 2316 * @see wp_trash_post() 2325 2317 * … … 2329 2321 * @return array|false|WP_Post False on failure. 2330 2322 */ 2331 2323 function wp_delete_post( $postid = 0, $force_delete = false ) { 2332 global $wpdb;2324 $wpdb = WP::get( 'wpdb' );; 2333 2325 2334 2326 if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) 2335 2327 return $post; … … 2582 2574 * 2583 2575 * @since 2.9.0 2584 2576 * 2585 * @global wpdb $wpdb WordPress database abstraction object.2586 *2587 2577 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 2588 2578 * @return mixed|void False on failure. 2589 2579 */ 2590 2580 function wp_trash_post_comments( $post = null ) { 2591 global $wpdb;2592 2593 2581 $post = get_post($post); 2594 2582 if ( empty($post) ) 2595 2583 return; … … 2605 2593 */ 2606 2594 do_action( 'trash_post_comments', $post_id ); 2607 2595 2596 $wpdb = WP::get( 'wpdb' ); 2608 2597 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) ); 2609 2598 if ( empty($comments) ) 2610 2599 return; … … 2638 2627 * 2639 2628 * @since 2.9.0 2640 2629 * 2641 * @global wpdb $wpdb WordPress database abstraction object.2642 *2643 2630 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 2644 2631 * @return true|void 2645 2632 */ 2646 2633 function wp_untrash_post_comments( $post = null ) { 2647 global $wpdb;2648 2649 2634 $post = get_post($post); 2650 2635 if ( empty($post) ) 2651 2636 return; … … 2671 2656 foreach ( $statuses as $comment_id => $comment_status ) 2672 2657 $group_by_status[$comment_status][] = $comment_id; 2673 2658 2659 $wpdb = WP::get( 'wpdb' ); 2674 2660 foreach ( $group_by_status as $status => $comments ) { 2675 2661 // Sanity check. This shouldn't happen. 2676 2662 if ( 'post-trashed' == $status ) { … … 2824 2810 * @since 4.4.0 A 'meta_input' array can now be passed to `$postarr` to add post meta data. 2825 2811 * 2826 2812 * @see sanitize_post() 2827 * @global wpdb $wpdb WordPress database abstraction object.2828 2813 * 2829 2814 * @param array $postarr { 2830 2815 * An array of elements that make up a post to update or insert. … … 2870 2855 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 2871 2856 */ 2872 2857 function wp_insert_post( $postarr, $wp_error = false ) { 2873 global $wpdb;2874 2875 2858 $user_id = get_current_user_id(); 2876 2859 2877 2860 $defaults = array( … … 3154 3137 3155 3138 $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' ); 3156 3139 3140 $wpdb = WP::get( 'wpdb' ); 3157 3141 foreach ( $emoji_fields as $emoji_field ) { 3158 3142 if ( isset( $data[ $emoji_field ] ) ) { 3159 3143 $charset = $wpdb->get_col_charset( $wpdb->posts, $emoji_field ); … … 3487 3471 * 3488 3472 * @since 2.1.0 3489 3473 * 3490 * @global wpdb $wpdb WordPress database abstraction object.3491 *3492 3474 * @param int|WP_Post $post Post ID or post object. 3493 3475 */ 3494 3476 function wp_publish_post( $post ) { 3495 global $wpdb;3496 3497 3477 if ( ! $post = get_post( $post ) ) 3498 3478 return; 3499 3479 … … 3500 3480 if ( 'publish' == $post->post_status ) 3501 3481 return; 3502 3482 3483 $wpdb = WP::get( 'wpdb' ); 3503 3484 $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); 3504 3485 3505 3486 clean_post_cache( $post->ID );