Ticket #17180: 17180.improvements.diff

File 17180.improvements.diff, 2.3 KB (added by westi, 8 months ago)

Improvements based on nacin's feedback

Line 
1Index: wp-includes/post.php
2===================================================================
3--- wp-includes/post.php        (revision 21921)
4+++ wp-includes/post.php        (working copy)
5@@ -2637,9 +2637,12 @@
6                $mm = substr( $post_date, 5, 2 );
7                $jj = substr( $post_date, 8, 2 );
8                $aa = substr( $post_date, 0, 4 );
9-               $valid_date = apply_filters( 'wp_insert_post_validate_date', checkdate( $mm, $jj, $aa ), $post_date );
10+               $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
11                if ( !$valid_date ) {
12-                       return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
13+                       if ( $wp_error )
14+                               return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
15+                       else
16+                               return 0;
17                }
18 
19        if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
20Index: wp-includes/functions.php
21===================================================================
22--- wp-includes/functions.php   (revision 21920)
23+++ wp-includes/functions.php   (working copy)
24@@ -3703,3 +3703,13 @@
25        return true;
26 }
27 
28+/**
29+ * Test if the supplied date is valid for the Gregorian calendar
30+ *
31+ * @since 3.5.0
32+ *
33+ * @return bool true|false
34+ */
35+function wp_checkdate( $month, $day, $year, $source_date ) {
36+       return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
37+}
38\ No newline at end of file
39Index: wp-admin/includes/post.php
40===================================================================
41--- wp-admin/includes/post.php  (revision 21921)
42+++ wp-admin/includes/post.php  (working copy)
43@@ -122,11 +122,11 @@
44                $hh = ($hh > 23 ) ? $hh -24 : $hh;
45                $mn = ($mn > 59 ) ? $mn -60 : $mn;
46                $ss = ($ss > 59 ) ? $ss -60 : $ss;
47-               $valid_date = apply_filters( '_wp_translate_postdata_valid_date', checkdate( $mm, $jj, $aa ), $post_data );
48+               $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
49+               $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
50                if ( !$valid_date ) {
51-                       return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
52+                       return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
53                }
54-               $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
55                $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
56        }
57