diff --git src/wp-includes/rest-api.php src/wp-includes/rest-api.php
index 31223c6f30..92e6af0d41 100644
|
|
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
1206 | 1206 | if ( isset( $args['format'] ) ) { |
1207 | 1207 | switch ( $args['format'] ) { |
1208 | 1208 | case 'date-time': |
1209 | | if ( ! rest_parse_date( $value ) ) { |
| 1209 | if ( '' !== $value && ! rest_parse_date( $value ) ) { |
1210 | 1210 | return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) ); |
1211 | 1211 | } |
1212 | 1212 | break; |
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index eff50e8e75..865694f97c 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | |
| 1039 | // Sending a blank date or date_gmt value resets date and date_gmt to their default values (`0000-00-00 00:00:00`). |
| 1040 | if ( |
| 1041 | ( isset( $request[ 'date_gmt' ] ) && '' === $request[ 'date_gmt' ] ) || |
| 1042 | ( isset( $request[ 'date' ] ) && '' === $request[ 'date' ] ) |
| 1043 | ) { |
| 1044 | $prepared_post->post_date_gmt = null; |
| 1045 | $prepared_post->post_date = null; |
| 1046 | } |
| 1047 | |
1039 | 1048 | // Post slug. |
1040 | 1049 | if ( ! empty( $schema['properties']['slug'] ) && isset( $request['slug'] ) ) { |
1041 | 1050 | $prepared_post->post_name = $request['slug']; |