diff --git a/includes/class-redis.php b/includes/class-redis.php index f024e33..23b2e1b 100644 --- a/includes/class-redis.php +++ b/includes/class-redis.php @@ -173,7 +173,7 @@ public static function add( ) { return [ self::set( $key, $value, self::expiry_time() ), - self::set( $key . '-modified', time(), self::expiry_time() ), + self::set( "{$key}-modified", time(), self::expiry_time() ), ]; } @@ -338,15 +338,18 @@ protected static function lua_flush_closure( } /** - * Retrieved set WP Rocket expiry time + * Retrieves set WP Rocket expiry time in hours * * @since 1.0.0 - * @return int + * @return int Expiry in hours */ protected static function expiry_time() { static $expiry; if ( ! isset( $expiry ) ) { - $expiry = get_rocket_purge_cron_interval(); + $hours = function_exists( 'get_rocket_option' ) + ? get_rocket_option( 'purge_cron_interval' ) + : 10; + $expiry = $hours * HOUR_IN_SECONDS; } return $expiry; } diff --git a/overrides/wp-rocket/buffer/functions.php b/overrides/wp-rocket/buffer/functions.php index 2a06301..5b31224 100644 --- a/overrides/wp-rocket/buffer/functions.php +++ b/overrides/wp-rocket/buffer/functions.php @@ -62,7 +62,9 @@ function filemtime( $filename ) { */ function readfile( $filename, $use_include_path = false, $context = null ) { if ( Redis::is_active() ) { - return Redis::get( $filename ); + $content = Redis::get( $filename ); + echo $content; + return strlen( $content ) ?: false; } return \readfile( $filename, $use_include_path, $context ); } @@ -77,7 +79,9 @@ function readfile( $filename, $use_include_path = false, $context = null ) { */ function readgzfile( $filename, $use_include_path = 0 ) { if ( Redis::is_active() ) { - return Redis::get( $filename ); + $content = Redis::get( $filename ); + echo gzdecode( $content ); + return strlen( $content ) ?: false; } return \readgzfile( $filename, $use_include_path ); } diff --git a/readme.txt b/readme.txt index f2a6337..e564700 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Tags: redis, cache, wp-rocket Tested up to: 5.2 Requires PHP: 7.0 -Stable tag: 1.0.0 +Stable tag: 1.0.2 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -22,6 +22,10 @@ It therefore requires a working Redis server. == Changelog == += 1.0.2 = +* Fixed the cache retrieval override functions +* Fixed the expiry time method of the redis class as WP Rocket changed its API + = 1.0.1 = * Allows for the translation of the plugin * Added German translations diff --git a/wpr-redis.php b/wpr-redis.php index 9d113ba..e20b56a 100644 --- a/wpr-redis.php +++ b/wpr-redis.php @@ -3,7 +3,7 @@ * Plugin Name: WP Rocket Redis * Plugin URI: https://github.com/naxvog/wpr-redis/ * Description: Addon to WP Rocket that allows storage of cache files in Redis. - * Version: 1.0.1 + * Version: 1.0.2 * Author: naxvog * Author URI: https://github.com/naxvog/ * Text Domain: wpr-redis @@ -34,12 +34,20 @@ $loader->add_namespace( 'WPR_Redis', WPR_REDIS_INCLUDE_PATH ); $loader->add_namespace( 'WP_Rocket', WPR_REDIS_OVERRIDE_PATH . '/wp-rocket' ); -function wpr_redis() { - static $instance; - if ( ! isset( $instance ) ) { - $instance = new WPR_Redis\WPR_Redis(); +if ( ! function_exists( 'wpr_redis' ) ) : + /** + * Instance function to initialize and/or retrieve the plugin instance. + * + * @since 1.0.0 + * @return \WPR_Redis\WPR_Redis + */ + function wpr_redis() { + static $instance; + if ( ! isset( $instance ) ) { + $instance = new WPR_Redis\WPR_Redis(); + } + return $instance; } - return $instance; -} +endif; wpr_redis();