Make WordPress Core


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