Cache Enabler – WordPress Cache - Version 1.5.2

Version Description

  • Update late cache engine start to be on the init hook instead of plugins_loaded (#153)
  • Add deprecated variable that was previously deleted to improve backwards compatibility (#153)
  • Fix WP-CLI notice errors (#153)
  • Fix creating settings file on plugin update
Download this release

Release Info

Developer keycdn
Plugin Icon 128x128 Cache Enabler – WordPress Cache
Version 1.5.2
Comparing to
See all releases

Code changes from version 1.5.1 to 1.5.2

advanced-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  * Cache Enabler advanced cache
4
  *
5
  * @since 1.2.0
6
- * @change 1.5.0
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) {
@@ -15,5 +15,5 @@ $ce_dir = ( ( defined( 'WP_PLUGIN_DIR' ) ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/
15
  require_once $ce_dir . '/inc/cache_enabler_engine.class.php';
16
  require_once $ce_dir . '/inc/cache_enabler_disk.class.php';
17
 
18
- $cache_engine = new Cache_Enabler_Engine;
19
- $cache_engine->deliver_cache();
3
  * Cache Enabler advanced cache
4
  *
5
  * @since 1.2.0
6
+ * @change 1.5.2
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) {
15
  require_once $ce_dir . '/inc/cache_enabler_engine.class.php';
16
  require_once $ce_dir . '/inc/cache_enabler_disk.class.php';
17
 
18
+ Cache_Enabler_Engine::start();
19
+ Cache_Enabler_Engine::deliver_cache();
cache-enabler.php CHANGED
@@ -6,7 +6,7 @@ Description: Simple and fast WordPress caching plugin.
6
  Author: KeyCDN
7
  Author URI: https://www.keycdn.com
8
  License: GPLv2 or later
9
- Version: 1.5.1
10
  */
11
 
12
  /*
@@ -32,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) {
32
  }
33
 
34
  // constants
35
- define( 'CE_VERSION', '1.5.1' );
36
  define( 'CE_MIN_WP', '5.1' );
37
  define( 'CE_FILE', __FILE__ );
38
  define( 'CE_BASE', plugin_basename( __FILE__ ) );
6
  Author: KeyCDN
7
  Author URI: https://www.keycdn.com
8
  License: GPLv2 or later
9
+ Version: 1.5.2
10
  */
11
 
12
  /*
32
  }
33
 
34
  // constants
35
+ define( 'CE_VERSION', '1.5.2' );
36
  define( 'CE_MIN_WP', '5.1' );
37
  define( 'CE_FILE', __FILE__ );
38
  define( 'CE_BASE', plugin_basename( __FILE__ ) );
inc/cache_enabler.class.php CHANGED
@@ -24,21 +24,26 @@ final class Cache_Enabler {
24
  }
25
 
26
 
 
 
 
 
 
 
 
 
 
27
  /**
28
  * constructor
29
  *
30
  * @since 1.0.0
31
- * @change 1.5.0
32
  */
33
 
34
  public function __construct() {
35
 
36
- // check if engine is running
37
- if ( ! Cache_Enabler_Engine::$started ) {
38
- new Cache_Enabler_Engine;
39
- }
40
-
41
  // init hooks
 
42
  add_action( 'init', array( 'Cache_Enabler_Engine', 'start_buffering' ) );
43
  add_action( 'init', array( __CLASS__, 'process_clear_cache_request' ) );
44
  add_action( 'init', array( __CLASS__, 'register_textdomain' ) );
@@ -252,7 +257,8 @@ final class Cache_Enabler {
252
  } else {
253
  $default_settings = self::get_default_settings();
254
  add_option( 'cache_enabler', $default_settings );
255
- // create settings file if action was not added, like when in activation hook
 
256
  if ( ! has_action( 'add_option_cache_enabler' ) ) {
257
  self::on_update_backend( 'cache_enabler', $default_settings );
258
  }
@@ -264,7 +270,7 @@ final class Cache_Enabler {
264
  * update backend requirements
265
  *
266
  * @since 1.5.0
267
- * @change 1.5.0
268
  *
269
  * @param $plugin_update whether or not an update is in progress
270
  * @return $new_option_value new or current database option value
@@ -299,8 +305,11 @@ final class Cache_Enabler {
299
  // merge defined settings into default settings
300
  $new_option_value = wp_parse_args( $old_option_value, self::get_default_settings() );
301
 
302
- // if database did not need to be updated create settings file anyway
303
- if ( ! update_option( 'cache_enabler', $new_option_value ) ) {
 
 
 
304
  self::on_update_backend( $old_option_value, $new_option_value );
305
  }
306
 
24
  }
25
 
26
 
27
+ /**
28
+ * settings from database (deprecated)
29
+ *
30
+ * @deprecated 1.5.0
31
+ */
32
+
33
+ public static $options;
34
+
35
+
36
  /**
37
  * constructor
38
  *
39
  * @since 1.0.0
40
+ * @change 1.5.2
41
  */
42
 
43
  public function __construct() {
44
 
 
 
 
 
 
45
  // init hooks
46
+ add_action( 'init', array( 'Cache_Enabler_Engine', 'start' ) );
47
  add_action( 'init', array( 'Cache_Enabler_Engine', 'start_buffering' ) );
48
  add_action( 'init', array( __CLASS__, 'process_clear_cache_request' ) );
49
  add_action( 'init', array( __CLASS__, 'register_textdomain' ) );
257
  } else {
258
  $default_settings = self::get_default_settings();
259
  add_option( 'cache_enabler', $default_settings );
260
+
261
+ // create settings file if action was not fired, like when in activation hook
262
  if ( ! has_action( 'add_option_cache_enabler' ) ) {
263
  self::on_update_backend( 'cache_enabler', $default_settings );
264
  }
270
  * update backend requirements
271
  *
272
  * @since 1.5.0
273
+ * @change 1.5.2
274
  *
275
  * @param $plugin_update whether or not an update is in progress
276
  * @return $new_option_value new or current database option value
305
  // merge defined settings into default settings
306
  $new_option_value = wp_parse_args( $old_option_value, self::get_default_settings() );
307
 
308
+ // update database option
309
+ update_option( 'cache_enabler', $new_option_value );
310
+
311
+ // create settings file if action was not fired, like when in upgrade hook or if a database update was unnecessary
312
+ if ( ! has_action( 'update_option_cache_enabler' ) ) {
313
  self::on_update_backend( $old_option_value, $new_option_value );
314
  }
315
 
inc/cache_enabler_disk.class.php CHANGED
@@ -16,7 +16,6 @@ final class Cache_Enabler_Disk {
16
  *
17
  * @since 1.5.0
18
  * @change 1.5.0
19
- *
20
  */
21
 
22
  public static $cache_dir = WP_CONTENT_DIR . '/cache/cache-enabler';
@@ -27,7 +26,6 @@ final class Cache_Enabler_Disk {
27
  *
28
  * @since 1.5.0
29
  * @change 1.5.0
30
- *
31
  */
32
 
33
  private static $settings_dir = WP_CONTENT_DIR . '/settings/cache-enabler';
16
  *
17
  * @since 1.5.0
18
  * @change 1.5.0
 
19
  */
20
 
21
  public static $cache_dir = WP_CONTENT_DIR . '/cache/cache-enabler';
26
  *
27
  * @since 1.5.0
28
  * @change 1.5.0
 
29
  */
30
 
31
  private static $settings_dir = WP_CONTENT_DIR . '/settings/cache-enabler';
inc/cache_enabler_engine.class.php CHANGED
@@ -11,6 +11,20 @@ if ( ! defined( 'ABSPATH' ) ) {
11
 
12
  final class Cache_Enabler_Engine {
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * engine status
16
  *
@@ -39,7 +53,7 @@ final class Cache_Enabler_Engine {
39
  * constructor
40
  *
41
  * @since 1.5.0
42
- * @change 1.5.0
43
  */
44
 
45
  public function __construct() {
@@ -50,15 +64,58 @@ final class Cache_Enabler_Engine {
50
  // get settings from database otherwise
51
  } elseif ( class_exists( 'Cache_Enabler' ) ) {
52
  self::$settings = Cache_Enabler::get_settings();
 
 
 
53
  }
54
 
55
- // check engine requirements
56
  if ( ! empty( self::$settings ) ) {
57
  self::$started = true;
58
  }
59
  }
60
 
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  /**
63
  * check if output buffering should start
64
  *
@@ -274,7 +331,7 @@ final class Cache_Enabler_Engine {
274
  * check if cache should be bypassed
275
  *
276
  * @since 1.0.0
277
- * @change 1.5.0
278
  *
279
  * @return boolean true if cache should be bypassed, false otherwise
280
  *
@@ -308,27 +365,12 @@ final class Cache_Enabler_Engine {
308
  return true;
309
  }
310
 
311
- // check if Ajax request
312
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
313
- return true;
314
- }
315
-
316
- // check if REST API request
317
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
318
- return true;
319
- }
320
-
321
- // check if XMLRPC request
322
- if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
323
- return true;
324
- }
325
-
326
  // check conditional tags
327
  if ( self::is_wrong_permalink_structure() || self::is_excluded() ) {
328
  return true;
329
  }
330
 
331
- // check conditional tags when output buffer has ended
332
  if ( class_exists( 'WP' ) ) {
333
  if ( is_admin() || is_search() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required() || self::is_mobile() ) {
334
  return true;
@@ -343,12 +385,12 @@ final class Cache_Enabler_Engine {
343
  * deliver cache
344
  *
345
  * @since 1.5.0
346
- * @change 1.5.0
347
  */
348
 
349
- public function deliver_cache() {
350
 
351
- if ( ! self::$started || Cache_Enabler_Disk::cache_expired() || self::bypass_cache() ) {
352
  return;
353
  }
354
 
11
 
12
  final class Cache_Enabler_Engine {
13
 
14
+ /**
15
+ * start engine
16
+ *
17
+ * @since 1.5.2
18
+ * @change 1.5.2
19
+ */
20
+
21
+ public static function start() {
22
+
23
+ if ( self::should_start() ) {
24
+ new self();
25
+ }
26
+ }
27
+
28
  /**
29
  * engine status
30
  *
53
  * constructor
54
  *
55
  * @since 1.5.0
56
+ * @change 1.5.2
57
  */
58
 
59
  public function __construct() {
64
  // get settings from database otherwise
65
  } elseif ( class_exists( 'Cache_Enabler' ) ) {
66
  self::$settings = Cache_Enabler::get_settings();
67
+ // set deprecated settings
68
+ Cache_Enabler::$options = self::$settings;
69
+ Cache_Enabler::$options['webp'] = self::$settings['convert_image_urls_to_webp'];
70
  }
71
 
72
+ // check engine status
73
  if ( ! empty( self::$settings ) ) {
74
  self::$started = true;
75
  }
76
  }
77
 
78
 
79
+ /**
80
+ * check if engine should start
81
+ *
82
+ * @since 1.5.2
83
+ * @change 1.5.2
84
+ *
85
+ * @return boolean true if engine should start, false otherwise
86
+ */
87
+
88
+ public static function should_start() {
89
+
90
+ // check if engine is running already
91
+ if ( self::$started ) {
92
+ return false;
93
+ }
94
+
95
+ // check if Ajax request
96
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
97
+ return false;
98
+ }
99
+
100
+ // check if REST API request
101
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
102
+ return false;
103
+ }
104
+
105
+ // check if XMLRPC request
106
+ if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
107
+ return false;
108
+ }
109
+
110
+ // check if Host request header is empty
111
+ if ( empty( $_SERVER['HTTP_HOST'] ) ) {
112
+ return false;
113
+ }
114
+
115
+ return true;
116
+ }
117
+
118
+
119
  /**
120
  * check if output buffering should start
121
  *
331
  * check if cache should be bypassed
332
  *
333
  * @since 1.0.0
334
+ * @change 1.5.2
335
  *
336
  * @return boolean true if cache should be bypassed, false otherwise
337
  *
365
  return true;
366
  }
367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  // check conditional tags
369
  if ( self::is_wrong_permalink_structure() || self::is_excluded() ) {
370
  return true;
371
  }
372
 
373
+ // check conditional tags when output buffering has ended
374
  if ( class_exists( 'WP' ) ) {
375
  if ( is_admin() || is_search() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required() || self::is_mobile() ) {
376
  return true;
385
  * deliver cache
386
  *
387
  * @since 1.5.0
388
+ * @change 1.5.2
389
  */
390
 
391
+ public static function deliver_cache() {
392
 
393
+ if ( ! self::$started || self::bypass_cache() ) {
394
  return;
395
  }
396
 
readme.txt CHANGED
@@ -80,6 +80,13 @@ When combined with Optimus, the WordPress Cache Enabler allows you to easily del
80
 
81
  == Changelog ==
82
 
 
 
 
 
 
 
 
83
  = 1.5.1 =
84
 
85
  * Fix getting settings file
@@ -261,5 +268,5 @@ When combined with Optimus, the WordPress Cache Enabler allows you to easily del
261
 
262
  == Screenshots ==
263
 
264
- 1. Display of the cache size in your dashboard
265
- 2. Cache Enabler settings page and "Clear Cache" link in the dashboard
80
 
81
  == Changelog ==
82
 
83
+ = 1.5.2 =
84
+
85
+ * Update late cache engine start to be on the `init` hook instead of `plugins_loaded` (#153)
86
+ * Add deprecated variable that was previously deleted to improve backwards compatibility (#153)
87
+ * Fix WP-CLI notice errors (#153)
88
+ * Fix creating settings file on plugin update
89
+
90
  = 1.5.1 =
91
 
92
  * Fix getting settings file
268
 
269
  == Screenshots ==
270
 
271
+ 1. Cache Enabler settings page
272
+ 2. Display of the cache size in your dashboard