[wp-trac] [WordPress Trac] #23290: When using switch_to_blog() with a persistent object cache that lacks wp_cache_switch_to_blog() support, non-persistent groups are not maintained
WordPress Trac
noreply at wordpress.org
Wed Feb 18 19:37:12 UTC 2026
#23290: When using switch_to_blog() with a persistent object cache that lacks
wp_cache_switch_to_blog() support, non-persistent groups are not maintained
-------------------------------------+------------------------------
Reporter: markjaquith | Owner: johnjamesjacoby
Type: defect (bug) | Status: assigned
Priority: low | Milestone: 7.0
Component: Cache API | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses: multisite
-------------------------------------+------------------------------
Comment (by johnjamesjacoby):
23290-3.patch is a shower-thought approach:
* Add a fallback `wp_cache_switch_to_blog()` function in `cache-
compat.php`
* Move the fallback code out of `switch_to_blog()` and
`restore_current_blog()` and stop using `function_exists()`
This works because `cache.php` is included before `cache-compat.php`, so
WordPress can easily identify internally that `wp_cache_switch_to_blog()`
is missing when it should not be and then include its own fallback for it.
I really like this approach, because it also ensures that
`wp_cache_switch_to_blog()` is always callable by plugins.
The only compromise with this patch iteration is: I could not see how to
retroactively introduce a new `switch_to_blog` feature inside of
`wp_cache_supports()` - it's a catch-22 because existing drop-in plugins
would not have needed to announce/register their supporting this, its
default return value is `false`, and it's already confusing enough without
added logic inside of the compat `wp_cache_supports()` function.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/23290#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list