#23474 closed defect (bug) (fixed)
wp_update_post returns incorrect WP_Error on invalid ID (if $wp_error is set)
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 3.6 | Priority: | normal |
| Severity: | normal | Version: | 3.5 |
| Component: | Warnings/Notices | Keywords: | has-patch |
| Focuses: | Cc: |
Description
$post_data = array( 'ID' => 999, // Does not exist 'post_title' => 'Test title', ); $res = wp_update_post( $post_data, true ); error_log( $res->get_error_message() ); // 'Content, title, and excerpt are empty.'
The error is misleading, and further an array_merge notice is thrown as the null returned by get_post is not an array.
Attachments (1)
Change History (10)
#2
@
13 years ago
- Component changed from General to Warnings/Notices
- Milestone changed from Awaiting Review to 3.6
#3
@
13 years ago
I guess wp_update_post() can hypothetically be used to create posts, but since wp_insert_post() then assumes if an ID is passed it is dealing with an update, things start to get wonky.
It would likely be best to fix this in both functions.
We can use "Invalid post ID." which is an existing string.
#5
@
13 years ago
Replying to nacin:
I guess wp_update_post() can hypothetically be used to create posts, but since wp_insert_post() then assumes if an ID is passed it is dealing with an update, things start to get wonky.
It would likely be best to fix this in both functions.
The patch now handles wp_update_post and wp_insert_post. Same error for both.
We can use "Invalid post ID." which is an existing string.
Done.
#7
@
13 years ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In 23740:
Patch
#23474.diffmodifieswp_update_postto return0if the$wp_errorparam is false, and to return aWP_Errorobject with an appropriate message and code otherwise.