Make WordPress Core


Ignore:
Timestamp:
10/10/2016 06:37:02 AM (7 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-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
Note: See TracChangeset for help on using the changeset viewer.