From 82d2927967e582ae3f81d6ee1cc8ccec78f1915c Mon Sep 17 00:00:00 2001 From: ed neville Date: Mon, 2 Sep 2024 11:58:46 +0100 Subject: [PATCH] Invent a cache key salt If the WP_CACHE_KEY_SALT is not set, use the md5 sum of DB parameters --- object-cache.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/object-cache.php b/object-cache.php index dd2ff80..eb43cea 100644 --- a/object-cache.php +++ b/object-cache.php @@ -12,8 +12,15 @@ // Users with setups where multiple installs share a common wp-config.php or $table_prefix // can use this to guarantee uniqueness for the keys generated by this object cache +// If WP_CACHE_KEY_SALT is not set, generate a key from DB parameters and blog id if ( ! defined( 'WP_CACHE_KEY_SALT' ) ) { - define( 'WP_CACHE_KEY_SALT', '' ); + if ( defined('DB_NAME') && defined('DB_USER') && defined('DB_PASSWORD') && defined('DB_HOST')) { + global $blog_id, $table_prefix; + define( 'WP_CACHE_KEY_SALT', md5( DB_NAME . ":" . DB_USER . ":" . DB_PASSWORD . ":" . DB_HOST . ":" . $table_prefix . ":" . $blog_id ) ); + } + else { + define( 'WP_CACHE_KEY_SALT', '' ); + } } function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {