Skip to content

Fatal error when gutenberg_render_block_core_post_terms is not returning string #65832

@david-binda

Description

@david-binda

Description

The gutenberg_render_block_core_post_terms function is supposed to return string and other code is expecting a string. However, the function directly returns the output of the get_the_term_list which may return string|false|WP_Error.

When a WP_Error is returned, there is a fatal error emitted in WordPress core's WP_Block::render where the output is typecasted to string:

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

IMHO, the code of the gutenberg_render_block_core_post_terms should check the output value of the get_the_term_list and eventually change the output similarly how WordPress core handles the WP_Error situations when dealing with the function.

Step-by-step reproduction instructions

  1. Have a block rendered by the gutenberg_render_block_core_post_terms on a page.
  2. Make the get_the_term_list to return an instance of WP_Error (eg.: by filtering the get_the_terms)
  3. Load the page

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.7 alpha, Gutenberg 19.2.0, PHP 8.1

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Metadata

Metadata

Assignees

Labels

[Block] Post TermsAffects the Post Terms Block[Status] In ProgressTracking issues with work in progress[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