Opened 6 years ago
Last modified 21 months ago
#30009 assigned defect (bug)
_wp_put_post_revision checks for errors incorrectly
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | 2.6 |
Component: | Revisions | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
_wp_put_post_revision
uses wp_insert_post
, then checks is_wp_error
to pass it up the stack (lines 259-261). However, wp_insert_post
only returns a WP_Error
if the second param is true. In this case, it is not.
Introduced in r7907.
Attachments (4)
Change History (8)
#1
follow-up:
↓ 2
@
6 years ago
- Keywords has-patch added
- Owner set to rmccue
- Status changed from new to assigned
Attached patches specify that we want a WP_Error
back from wp_insert_post
, pretty straight forward patch.
30009.diff fixes the problem, 30009.2.diff goes a bit further and corrects coding standards in the function while we're in there.
#2
in reply to:
↑ 1
@
6 years ago
looks good. I updated the doc block slightly in 30009.3.diff to reflect the return value.
I tried to write a unit test for this and couldn't actually get wp_insert_post
to return an error - it only does so when get_post( post_id ) fails (returns null) and that check already happens earlier in _wp_put_post_revision
. For this reason, I believe we could remove the entire error check conditional, we are returning $revision_id in any case...
Good catch in any case, the check as is will never work!
Replying to rmccue:
Attached patches specify that we want a
WP_Error
back fromwp_insert_post
, pretty straight forward patch.
30009.diff fixes the problem, 30009.2.diff goes a bit further and corrects coding standards in the function while we're in there.
#3
@
5 years ago
- Keywords dev-feedback added
- Refresh against trunk
Lets keep this patch simple and stick to adding the true
value to wp_insert_post
so it will potentially return the WP_Error we are looking out for.
#5
@
2 years ago
Fine leaving closed, this was fixed in WordPress 5.0: https://github.com/WordPress/wordpress-develop/blob/c2390f96a212aa57afe076bfe098c5b1676f5ec6/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L365
Specify we want a WP_Error on insertion error