Change term objects in format_hits_as_terms
to WP_Term
instead of stdClass
#2913
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.
Description of the Change
The description of the
format_hits_as_terms
method reads like this:This pull request makes the term objects into
WP_Term
objects instead ofstdClass
objects. This brings it in line with how WordPress uses this result in actions likepost_tag_row_actions
, which specify that the term parameter should be aWP_Term
object.I'm not aware of any drawbacks, but I do realize that this method has been returning
stdClass
objects, even if incorrectly, for some time. I think likely this is causing issues unless the code using it is not using standard WordPress methods, but that is worth noting.An alternative would be to add a filter instead, allowing developers to use
WP_Term
on their own. Ex:$term = apply_filters( 'ep_wp_query_terms_object', $term );
. I don't think that is ideal, but if it's necessary for backward compatibility I would understand that.Closes #2912
How to test the Change
The way I found this was using The Events Calendar:
post_tag
, at least, with some post tags./wp-admin/edit-tags.php?taxonomy=post_tag&post_type=post
and search for a value that will return some tags. Instead of giving a fatal error, it will return the same data but formatted as aWP_Term
object. Verify by logging in these lines like this:Changelog Entry
Credits
Props @jonathanstegall
Checklist:
I don't see any documentation or relevant tests, but am willing to update those if they do apply.