Skip to content

#29247 - Clear a deleted site's option caches - #14668

Open
skikken wants to merge 2 commits into
WordPress:trunkfrom
skikken:fix/29247-clear-site-option-caches
Open

skikken wants to merge 2 commits into
WordPress:trunkfrom
skikken:fix/29247-clear-site-option-caches

Conversation

@skikken

@skikken skikken commented Oct 21, 2026

Copy link
Copy Markdown

Deleting a site leaves that site's option caches populated. alloptions, notoptions and is_blog_installed keep answering for a site whose tables no longer exist, so a deleted site continues to behave as installed. A switch_to_blog() into the deleted site succeeds without any indication that the site is gone, whereas clearing the caches surfaces the expected Table '..._options' doesn't exist error and makes the failure debuggable.

The gap is still live on trunk. clean_blog_cache() only clears the network level site, blog-details, blog-lookup and blog_meta groups. The options group is per site, and nothing in the deletion path clears it.

This clears the three keys in wp_uninitialize_site() once the site's tables have been dropped, while the function is still switched into the deleted site's context, so the per blog keys are hit directly. The whole options group is deliberately not flushed: on multisite that group holds every site's prefixed option keys, so flushing it would evict the entire network's option cache.

clean_blog_cache() is intentionally untouched. As noted in the ticket discussion, it is a network level cache cleaner, and site level clearing belongs to the site deletion routine itself. The second test pins that scope so a later change cannot widen it silently.

The alloptions half of the report is the one that reproduces most visibly: an autoloaded option is served straight from that cache, so a stale read survives the deletion of the table it came from.

Trac ticket: https://core.trac.wordpress.org/ticket/29247

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet
Used for: test cases, code review


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.

wp_uninitialize_site() drops a site's tables but left that site's
option caches populated. alloptions, notoptions and is_blog_installed
therefore kept answering for a site that no longer had any tables, so
a deleted site still behaved as installed and switch_to_blog() gave no
indication that anything was wrong.

Clear those three keys once the site's tables have been dropped, while
the function is still switched into the deleted site's context. The
whole options group is deliberately not flushed, as on multisite it
holds every site's prefixed keys.

clean_blog_cache() is left untouched. Per the ticket discussion it is
a network level cache cleaner, and site level clearing belongs to the
deletion routine.

Props rmccue, johnjamesjacoby, jeremyfelt.
Fixes #29247.
Cover that wp_delete_site() clears alloptions, notoptions and
is_blog_installed for the deleted site, and pin that clean_blog_cache()
intentionally leaves the site's option caches alone.

Props rmccue, johnjamesjacoby, jeremyfelt.
Fixes #29247.
@github-actions

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 whopiyush.

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.

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.

1 participant