Skip to content

Taxonomy: Guard against non-object values in the terms cache. - #13204

Open
BogdanUngureanu wants to merge 3 commits into
WordPress:trunkfrom
BogdanUngureanu:fix-wp-term-get-instance
Open

Taxonomy: Guard against non-object values in the terms cache.#13204
BogdanUngureanu wants to merge 3 commits into
WordPress:trunkfrom
BogdanUngureanu:fix-wp-term-get-instance

Conversation

@BogdanUngureanu

Copy link
Copy Markdown

A truthy non-object in the terms cache group skipped the database lookup and fataled in get_object_vars(), taking down any get_terms() call that reached it.

This happens when the site uses a persistent cache (like redis) that fails to unserialize the object. In which case, it returns a string.

In this case, Core should check if the value returned from the cache can be properly used. If not, it should pull the term directly from the database.

Trac ticket: https://core.trac.wordpress.org/ticket/65915#ticket

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 4.8
Used for: Writing the test


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

A truthy non-object in the `terms` cache group skipped the database
lookup and fataled in `get_object_vars()`, taking down any `get_terms()`
call that reached it.

Fixes #65915.
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props bogdanungureanu, westonruter.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@BogdanUngureanu

Copy link
Copy Markdown
Author

Discovered as an issue in WooCommerce: woocommerce/woocommerce#67520

@BogdanUngureanu

BogdanUngureanu commented Aug 20, 2026

Copy link
Copy Markdown
Author

Another thing to note here: with PHP 8, get_object_vars now triggers a TypeError. Previously (PHP 7 and older) it was triggering a PHP warning. This means that on older versions of PHP, this introduced a silent bug that returned a blank WP_Term object (without even an ID).

This can be observed here: https://3v4l.org/8f1VN#v

Comment thread tests/phpunit/tests/term/wpTerm.php Outdated
Comment thread tests/phpunit/tests/term/wpTerm.php Outdated
Comment thread tests/phpunit/tests/term/wpTerm.php Outdated
Comment thread src/wp-includes/class-wp-term.php Outdated
Comment thread tests/phpunit/tests/term/wpTerm.php
BogdanUngureanu and others added 2 commits August 21, 2026 13:04
Validate if the taxonomy exists on the object to avoid a potential PHP Warning/notice and update the docblocks with PHPStan definitions

Co-authored-by: Weston Ruter <westonruter@gmail.com>
@BogdanUngureanu

Copy link
Copy Markdown
Author

Thanks @westonruter for the fast response. I've pushed a commit that updates the test.

Let me know if more changes are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants