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/date.php

    r38280 r38768  
    6262         */
    6363        public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' );
    64 
    65         /**
    66          * @since 4.7.0
    67          * @access protected
    68          * @var wpdb
    69          */
    70         protected $db;
    7164
    7265        /**
    … …  
    159152         */
    160153        public function __construct( $date_query, $default_column = 'post_date' ) {
    161                 $this->db = $GLOBALS['wpdb'];
    162 
    163154                if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
    164155                        $this->relation = 'OR';
    … …  
    495486         */
    496487        public function validate_column( $column ) {
     488                global $wpdb;
     489
    497490                $valid_columns = array(
    498491                        'post_date', 'post_date_gmt', 'post_modified',
    … …  
    519512
    520513                        $known_columns = array(
    521                                 $this->db->posts => array(
     514                                $wpdb->posts => array(
    522515                                        'post_date',
    523516                                        'post_date_gmt',
    … …  
    525518                                        'post_modified_gmt',
    526519                                ),
    527                                 $this->db->comments => array(
     520                                $wpdb->comments => array(
    528521                                        'comment_date',
    529522                                        'comment_date_gmt',
    530523                                ),
    531                                 $this->db->users => array(
     524                                $wpdb->users => array(
    532525                                        'user_registered',
    533526                                ),
    534                                 $this->db->blogs => array(
     527                                $wpdb->blogs => array(
    535528                                        'registered',
    536529                                        'last_updated',
    … …  
    724717         */
    725718        protected function get_sql_for_clause( $query, $parent_query ) {
     719                global $wpdb;
     720
    726721                // The sub-parts of a $where part.
    727722                $where_parts = array();
    … …  
    746741                // Range queries.
    747742                if ( ! empty( $query['after'] ) ) {
    748                         $where_parts[] = $this->db->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
     743                        $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
    749744                }
    750745                if ( ! empty( $query['before'] ) ) {
    751                         $where_parts[] = $this->db->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
     746                        $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
    752747                }
    753748                // Specific value queries.
    … …  
    963958         */
    964959        public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) {
     960                global $wpdb;
     961
    965962                // Have to have at least one
    966963                if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) )
    … …  
    10161013                }
    10171014
    1018                 return $this->db->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
     1015                return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
    10191016        }
    10201017}
Note: See TracChangeset for help on using the changeset viewer.