Make WordPress Core

Changeset 21921


Ignore:
Timestamp:
09/19/2012 09:43:35 PM (12 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.

Location:
trunk
Files:
3 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'] );
  • trunk/wp-admin/js/post.js

    r21789 r21921  
    527527            }
    528528            return false;
     529        });
     530
     531        $('#post').submit(function(e){
     532            if ( !updateText() ) {
     533                e.preventDefault();
     534                $('#timestampdiv').show();
     535                $('#publishing-action .ajax-loading').css('visibility', 'hidden');
     536                $('#publish').prop('disabled', false).removeClass('button-primary-disabled');
     537                return false;
     538            }
    529539        });
    530540
  • 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.