WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2019 05:24:58 PM (19 months ago)
Author:
kadamwhite
Message:

REST API: Pass "null" as the post date property to reset post to initial "floating" date value.

Props TimothyBlynJacobs, adamsilverstein, jnylen0, mnelson4.
Fixes #44975.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r46184 r46249  
    10371037        }
    10381038
     1039        // Sending a null date or date_gmt value resets date and date_gmt to their
     1040        // default values (`0000-00-00 00:00:00`).
     1041        if (
     1042            ( ! empty( $schema['properties']['date_gmt'] ) && $request->has_param( 'date_gmt' ) && null === $request['date_gmt'] ) ||
     1043            ( ! empty( $schema['properties']['date'] ) && $request->has_param( 'date' ) && null === $request['date'] )
     1044        ) {
     1045            $prepared_post->post_date_gmt = null;
     1046            $prepared_post->post_date     = null;
     1047        }
     1048
    10391049        // Post slug.
    10401050        if ( ! empty( $schema['properties']['slug'] ) && isset( $request['slug'] ) ) {
     
    18921902                'date'         => array(
    18931903                    'description' => __( "The date the object was published, in the site's timezone." ),
    1894                     'type'        => 'string',
     1904                    'type'        => array( 'string', 'null' ),
    18951905                    'format'      => 'date-time',
    18961906                    'context'     => array( 'view', 'edit', 'embed' ),
     
    18981908                'date_gmt'     => array(
    18991909                    'description' => __( 'The date the object was published, as GMT.' ),
    1900                     'type'        => 'string',
     1910                    'type'        => array( 'string', 'null' ),
    19011911                    'format'      => 'date-time',
    19021912                    'context'     => array( 'view', 'edit' ),
Note: See TracChangeset for help on using the changeset viewer.