Skip to content

Commit

Permalink
improved shutdown hook handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss committed May 31, 2020
1 parent 4909cb9 commit c76dcf8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## [Unreleased]
## 1.6.3

- Improved registration of `shutdown` callback
- Prevent PHP warnings in `maybe_print_comment()`

## 1.6.2
Expand Down
2 changes: 1 addition & 1 deletion includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Redis Object Cache Drop-In
Plugin URI: http://wordpress.org/plugins/redis-cache/
Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication, clustering and WP-CLI.
Version: 1.6.2
Version: 1.6.3
Author: Till Krüss
Author URI: https://till.im/
License: GPLv3
Expand Down
35 changes: 17 additions & 18 deletions redis-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Redis Object Cache
Plugin URI: https://wordpress.org/plugins/redis-cache/
Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, HHVM, replication, clustering and WP-CLI.
Version: 1.6.2
Version: 1.6.3
Text Domain: redis-cache
Domain Path: /languages
Author: Till Krüss
Expand Down Expand Up @@ -49,7 +49,7 @@ public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_action( 'load-' . $this->screen, array( $this, 'do_admin_actions' ) );
add_action( 'load-' . $this->screen, array( $this, 'add_admin_page_notices' ) );
add_action( 'shutdown', array( $this, 'maybe_print_comment' ), 0 );
add_action( 'wp_head', array( $this, 'register_shutdown_hooks' ) );
add_action( 'wp_ajax_roc_dismiss_notice', array( $this, 'dismiss_notice' ) );

add_filter( sprintf(
Expand Down Expand Up @@ -478,24 +478,15 @@ public function wc_pro_notice() {
);
}

public function maybe_print_comment() {
global $wp_object_cache;

if (
! isset( $wp_object_cache->cache_hits ) ||
! isset( $wp_object_cache->redis_client ) ||
! is_array( $wp_object_cache->cache )
) {
return;
}

if ( defined( 'WP_REDIS_DISABLE_COMMENT' ) && WP_REDIS_DISABLE_COMMENT ) {
return;
public function register_shutdown_hooks()
{
if ( ! defined( 'WP_REDIS_DISABLE_COMMENT' ) || ! WP_REDIS_DISABLE_COMMENT ) {
add_action( 'shutdown', array( $this, 'maybe_print_comment' ), 0 );
}
}

if ( ! defined( 'WP_USE_THEMES' ) || ! WP_USE_THEMES ) {
return;
}
public function maybe_print_comment() {
global $wp_object_cache;

if (
( defined( 'DOING_CRON' ) && DOING_CRON ) ||
Expand All @@ -513,6 +504,14 @@ public function maybe_print_comment() {
return;
}

if (
! isset( $wp_object_cache->cache_hits ) ||
! isset( $wp_object_cache->redis_client ) ||
! is_array( $wp_object_cache->cache )
) {
return;
}

$message = sprintf(
__( 'Performance optimized by Redis Object Cache. Learn more: %s', 'redis-cache' ),
'https://wprediscache.com'
Expand Down

0 comments on commit c76dcf8

Please sign in to comment.