Directory

Block Post Terms: Fix PHP fatal when get_the_term_list returns a WP_Error object by xknown · Pull Request #59787 · WordPress/gutenberg · GitHub
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

Block Post Terms: Fix PHP fatal when get_the_term_list returns a WP_Error object #59787

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

xknown
Copy link
Member

@xknown xknown commented Mar 12, 2024

What?

Why?

If get_the_term_list() returns for some reason a WP_Error object for a given post (we noticed this as a result of a cache invalidation bug), the affected request will result in the following PHP fatal. While the problem is not really on the post terms block, I think it should handle such cases gracefully.

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

/var/www/html/wp-includes/class-wp-block.php:463
/var/www/html/wp-includes/class-wp-block.php:443
/var/www/html/wp-includes/blocks.php:1705
/var/www/html/wp-includes/blocks.php:1743
/var/www/html/wp-includes/class-wp-hook.php:324
/var/www/html/wp-includes/plugin.php:205
/var/www/html/wp-content/plugins/gutenberg/phpunit/blocks/render-block-post-terms-test.php:29

How?

It checks the return value of get_the_term_list() to make sure we are always returning a string on the block render callback.

Testing Instructions

See the unit test

Testing Instructions for Keyboard

Screenshots or screencast

This adds a new unit test to expose a problem when `get_the_term_list`
does not return the expected value.
@xknown xknown requested a review from ajitbohra as a code owner March 12, 2024 13:57
Copy link

github-actions bot commented Mar 12, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: xknown <xknown@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@xknown xknown added [Type] Bug An existing feature does not function as intended [Block] Post Terms Affects the Post Terms Block labels Mar 13, 2024
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

phpunit/blocks/render-block-post-terms-test.php Outdated Show resolved Hide resolved
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.

None yet

2 participants