-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Fatal for unregistered taxonomy (#26851) #26854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this one. I see that you are right about get_the_terms
and its return value.
Should we add this check to the existing condition?
@@ -19,6 +19,9 @@ function render_block_core_post_hierarchical_terms( $attributes, $content, $bloc | |||
} | |||
|
|||
$post_hierarchical_terms = get_the_terms( $block->context['postId'], $attributes['term'] ); | |||
if ( is_wp_error( $post_hierarchical_terms ) ) { | |||
return ''; | |||
} | |||
if ( empty( $post_hierarchical_terms ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new condition could be combined with empty
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. What do the coding guidelines say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of coding styles that cover it. I can merge as is if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. Then I can continue working on PRs for other issues.
Description
When the
core/post-hierarchical-terms
block has been passed an invalid taxonomy name for theterm
attribute it produced a Fatal error due to not detecting a WordPress error (WP_error
object ) returned fromget_the_terms()
.This fix adds an
is_wp_error()
test, returning an empty string when detected.How has this been tested?
Tested with Twenty Twenty-One Blocks in WordPress 5.6-beta3
I manually created a post using the code editor containing.
Prior to applying the fix I got the Fatal error.
After applying the fix the output showed the taxonomy terms associated with Categories.
There was no visible output for the unknown taxonomy.
With the fix applied the post could be viewed and edited, using both the Code and Visual editor.
Screenshots
Types of changes
Fixes #26851
Checklist: