Opened 10 years ago
Closed 3 years ago
#30009 closed defect (bug) (fixed)
_wp_put_post_revision checks for errors incorrectly
Reported by: | rmccue | Owned by: | whyisjake |
---|---|---|---|
Milestone: | 5.8 | Priority: | normal |
Severity: | minor | Version: | 2.6 |
Component: | Revisions | Keywords: | has-patch has-unit-tests commit |
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 (6)
Change History (17)
#1
follow-up:
↓ 2
@
10 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
@
10 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
@
9 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
@
6 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
#6
@
4 years ago
Just came here to report this same issue. Looks like 30009.4.diff would be a quick fix.
#7
@
4 years ago
- Milestone changed from Awaiting Review to 5.8
- Owner changed from rmccue to SergeyBiryukov
- Status changed from assigned to reviewing
This ticket was mentioned in PR #1279 on WordPress/wordpress-develop by adamsilverstein.
3 years ago
#8
Trac ticket: https://core.trac.wordpress.org/ticket/30009
#9
@
3 years ago
- Keywords has-unit-tests commit added; dev-feedback removed
@SergeyBiryukov I added a test and am running all tests in https://github.com/WordPress/wordpress-develop/pull/1279.
If everything looks good, this is ready for commit. Before this fix is_wp_error
on line 274 would never pass!
#10
@
3 years ago
30009.5.diff includes a test to verify a WP_Error is returned now. I was able to trigger an error by passing an invalid post ID directly to the inner function.
Specify we want a WP_Error on insertion error