Make WordPress Core


Ignore:
Timestamp:
10/10/2016 06:37:02 AM (10 years ago)
Author:
pento
Message:

General: Restore usage of $wpdb, instead of $this->db.

Hiding the $wpdb global behind a property decreases the readability of the code, as well as causing irrelevant output when dumping an object.

Reverts [38275], [38278], [38279], [38280], [38387].
See #37699.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r38586 r38768  
    486486
    487487        private $compat_methods = array( 'init_query_flags', 'parse_tax_query' );
    488 
    489         /**
    490          * @since 4.7.0
    491          * @access protected
    492          * @var wpdb
    493          */
    494         protected $db;
    495488
    496489        /**
    … …  
    12981291         */
    12991292        protected function parse_search( &$q ) {
     1293                global $wpdb;
     1294
    13001295                $search = '';
    13011296
    … …  
    13371332
    13381333                        if ( $n && $include ) {
    1339                                 $like = '%' . $this->db->esc_like( $term ) . '%';
    1340                                 $q['search_orderby_title'][] = $this->db->prepare( "{$this->db->posts}.post_title LIKE %s", $like );
    1341                         }
    1342 
    1343                         $like = $n . $this->db->esc_like( $term ) . $n;
    1344                         $search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like );
     1334                                $like = '%' . $wpdb->esc_like( $term ) . '%';
     1335                                $q['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like );
     1336                        }
     1337
     1338                        $like = $n . $wpdb->esc_like( $term ) . $n;
     1339                        $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like );
    13451340                        $searchand = ' AND ';
    13461341                }
    … …  
    13491344                        $search = " AND ({$search}) ";
    13501345                        if ( ! is_user_logged_in() ) {
    1351                                 $search .= " AND ({$this->db->posts}.post_password = '') ";
     1346                                $search .= " AND ({$wpdb->posts}.post_password = '') ";
    13521347                        }
    13531348                }
    … …  
    14371432         */
    14381433        protected function parse_search_order( &$q ) {
     1434                global $wpdb;
     1435
    14391436                if ( $q['search_terms_count'] > 1 ) {
    14401437                        $num_terms = count( $q['search_orderby_title'] );
    … …  
    14431440                        $like = '';
    14441441                        if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) {
    1445                                 $like = '%' . $this->db->esc_like( $q['s'] ) . '%';
     1442                                $like = '%' . $wpdb->esc_like( $q['s'] ) . '%';
    14461443                        }
    14471444
    … …  
    14501447                        // sentence match in 'post_title'
    14511448                        if ( $like ) {
    1452                                 $search_orderby .= $this->db->prepare( "WHEN {$this->db->posts}.post_title LIKE %s THEN 1 ", $like );
     1449                                $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like );
    14531450                        }
    14541451
    … …  
    14651462                        // Sentence match in 'post_content' and 'post_excerpt'.
    14661463                        if ( $like ) {
    1467                                 $search_orderby .= $this->db->prepare( "WHEN {$this->db->posts}.post_excerpt LIKE %s THEN 4 ", $like );
    1468                                 $search_orderby .= $this->db->prepare( "WHEN {$this->db->posts}.post_content LIKE %s THEN 5 ", $like );
     1464                                $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_excerpt LIKE %s THEN 4 ", $like );
     1465                                $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_content LIKE %s THEN 5 ", $like );
    14691466                        }
    14701467
    … …  
    14911488         */
    14921489        protected function parse_orderby( $orderby ) {
     1490                global $wpdb;
     1491
    14931492                // Used to filter values.
    14941493                $allowed_keys = array(
    … …  
    15371536                        case 'menu_order':
    15381537                        case 'comment_count':
    1539                                 $orderby_clause = "{$this->db->posts}.{$orderby}";
     1538                                $orderby_clause = "{$wpdb->posts}.{$orderby}";
    15401539                                break;
    15411540                        case 'rand':
    … …  
    15621561                                } else {
    15631562                                        // Default: order by post field.
    1564                                         $orderby_clause = "{$this->db->posts}.post_" . sanitize_key( $orderby );
     1563                                        $orderby_clause = "{$wpdb->posts}.post_" . sanitize_key( $orderby );
    15651564                                }
    15661565
    … …  
    16521651         */
    16531652        public function get_posts() {
     1653                global $wpdb;
     1654
    16541655                $this->parse_query();
    16551656
    … …  
    17871788                switch ( $q['fields'] ) {
    17881789                        case 'ids':
    1789                                 $fields = "{$this->db->posts}.ID";
     1790                                $fields = "{$wpdb->posts}.ID";
    17901791                                break;
    17911792                        case 'id=>parent':
    1792                                 $fields = "{$this->db->posts}.ID, {$this->db->posts}.post_parent";
     1793                                $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent";
    17931794                                break;
    17941795                        default:
    1795                                 $fields = "{$this->db->posts}.*";
     1796                                $fields = "{$wpdb->posts}.*";
    17961797                }
    17971798
    17981799                if ( '' !== $q['menu_order'] ) {
    1799                         $where .= " AND {$this->db->posts}.menu_order = " . $q['menu_order'];
     1800                        $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order'];
    18001801                }
    18011802                // The "m" parameter is meant for months but accepts datetimes of varying specificity
    18021803                if ( $q['m'] ) {
    1803                         $where .= " AND YEAR({$this->db->posts}.post_date)=" . substr($q['m'], 0, 4);
     1804                        $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr($q['m'], 0, 4);
    18041805                        if ( strlen($q['m']) > 5 ) {
    1805                                 $where .= " AND MONTH({$this->db->posts}.post_date)=" . substr($q['m'], 4, 2);
     1806                                $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 4, 2);
    18061807                        }
    18071808                        if ( strlen($q['m']) > 7 ) {
    1808                                 $where .= " AND DAYOFMONTH({$this->db->posts}.post_date)=" . substr($q['m'], 6, 2);
     1809                                $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr($q['m'], 6, 2);
    18091810                        }
    18101811                        if ( strlen($q['m']) > 9 ) {
    1811                                 $where .= " AND HOUR({$this->db->posts}.post_date)=" . substr($q['m'], 8, 2);
     1812                                $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr($q['m'], 8, 2);
    18121813                        }
    18131814                        if ( strlen($q['m']) > 11 ) {
    1814                                 $where .= " AND MINUTE({$this->db->posts}.post_date)=" . substr($q['m'], 10, 2);
     1815                                $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr($q['m'], 10, 2);
    18151816                        }
    18161817                        if ( strlen($q['m']) > 13 ) {
    1817                                 $where .= " AND SECOND({$this->db->posts}.post_date)=" . substr($q['m'], 12, 2);
     1818                                $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr($q['m'], 12, 2);
    18181819                        }
    18191820                }
    … …  
    18791880
    18801881                if ( '' !== $q['title'] ) {
    1881                         $where .= $this->db->prepare( " AND {$this->db->posts}.post_title = %s", stripslashes( $q['title'] ) );
     1882                        $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q['title'] ) );
    18821883                }
    18831884
    … …  
    18851886                if ( '' != $q['name'] ) {
    18861887                        $q['name'] = sanitize_title_for_query( $q['name'] );
    1887                         $where .= " AND {$this->db->posts}.post_name = '" . $q['name'] . "'";
     1888                        $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";
    18881889                } elseif ( '' != $q['pagename'] ) {
    18891890                        if ( isset($this->queried_object_id) ) {
    … …  
    19141915                                $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) );
    19151916                                $q['name'] = $q['pagename'];
    1916                                 $where .= " AND ({$this->db->posts}.ID = '$reqpage')";
     1917                                $where .= " AND ({$wpdb->posts}.ID = '$reqpage')";
    19171918                                $reqpage_obj = get_post( $reqpage );
    19181919                                if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) {
    … …  
    19261927                        $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) );
    19271928                        $q['name'] = $q['attachment'];
    1928                         $where .= " AND {$this->db->posts}.post_name = '" . $q['attachment'] . "'";
     1929                        $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'";
    19291930                } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) {
    19301931                        $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] );
    19311932                        $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'";
    1932                         $where .= " AND {$this->db->posts}.post_name IN ($post_name__in)";
     1933                        $where .= " AND {$wpdb->posts}.post_name IN ($post_name__in)";
    19331934                }
    19341935
    … …  
    19391940                // If a post number is specified, load that post
    19401941                if ( $q['p'] ) {
    1941                         $where .= " AND {$this->db->posts}.ID = " . $q['p'];
     1942                        $where .= " AND {$wpdb->posts}.ID = " . $q['p'];
    19421943                } elseif ( $q['post__in'] ) {
    19431944                        $post__in = implode(',', array_map( 'absint', $q['post__in'] ));
    1944                         $where .= " AND {$this->db->posts}.ID IN ($post__in)";
     1945                        $where .= " AND {$wpdb->posts}.ID IN ($post__in)";
    19451946                } elseif ( $q['post__not_in'] ) {
    19461947                        $post__not_in = implode(',',  array_map( 'absint', $q['post__not_in'] ));
    1947                         $where .= " AND {$this->db->posts}.ID NOT IN ($post__not_in)";
     1948                        $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
    19481949                }
    19491950
    19501951                if ( is_numeric( $q['post_parent'] ) ) {
    1951                         $where .= $this->db->prepare( " AND {$this->db->posts}.post_parent = %d ", $q['post_parent'] );
     1952                        $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $q['post_parent'] );
    19521953                } elseif ( $q['post_parent__in'] ) {
    19531954                        $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) );
    1954                         $where .= " AND {$this->db->posts}.post_parent IN ($post_parent__in)";
     1955                        $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)";
    19551956                } elseif ( $q['post_parent__not_in'] ) {
    19561957                        $post_parent__not_in = implode( ',',  array_map( 'absint', $q['post_parent__not_in'] ) );
    1957                         $where .= " AND {$this->db->posts}.post_parent NOT IN ($post_parent__not_in)";
     1958                        $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)";
    19581959                }
    19591960
    … …  
    19611962                        if  ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) {
    19621963                                $q['p'] = $q['page_id'];
    1963                                 $where = " AND {$this->db->posts}.ID = " . $q['page_id'];
     1964                                $where = " AND {$wpdb->posts}.ID = " . $q['page_id'];
    19641965                        }
    19651966                }
    … …  
    19861987                        $this->parse_tax_query( $q );
    19871988
    1988                         $clauses = $this->tax_query->get_sql( $this->db->posts, 'ID' );
     1989                        $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' );
    19891990
    19901991                        $join .= $clauses['join'];
    … …  
    20702071
    20712072                if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
    2072                         $groupby = "{$this->db->posts}.ID";
     2073                        $groupby = "{$wpdb->posts}.ID";
    20732074                }
    20742075
    … …  
    20872088                if ( ! empty( $q['author__not_in'] ) ) {
    20882089                        $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) );
    2089                         $where .= " AND {$this->db->posts}.post_author NOT IN ($author__not_in) ";
     2090                        $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) ";
    20902091                } elseif ( ! empty( $q['author__in'] ) ) {
    20912092                        $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) );
    2092                         $where .= " AND {$this->db->posts}.post_author IN ($author__in) ";
     2093                        $where .= " AND {$wpdb->posts}.post_author IN ($author__in) ";
    20932094                }
    20942095
    … …  
    21082109                        if ( $q['author'] )
    21092110                                $q['author'] = $q['author']->ID;
    2110                         $whichauthor .= " AND ({$this->db->posts}.post_author = " . absint($q['author']) . ')';
     2111                        $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint($q['author']) . ')';
    21112112                }
    21122113
    … …  
    21142115
    21152116                if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) {
    2116                         $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $this->db->posts );
     2117                        $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts );
    21172118                }
    21182119                $where .= $search . $whichauthor . $whichmimetype;
    21192120
    21202121                if ( ! empty( $this->meta_query->queries ) ) {
    2121                         $clauses = $this->meta_query->get_sql( 'post', $this->db->posts, 'ID', $this );
     2122                        $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    21222123                        $join   .= $clauses['join'];
    21232124                        $where  .= $clauses['where'];
    … …  
    21402141                                $orderby = '';
    21412142                        } else {
    2142                                 $orderby = "{$this->db->posts}.post_date " . $q['order'];
     2143                                $orderby = "{$wpdb->posts}.post_date " . $q['order'];
    21432144                        }
    21442145                } elseif ( 'none' == $q['orderby'] ) {
    21452146                        $orderby = '';
    21462147                } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) {
    2147                         $orderby = "FIELD( {$this->db->posts}.ID, $post__in )";
     2148                        $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )";
    21482149                } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) {
    2149                         $orderby = "FIELD( {$this->db->posts}.post_parent, $post_parent__in )";
     2150                        $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )";
    21502151                } elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) {
    2151                         $orderby = "FIELD( {$this->db->posts}.post_name, $post_name__in )";
     2152                        $orderby = "FIELD( {$wpdb->posts}.post_name, $post_name__in )";
    21522153                } else {
    21532154                        $orderby_array = array();
    … …  
    21812182
    21822183                                if ( empty( $orderby ) ) {
    2183                                         $orderby = "{$this->db->posts}.post_date " . $q['order'];
     2184                                        $orderby = "{$wpdb->posts}.post_date " . $q['order'];
    21842185                                } elseif ( ! empty( $q['order'] ) ) {
    21852186                                        $orderby .= " {$q['order']}";
    … …  
    22212222
    22222223                if ( isset( $q['post_password'] ) ) {
    2223                         $where .= $this->db->prepare( " AND {$this->db->posts}.post_password = %s", $q['post_password'] );
     2224                        $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q['post_password'] );
    22242225                        if ( empty( $q['perm'] ) ) {
    22252226                                $q['perm'] = 'readable';
    22262227                        }
    22272228                } elseif ( isset( $q['has_password'] ) ) {
    2228                         $where .= sprintf( " AND {$this->db->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' );
     2229                        $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' );
    22292230                }
    22302231
    22312232                if ( ! empty( $q['comment_status'] ) ) {
    2232                         $where .= $this->db->prepare( " AND {$this->db->posts}.comment_status = %s ", $q['comment_status'] );
     2233                        $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q['comment_status'] );
    22332234                }
    22342235
    22352236                if ( ! empty( $q['ping_status'] ) )  {
    2236                         $where .= $this->db->prepare( " AND {$this->db->posts}.ping_status = %s ", $q['ping_status'] );
     2237                        $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] );
    22372238                }
    22382239
    … …  
    22422243                                $where .= ' AND 1=0 ';
    22432244                        } else {
    2244                                 $where .= " AND {$this->db->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')";
     2245                                $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", $in_search_post_types ) . "')";
    22452246                        }
    22462247                } elseif ( !empty( $post_type ) && is_array( $post_type ) ) {
    2247                         $where .= " AND {$this->db->posts}.post_type IN ('" . join("', '", $post_type) . "')";
     2248                        $where .= " AND {$wpdb->posts}.post_type IN ('" . join("', '", $post_type) . "')";
    22482249                } elseif ( ! empty( $post_type ) ) {
    2249                         $where .= " AND {$this->db->posts}.post_type = '$post_type'";
     2250                        $where .= " AND {$wpdb->posts}.post_type = '$post_type'";
    22502251                        $post_type_object = get_post_type_object ( $post_type );
    22512252                } elseif ( $this->is_attachment ) {
    2252                         $where .= " AND {$this->db->posts}.post_type = 'attachment'";
     2253                        $where .= " AND {$wpdb->posts}.post_type = 'attachment'";
    22532254                        $post_type_object = get_post_type_object ( 'attachment' );
    22542255                } elseif ( $this->is_page ) {
    2255                         $where .= " AND {$this->db->posts}.post_type = 'page'";
     2256                        $where .= " AND {$wpdb->posts}.post_type = 'page'";
    22562257                        $post_type_object = get_post_type_object ( 'page' );
    22572258                } else {
    2258                         $where .= " AND {$this->db->posts}.post_type = 'post'";
     2259                        $where .= " AND {$wpdb->posts}.post_type = 'post'";
    22592260                        $post_type_object = get_post_type_object ( 'post' );
    22602261                }
    … …  
    22852286                                foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) {
    22862287                                        if ( ! in_array( $status, $q_status ) ) {
    2287                                                 $e_status[] = "{$this->db->posts}.post_status <> '$status'";
     2288                                                $e_status[] = "{$wpdb->posts}.post_status <> '$status'";
    22882289                                        }
    22892290                                }
    … …  
    22922293                                        if ( in_array( $status, $q_status ) ) {
    22932294                                                if ( 'private' == $status ) {
    2294                                                         $p_status[] = "{$this->db->posts}.post_status = '$status'";
     2295                                                        $p_status[] = "{$wpdb->posts}.post_status = '$status'";
    22952296                                                } else {
    2296                                                         $r_status[] = "{$this->db->posts}.post_status = '$status'";
     2297                                                        $r_status[] = "{$wpdb->posts}.post_status = '$status'";
    22972298                                                }
    22982299                                        }
    … …  
    23102311                        if ( !empty($r_status) ) {
    23112312                                if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) {
    2312                                         $statuswheres[] = "({$this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";
     2313                                        $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))";
    23132314                                } else {
    23142315                                        $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
    … …  
    23172318                        if ( !empty($p_status) ) {
    23182319                                if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) {
    2319                                         $statuswheres[] = "({$this->db->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";
     2320                                        $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))";
    23202321                                } else {
    23212322                                        $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
    … …  
    23232324                        }
    23242325                        if ( $post_status_join ) {
    2325                                 $join .= " LEFT JOIN {$this->db->posts} AS p2 ON ({$this->db->posts}.post_parent = p2.ID) ";
     2326                                $join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) ";
    23262327                                foreach ( $statuswheres as $index => $statuswhere ) {
    2327                                         $statuswheres[$index] = "($statuswhere OR ({$this->db->posts}.post_status = 'inherit' AND " . str_replace( $this->db->posts, 'p2', $statuswhere ) . "))";
     2328                                        $statuswheres[$index] = "($statuswhere OR ({$wpdb->posts}.post_status = 'inherit' AND " . str_replace( $wpdb->posts, 'p2', $statuswhere ) . "))";
    23282329                                }
    23292330                        }
    … …  
    23332334                        }
    23342335                } elseif ( !$this->is_singular ) {
    2335                         $where .= " AND ({$this->db->posts}.post_status = 'publish'";
     2336                        $where .= " AND ({$wpdb->posts}.post_status = 'publish'";
    23362337
    23372338                        // Add public states.
    … …  
    23402341                                if ( 'publish' == $state ) // Publish is hard-coded above.
    23412342                                        continue;
    2342                                 $where .= " OR {$this->db->posts}.post_status = '$state'";
     2343                                $where .= " OR {$wpdb->posts}.post_status = '$state'";
    23432344                        }
    23442345
    … …  
    23472348                                $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) );
    23482349                                foreach ( (array) $admin_all_states as $state ) {
    2349                                         $where .= " OR {$this->db->posts}.post_status = '$state'";
     2350                                        $where .= " OR {$wpdb->posts}.post_status = '$state'";
    23502351                                }
    23512352                        }
    … …  
    23552356                                $private_states = get_post_stati( array('private' => true) );
    23562357                                foreach ( (array) $private_states as $state ) {
    2357                                         $where .= current_user_can( $read_private_cap ) ? " OR {$this->db->posts}.post_status = '$state'" : " OR {$this->db->posts}.post_author = $user_id AND {$this->db->posts}.post_status = '$state'";
     2358                                        $where .= current_user_can( $read_private_cap ) ? " OR {$wpdb->posts}.post_status = '$state'" : " OR {$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$state'";
    23582359                                }
    23592360                        }
    … …  
    24072408                if ( $this->is_comment_feed && ! $this->is_singular ) {
    24082409                        if ( $this->is_archive || $this->is_search ) {
    2409                                 $cjoin = "JOIN {$this->db->posts} ON ({$this->db->comments}.comment_post_ID = {$this->db->posts}.ID) $join ";
     2410                                $cjoin = "JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID) $join ";
    24102411                                $cwhere = "WHERE comment_approved = '1' $where";
    2411                                 $cgroupby = "{$this->db->comments}.comment_id";
     2412                                $cgroupby = "{$wpdb->comments}.comment_id";
    24122413                        } else { // Other non singular e.g. front
    2413                                 $cjoin = "JOIN {$this->db->posts} ON ( {$this->db->comments}.comment_post_ID = {$this->db->posts}.ID )";
     2414                                $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )";
    24142415                                $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'";
    24152416                                $cgroupby = '';
    … …  
    24702471                        $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
    24712472
    2472                         $comments = (array) $this->db->get_results("SELECT $distinct {$this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits");
     2473                        $comments = (array) $wpdb->get_results("SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits");
    24732474                        // Convert to WP_Comment
    24742475                        $this->comments = array_map( 'get_comment', $comments );
    … …  
    24832484                        $join = '';
    24842485                        if ( $post_ids ) {
    2485                                 $where = "AND {$this->db->posts}.ID IN ($post_ids) ";
     2486                                $where = "AND {$wpdb->posts}.ID IN ($post_ids) ";
    24862487                        } else {
    24872488                                $where = "AND 0";
    … …  
    27252726                        $found_rows = 'SQL_CALC_FOUND_ROWS';
    27262727
    2727                 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
     2728                $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
    27282729
    27292730                if ( !$q['suppress_filters'] ) {
    … …  
    27592760                if ( 'ids' == $q['fields'] ) {
    27602761                        if ( null === $this->posts ) {
    2761                                 $this->posts = $this->db->get_col( $this->request );
     2762                                $this->posts = $wpdb->get_col( $this->request );
    27622763                        }
    27632764
    … …  
    27712772                if ( 'id=>parent' == $q['fields'] ) {
    27722773                        if ( null === $this->posts ) {
    2773                                 $this->posts = $this->db->get_results( $this->request );
     2774                                $this->posts = $wpdb->get_results( $this->request );
    27742775                        }
    27752776
    … …  
    27892790
    27902791                if ( null === $this->posts ) {
    2791                         $split_the_query = ( $old_request == $this->request && "{$this->db->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
     2792                        $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
    27922793
    27932794                        /**
    … …  
    28082809                                // First get the IDs and then fill in the objects
    28092810
    2810                                 $this->request = "SELECT $found_rows $distinct {$this->db->posts}.ID FROM {$this->db->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
     2811                                $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
    28112812
    28122813                                /**
    … …  
    28202821                                $this->request = apply_filters( 'posts_request_ids', $this->request, $this );
    28212822
    2822                                 $ids = $this->db->get_col( $this->request );
     2823                                $ids = $wpdb->get_col( $this->request );
    28232824
    28242825                                if ( $ids ) {
    … …  
    28302831                                }
    28312832                        } else {
    2832                                 $this->posts = $this->db->get_results( $this->request );
     2833                                $this->posts = $wpdb->get_results( $this->request );
    28332834                                $this->set_found_posts( $q, $limits );
    28342835                        }
    … …  
    28702871                        $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );
    28712872
    2872                         $comments_request = "SELECT {$this->db->comments}.* FROM {$this->db->comments} $cjoin $cwhere $cgroupby $corderby $climits";
    2873                         $comments = $this->db->get_results($comments_request);
     2873                        $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
     2874                        $comments = $wpdb->get_results($comments_request);
    28742875                        // Convert to WP_Comment
    28752876                        $this->comments = array_map( 'get_comment', $comments );
    … …  
    30183019         */
    30193020        private function set_found_posts( $q, $limits ) {
     3021                global $wpdb;
    30203022                // Bail if posts is an empty array. Continue if posts is an empty string,
    30213023                // null, or false to accommodate caching plugins that fill posts later.
    … …  
    30323034                         * @param WP_Query &$this       The WP_Query instance (passed by reference).
    30333035                         */
    3034                         $this->found_posts = $this->db->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     3036                        $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
    30353037                } else {
    30363038                        $this->found_posts = count( $this->posts );
    … …  
    33293331         */
    33303332        public function __construct( $query = '' ) {
    3331                 $this->db = $GLOBALS['wpdb'];
    3332 
    33333333                if ( ! empty( $query ) ) {
    33343334                        $this->query( $query );
Note: See TracChangeset for help on using the changeset viewer.