Do not use a failed insert's Error object as a post ID - #331
Open
mrcgrtz wants to merge 1 commit into
Open
Conversation
check_error() returns a Micropub\Error rather than throwing, so when
wp_insert_post() fails, $args['ID'] holds an object. An object is truthy, so
the guard on $args['ID'] let it through and the Error reached
wp_set_object_terms() as $object_id, which casts it to int:
PHP Warning: Object of class Micropub\Error could not be converted to int
in wp-includes/taxonomy.php
get_permalink() then received the same object and produced a bogus post_url.
handle_create() does check is_micropub_error( $args['ID'] ), but only after
insert_post() has returned, by which point both calls have already run.
Test for the error explicitly and return early. kses_init_filters() moves up
to directly after the insert so the filters are restored on the error path
too — it only needs to be suspended for wp_insert_post() itself.
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.
check_error()returns aMicropub\Errorrather than throwing, so whenwp_insert_post()fails,$args['ID']holds an object. An object is truthy, so the guard on$args['ID']let it through and the Error reachedwp_set_object_terms()as$object_id, which casts it to int:(Found this in my logs.)
get_permalink()then received the same object and produced a boguspost_url.handle_create()does checkis_micropub_error( $args['ID'] ), but only afterinsert_post()has returned, by which point both calls have already run.Test for the error explicitly and return early.
kses_init_filters()moves up to directly after the insert so the filters are restored on the error path too — it only needs to be suspended forwp_insert_post()itself.