Skip to content

Fatal error in post-hierarchical-terms.php for unregistered taxonomy name #26851

@bobbingwide

Description

@bobbingwide

Describe the bug
When the core/post-hierarchical-terms block is invoked with a taxonomy name that's not registered a Fatal error is issued.
This is due to the logic trying to process a WP_error.

To reproduce
Steps to reproduce the behavior:

  1. Create a template containing the core/post-hierarchical-terms block with an unknown taxonomy name.
 <!-- wp:post-hierarchical-terms {"term":"26851"} /-->
  1. Attempt to view content using this template.
  2. See two Notices and a Fatal error

Notice: Trying to get property 'term_id' of non-object in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php on line 32

Notice: Trying to get property 'name' of non-object in C:\apache\htdocs\wp55\wp-content\plugins\gutenberg\build\block-library\blocks\post-hierarchical-terms.php on line 33

Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string.

Expected behavior
Fail gracefully by returning '' when a WP_Error has been detected.

Screenshots

Editor version (please complete the following information):

  • WordPress version: [e.g: 5.3.2] 5.6-beta3
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? [e.g: "gutenberg plugin", "default"] 9.3.0
  • If the Gutenberg plugin is installed, which version is it? [e.g., 7.6]

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] Version 86.0.4240.183 (Official Build) (64-bit)

Additional context

  • Originally raised as Fatal error in post-hierarchical-terms.php bobbingwide/fizzie#29

  • In my opinion the attribute should not be called term; it is the taxonomy name.

  • It is possible to create this problem using the Code editor in a post.

  • If you do so, and you quit the editor in Visual editor mode, then you may find it difficult to fix the error.

  • The problem occurs in the editor as well as the front-end.

  • You may have to resort to the classic editor.
    image

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Post TermsAffects the Post Terms Block[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions