Posting: Improve the invalid date protection code based on feedback from nacin.
* Introduce a wp_checkdate() function with a single filter to centralise the code that validates dates. * Improve the error message * Correctly handle the return value of wp_insert_post which is not always a WP_Error on failure Fixes #17180 git-svn-id: http://core.svn.wordpress.org/trunk@21922 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -122,11 +122,11 @@ 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 );
|
||||
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
|
||||
if ( !$valid_date ) {
|
||||
return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
|
||||
}
|
||||
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user