diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 223f1b9728..8296607968 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -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'] ); } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 631be64dc1..e78be346b0 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3703,3 +3703,13 @@ function _device_can_upload() { return true; } +/** + * Test if the supplied date is valid for the Gregorian calendar + * + * @since 3.5.0 + * + * @return bool true|false + */ +function wp_checkdate( $month, $day, $year, $source_date ) { + return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); +} \ No newline at end of file diff --git a/wp-includes/post.php b/wp-includes/post.php index ff544404f9..b2c3c8f5d1 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2637,9 +2637,12 @@ function wp_insert_post($postarr, $wp_error = false) { $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 ); + $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); if ( !$valid_date ) { - return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) ); + if ( $wp_error ) + return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); + else + return 0; } if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {