diff --git a/wp-includes/date.php b/wp-includes/date.php index d1f85f8c0d..1b46e2c5a3 100644 --- a/wp-includes/date.php +++ b/wp-includes/date.php @@ -62,6 +62,13 @@ class WP_Date_Query { */ public $time_keys = array( 'after', 'before', 'year', 'month', 'monthnum', 'week', 'w', 'dayofyear', 'day', 'dayofweek', 'dayofweek_iso', 'hour', 'minute', 'second' ); + /** + * @since 4.7.0 + * @access protected + * @var wpdb + */ + protected $db; + /** * Constructor. * @@ -151,6 +158,7 @@ class WP_Date_Query { * 'comment_date', 'comment_date_gmt'. */ public function __construct( $date_query, $default_column = 'post_date' ) { + $this->db = $GLOBALS['wpdb']; if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) { $this->relation = 'OR'; @@ -486,8 +494,6 @@ class WP_Date_Query { * @return string A validated column name value. */ public function validate_column( $column ) { - global $wpdb; - $valid_columns = array( 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt', @@ -512,20 +518,20 @@ class WP_Date_Query { } $known_columns = array( - $wpdb->posts => array( + $this->db->posts => array( 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt', ), - $wpdb->comments => array( + $this->db->comments => array( 'comment_date', 'comment_date_gmt', ), - $wpdb->users => array( + $this->db->users => array( 'user_registered', ), - $wpdb->blogs => array( + $this->db->blogs => array( 'registered', 'last_updated', ), @@ -717,8 +723,6 @@ class WP_Date_Query { * } */ protected function get_sql_for_clause( $query, $parent_query ) { - global $wpdb; - // The sub-parts of a $where part. $where_parts = array(); @@ -740,12 +744,12 @@ class WP_Date_Query { } // Range queries. - if ( ! empty( $query['after'] ) ) - $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) ); - - if ( ! empty( $query['before'] ) ) - $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) ); - + if ( ! empty( $query['after'] ) ) { + $where_parts[] = $this->db->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) ); + } + if ( ! empty( $query['before'] ) ) { + $where_parts[] = $this->db->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) ); + } // Specific value queries. if ( isset( $query['year'] ) && $value = $this->build_value( $compare, $query['year'] ) ) @@ -958,8 +962,6 @@ class WP_Date_Query { * @return string|false A query part or false on failure. */ public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) { - global $wpdb; - // Have to have at least one if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) return false; @@ -1013,6 +1015,6 @@ class WP_Date_Query { $time .= sprintf( '%02d', $second ); } - return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time ); + return $this->db->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index eff399c4f6..6bcb8e8368 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38279'; +$wp_version = '4.7-alpha-38280'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.