Skip to content
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

Merged
merged 1 commit into from
Nov 15, 2020

Conversation

bobbingwide
Copy link
Contributor

Description

When the core/post-hierarchical-terms block has been passed an invalid taxonomy name for the term attribute it produced a Fatal error due to not detecting a WordPress error ( WP_error object ) returned from get_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.

<!-- wp:post-hierarchical-terms {"term":"26851"} /-->

<!-- wp:post-hierarchical-terms {"term":"category"} /-->

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

image

Types of changes

Fixes #26851

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@gziolo gziolo added [Block] Post Terms Affects the Post Terms Block [Type] Bug An existing feature does not function as intended labels Nov 14, 2020
Copy link
Member

@gziolo gziolo left a 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 ) ) {
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@gziolo gziolo merged commit 98df266 into WordPress:master Nov 15, 2020
@github-actions github-actions bot added this to the Gutenberg 9.4 milestone Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Terms Affects the Post Terms Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal error in post-hierarchical-terms.php for unregistered taxonomy name
2 participants