Tag person categories by their URL instead of crashing - #332
Open
mrcgrtz wants to merge 1 commit into
Open
Conversation
A category is not always a string. Person tags are sent as nested h-cards,
for example by OwnYourSwarm on a check-in:
"category": [ { "type": [ "h-card" ], "properties": { … } } ]
mp_to_wp() passed every category it could not resolve to an existing
WordPress category straight into tags_input, so the h-card array reached
trim() inside wp_set_object_terms() and raised a TypeError on PHP 8. That
happens inside wp_insert_post() after the row is written but before
meta_input is stored, so the post survived without any mf2_* or geo_* value
and the request died with a 500.
Resolve an h-card to its URL and tag the person with that. An h-card without
a URL, or a nested object of some other kind, yields no term rather than a
fatal. Scalar categories keep their existing handling, including integers,
which WordPress resolves as term IDs.
The full h-card is unaffected in the mf2_category meta: store_mf2() builds
that from $this->input rather than from these arguments, so the people
tagged in a check-in stay recorded in full, and now get a post tag too.
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.
Another error I found in my logs:
A category is not always a string. Person tags are sent as nested h-cards, for example by OwnYourSwarm on a check-in:
mp_to_wp()passed every category it could not resolve to an existing WordPress category straight intotags_input, so the h-card array reachedtrim()insidewp_set_object_terms()and raised a TypeError on PHP 8. That happens insidewp_insert_post()after the row is written but beforemeta_inputis stored, so the post survived without anymf2_*orgeo_*value and the request died with a 500.Resolve an h-card to its URL and tag the person with that. An h-card without a URL, or a nested object of some other kind, yields no term rather than a fatal. Scalar categories keep their existing handling, including integers, which WordPress resolves as term IDs.
The full h-card is unaffected in the
mf2_categorymeta:store_mf2()builds that from$this->inputrather than from these arguments, so people tagged in a Swarm check-in stay recorded in full, and now get a post tag too.Fixes #329