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. git-svn-id: https://develop.svn.wordpress.org/trunk@21921 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
42f1232e5e
commit
59dd4b7d2b
@ -122,6 +122,10 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
|
||||
$hh = ($hh > 23 ) ? $hh -24 : $hh;
|
||||
$mn = ($mn > 59 ) ? $mn -60 : $mn;
|
||||
$ss = ($ss > 59 ) ? $ss -60 : $ss;
|
||||
$valid_date = apply_filters( '_wp_translate_postdata_valid_date', checkdate( $mm, $jj, $aa ), $post_data );
|
||||
if ( !$valid_date ) {
|
||||
return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
|
||||
}
|
||||
$post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
|
||||
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
|
||||
}
|
||||
|
@ -528,6 +528,16 @@ jQuery(document).ready( function($) {
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#post').submit(function(e){
|
||||
if ( !updateText() ) {
|
||||
e.preventDefault();
|
||||
$('#timestampdiv').show();
|
||||
$('#publishing-action .ajax-loading').css('visibility', 'hidden');
|
||||
$('#publish').prop('disabled', false).removeClass('button-primary-disabled');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$('#post-status-select').siblings('a.edit-post-status').click(function() {
|
||||
if ($('#post-status-select').is(":hidden")) {
|
||||
$('#post-status-select').slideDown('fast');
|
||||
|
@ -2633,6 +2633,15 @@ function wp_insert_post($postarr, $wp_error = false) {
|
||||
if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date )
|
||||
$post_date = current_time('mysql');
|
||||
|
||||
// validate the date
|
||||
$mm = substr( $post_date, 5, 2 );
|
||||
$jj = substr( $post_date, 8, 2 );
|
||||
$aa = substr( $post_date, 0, 4 );
|
||||
$valid_date = apply_filters( 'wp_insert_post_validate_date', checkdate( $mm, $jj, $aa ), $post_date );
|
||||
if ( !$valid_date ) {
|
||||
return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
|
||||
}
|
||||
|
||||
if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
|
||||
if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
|
||||
$post_date_gmt = get_gmt_from_date($post_date);
|
||||
|
Loading…
Reference in New Issue
Block a user