Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Give `null` as date for draft posts #230

Merged
merged 1 commit into from

2 participants

@rmccue
Owner

Fixes #229.

@rmccue
Owner

@rachelbaker #reviewmerge

@rmccue rmccue added this to the 1.1 milestone
@rmccue rmccue added the Bug label
@rachelbaker rachelbaker was assigned by rmccue
@rmccue rmccue added Has Patch Review and removed Has Patch labels
@rachelbaker rachelbaker merged commit 1fd78d3 into from
@rachelbaker rachelbaker deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 27, 2014
  1. @rmccue
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 9 deletions.
  1. +24 −9 lib/class-wp-json-posts.php
View
33 lib/class-wp-json-posts.php
@@ -642,15 +642,30 @@ protected function prepare_post( $post, $context = 'view' ) {
// Dates
$timezone = $this->server->get_timezone();
- $date = WP_JSON_DateTime::createFromFormat( 'Y-m-d H:i:s', $post['post_date'], $timezone );
- $post_fields['date'] = $date->format( 'c' );
- $post_fields_extended['date_tz'] = $date->format( 'e' );
- $post_fields_extended['date_gmt'] = date( 'c', strtotime( $post['post_date_gmt'] ) );
-
- $modified = WP_JSON_DateTime::createFromFormat( 'Y-m-d H:i:s', $post['post_modified'], $timezone );
- $post_fields['modified'] = $modified->format( 'c' );
- $post_fields_extended['modified_tz'] = $modified->format( 'e' );
- $post_fields_extended['modified_gmt'] = date( 'c', strtotime( $post['post_modified_gmt'] ) );
+
+ if ( $post['post_date_gmt'] === '0000-00-00 00:00:00' ) {
+ $post_fields['date'] = null;
+ $post_fields_extended['date_tz'] = null;
+ $post_fields_extended['date_gmt'] = null;
+ }
+ else {
+ $date = WP_JSON_DateTime::createFromFormat( 'Y-m-d H:i:s', $post['post_date'], $timezone );
+ $post_fields['date'] = $date->format( 'c' );
+ $post_fields_extended['date_tz'] = $date->format( 'e' );
+ $post_fields_extended['date_gmt'] = date( 'c', strtotime( $post['post_date_gmt'] ) );
+ }
+
+ if ( $post['post_modified_gmt'] === '0000-00-00 00:00:00' ) {
+ $post_fields['modified'] = null;
+ $post_fields_extended['modified_tz'] = null;
+ $post_fields_extended['modified_gmt'] = null;
+ }
+ else {
+ $modified = WP_JSON_DateTime::createFromFormat( 'Y-m-d H:i:s', $post['post_modified'], $timezone );
+ $post_fields['modified'] = $modified->format( 'c' );
+ $post_fields_extended['modified_tz'] = $modified->format( 'e' );
+ $post_fields_extended['modified_gmt'] = date( 'c', strtotime( $post['post_modified_gmt'] ) );
+ }
// Authorized fields
// TODO: Send `Vary: Authorization` to clarify that the data can be
Something went wrong with that request. Please try again.