Make WordPress Core

Changeset 38768


Ignore:
Timestamp:
10/10/2016 06:37:02 AM (8 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.

Location:
trunk
Files:
13 edited

Legend:

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

    r38639 r38768  
    141141        return false;
    142142    }
    143 
    144     /**
    145      * @since 4.7.0
    146      * @access protected
    147      * @var wpdb
    148      */
    149     protected $db;
    150143
    151144    /**
     
    268261     */
    269262    public function __construct( $query = '' ) {
    270         $this->db = $GLOBALS['wpdb'];
    271 
    272263        $this->query_var_defaults = array(
    273264            'author_email' => '',
     
    373364     * @access public
    374365     *
     366     * @global wpdb $wpdb WordPress database abstraction object.
     367     *
    375368     * @return int|array List of comments or number of found comments if `$count` argument is true.
    376369     */
    377370    public function get_comments() {
     371        global $wpdb;
     372
    378373        $this->parse_query();
    379374
     
    394389        $this->meta_query->parse_query_vars( $this->query_vars );
    395390        if ( ! empty( $this->meta_query->queries ) ) {
    396             $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $this->db->comments, 'comment_ID', $this );
     391            $this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
    397392        }
    398393
     
    486481     * @since 4.4.0
    487482     * @access protected
     483     *
     484     * @global wpdb $wpdb WordPress database abstraction object.
    488485     */
    489486    protected function get_comment_ids() {
     487        global $wpdb;
     488
    490489        // Assemble clauses related to 'comment_approved'.
    491490        $approved_clauses = array();
     
    516515
    517516                    default :
    518                         $status_clauses[] = $this->db->prepare( "comment_approved = %s", $status );
     517                        $status_clauses[] = $wpdb->prepare( "comment_approved = %s", $status );
    519518                        break;
    520519                }
     
    539538                // Numeric values are assumed to be user ids.
    540539                if ( is_numeric( $unapproved_identifier ) ) {
    541                     $approved_clauses[] = $this->db->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );
     540                    $approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier );
    542541
    543542                // Otherwise we match against email addresses.
    544543                } else {
    545                     $approved_clauses[] = $this->db->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
     544                    $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier );
    546545                }
    547546            }
     
    602601            // If no valid clauses were found, order by comment_date_gmt.
    603602            if ( empty( $orderby_array ) ) {
    604                 $orderby_array[] = "{$this->db->comments}.comment_date_gmt $order";
     603                $orderby_array[] = "$wpdb->comments.comment_date_gmt $order";
    605604            }
    606605
     
    635634                }
    636635
    637                 $orderby_array[] = "{$this->db->comments}.comment_ID $comment_ID_order";
     636                $orderby_array[] = "$wpdb->comments.comment_ID $comment_ID_order";
    638637            }
    639638
    640639            $orderby = implode( ', ', $orderby_array );
    641640        } else {
    642             $orderby = "{$this->db->comments}.comment_date_gmt $order";
     641            $orderby = "$wpdb->comments.comment_date_gmt $order";
    643642        }
    644643
     
    657656            $fields = 'COUNT(*)';
    658657        } else {
    659             $fields = "{$this->db->comments}.comment_ID";
     658            $fields = "$wpdb->comments.comment_ID";
    660659        }
    661660
    662661        $post_id = absint( $this->query_vars['post_id'] );
    663662        if ( ! empty( $post_id ) ) {
    664             $this->sql_clauses['where']['post_id'] = $this->db->prepare( 'comment_post_ID = %d', $post_id );
     663            $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
    665664        }
    666665
    667666        // Parse comment IDs for an IN clause.
    668667        if ( ! empty( $this->query_vars['comment__in'] ) ) {
    669             $this->sql_clauses['where']['comment__in'] = "{$this->db->comments}.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
     668            $this->sql_clauses['where']['comment__in'] = "$wpdb->comments.comment_ID IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__in'] ) ) . ' )';
    670669        }
    671670
    672671        // Parse comment IDs for a NOT IN clause.
    673672        if ( ! empty( $this->query_vars['comment__not_in'] ) ) {
    674             $this->sql_clauses['where']['comment__not_in'] = "{$this->db->comments}.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
     673            $this->sql_clauses['where']['comment__not_in'] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )';
    675674        }
    676675
     
    696695
    697696        if ( '' !== $this->query_vars['author_email'] ) {
    698             $this->sql_clauses['where']['author_email'] = $this->db->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );
     697            $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] );
    699698        }
    700699
    701700        if ( '' !== $this->query_vars['author_url'] ) {
    702             $this->sql_clauses['where']['author_url'] = $this->db->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );
     701            $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );
    703702        }
    704703
    705704        if ( '' !== $this->query_vars['karma'] ) {
    706             $this->sql_clauses['where']['karma'] = $this->db->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
     705            $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
    707706        }
    708707
     
    735734
    736735                    default:
    737                         $comment_types[ $operator ][] = $this->db->prepare( '%s', $type );
     736                        $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type );
    738737                        break;
    739738                }
     
    752751
    753752        if ( '' !== $parent ) {
    754             $this->sql_clauses['where']['parent'] = $this->db->prepare( 'comment_parent = %d', $parent );
     753            $this->sql_clauses['where']['parent'] = $wpdb->prepare( 'comment_parent = %d', $parent );
    755754        }
    756755
     
    758757            $this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')';
    759758        } elseif ( '' !== $this->query_vars['user_id'] ) {
    760             $this->sql_clauses['where']['user_id'] = $this->db->prepare( 'user_id = %d', $this->query_vars['user_id'] );
     759            $this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );
    761760        }
    762761
     
    782781                // $field_value may be an array.
    783782                $esses = array_fill( 0, count( (array) $field_value ), '%s' );
    784                 $this->sql_clauses['where'][ $field_name ] = $this->db->prepare( " {$this->db->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
     783                $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
    785784            }
    786785        }
     
    803802
    804803                $esses = array_fill( 0, count( $q_values ), '%s' );
    805                 $this->sql_clauses['where'][ $field_name ] = $this->db->prepare( " {$this->db->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values );
     804                $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values );
    806805            }
    807806        }
     
    832831
    833832        if ( $join_posts_table ) {
    834             $join .= "JOIN {$this->db->posts} ON {$this->db->posts}.ID = {$this->db->comments}.comment_post_ID";
     833            $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
    835834        }
    836835
     
    842841
    843842            if ( ! $this->query_vars['count'] ) {
    844                 $groupby = "{$this->db->comments}.comment_ID";
     843                $groupby = "{$wpdb->comments}.comment_ID";
    845844            }
    846845        }
     
    891890
    892891        $this->sql_clauses['select']  = "SELECT $found_rows $fields";
    893         $this->sql_clauses['from']    = "FROM {$this->db->comments} $join";
     892        $this->sql_clauses['from']    = "FROM $wpdb->comments $join";
    894893        $this->sql_clauses['groupby'] = $groupby;
    895894        $this->sql_clauses['orderby'] = $orderby;
     
    899898
    900899        if ( $this->query_vars['count'] ) {
    901             return intval( $this->db->get_var( $this->request ) );
     900            return intval( $wpdb->get_var( $this->request ) );
    902901        } else {
    903             $comment_ids = $this->db->get_col( $this->request );
     902            $comment_ids = $wpdb->get_col( $this->request );
    904903            return array_map( 'intval', $comment_ids );
    905904        }
     
    912911     * @since 4.6.0
    913912     * @access private
     913     *
     914     * @global wpdb $wpdb WordPress database abstraction object.
    914915     */
    915916    private function set_found_comments() {
     917        global $wpdb;
     918
    916919        if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {
    917920            /**
     
    925928            $found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this );
    926929
    927             $this->found_comments = (int) $this->db->get_var( $found_comments_query );
     930            $this->found_comments = (int) $wpdb->get_var( $found_comments_query );
    928931        }
    929932    }
     
    941944     */
    942945    protected function fill_descendants( $comments ) {
     946        global $wpdb;
     947
    943948        $levels = array(
    944949            0 => wp_list_pluck( $comments, 'comment_ID' ),
     
    10711076     * @access protected
    10721077     *
     1078     * @global wpdb $wpdb WordPress database abstraction object.
     1079     *
    10731080     * @param string $string
    10741081     * @param array $cols
     
    10761083     */
    10771084    protected function get_search_sql( $string, $cols ) {
    1078         $like = '%' . $this->db->esc_like( $string ) . '%';
     1085        global $wpdb;
     1086
     1087        $like = '%' . $wpdb->esc_like( $string ) . '%';
    10791088
    10801089        $searches = array();
    10811090        foreach ( $cols as $col ) {
    1082             $searches[] = $this->db->prepare( "$col LIKE %s", $like );
     1091            $searches[] = $wpdb->prepare( "$col LIKE %s", $like );
    10831092        }
    10841093
     
    10921101     * @access protected
    10931102     *
     1103     * @global wpdb $wpdb WordPress database abstraction object.
     1104     *
    10941105     * @param string $orderby Alias for the field to order by.
    10951106     * @return string|false Value to used in the ORDER clause. False otherwise.
    10961107     */
    10971108    protected function parse_orderby( $orderby ) {
     1109        global $wpdb;
     1110
    10981111        $allowed_keys = array(
    10991112            'comment_agent',
     
    11271140        $parsed = false;
    11281141        if ( $orderby == $this->query_vars['meta_key'] || $orderby == 'meta_value' ) {
    1129             $parsed = "{$this->db->commentmeta}.meta_value";
     1142            $parsed = "$wpdb->commentmeta.meta_value";
    11301143        } elseif ( $orderby == 'meta_value_num' ) {
    1131             $parsed = "{$this->db->commentmeta}.meta_value+0";
     1144            $parsed = "$wpdb->commentmeta.meta_value+0";
    11321145        } elseif ( $orderby == 'comment__in' ) {
    11331146            $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) );
    1134             $parsed = "FIELD( {$this->db->comments}.comment_ID, $comment__in )";
     1147            $parsed = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )";
    11351148        } elseif ( in_array( $orderby, $allowed_keys ) ) {
    11361149
     
    11391152                $parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );
    11401153            } else {
    1141                 $parsed = "{$this->db->comments}.$orderby";
     1154                $parsed = "$wpdb->comments.$orderby";
    11421155            }
    11431156        }
  • trunk/src/wp-includes/class-wp-meta-query.php

    r38275 r38768  
    107107
    108108    /**
    109      * @since 4.7.0
    110      * @access protected
    111      * @var wpdb
    112      */
    113     protected $db;
    114 
    115     /**
    116109     * Constructor.
    117110     *
     
    145138     */
    146139    public function __construct( $meta_query = false ) {
    147         $this->db = $GLOBALS['wpdb'];
    148 
    149         if ( ! $meta_query ) {
     140        if ( !$meta_query )
    150141            return;
    151         }
    152142
    153143        if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) {
     
    495485     * @access public
    496486     *
     487     * @global wpdb $wpdb WordPress database abstraction object.
     488     *
    497489     * @param array  $clause       Query clause, passed by reference.
    498490     * @param array  $parent_query Parent query array.
     
    507499     */
    508500    public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) {
     501        global $wpdb;
     502
    509503        $sql_chunks = array(
    510504            'where' => array(),
     
    544538                $join .= " LEFT JOIN $this->meta_table";
    545539                $join .= $i ? " AS $alias" : '';
    546                 $join .= $this->db->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] );
     540                $join .= $wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] );
    547541
    548542            // All other JOIN clauses.
     
    588582                $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL';
    589583            } else {
    590                 $sql_chunks['where'][] = $this->db->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );
     584                $sql_chunks['where'][] = $wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );
    591585            }
    592586        }
     
    608602                case 'NOT IN' :
    609603                    $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';
    610                     $where = $this->db->prepare( $meta_compare_string, $meta_value );
     604                    $where = $wpdb->prepare( $meta_compare_string, $meta_value );
    611605                    break;
    612606
     
    614608                case 'NOT BETWEEN' :
    615609                    $meta_value = array_slice( $meta_value, 0, 2 );
    616                     $where = $this->db->prepare( '%s AND %s', $meta_value );
     610                    $where = $wpdb->prepare( '%s AND %s', $meta_value );
    617611                    break;
    618612
    619613                case 'LIKE' :
    620614                case 'NOT LIKE' :
    621                     $meta_value = '%' . $this->db->esc_like( $meta_value ) . '%';
    622                     $where = $this->db->prepare( '%s', $meta_value );
     615                    $meta_value = '%' . $wpdb->esc_like( $meta_value ) . '%';
     616                    $where = $wpdb->prepare( '%s', $meta_value );
    623617                    break;
    624618
     
    626620                case 'EXISTS' :
    627621                    $meta_compare = '=';
    628                     $where = $this->db->prepare( '%s', $meta_value );
     622                    $where = $wpdb->prepare( '%s', $meta_value );
    629623                    break;
    630624
     
    635629
    636630                default :
    637                     $where = $this->db->prepare( '%s', $meta_value );
     631                    $where = $wpdb->prepare( '%s', $meta_value );
    638632                    break;
    639633
  • trunk/src/wp-includes/class-wp-network-query.php

    r38595 r38768  
    8686     */
    8787    public $max_num_pages = 0;
    88 
    89     /**
    90      * @since 4.7.0
    91      * @access protected
    92      * @var wpdb
    93      */
    94     protected $db;
    9588
    9689    /**
     
    130123     */
    131124    public function __construct( $query = '' ) {
    132         $this->db = $GLOBALS['wpdb'];
    133 
    134125        $this->query_var_defaults = array(
    135126            'network__in'          => '',
     
    298289     */
    299290    protected function get_network_ids() {
     291        global $wpdb;
     292
    300293        $order = $this->parse_order( $this->query_vars['order'] );
    301294
     
    338331            $orderby = implode( ', ', $orderby_array );
    339332        } else {
    340             $orderby = "{$this->db->site}.id $order";
     333            $orderby = "$wpdb->site.id $order";
    341334        }
    342335
     
    355348            $fields = 'COUNT(*)';
    356349        } else {
    357             $fields = "{$this->db->site}.id";
     350            $fields = "$wpdb->site.id";
    358351        }
    359352
    360353        // Parse network IDs for an IN clause.
    361354        if ( ! empty( $this->query_vars['network__in'] ) ) {
    362             $this->sql_clauses['where']['network__in'] = "{$this->db->site}.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )';
     355            $this->sql_clauses['where']['network__in'] = "$wpdb->site.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )';
    363356        }
    364357
    365358        // Parse network IDs for a NOT IN clause.
    366359        if ( ! empty( $this->query_vars['network__not_in'] ) ) {
    367             $this->sql_clauses['where']['network__not_in'] = "{$this->db->site}.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )';
     360            $this->sql_clauses['where']['network__not_in'] = "$wpdb->site.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )';
    368361        }
    369362
    370363        if ( ! empty( $this->query_vars['domain'] ) ) {
    371             $this->sql_clauses['where']['domain'] = $this->db->prepare( "{$this->db->site}.domain = %s", $this->query_vars['domain'] );
     364            $this->sql_clauses['where']['domain'] = $wpdb->prepare( "$wpdb->site.domain = %s", $this->query_vars['domain'] );
    372365        }
    373366
    374367        // Parse network domain for an IN clause.
    375368        if ( is_array( $this->query_vars['domain__in'] ) ) {
    376             $this->sql_clauses['where']['domain__in'] = "{$this->db->site}.domain IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__in'] ) ) . "' )";
     369            $this->sql_clauses['where']['domain__in'] = "$wpdb->site.domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";
    377370        }
    378371
    379372        // Parse network domain for a NOT IN clause.
    380373        if ( is_array( $this->query_vars['domain__not_in'] ) ) {
    381             $this->sql_clauses['where']['domain__not_in'] = "{$this->db->site}.domain NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";
     374            $this->sql_clauses['where']['domain__not_in'] = "$wpdb->site.domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";
    382375        }
    383376
    384377        if ( ! empty( $this->query_vars['path'] ) ) {
    385             $this->sql_clauses['where']['path'] = $this->db->prepare( "{$this->db->site}.path = %s", $this->query_vars['path'] );
     378            $this->sql_clauses['where']['path'] = $wpdb->prepare( "$wpdb->site.path = %s", $this->query_vars['path'] );
    386379        }
    387380
    388381        // Parse network path for an IN clause.
    389382        if ( is_array( $this->query_vars['path__in'] ) ) {
    390             $this->sql_clauses['where']['path__in'] = "{$this->db->site}.path IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__in'] ) ) . "' )";
     383            $this->sql_clauses['where']['path__in'] = "$wpdb->site.path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";
    391384        }
    392385
    393386        // Parse network path for a NOT IN clause.
    394387        if ( is_array( $this->query_vars['path__not_in'] ) ) {
    395             $this->sql_clauses['where']['path__not_in'] = "{$this->db->site}.path NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__not_in'] ) ) . "' )";
     388            $this->sql_clauses['where']['path__not_in'] = "$wpdb->site.path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";
    396389        }
    397390
     
    400393            $this->sql_clauses['where']['search'] = $this->get_search_sql(
    401394                $this->query_vars['search'],
    402                 array( "{$this->db->site}.domain", "{$this->db->site}.path" )
     395                array( "$wpdb->site.domain", "$wpdb->site.path" )
    403396            );
    404397        }
     
    445438
    446439        $this->sql_clauses['select']  = "SELECT $found_rows $fields";
    447         $this->sql_clauses['from']    = "FROM {$this->db->site} $join";
     440        $this->sql_clauses['from']    = "FROM $wpdb->site $join";
    448441        $this->sql_clauses['groupby'] = $groupby;
    449442        $this->sql_clauses['orderby'] = $orderby;
     
    453446
    454447        if ( $this->query_vars['count'] ) {
    455             return intval( $this->db->get_var( $this->request ) );
    456         }
    457 
    458         $network_ids = $this->db->get_col( $this->request );
     448            return intval( $wpdb->get_var( $this->request ) );
     449        }
     450
     451        $network_ids = $wpdb->get_col( $this->request );
    459452
    460453        return array_map( 'intval', $network_ids );
     
    467460     * @since 4.6.0
    468461     * @access private
     462     *
     463     * @global wpdb $wpdb WordPress database abstraction object.
    469464     */
    470465    private function set_found_networks() {
     466        global $wpdb;
     467
    471468        if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {
    472469            /**
     
    480477            $found_networks_query = apply_filters( 'found_networks_query', 'SELECT FOUND_ROWS()', $this );
    481478
    482             $this->found_networks = (int) $this->db->get_var( $found_networks_query );
     479            $this->found_networks = (int) $wpdb->get_var( $found_networks_query );
    483480        }
    484481    }
     
    489486     * @since 4.6.0
    490487     * @access protected
     488     *
     489     * @global wpdb  $wpdb WordPress database abstraction object.
    491490     *
    492491     * @param string $string  Search string.
     
    496495     */
    497496    protected function get_search_sql( $string, $columns ) {
    498         $like = '%' . $this->db->esc_like( $string ) . '%';
     497        global $wpdb;
     498
     499        $like = '%' . $wpdb->esc_like( $string ) . '%';
    499500
    500501        $searches = array();
    501502        foreach ( $columns as $column ) {
    502             $searches[] = $this->db->prepare( "$column LIKE %s", $like );
     503            $searches[] = $wpdb->prepare( "$column LIKE %s", $like );
    503504        }
    504505
     
    511512     * @since 4.6.0
    512513     * @access protected
     514     *
     515     * @global wpdb $wpdb WordPress database abstraction object.
    513516     *
    514517     * @param string $orderby Alias for the field to order by.
     
    516519     */
    517520    protected function parse_orderby( $orderby ) {
     521        global $wpdb;
     522
    518523        $allowed_keys = array(
    519524            'id',
     
    525530        if ( $orderby == 'network__in' ) {
    526531            $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) );
    527             $parsed = "FIELD( {$this->db->site}.id, $network__in )";
     532            $parsed = "FIELD( {$wpdb->site}.id, $network__in )";
    528533        } elseif ( $orderby == 'domain_length' || $orderby == 'path_length' ) {
    529534            $field = substr( $orderby, 0, -7 );
    530             $parsed = "CHAR_LENGTH({$this->db->site}.$field)";
     535            $parsed = "CHAR_LENGTH($wpdb->site.$field)";
    531536        } elseif ( in_array( $orderby, $allowed_keys ) ) {
    532             $parsed = "{$this->db->site}.$orderby";
     537            $parsed = "$wpdb->site.$orderby";
    533538        }
    534539
  • 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 );
  • trunk/src/wp-includes/class-wp-roles.php

    r38387 r38768  
    7171
    7272    /**
    73      * @since 4.7.0
    74      * @access protected
    75      * @var wpdb
    76      */
    77     protected $db;
    78 
    79     /**
    8073     * Constructor
    8174     *
     
    8376     */
    8477    public function __construct() {
    85         $this->db = $GLOBALS['wpdb'];
    86 
    8778        $this->_init();
    8879    }
     
    118109     */
    119110    protected function _init() {
    120         global $wp_user_roles;
    121         $this->role_key = $this->db->get_blog_prefix() . 'user_roles';
     111        global $wp_user_roles, $wpdb;
     112
     113        $this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
    122114        if ( ! empty( $wp_user_roles ) ) {
    123115            $this->roles = $wp_user_roles;
     
    148140     */
    149141    public function reinit() {
     142        global $wpdb;
     143
    150144        // There is no need to reinit if using the wp_user_roles global.
    151145        if ( ! $this->use_db ) {
     
    154148
    155149        // Duplicated from _init() to avoid an extra function call.
    156         $this->role_key = $this->db->get_blog_prefix() . 'user_roles';
     150        $this->role_key = $wpdb->get_blog_prefix() . 'user_roles';
    157151        $this->roles = get_option( $this->role_key );
    158152        if ( empty( $this->roles ) )
  • trunk/src/wp-includes/class-wp-site-query.php

    r38631 r38768  
    9595     */
    9696    public $max_num_pages = 0;
    97 
    98     /**
    99      * @since 4.7.0
    100      * @access protected
    101      * @var wpdb
    102      */
    103     protected $db;
    10497
    10598    /**
     
    153146     */
    154147    public function __construct( $query = '' ) {
    155         $this->db = $GLOBALS['wpdb'];
    156 
    157148        $this->query_var_defaults = array(
    158149            'fields'            => '',
     
    333324     * @access protected
    334325     *
     326     * @global wpdb $wpdb WordPress database abstraction object.
     327     *
    335328     * @return int|array A single count of site IDs if a count query. An array of site IDs if a full query.
    336329     */
    337330    protected function get_site_ids() {
     331        global $wpdb;
     332
    338333        $order = $this->parse_order( $this->query_vars['order'] );
    339334
     
    399394        $site_id = absint( $this->query_vars['ID'] );
    400395        if ( ! empty( $site_id ) ) {
    401             $this->sql_clauses['where']['ID'] = $this->db->prepare( 'blog_id = %d', $site_id );
     396            $this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id );
    402397        }
    403398
     
    415410
    416411        if ( ! empty( $network_id ) ) {
    417             $this->sql_clauses['where']['network_id'] = $this->db->prepare( 'site_id = %d', $network_id );
     412            $this->sql_clauses['where']['network_id'] = $wpdb->prepare( 'site_id = %d', $network_id );
    418413        }
    419414
     
    429424
    430425        if ( ! empty( $this->query_vars['domain'] ) ) {
    431             $this->sql_clauses['where']['domain'] = $this->db->prepare( 'domain = %s', $this->query_vars['domain'] );
     426            $this->sql_clauses['where']['domain'] = $wpdb->prepare( 'domain = %s', $this->query_vars['domain'] );
    432427        }
    433428
    434429        // Parse site domain for an IN clause.
    435430        if ( is_array( $this->query_vars['domain__in'] ) ) {
    436             $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__in'] ) ) . "' )";
     431            $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )";
    437432        }
    438433
    439434        // Parse site domain for a NOT IN clause.
    440435        if ( is_array( $this->query_vars['domain__not_in'] ) ) {
    441             $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";
     436            $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )";
    442437        }
    443438
    444439        if ( ! empty( $this->query_vars['path'] ) ) {
    445             $this->sql_clauses['where']['path'] = $this->db->prepare( 'path = %s', $this->query_vars['path'] );
     440            $this->sql_clauses['where']['path'] = $wpdb->prepare( 'path = %s', $this->query_vars['path'] );
    446441        }
    447442
    448443        // Parse site path for an IN clause.
    449444        if ( is_array( $this->query_vars['path__in'] ) ) {
    450             $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__in'] ) ) . "' )";
     445            $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )";
    451446        }
    452447
    453448        // Parse site path for a NOT IN clause.
    454449        if ( is_array( $this->query_vars['path__not_in'] ) ) {
    455             $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $this->db->_escape( $this->query_vars['path__not_in'] ) ) . "' )";
     450            $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";
    456451        }
    457452
    458453        if ( is_numeric( $this->query_vars['archived'] ) ) {
    459454            $archived = absint( $this->query_vars['archived'] );
    460             $this->sql_clauses['where']['archived'] = $this->db->prepare( "archived = %d ", $archived );
     455            $this->sql_clauses['where']['archived'] = $wpdb->prepare( "archived = %d ", $archived );
    461456        }
    462457
    463458        if ( is_numeric( $this->query_vars['mature'] ) ) {
    464459            $mature = absint( $this->query_vars['mature'] );
    465             $this->sql_clauses['where']['mature'] = $this->db->prepare( "mature = %d ", $mature );
     460            $this->sql_clauses['where']['mature'] = $wpdb->prepare( "mature = %d ", $mature );
    466461        }
    467462
    468463        if ( is_numeric( $this->query_vars['spam'] ) ) {
    469464            $spam = absint( $this->query_vars['spam'] );
    470             $this->sql_clauses['where']['spam'] = $this->db->prepare( "spam = %d ", $spam );
     465            $this->sql_clauses['where']['spam'] = $wpdb->prepare( "spam = %d ", $spam );
    471466        }
    472467
    473468        if ( is_numeric( $this->query_vars['deleted'] ) ) {
    474469            $deleted = absint( $this->query_vars['deleted'] );
    475             $this->sql_clauses['where']['deleted'] = $this->db->prepare( "deleted = %d ", $deleted );
     470            $this->sql_clauses['where']['deleted'] = $wpdb->prepare( "deleted = %d ", $deleted );
    476471        }
    477472
    478473        if ( is_numeric( $this->query_vars['public'] ) ) {
    479474            $public = absint( $this->query_vars['public'] );
    480             $this->sql_clauses['where']['public'] = $this->db->prepare( "public = %d ", $public );
     475            $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public );
    481476        }
    482477
     
    556551
    557552        $this->sql_clauses['select']  = "SELECT $found_rows $fields";
    558         $this->sql_clauses['from']    = "FROM {$this->db->blogs} $join";
     553        $this->sql_clauses['from']    = "FROM $wpdb->blogs $join";
    559554        $this->sql_clauses['groupby'] = $groupby;
    560555        $this->sql_clauses['orderby'] = $orderby;
     
    564559
    565560        if ( $this->query_vars['count'] ) {
    566             return intval( $this->db->get_var( $this->request ) );
    567         }
    568 
    569         $site_ids = $this->db->get_col( $this->request );
     561            return intval( $wpdb->get_var( $this->request ) );
     562        }
     563
     564        $site_ids = $wpdb->get_col( $this->request );
    570565
    571566        return array_map( 'intval', $site_ids );
     
    578573     * @since 4.6.0
    579574     * @access private
     575     *
     576     * @global wpdb $wpdb WordPress database abstraction object.
    580577     */
    581578    private function set_found_sites() {
     579        global $wpdb;
     580
    582581        if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {
    583582            /**
     
    591590            $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this );
    592591
    593             $this->found_sites = (int) $this->db->get_var( $found_sites_query );
     592            $this->found_sites = (int) $wpdb->get_var( $found_sites_query );
    594593        }
    595594    }
     
    600599     * @since 4.6.0
    601600     * @access protected
     601     *
     602     * @global wpdb  $wpdb WordPress database abstraction object.
    602603     *
    603604     * @param string $string  Search string.
     
    606607     */
    607608    protected function get_search_sql( $string, $columns ) {
     609        global $wpdb;
     610
    608611        if ( false !== strpos( $string, '*' ) ) {
    609             $like = '%' . implode( '%', array_map( array( $this->db, 'esc_like' ), explode( '*', $string ) ) ) . '%';
     612            $like = '%' . implode( '%', array_map( array( $wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%';
    610613        } else {
    611             $like = '%' . $this->db->esc_like( $string ) . '%';
     614            $like = '%' . $wpdb->esc_like( $string ) . '%';
    612615        }
    613616
    614617        $searches = array();
    615618        foreach ( $columns as $column ) {
    616             $searches[] = $this->db->prepare( "$column LIKE %s", $like );
     619            $searches[] = $wpdb->prepare( "$column LIKE %s", $like );
    617620        }
    618621
     
    625628     * @since 4.6.0
    626629     * @access protected
     630     *
     631     * @global wpdb $wpdb WordPress database abstraction object.
    627632     *
    628633     * @param string $orderby Alias for the field to order by.
     
    630635     */
    631636    protected function parse_orderby( $orderby ) {
     637        global $wpdb;
     638
    632639        $parsed = false;
    633640
     
    635642            case 'site__in':
    636643                $site__in = implode( ',', array_map( 'absint', $this->query_vars['site__in'] ) );
    637                 $parsed = "FIELD( {$this->db->blogs}.blog_id, $site__in )";
     644                $parsed = "FIELD( {$wpdb->blogs}.blog_id, $site__in )";
    638645                break;
    639646            case 'network__in':
    640647                $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) );
    641                 $parsed = "FIELD( {$this->db->blogs}.site_id, $network__in )";
     648                $parsed = "FIELD( {$wpdb->blogs}.site_id, $network__in )";
    642649                break;
    643650            case 'domain':
  • trunk/src/wp-includes/class-wp-tax-query.php

    r38275 r38768  
    9393
    9494    /**
    95      * @since 4.7.0
    96      * @access protected
    97      * @var wpdb
    98      */
    99     protected $db;
    100 
    101     /**
    10295     * Constructor.
    10396     *
     
    127120     */
    128121    public function __construct( $tax_query ) {
    129         $this->db = $GLOBALS['wpdb'];
    130 
    131122        if ( isset( $tax_query['relation'] ) ) {
    132123            $this->relation = $this->sanitize_relation( $tax_query['relation'] );
     
    397388     * @access public
    398389     *
     390     * @global wpdb $wpdb The WordPress database abstraction object.
     391     *
    399392     * @param array $clause       Query clause, passed by reference.
    400393     * @param array $parent_query Parent query array.
     
    407400     */
    408401    public function get_sql_for_clause( &$clause, $parent_query ) {
     402        global $wpdb;
     403
    409404        $sql = array(
    410405            'where' => array(),
     
    438433            if ( false === $alias ) {
    439434                $i = count( $this->table_aliases );
    440                 $alias = $i ? 'tt' . $i : $this->db->term_relationships;
     435                $alias = $i ? 'tt' . $i : $wpdb->term_relationships;
    441436
    442437                // Store the alias as part of a flat array to build future iterators.
     
    446441                $clause['alias'] = $alias;
    447442
    448                 $join .= " LEFT JOIN {$this->db->term_relationships}";
     443                $join .= " LEFT JOIN $wpdb->term_relationships";
    449444                $join .= $i ? " AS $alias" : '';
    450445                $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)";
     
    464459            $where = "$this->primary_table.$this->primary_id_column NOT IN (
    465460                SELECT object_id
    466                 FROM {$this->db->term_relationships}
     461                FROM $wpdb->term_relationships
    467462                WHERE term_taxonomy_id IN ($terms)
    468463            )";
     
    480475            $where = "(
    481476                SELECT COUNT(1)
    482                 FROM {$this->db->term_relationships}
     477                FROM $wpdb->term_relationships
    483478                WHERE term_taxonomy_id IN ($terms)
    484479                AND object_id = $this->primary_table.$this->primary_id_column
     
    487482        } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) {
    488483
    489             $where = $this->db->prepare( "$operator (
     484            $where = $wpdb->prepare( "$operator (
    490485                SELECT 1
    491                 FROM {$this->db->term_relationships}
    492                 INNER JOIN {$this->db->term_taxonomy}
    493                 ON {$this->db->term_taxonomy}.term_taxonomy_id = {$this->db->term_relationships}.term_taxonomy_id
    494                 WHERE {$this->db->term_taxonomy}.taxonomy = %s
    495                 AND {$this->db->term_relationships}.object_id = $this->primary_table.$this->primary_id_column
     486                FROM $wpdb->term_relationships
     487                INNER JOIN $wpdb->term_taxonomy
     488                ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id
     489                WHERE $wpdb->term_taxonomy.taxonomy = %s
     490                AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column
    496491            )", $clause['taxonomy'] );
    497492
     
    603598     * @since 3.2.0
    604599     *
     600     * @global wpdb $wpdb The WordPress database abstraction object.
     601     *
    605602     * @param array  $query           The single query. Passed by reference.
    606603     * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id',
     
    608605     */
    609606    public function transform_query( &$query, $resulting_field ) {
     607        global $wpdb;
     608
    610609        if ( empty( $query['terms'] ) )
    611610            return;
     
    630629                $terms = implode( ",", $query['terms'] );
    631630
    632                 $terms = $this->db->get_col( "
    633                     SELECT {$this->db->term_taxonomy}.$resulting_field
    634                     FROM {$this->db->term_taxonomy}
    635                     INNER JOIN {$this->db->terms} USING (term_id)
     631                $terms = $wpdb->get_col( "
     632                    SELECT $wpdb->term_taxonomy.$resulting_field
     633                    FROM $wpdb->term_taxonomy
     634                    INNER JOIN $wpdb->terms USING (term_id)
    636635                    WHERE taxonomy = '{$query['taxonomy']}'
    637                     AND {$this->db->terms}.{$query['field']} IN ($terms)
     636                    AND $wpdb->terms.{$query['field']} IN ($terms)
    638637                " );
    639638                break;
    640639            case 'term_taxonomy_id':
    641640                $terms = implode( ',', array_map( 'intval', $query['terms'] ) );
    642                 $terms = $this->db->get_col( "
     641                $terms = $wpdb->get_col( "
    643642                    SELECT $resulting_field
    644                     FROM {$this->db->term_taxonomy}
     643                    FROM $wpdb->term_taxonomy
    645644                    WHERE term_taxonomy_id IN ($terms)
    646645                " );
     
    648647            default:
    649648                $terms = implode( ',', array_map( 'intval', $query['terms'] ) );
    650                 $terms = $this->db->get_col( "
     649                $terms = $wpdb->get_col( "
    651650                    SELECT $resulting_field
    652                     FROM {$this->db->term_taxonomy}
     651                    FROM $wpdb->term_taxonomy
    653652                    WHERE taxonomy = '{$query['taxonomy']}'
    654653                    AND term_id IN ($terms)
  • trunk/src/wp-includes/class-wp-term-query.php

    r38667 r38768  
    8686     */
    8787    public $terms;
    88 
    89     /**
    90      * @since 4.7.0
    91      * @access protected
    92      * @var wpdb
    93      */
    94     protected $db;
    9588
    9689    /**
     
    187180     */
    188181    public function __construct( $query = '' ) {
    189         $this->db = $GLOBALS['wpdb'];
    190 
    191182        $this->query_var_defaults = array(
    192183            'taxonomy'               => null,
     
    315306     * @access public
    316307     *
     308     * @global wpdb $wpdb WordPress database abstraction object.
     309     *
    317310     * @return array
    318311     */
    319312    public function get_terms() {
     313        global $wpdb;
     314
    320315        $this->parse_query( $this->query_vars );
    321316        $args = $this->query_vars;
     
    510505                $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})";
    511506            } else {
    512                 $this->sql_clauses['where']['term_taxonomy_id'] = $this->db->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );
     507                $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );
    513508            }
    514509        }
    515510
    516511        if ( ! empty( $args['name__like'] ) ) {
    517             $this->sql_clauses['where']['name__like'] = $this->db->prepare( "t.name LIKE %s", '%' . $this->db->esc_like( $args['name__like'] ) . '%' );
     512            $this->sql_clauses['where']['name__like'] = $wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );
    518513        }
    519514
    520515        if ( ! empty( $args['description__like'] ) ) {
    521             $this->sql_clauses['where']['description__like'] = $this->db->prepare( "tt.description LIKE %s", '%' . $this->db->esc_like( $args['description__like'] ) . '%' );
     516            $this->sql_clauses['where']['description__like'] = $wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );
    522517        }
    523518
     
    639634        $fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) );
    640635
    641         $join .= " INNER JOIN {$this->db->term_taxonomy} AS tt ON t.term_id = tt.term_id";
     636        $join .= " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id";
    642637
    643638        if ( ! empty( $this->query_vars['object_ids'] ) ) {
    644             $join .= " INNER JOIN {$this->db->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";
     639            $join .= " INNER JOIN {$wpdb->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";
    645640        }
    646641
     
    671666
    672667        $this->sql_clauses['select']  = "SELECT $distinct $fields";
    673         $this->sql_clauses['from']    = "FROM {$this->db->terms} AS t $join";
     668        $this->sql_clauses['from']    = "FROM $wpdb->terms AS t $join";
    674669        $this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : '';
    675670        $this->sql_clauses['limits']  = $limits;
     
    696691
    697692        if ( 'count' == $_fields ) {
    698             return $this->db->get_var( $this->request );
    699         }
    700 
    701         $terms = $this->db->get_results( $this->request );
     693            return $wpdb->get_var( $this->request );
     694        }
     695
     696        $terms = $wpdb->get_results( $this->request );
    702697        if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) {
    703698            update_term_cache( $terms );
     
    830825     * @since 4.6.0
    831826     * @access protected
     827     *
     828     * @global wpdb $wpdb WordPress database abstraction object.
    832829     *
    833830     * @param string $orderby_raw Alias for the field to order by.
     
    967964     * @access protected
    968965     *
     966     * @global wpdb $wpdb WordPress database abstraction object.
     967     *
    969968     * @param string $string
    970969     * @return string
    971970     */
    972971    protected function get_search_sql( $string ) {
    973         $like = '%' . $this->db->esc_like( $string ) . '%';
    974 
    975         return $this->db->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like );
     972        global $wpdb;
     973
     974        $like = '%' . $wpdb->esc_like( $string ) . '%';
     975
     976        return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like );
    976977    }
    977978}
  • trunk/src/wp-includes/class-wp-user-query.php

    r38715 r38768  
    7272
    7373    /**
    74      * @since 4.7.0
    75      * @access protected
    76      * @var wpdb
    77      */
    78     protected $db;
    79 
    80     /**
    8174     * PHP5 constructor.
    8275     *
     
    8679     */
    8780    public function __construct( $query = null ) {
    88         $this->db = $GLOBALS['wpdb'];
    89 
    9081        if ( ! empty( $query ) ) {
    9182            $this->prepare_query( $query );
     
    152143     * @access public
    153144     *
     145     * @global wpdb $wpdb WordPress database abstraction object.
    154146     * @global int  $blog_id
    155147     *
     
    225217     */
    226218    public function prepare_query( $query = array() ) {
     219        global $wpdb;
     220
    227221        if ( empty( $this->query_vars ) || ! empty( $query ) ) {
    228222            $this->query_limit = null;
     
    253247            foreach ( $qv['fields'] as $field ) {
    254248                $field = 'ID' === $field ? 'ID' : sanitize_key( $field );
    255                 $this->query_fields[] = "{$this->db->users}.$field";
     249                $this->query_fields[] = "$wpdb->users.$field";
    256250            }
    257251            $this->query_fields = implode( ',', $this->query_fields );
    258252        } elseif ( 'all' == $qv['fields'] ) {
    259             $this->query_fields = "{$this->db->users}.*";
     253            $this->query_fields = "$wpdb->users.*";
    260254        } else {
    261             $this->query_fields = "{$this->db->users}.ID";
     255            $this->query_fields = "$wpdb->users.ID";
    262256        }
    263257
     
    265259            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
    266260
    267         $this->query_from = "FROM {$this->db->users}";
     261        $this->query_from = "FROM $wpdb->users";
    268262        $this->query_where = "WHERE 1=1";
    269263
     
    288282
    289283            foreach ( $post_types as &$post_type ) {
    290                 $post_type = $this->db->prepare( '%s', $post_type );
    291             }
    292 
    293             $posts_table = $this->db->get_blog_prefix( $blog_id ) . 'posts';
    294             $this->query_where .= " AND {$this->db->users}.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )";
     284                $post_type = $wpdb->prepare( '%s', $post_type );
     285            }
     286
     287            $posts_table = $wpdb->get_blog_prefix( $blog_id ) . 'posts';
     288            $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )";
    295289        }
    296290
    297291        // nicename
    298292        if ( '' !== $qv['nicename']) {
    299             $this->query_where .= $this->db->prepare( ' AND user_nicename = %s', $qv['nicename'] );
     293            $this->query_where .= $wpdb->prepare( ' AND user_nicename = %s', $qv['nicename'] );
    300294        }
    301295
     
    314308        // login
    315309        if ( '' !== $qv['login']) {
    316             $this->query_where .= $this->db->prepare( ' AND user_login = %s', $qv['login'] );
     310            $this->query_where .= $wpdb->prepare( ' AND user_login = %s', $qv['login'] );
    317311        }
    318312
     
    335329        if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {
    336330            $who_query = array(
    337                 'key' => $this->db->get_blog_prefix( $blog_id ) . 'user_level',
     331                'key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level',
    338332                'value' => 0,
    339333                'compare' => '!=',
     
    382376                foreach ( $roles as $role ) {
    383377                    $roles_clauses[] = array(
    384                         'key'     => $this->db->get_blog_prefix( $blog_id ) . 'capabilities',
     378                        'key'     => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
    385379                        'value'   => '"' . $role . '"',
    386380                        'compare' => 'LIKE',
     
    395389                foreach ( $role__in as $role ) {
    396390                    $role__in_clauses[] = array(
    397                         'key'     => $this->db->get_blog_prefix( $blog_id ) . 'capabilities',
     391                        'key'     => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
    398392                        'value'   => '"' . $role . '"',
    399393                        'compare' => 'LIKE',
     
    408402                foreach ( $role__not_in as $role ) {
    409403                    $role__not_in_clauses[] = array(
    410                         'key'     => $this->db->get_blog_prefix( $blog_id ) . 'capabilities',
     404                        'key'     => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
    411405                        'value'   => '"' . $role . '"',
    412406                        'compare' => 'NOT LIKE',
     
    420414            if ( empty( $role_queries ) ) {
    421415                $role_queries[] = array(
    422                     'key' => $this->db->get_blog_prefix( $blog_id ) . 'capabilities',
     416                    'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
    423417                    'compare' => 'EXISTS',
    424418                );
     
    442436
    443437        if ( ! empty( $this->meta_query->queries ) ) {
    444             $clauses = $this->meta_query->get_sql( 'user', $this->db->users, 'ID', $this );
     438            $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
    445439            $this->query_from .= $clauses['join'];
    446440            $this->query_where .= $clauses['where'];
     
    504498        if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
    505499            if ( $qv['offset'] ) {
    506                 $this->query_limit = $this->db->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
     500                $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
    507501            } else {
    508                 $this->query_limit = $this->db->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
     502                $this->query_limit = $wpdb->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
    509503            }
    510504        }
     
    562556            // Sanitized earlier.
    563557            $ids = implode( ',', $include );
    564             $this->query_where .= " AND {$this->db->users}.ID IN ($ids)";
     558            $this->query_where .= " AND $wpdb->users.ID IN ($ids)";
    565559        } elseif ( ! empty( $qv['exclude'] ) ) {
    566560            $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
    567             $this->query_where .= " AND {$this->db->users}.ID NOT IN ($ids)";
     561            $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
    568562        }
    569563
     
    593587     *
    594588     * @since 3.1.0
     589     *
     590     * @global wpdb $wpdb WordPress database abstraction object.
    595591     */
    596592    public function query() {
     593        global $wpdb;
     594
    597595        $qv =& $this->query_vars;
    598596
     
    600598
    601599        if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
    602             $this->results = $this->db->get_results( $this->request );
     600            $this->results = $wpdb->get_results( $this->request );
    603601        } else {
    604             $this->results = $this->db->get_col( $this->request );
     602            $this->results = $wpdb->get_col( $this->request );
    605603        }
    606604
     
    610608         * @since 3.2.0
    611609         *
     610         * @global wpdb $wpdb WordPress database abstraction object.
     611         *
    612612         * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
    613613         */
    614         if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
    615             $this->total_users = $this->db->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    616         }
    617 
    618         if ( ! $this->results ) {
     614        if ( isset( $qv['count_total'] ) && $qv['count_total'] )
     615            $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
     616
     617        if ( !$this->results )
    619618            return;
    620         }
    621619
    622620        if ( 'all_with_meta' == $qv['fields'] ) {
     
    669667     * @access protected
    670668     * @since 3.1.0
     669     *
     670     * @global wpdb $wpdb WordPress database abstraction object.
    671671     *
    672672     * @param string $string
     
    677677     */
    678678    protected function get_search_sql( $string, $cols, $wild = false ) {
     679        global $wpdb;
     680
    679681        $searches = array();
    680682        $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : '';
    681683        $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : '';
    682         $like = $leading_wild . $this->db->esc_like( $string ) . $trailing_wild;
     684        $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild;
    683685
    684686        foreach ( $cols as $col ) {
    685687            if ( 'ID' == $col ) {
    686                 $searches[] = $this->db->prepare( "$col = %s", $string );
     688                $searches[] = $wpdb->prepare( "$col = %s", $string );
    687689            } else {
    688                 $searches[] = $this->db->prepare( "$col LIKE %s", $like );
     690                $searches[] = $wpdb->prepare( "$col LIKE %s", $like );
    689691            }
    690692        }
     
    723725     * @access protected
    724726     *
     727     * @global wpdb $wpdb WordPress database abstraction object.
     728     *
    725729     * @param string $orderby Alias for the field to order by.
    726730     * @return string Value to used in the ORDER clause, if `$orderby` is valid.
    727731     */
    728732    protected function parse_orderby( $orderby ) {
     733        global $wpdb;
     734
    729735        $meta_query_clauses = $this->meta_query->get_clauses();
    730736
     
    741747            $this->query_from .= " LEFT OUTER JOIN (
    742748                SELECT post_author, COUNT(*) as post_count
    743                 FROM {$this->db->posts}
     749                FROM $wpdb->posts
    744750                $where
    745751                GROUP BY post_author
    746             ) p ON ({$this->db->users}.ID = p.post_author)
     752            ) p ON ({$wpdb->users}.ID = p.post_author)
    747753            ";
    748754            $_orderby = 'post_count';
     
    750756            $_orderby = 'ID';
    751757        } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) {
    752             $_orderby = "{$this->db->usermeta}.meta_value";
     758            $_orderby = "$wpdb->usermeta.meta_value";
    753759        } elseif ( 'meta_value_num' == $orderby ) {
    754             $_orderby = "{$this->db->usermeta}.meta_value+0";
     760            $_orderby = "$wpdb->usermeta.meta_value+0";
    755761        } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
    756762            $include = wp_parse_id_list( $this->query_vars['include'] );
    757763            $include_sql = implode( ',', $include );
    758             $_orderby = "FIELD( {$this->db->users}.ID, $include_sql )";
     764            $_orderby = "FIELD( $wpdb->users.ID, $include_sql )";
    759765        } elseif ( 'nicename__in' === $orderby ) {
    760766            $sanitized_nicename__in = array_map( 'esc_sql', $this->query_vars['nicename__in'] );
  • trunk/src/wp-includes/class-wp-user.php

    r38705 r38768  
    105105
    106106    /**
    107      * @since 4.7.0
    108      * @access protected
    109      * @var wpdb
    110      */
    111     protected $db;
    112 
    113     /**
    114107     * Constructor.
    115108     *
     
    118111     * @since 2.0.0
    119112     * @access public
     113     *
     114     * @global wpdb $wpdb WordPress database abstraction object.
    120115     *
    121116     * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB.
     
    124119     */
    125120    public function __construct( $id = 0, $name = '', $blog_id = '' ) {
    126         $this->db = $GLOBALS['wpdb'];
    127 
    128121        if ( ! isset( self::$back_compat_keys ) ) {
    129             $prefix = $this->db->prefix;
     122            $prefix = $GLOBALS['wpdb']->prefix;
    130123            self::$back_compat_keys = array(
    131124                'user_firstname' => 'first_name',
     
    242235
    243236        if ( !$user = $wpdb->get_row( $wpdb->prepare(
    244             "SELECT * FROM {$wpdb->users} WHERE $db_field = %s", $value
    245         ) ) ) {
     237            "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
     238        ) ) )
    246239            return false;
    247         }
     240
    248241        update_user_caches( $user );
    249242
     
    452445     * @since 2.1.0
    453446     *
     447     * @global wpdb $wpdb WordPress database abstraction object.
     448     *
    454449     * @param string $cap_key Optional capability key
    455450     */
    456451    protected function _init_caps( $cap_key = '' ) {
    457         if ( empty( $cap_key ) ) {
    458             $this->cap_key = $this->db->get_blog_prefix() . 'capabilities';
    459         } else {
     452        global $wpdb;
     453
     454        if ( empty($cap_key) )
     455            $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities';
     456        else
    460457            $this->cap_key = $cap_key;
    461         }
     458
    462459        $this->caps = get_user_meta( $this->ID, $this->cap_key, true );
    463460
     
    637634     * @since 2.0.0
    638635     * @access public
     636     *
     637     * @global wpdb $wpdb WordPress database abstraction object.
    639638     */
    640639    public function update_user_level_from_caps() {
     640        global $wpdb;
    641641        $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 );
    642         update_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level', $this->user_level );
     642        update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level );
    643643    }
    644644
     
    682682     * @since 2.1.0
    683683     * @access public
     684     *
     685     * @global wpdb $wpdb WordPress database abstraction object.
    684686     */
    685687    public function remove_all_caps() {
     688        global $wpdb;
    686689        $this->caps = array();
    687690        delete_user_meta( $this->ID, $this->cap_key );
    688         delete_user_meta( $this->ID, $this->db->get_blog_prefix() . 'user_level' );
     691        delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' );
    689692        $this->get_role_caps();
    690693    }
     
    772775     * @since 3.0.0
    773776     *
     777     * @global wpdb $wpdb WordPress database abstraction object.
     778     *
    774779     * @param int $blog_id Optional. Site ID, defaults to current site.
    775780     */
    776781    public function for_blog( $blog_id = '' ) {
    777         if ( ! empty( $blog_id ) ) {
    778             $cap_key = $this->db->get_blog_prefix( $blog_id ) . 'capabilities';
    779         } else {
     782        global $wpdb;
     783        if ( ! empty( $blog_id ) )
     784            $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
     785        else
    780786            $cap_key = '';
    781         }
    782787        $this->_init_caps( $cap_key );
    783788    }
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r38747 r38768  
    5555
    5656    /**
    57      * @since 4.7.0
    58      * @access protected
    59      * @var wpdb
    60      */
    61     protected $db;
    62 
    63     /**
    6457     * Registers all of the XMLRPC methods that XMLRPC server understands.
    6558     *
     
    7164     */
    7265    public function __construct() {
    73         $this->db = $GLOBALS['wpdb'];
    74 
    7566        $this->methods = array(
    7667            // WordPress API
     
    28952886     * @since 2.2.0
    28962887     *
     2888     * @global wpdb $wpdb WordPress database abstraction object.
     2889     *
    28972890     * @param array  $args {
    28982891     *     Method arguments. Note: arguments must be ordered as documented.
     
    29052898     */
    29062899    public function wp_getPageList( $args ) {
     2900        global $wpdb;
     2901
    29072902        $this->escape( $args );
    29082903
     
    29202915
    29212916        // Get list of pages ids and titles
    2922         $page_list = $this->db->get_results("
     2917        $page_list = $wpdb->get_results("
    29232918            SELECT ID page_id,
    29242919                post_title page_title,
     
    29272922                post_date,
    29282923                post_status
    2929             FROM {$this->db->posts}
     2924            FROM {$wpdb->posts}
    29302925            WHERE post_type = 'page'
    29312926            ORDER BY ID
     
    51445139     * @since 2.1.0
    51455140     *
     5141     * @global wpdb $wpdb WordPress database abstraction object.
     5142     *
    51465143     * @param int $post_ID Post ID.
    51475144     * @param string $post_content Post Content for attachment.
    51485145     */
    51495146    public function attach_uploads( $post_ID, $post_content ) {
     5147        global $wpdb;
     5148
    51505149        // find any unattached files
    5151         $attachments = $this->db->get_results( "SELECT ID, guid FROM {$this->db->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );
     5150        $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" );
    51525151        if ( is_array( $attachments ) ) {
    51535152            foreach ( $attachments as $file ) {
    5154                 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) {
    5155                     $this->db->update( $this->db->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) );
    5156                 }
     5153                if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false )
     5154                    $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) );
    51575155            }
    51585156        }
     
    57745772     * @since 1.5.0
    57755773     *
     5774     * @global wpdb $wpdb WordPress database abstraction object.
     5775     *
    57765776     * @param array  $args {
    57775777     *     Method arguments. Note: arguments must be ordered as documented.
     
    57855785     */
    57865786    public function mw_newMediaObject( $args ) {
     5787        global $wpdb;
     5788
    57875789        $username = $this->escape( $args[1] );
    57885790        $password = $this->escape( $args[2] );
     
    61106112     * @since 1.5.0
    61116113     *
     6114     * @global wpdb $wpdb WordPress database abstraction object.
     6115     *
    61126116     * @param int $post_ID
    61136117     * @return array|IXR_Error
    61146118     */
    61156119    public function mt_getTrackbackPings( $post_ID ) {
     6120        global $wpdb;
     6121
    61166122        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    61176123        do_action( 'xmlrpc_call', 'mt.getTrackbackPings' );
     
    61226128            return new IXR_Error(404, __('Sorry, no such post.'));
    61236129
    6124         $comments = $this->db->get_results( $this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments} WHERE comment_post_ID = %d", $post_ID) );
     6130        $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
    61256131
    61266132        if ( !$comments )
     
    62576263                // ...or a string #title, a little more complicated
    62586264                $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
    6259                 $sql = $this->db->prepare("SELECT ID FROM {$this->db->posts} WHERE post_title RLIKE %s", $title );
    6260                 if (! ($post_ID = $this->db->get_var($sql)) ) {
     6265                $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title );
     6266                if (! ($post_ID = $wpdb->get_var($sql)) ) {
    62616267                    // returning unknown error '0' is better than die()ing
    62626268                    return $this->pingback_error( 0, '' );
     
    62826288
    62836289        // Let's check that the remote site didn't already pingback this entry
    6284         if ( $this->db->get_results( $this->db->prepare("SELECT * FROM {$this->db->comments} WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )
     6290        if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )
    62856291            return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) );
    62866292
     
    64096415     * @since 1.5.0
    64106416     *
     6417     * @global wpdb $wpdb WordPress database abstraction object.
     6418     *
    64116419     * @param string $url
    64126420     * @return array|IXR_Error
    64136421     */
    64146422    public function pingback_extensions_getPingbacks( $url ) {
     6423        global $wpdb;
     6424
    64156425        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    64166426        do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' );
     
    64316441        }
    64326442
    6433         $comments = $this->db->get_results( $this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments} WHERE comment_post_ID = %d", $post_ID) );
     6443        $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
    64346444
    64356445        if ( !$comments )
  • trunk/src/wp-includes/date.php

    r38280 r38768  
    6262     */
    6363    public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
    64 
    65     /**
    66      * @since 4.7.0
    67      * @access protected
    68      * @var wpdb
    69      */
    70     protected $db;
    7164
    7265    /**
     
    159152     */
    160153    public function __construct( $date_query, $default_column = 'post_date' ) {
    161         $this->db = $GLOBALS['wpdb'];
    162 
    163154        if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
    164155            $this->relation = 'OR';
     
    495486     */
    496487    public function validate_column( $column ) {
     488        global $wpdb;
     489
    497490        $valid_columns = array(
    498491            'post_date', 'post_date_gmt', 'post_modified',
     
    519512
    520513            $known_columns = array(
    521                 $this->db->posts => array(
     514                $wpdb->posts => array(
    522515                    'post_date',
    523516                    'post_date_gmt',
     
    525518                    'post_modified_gmt',
    526519                ),
    527                 $this->db->comments => array(
     520                $wpdb->comments => array(
    528521                    'comment_date',
    529522                    'comment_date_gmt',
    530523                ),
    531                 $this->db->users => array(
     524                $wpdb->users => array(
    532525                    'user_registered',
    533526                ),
    534                 $this->db->blogs => array(
     527                $wpdb->blogs => array(
    535528                    'registered',
    536529                    'last_updated',
     
    724717     */
    725718    protected function get_sql_for_clause( $query, $parent_query ) {
     719        global $wpdb;
     720
    726721        // The sub-parts of a $where part.
    727722        $where_parts = array();
     
    746741        // Range queries.
    747742        if ( ! empty( $query['after'] ) ) {
    748             $where_parts[] = $this->db->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
     743            $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
    749744        }
    750745        if ( ! empty( $query['before'] ) ) {
    751             $where_parts[] = $this->db->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
     746            $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
    752747        }
    753748        // Specific value queries.
     
    963958     */
    964959    public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) {
     960        global $wpdb;
     961
    965962        // Have to have at least one
    966963        if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) )
     
    10161013        }
    10171014
    1018         return $this->db->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
     1015        return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
    10191016    }
    10201017}
  • trunk/tests/phpunit/tests/user.php

    r38398 r38768  
    182182
    183183        foreach ( (array) $user as $key => $value ) {
    184             if ( $value instanceof wpdb ) {
    185                 continue;
    186             }
    187184            $this->assertEquals( $value, $user->$key );
    188185        }
Note: See TracChangeset for help on using the changeset viewer.