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-admin/includes/post.php

    r21857 r21921  
    123123        $mn = ($mn > 59 ) ? $mn -60 : $mn;
    124124        $ss = ($ss > 59 ) ? $ss -60 : $ss;
     125        $valid_date = apply_filters( '_wp_translate_postdata_valid_date', checkdate( $mm, $jj, $aa ), $post_data );
     126        if ( !$valid_date ) {
     127            return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
     128        }
    125129        $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
    126130        $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
Note: See TracChangeset for help on using the changeset viewer.