Return errors from wp_insert_post / wp_update_post failures - #320
Merged
Conversation
Previously, when wp_insert_post or wp_update_post returned a WP_Error, the error was wrapped and stored in $args['ID'] but the array was returned as if creation succeeded. The endpoint then responded with HTTP 201 and a body containing the error nested inside the ID field. Propagate the Micropub error from handle_create() and handle_update() when insertion fails, and default micropub_wp_error()'s status to 400 instead of 200 since a WP_Error always indicates failure. Fixes #319
Member
|
This makes sense to me |
dshanske
self-requested a review
May 2, 2026 17:51
dshanske
approved these changes
May 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #319.
When
wp_insert_postorwp_update_postreturned aWP_Error,check_error()wrapped it as a MicropubErrorand stored it in$args['ID'], buthandle_create()/handle_update()returned the$argsarray as if the operation had succeeded. The endpoint then responded with HTTP 201 and a body that included the error nested inside theIDfield, pluspost_url: falseandLocation: false.handle_create()andhandle_update()when insertion fails, socreate_item()returns a proper error response.micropub_wp_error()from 200 to 400. AWP_Erroralways indicates failure, so a 200 default never made sense; this also surfaces the correct status forwp_insert_post's built-in errors (likeempty_content) which carry nostatusdata.Test plan
test_create_returns_error_when_wp_insert_post_failsreproduces the exact scenario from Errors return HTTP 201 status #319 (uses thewp_insert_post_empty_contentfilter to force the error). Fails ontrunk(returns 201), passes with the fix (returns 400 witherror: empty_content).