fix: prevent get_custom_statuses() from corrupting WordPress's term cache#852
Merged
fix: prevent get_custom_statuses() from corrupting WordPress's term cache#852
Conversation
…ache Previously, get_custom_statuses() modified term objects in-place to add pseudo-meta properties like 'position'. Because WordPress caches term objects globally, this corrupted the cached objects, causing subtle bugs where subsequent calls to get_term_by() would return objects with unexpected properties. The fix creates new objects via array_merge() to avoid modifying the originals. This matches the pattern already used in editorial-metadata. Also fixes cache timing in delete_custom_status() - the internal cache is now cleared after wp_delete_term() completes rather than before. This prevents stale data from being re-cached when get_custom_statuses() is called during the delete operation. Adds integration tests for cache behaviour and fixes "psuedo" typo. Fixes #51 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #51 - ensuring
get_*s()methods don't accidentally corrupt cached object values.Problem
get_custom_statuses()was modifying term objects in-place to add pseudo-meta properties likeposition. Since WordPress caches term objects globally viaget_terms(), this corrupted the cached objects. Subsequent calls toget_term_by()would return objects with unexpected properties, causing subtle bugs.Additionally,
delete_custom_status()cleared the internal cache before callingwp_delete_term(), allowing stale data to be re-cached ifget_custom_statuses()was called during the delete operation.Solution
array_merge()instead of modifying the original term objects. This matches the pattern already used in the editorial-metadata module.wp_delete_term()instead of before, ensuring the deleted term isn't re-cached.get_custom_statuses()doesn't corrupt WordPress's term cacheget_custom_statuses()returns consistent results across callsdelete_custom_status()properly invalidates cacheupdate_custom_status()properly invalidates cacheFixes #51
Test plan
get_custom_statuses(), verify original term object isn't modified🤖 Generated with Claude Code