From f178cca7439034cfd7e19073ef6eaec2b4e0e1e9 Mon Sep 17 00:00:00 2001 From: johnjamesjacoby Date: Sat, 28 Feb 2026 00:13:45 +0000 Subject: [PATCH] Cache API: Handle numerically-keyed `global_groups` when switching sites. This commit protects against another multisite cache edge-case where a persistent object-cache drop-in plugin (namely memcached) may use a numerically-keyed `global_groups` array instead of `'key' => true` like the default object-cache class, and includes the following changes: * Use `wp_is_numeric_array()` inside of `wp_cache_switch_to_blog_fallback()` so that the global group names array are always properly formatted regardless of the caching back-end in use * Add private helper methods to `Tests_Multisite_WpCacheSwitchToBlogFallback` to properly format global group names, and tweak a few tests to make them more resilient to different caching back-ends Follow up to r61760. See #23290. Built from https://develop.svn.wordpress.org/trunk@61772 git-svn-id: http://core.svn.wordpress.org/trunk@61078 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/ms-blogs.php | 26 ++++++++++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 8032123d18..f8323dd3b7 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -614,10 +614,28 @@ function wp_cache_switch_to_blog_fallback() { $global_groups = false; $non_persistent_groups = false; - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { - $global_groups = array_keys( $wp_object_cache->global_groups ); - $all_groups = array_fill_keys( array_keys( $wp_object_cache->cache ), true ); - $non_persistent_groups = array_keys( array_diff_key( $all_groups, $wp_object_cache->global_groups ) ); + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) && is_array( $wp_object_cache->global_groups ) ) { + + // Get the global groups as they are. + $group_names = $wp_object_cache->global_groups; + + // Get global group keys if non-numeric array. + if ( ! wp_is_numeric_array( $group_names ) ) { + $group_names = array_keys( $group_names ); + } + + $global_groups = $group_names; + + /* + * Non-persistent groups: Check for no_mc_groups first (memcached drop-in). + * Fall back to cache structure (default cache). + */ + if ( isset( $wp_object_cache->no_mc_groups ) && is_array( $wp_object_cache->no_mc_groups ) && ! empty( $wp_object_cache->no_mc_groups ) ) { + $non_persistent_groups = $wp_object_cache->no_mc_groups; + } elseif ( isset( $wp_object_cache->cache ) && is_array( $wp_object_cache->cache ) ) { + $all_groups = array_keys( $wp_object_cache->cache ); + $non_persistent_groups = array_values( array_diff( $all_groups, $global_groups ) ); + } } wp_cache_init(); diff --git a/wp-includes/version.php b/wp-includes/version.php index bcc0308346..aad719a746 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-beta2-61771'; +$wp_version = '7.0-beta2-61772'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.