diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index fe3c7f1210..9011f49cc7 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1385,7 +1385,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } if ( ! empty( $schema['properties']['date_gmt'] ) ) { - $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt ); + // For drafts, `post_date_gmt` may not be set, indicating that the + // date of the draft should be updated each time it is saved (see + // #38883). In this case, shim the value based on the `post_date` + // field with the site's timezone offset applied. + if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { + $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) - ( get_option( 'gmt_offset' ) * 3600 ) ); + } else { + $post_date_gmt = $post->post_date_gmt; + } + $data['date_gmt'] = $this->prepare_date_response( $post_date_gmt ); } if ( ! empty( $schema['properties']['guid'] ) ) { @@ -1401,7 +1410,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } if ( ! empty( $schema['properties']['modified_gmt'] ) ) { - $data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt ); + // For drafts, `post_modified_gmt` may not be set (see + // `post_date_gmt` comments above). In this case, shim the value + // based on the `post_modified` field with the site's timezone + // offset applied. + if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) { + $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - ( get_option( 'gmt_offset' ) * 3600 ) ); + } else { + $post_modified_gmt = $post->post_modified_gmt; + } + $data['modified_gmt'] = $this->prepare_date_response( $post_modified_gmt ); } if ( ! empty( $schema['properties']['password'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 4ef4490f99..7658062dd4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7.3-alpha-40114'; +$wp_version = '4.7.3-alpha-40115'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.