#45322 closed defect (bug) (fixed)
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 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:
- 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.
- 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)
Change History (22)
This ticket was mentioned in Slack in #mobile by redsweater. View the logs.
6 years ago
This ticket was mentioned in Slack in #core by redsweater. View the logs.
6 years ago
#4
@
6 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
#5
@
6 years 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.
6 years ago
#7
@
6 years ago
- Milestone changed from Future Release to 5.1
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
5 years ago
#10
@
5 years 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
@
5 years 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.
5 years ago
#13
@
5 years ago
- Keywords early added
This seems like a fairly simple fix that should land early in 5.3, for soak.
Patch to fix the described the bug