Make WordPress Core


Ignore:
Timestamp:
09/06/2013 04:35:22 PM (12 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r24594 r25280  
    100100                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
    101101            }
     102        }
     103
     104        if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) {
     105            $year  = get_query_var( 'year' );
     106            $month = get_query_var( 'monthnum' );
     107            $day   = get_query_var( 'day' );
     108            $date  = sprintf( '%04d-%02d-%02d', $year, $month, $day );
     109            if ( ! wp_checkdate( $month, $day, $year, $date ) ) {
     110                $redirect_url = get_month_link( $year, $month );
     111                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url );
     112            }
     113        } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) {
     114            $redirect_url = get_year_link( get_query_var( 'year' ) );
     115            $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url );
    102116        }
    103117
Note: See TracChangeset for help on using the changeset viewer.