Skip to content

fix: prevent get_custom_statuses() from corrupting WordPress's term cache#852

Merged
GaryJones merged 1 commit intodevelopfrom
fix/51-cache-object-safety
Dec 21, 2025
Merged

fix: prevent get_custom_statuses() from corrupting WordPress's term cache#852
GaryJones merged 1 commit intodevelopfrom
fix/51-cache-object-safety

Conversation

@GaryJones
Copy link
Copy Markdown
Contributor

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 like position. Since WordPress caches term objects globally via get_terms(), this corrupted the cached objects. Subsequent calls to get_term_by() would return objects with unexpected properties, causing subtle bugs.

Additionally, delete_custom_status() cleared the internal cache before calling wp_delete_term(), allowing stale data to be re-cached if get_custom_statuses() was called during the delete operation.

Solution

  • Create new objects via array_merge() instead of modifying the original term objects. This matches the pattern already used in the editorial-metadata module.
  • Clear cache after wp_delete_term() instead of before, ensuring the deleted term isn't re-cached.
  • Fixed spelling of "psuedo" → "pseudo" in both modules.
  • Added integration tests that verify:
    • get_custom_statuses() doesn't corrupt WordPress's term cache
    • get_custom_statuses() returns consistent results across calls
    • delete_custom_status() properly invalidates cache
    • update_custom_status() properly invalidates cache

Fixes #51

Test plan

  • All 177 integration tests pass
  • New cache tests verify the fix works correctly
  • Manual testing: Create a custom status, call get_custom_statuses(), verify original term object isn't modified

🤖 Generated with Claude Code

…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>
@GaryJones GaryJones requested a review from a team as a code owner December 21, 2025 14:33
@GaryJones GaryJones self-assigned this Dec 21, 2025
@GaryJones GaryJones added this to the Next (minor) milestone Dec 21, 2025
@GaryJones GaryJones merged commit 98b94ab into develop Dec 21, 2025
12 checks passed
@GaryJones GaryJones deleted the fix/51-cache-object-safety branch December 21, 2025 14:39
@GaryJones GaryJones mentioned this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make sure get_*_by() and get_*s() methods don't accidentally blow away cached object values

1 participant