Check bad dates and redirect, instead of 404ing, as necessary and appropriate.
Adds query, conditional, and canonical Unit Tests. Props kovshenin, SergeyBiryukov, DrewAPicture. Fixes #10935. Built from https://develop.svn.wordpress.org/trunk@25280 git-svn-id: http://core.svn.wordpress.org/trunk@25244 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5e0040a6ca
commit
b22bc5e389
|
@ -101,6 +101,20 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) {
|
||||||
|
$year = get_query_var( 'year' );
|
||||||
|
$month = get_query_var( 'monthnum' );
|
||||||
|
$day = get_query_var( 'day' );
|
||||||
|
$date = sprintf( '%04d-%02d-%02d', $year, $month, $day );
|
||||||
|
if ( ! wp_checkdate( $month, $day, $year, $date ) ) {
|
||||||
|
$redirect_url = get_month_link( $year, $month );
|
||||||
|
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url );
|
||||||
|
}
|
||||||
|
} elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) {
|
||||||
|
$redirect_url = get_year_link( get_query_var( 'year' ) );
|
||||||
|
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url );
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! $redirect_url ) {
|
if ( ! $redirect_url ) {
|
||||||
if ( $redirect_url = redirect_guess_404_permalink() ) {
|
if ( $redirect_url = redirect_guess_404_permalink() ) {
|
||||||
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
|
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
|
||||||
|
|
|
@ -1513,15 +1513,24 @@ class WP_Query {
|
||||||
|
|
||||||
if ( $qv['day'] ) {
|
if ( $qv['day'] ) {
|
||||||
if ( ! $this->is_date ) {
|
if ( ! $this->is_date ) {
|
||||||
$this->is_day = true;
|
$date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] );
|
||||||
$this->is_date = true;
|
if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) {
|
||||||
|
$qv['error'] = '404';
|
||||||
|
} else {
|
||||||
|
$this->is_day = true;
|
||||||
|
$this->is_date = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $qv['monthnum'] ) {
|
if ( $qv['monthnum'] ) {
|
||||||
if ( ! $this->is_date ) {
|
if ( ! $this->is_date ) {
|
||||||
$this->is_month = true;
|
if ( 12 < $qv['monthnum'] ) {
|
||||||
$this->is_date = true;
|
$qv['error'] = '404';
|
||||||
|
} else {
|
||||||
|
$this->is_month = true;
|
||||||
|
$this->is_date = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue