Make WordPress Core


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

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

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-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}
Note: See TracChangeset for help on using the changeset viewer.