WordPress.org

Make WordPress Core

Ticket #44975: 44975.diff

File 44975.diff, 1.5 KB (added by adamsilverstein, 15 months ago)
  • src/wp-includes/rest-api.php

    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 = '' ) { 
    12061206        if ( isset( $args['format'] ) ) {
    12071207                switch ( $args['format'] ) {
    12081208                        case 'date-time':
    1209                                 if ( ! rest_parse_date( $value ) ) {
     1209                                if ( '' !== $value && ! rest_parse_date( $value ) ) {
    12101210                                        return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) );
    12111211                                }
    12121212                                break;
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    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 { 
    10361036                        }
    10371037                }
    10381038
     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
    10391048                // Post slug.
    10401049                if ( ! empty( $schema['properties']['slug'] ) && isset( $request['slug'] ) ) {
    10411050                        $prepared_post->post_name = $request['slug'];