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