Make WordPress Core


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.