From d247b513d1e495f619530af9b98eef88ebf42429 Mon Sep 17 00:00:00 2001 From: Dekart Deploy Bot Date: Fri, 17 Jul 2026 19:23:56 +0000 Subject: [PATCH] fix: re-salt Memcached keys after drop-in load to isolate multi-site cache - WP_CACHE_KEY_SALT defined in MU-plugin is too late: object-cache.php (Memcached drop-in) loads before MU-plugins - Add muplugins_loaded hook: call salt_keys(DB_NAME) directly on the initialized Memcached object cache instance - Each site gets unique key prefix from its database name - Prevents cross-site cache collision when multiple WP sites share one Memcached server --- wp-content/mu-plugins/object-cache-bootstrap.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wp-content/mu-plugins/object-cache-bootstrap.php b/wp-content/mu-plugins/object-cache-bootstrap.php index 0a0b0a4..28307b3 100644 --- a/wp-content/mu-plugins/object-cache-bootstrap.php +++ b/wp-content/mu-plugins/object-cache-bootstrap.php @@ -29,6 +29,18 @@ if ( ! defined( 'WP_CACHE_KEY_SALT' ) && defined( 'DB_NAME' ) ) { if ( ! defined( 'WP_REDIS_HOST' ) ) { define( 'WP_REDIS_HOST', '127.0.0.1' ); } + +// Пересолить ключи объектного кеша после загрузки drop-in. +// WP_CACHE_KEY_SALT в MU-плагине — слишком поздно (drop-in грузится раньше). +// Вызываем salt_keys() напрямую на уже инициализированном объекте кеша. +if ( defined( 'DB_NAME' ) ) { + add_action( 'muplugins_loaded', function () { + global $wp_object_cache; + if ( isset( $wp_object_cache ) && method_exists( $wp_object_cache, 'salt_keys' ) ) { + $wp_object_cache->salt_keys( DB_NAME ); + } + }, 0 ); +} if ( ! defined( 'WP_REDIS_PORT' ) ) { define( 'WP_REDIS_PORT', 6379 ); }