Skip to content

Do not use a failed insert's Error object as a post ID - #331

Open
mrcgrtz wants to merge 1 commit into
indieweb:trunkfrom
mrcgrtz:fix/error-as-post-id
Open

Do not use a failed insert's Error object as a post ID#331
mrcgrtz wants to merge 1 commit into
indieweb:trunkfrom
mrcgrtz:fix/error-as-post-id

Conversation

@mrcgrtz

@mrcgrtz mrcgrtz commented Aug 24, 2026

Copy link
Copy Markdown

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

(Found this in my logs.)

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant