Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#43219 closed defect (bug) (worksforme)

wp.api.models.Post.save method should not send date fields for drafts

Reported by: goldenapples's profile goldenapples Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: REST API Keywords:
Focuses: javascript, rest-api Cc:

Description

When a new Post model is created through the REST API client, it will be hydrated complete with "date_gmt" and "date_modified_gmt" properties as a result of the changeset in https://core.trac.wordpress.org/changeset/40115

However, those properties are not filtered out before saving the model, and so the date_gmt field is posted as part of the save request. This causes inconsistencies with the way core leaves the post_date_gmt field as zeroes for unpublished posts.

In addition, if the "date" field is posted when saving the model, a "date_gmt" field will be created from it in the WP_REST_Posts_Controller::prepare_item_for_database method.

I'm not sure what the best way of addressing this is, but it seems like two changes are in order.

  • Perhaps the API schema for a post could set a flag indicating whether the value returned for 'date_gmt' or 'date_modified_gmt' is a real value or a shimmed date that should not be saved, and, if that flag is set, the Backbone client would be responsible for unsetting that field before saving.
  • In WP_REST_Posts_Controller::prepare_item_for_database, a draft post with a "date" field set shouldn't be passing a value in post_date_gmt along to wp_update_post - that's different behavior than saving in any other way and is unexpected. I could well be missing something, but it seems like that logic could be removed safely.

Change History (4)

This ticket was mentioned in Slack in #core-restapi by schlessera. View the logs.


6 years ago

#2 @schlessera
6 years ago

  • Milestone changed from Awaiting Review to 5.0

#3 @danielbachhuber
6 years ago

  • Focuses rest-api added
  • Milestone changed from 5.0 to Future Release

Bumping out of 5.0 because it's not necessary for Gutenberg.

#4 @TimothyBlynJacobs
4 years ago

  • Focuses javascript added
  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I think this has now been fixed on the server side of things #39953.

Note: See TracTickets for help on using tickets.