X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/849f15aeed7a5e39314057bdc0064d8edd60dd7d..caeaf8dc94b5e3f75dc98ec92dc7b76049cdddb6:/wp-includes/date.php diff --git a/wp-includes/date.php b/wp-includes/date.php index 51c5d84b..9869611e 100644 --- a/wp-includes/date.php +++ b/wp-includes/date.php @@ -305,8 +305,17 @@ class WP_Date_Query { // Days per year. if ( array_key_exists( 'year', $date_query ) ) { - // If a year exists in the date query, we can use it to get the days. - $max_days_of_year = date( 'z', mktime( 0, 0, 0, 12, 31, $date_query['year'] ) ) + 1; + /* + * If a year exists in the date query, we can use it to get the days. + * If multiple years are provided (as in a BETWEEN), use the first one. + */ + if ( is_array( $date_query['year'] ) ) { + $_year = reset( $date_query['year'] ); + } else { + $_year = $date_query['year']; + } + + $max_days_of_year = date( 'z', mktime( 0, 0, 0, 12, 31, $_year ) ) + 1; } else { // otherwise we use the max of 366 (leap-year) $max_days_of_year = 366; @@ -336,10 +345,10 @@ class WP_Date_Query { ); // Weeks per year. - if ( array_key_exists( 'year', $date_query ) ) { + if ( isset( $_year ) ) { // If we have a specific year, use it to calculate number of weeks. $date = new DateTime(); - $date->setISODate( $date_query['year'], 53 ); + $date->setISODate( $_year, 53 ); $week_count = $date->format( "W" ) === "53" ? 53 : 52; } else { @@ -360,7 +369,7 @@ class WP_Date_Query { // Hours per day. $min_max_checks['hour'] = array( - 'min' => 1, + 'min' => 0, 'max' => 23 ); @@ -382,22 +391,25 @@ class WP_Date_Query { continue; } - $is_between = $date_query[ $key ] >= $check['min'] && $date_query[ $key ] <= $check['max']; - - if ( ! $is_between ) { + // Throw a notice for each failing value. + $is_between = true; + foreach ( (array) $date_query[ $key ] as $_value ) { + $is_between = $_value >= $check['min'] && $_value <= $check['max']; - $error = sprintf( - /* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */ - __( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ), - '' . esc_html( $date_query[ $key ] ) . '', - '' . esc_html( $key ) . '', - '' . esc_html( $check['min'] ) . '', - '' . esc_html( $check['max'] ) . '' - ); + if ( ! is_numeric( $_value ) || ! $is_between ) { + $error = sprintf( + /* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */ + __( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ), + '' . esc_html( $_value ) . '', + '' . esc_html( $key ) . '', + '' . esc_html( $check['min'] ) . '', + '' . esc_html( $check['max'] ) . '' + ); - _doing_it_wrong( __CLASS__, $error, '4.1.0' ); + _doing_it_wrong( __CLASS__, $error, '4.1.0' ); - $valid = false; + $valid = false; + } } }