From 999f7c41db867031aa1f8d6ea8cc13c5da2f54bb Mon Sep 17 00:00:00 2001
From: Erick Hitter <ehitter@gmail.com>
Date: Wed, 26 Feb 2014 13:02:30 -0800
Subject: [PATCH] Since admin requests aren't routed through the cache
 frontend, the global variable isn't available. Use defines for these
 overrides instead.

Unfortunately does mean that settings are split, but alternatives weren't appealing:
* store settings into an option via the front-end proxy (front-end writes are bad)
* store in Redis (could lose the option, randomly revealing a UI)
* pass all wp-admin requests through the proxy with early bailing to avoid breakage seems overly complicated and fragile/prone to bugs.
---
 wp-redis-cache/wp-redis-cache.php | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/wp-redis-cache/wp-redis-cache.php b/wp-redis-cache/wp-redis-cache.php
index efb37fa..d1689c6 100644
--- a/wp-redis-cache/wp-redis-cache.php
+++ b/wp-redis-cache/wp-redis-cache.php
@@ -123,7 +123,7 @@ class WP_Redis_Cache {
 	private $ns = 'wp-redis-cache';
 
 	/**
-	 *
+	 * Singleton instantiation
 	 */
 	public static function get_instance() {
 		if ( ! is_a( self::$__instance, __CLASS__ ) ) {
@@ -161,12 +161,9 @@ class WP_Redis_Cache {
 	 * @return null
 	 */
 	public function register_ui() {
-		// If cache life is set globally, don't show the UI
-		global $wp_redis_cache_config;
-		if ( is_array( $wp_redis_cache_config ) &&
-			( isset( $wp_redis_cache_config['cache_duration' ] ) || isset( $wp_redis_cache_config['unlimited' ] ) )
-		) {
-			return;
+		// Don't show UI
+		if ( defined( 'WP_REDIS_CACHE_HIDE_UI' ) && WP_REDIS_CACHE_HIDE_UI ) {
+			return
 		}
 
 		add_options_page( 'WP Redis Cache', 'WP Redis Cache', 'manage_options', $this->ns, array( $this, 'render_ui' ) );
@@ -232,10 +229,14 @@ class WP_Redis_Cache {
 			);
 
 			// Override default connection settings with global values, when present
-			global $wp_redis_cache_config;
-			if ( is_array( $wp_redis_cache_config ) ) {
-				$_redis_settings = array_intersect( $wp_redis_cache_config, $redis_settings );
-				$redis_settings = wp_parse_args( $_redis_settings, $redis_settings );
+			if ( defined( 'WP_REDIS_CACHE_REDIS_HOST' ) ) {
+				$redis_settings['host'] = WP_REDIS_CACHE_REDIS_HOST;
+			}
+			if ( defined( 'WP_REDIS_CACHE_REDIS_PORT' ) ) {
+				$redis_settings['port'] = WP_REDIS_CACHE_REDIS_PORT;
+			}
+			if ( defined( 'WP_REDIS_CACHE_REDIS_DB' ) ) {
+				$redis_settings['database'] = WP_REDIS_CACHE_REDIS_DB;
 			}
 
 			$permalink = get_permalink( $post->ID );
-- 
GitLab