WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 2 weeks ago

#45322 reviewing defect (bug)

Editing a draft post with wp.editPost causes its published date to be set

Reported by: redsweater Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: has-unit-tests needs-refresh has-patch early
Focuses: Cc:

Description

This bug exhibits the exact same behavior as #16985 did for the MetaWeblog-based API before wp.editPost came along. When wp.editPost was implemented, evidently a regression occurred causing the buggy behavior to rear its head again.

The practical effect of this bug is that a draft post submitted by an API client, and then edited by an API client, will have its publish date "locked in time" to the original submission time. So for example if you start a draft post on May 1, and edit it for two weeks before publishing on May 15, the published post will have a publish date of May 1.

To reproduce using the WordPress XMLRPC API:

  1. Create a new draft status post using wp.newPost, omitting dates from the submitted post. This results in a post that has a post_date_gmt that is zeroed out, reflecting the fact it should receive the current time when the post is changed from Draft to Publish.
  1. Edit that draft post using wp.editPost, again omitting any dates.

Expected result: the draft post should still have zeroed out publish date (post_date_gmt).

Actual result: the post now has a post_date_gmt value matching the original post_date value that was created when the draft was submitted.

The bug appears to be rooted in the wp.editPost implementation in class-wp-xmlrpc-server.php. Because this method uses the existing post struct from the database as a baseline of all submitted content, the post_date value ends up being set on the struct that is passed to _insert_post. But _insert_post makes assumptions about client intent based on the presence of or absence of values on that struct. So in this case the post_date value on the struct is interpreted as being a client-asserted publish date for the post.

I'm attaching a patch with a possible fix, which is to make a point of unsetting the post_date value on the struct whenever the post_date value is missing from the content_struct provided by the API client.

Attachments (3)

fix-wp-editpost-draft-dates.patch (960 bytes) - added by redsweater 7 months ago.
Patch to fix the described the bug
fix-wp-editpost-draft-dates.2.patch (960 bytes) - added by redsweater 7 months ago.
Tests confirming the fix included in the other attachment
test-wp-editpost-draft-dates.patch (1.4 KB) - added by redsweater 7 months ago.
Tests confirming the fix included in the other attachment

Download all attachments as: .zip

Change History (17)

@redsweater
7 months ago

Patch to fix the described the bug

This ticket was mentioned in Slack in #mobile by redsweater. View the logs.


7 months ago

This ticket was mentioned in Slack in #core by redsweater. View the logs.


7 months ago

#3 @redsweater
7 months ago

I am going to work on unit tests to attach along with the code patch.

#4 @danielbachhuber
7 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

@redsweater
7 months ago

Tests confirming the fix included in the other attachment

@redsweater
7 months ago

Tests confirming the fix included in the other attachment

#5 @redsweater
7 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

I accidentally added the fix patch twice and don't know how to delete. I added a patch with unit tests. Let me know if there's anything else I can do to encourage incorporating this fix. Thanks!

This ticket was mentioned in Slack in #core by redsweater. View the logs.


7 months ago

#7 @SergeyBiryukov
7 months ago

  • Milestone changed from Future Release to 5.1
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#8 @pento
5 months ago

  • Milestone changed from 5.1 to 5.2

Patch needs review and testing.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


2 months ago

#10 @audrasjb
2 months ago

  • Keywords needs-refresh added
  • Milestone changed from 5.2 to 5.3

As per today's bug scrub, we are going to punt this one to the next release since beta 3 and RC are approaching.

#11 @redsweater
2 months ago

Thanks! I would still love to see this fix taken at some point. I think it's low risk and it will have an immediate benefit for users of apps that publish via the API.

This ticket was mentioned in Slack in #core by redsweater. View the logs.


7 weeks ago

#13 @Otto42
2 weeks ago

  • Keywords early added

This seems like a fairly simple fix that should land early in 5.3, for soak.

#14 @redsweater
2 weeks ago

Thanks, @Otto42 !

Note: See TracTickets for help on using tickets.