]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/date.php
WordPress 4.0
[autoinstalls/wordpress.git] / wp-includes / date.php
index 99bbb4e0123eaf5b02e372e0d35acfcb76424b25..a060239ea3857985aedfa5a21b1c76b476d1d6f4 100644 (file)
@@ -48,6 +48,9 @@ class WP_Date_Query {
        /**
         * Constructor.
         *
+        * @since 3.7.0
+        * @since 4.0.0 The $inclusive logic was updated to include all times within the date range.
+        *
         * @param array $date_query {
         *     One or more associative arrays of date query parameters.
         *
@@ -81,7 +84,7 @@ class WP_Date_Query {
         *                                     Default (string:empty)|(array:last day of month). Accepts numbers 1-31.
         *             }
         *             @type string       $column    Optional. Used to add a clause comparing a column other than the column
-        *                                           specified in the top-level $column paramater.  Default is the value
+        *                                           specified in the top-level $column parameter.  Default is the value
         *                                           of top-level $column. Accepts 'post_date', 'post_date_gmt',
         *                                           'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'.
         *             @type string       $compare   Optional. The comparison operator. Default '='. Accepts '=', '!=',
@@ -105,7 +108,7 @@ class WP_Date_Query {
         *                              Accepts 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt',
         *                              'comment_date', 'comment_date_gmt'.
         */
-       function __construct( $date_query, $default_column = 'post_date' ) {
+       public function __construct( $date_query, $default_column = 'post_date' ) {
                if ( empty( $date_query ) || ! is_array( $date_query ) )
                        return;
 
@@ -235,19 +238,23 @@ class WP_Date_Query {
 
                $compare = $this->get_compare( $query );
 
+               $inclusive = ! empty( $query['inclusive'] );
+
+               // Assign greater- and less-than values.
                $lt = '<';
                $gt = '>';
-               if ( ! empty( $query['inclusive'] ) ) {
+
+               if ( $inclusive ) {
                        $lt .= '=';
                        $gt .= '=';
                }
 
                // Range queries
                if ( ! empty( $query['after'] ) )
-                       $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], true ) );
+                       $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'], false ) );
+                       $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
 
                // Specific value queries
 
@@ -256,16 +263,12 @@ class WP_Date_Query {
 
                if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) )
                        $where_parts[] = "MONTH( $column ) $compare $value";
-
-               // Legacy
-               if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
+               else if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
                        $where_parts[] = "MONTH( $column ) $compare $value";
 
                if ( isset( $query['week'] ) && false !== ( $value = $this->build_value( $compare, $query['week'] ) ) )
                        $where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
-
-               // Legacy
-               if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
+               else if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
                        $where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
 
                if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) )