WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/19/2012 09:43:35 PM (8 years ago)
Author:
westi
Message:

Posting: Make it much harder to create posts with invalid dates by enforcing the post date tests in the UI and the backend code.

Previously you could quite easily send a new post into the back of beyond by specifying an invalid date like the 30th Feb and this was very confusing.
Sometimes it would seem to work and sometimes the post would end up very far in the past - depending on the mysql version and other factors.

Fixes #17180 props jkudish.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r21847 r21921  
    26342634        $post_date = current_time('mysql');
    26352635
     2636        // validate the date
     2637        $mm = substr( $post_date, 5, 2 );
     2638        $jj = substr( $post_date, 8, 2 );
     2639        $aa = substr( $post_date, 0, 4 );
     2640        $valid_date = apply_filters( 'wp_insert_post_validate_date', checkdate( $mm, $jj, $aa ), $post_date );
     2641        if ( !$valid_date ) {
     2642            return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
     2643        }
     2644
    26362645    if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
    26372646        if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
Note: See TracChangeset for help on using the changeset viewer.