$fields =
$this->
get_fields_for_response( $request );
// Base fields for every post.
$data = array
();
if ( rest_is_field_included( 'id',
$fields ) ) { $data['id'
] =
$post->ID;
} if ( rest_is_field_included( 'date',
$fields ) ) { $data['date'
] =
$this->
prepare_date_response( $post->post_date_gmt,
$post->post_date
);
} if ( rest_is_field_included( 'date_gmt',
$fields ) ) { /*
* 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 =
get_gmt_from_date( $post->post_date
);
}