Cache Enabler – WordPress Cache - Version 1.3.5

Version Description

  • WP CLI cache clearing (Thanks to Steve Grunwell)
  • Added cache_enabler_disk_webp_converted_data filter
  • Improved WebP URL conversion
  • Fixed advanced cache issue
Download this release

Release Info

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

Code changes from version 1.3.4 to 1.3.5

advanced-cache.php CHANGED
@@ -16,7 +16,7 @@ $path_webp_gzip = $path . 'index-webp.html.gz';
16
 
17
 
18
  // if we don't have a cache copy, we do not need to proceed
19
- if ( ! is_readable( $path_html ) ) {
20
  return false;
21
  }
22
 
@@ -42,16 +42,16 @@ if ( !empty($settings['excl_regexp']) ) {
42
 
43
  // check GET variables
44
  if ( !empty($_GET) ) {
45
- // set regex of analytics campaign tags that shall not prevent caching
46
- if ( !empty($settings['incl_attributes']) ) {
47
- $attributes_regex = $settings['incl_attributes'];
48
- } else {
49
- $attributes_regex = '/^utm_(source|medium|campaign|term|content)$/';
50
- }
51
- // prevent cache use if there is any GET variable not covered by the campaign tag regex
52
- if ( sizeof( preg_grep( $attributes_regex, array_keys( $_GET ), PREG_GREP_INVERT ) ) > 0 ) {
53
- return false;
54
- }
55
  }
56
 
57
  // check cookie values
@@ -88,7 +88,10 @@ if ( !empty($settings["cache_timeout"]) ) {
88
 
89
  // check if timeout has been reached
90
  if ( $settings["cache_timeout"] <= $now ) {
91
- unlink($timeout_file);
 
 
 
92
  return false;
93
  }
94
  }
16
 
17
 
18
  // if we don't have a cache copy, we do not need to proceed
19
+ if ( !is_readable( $path_html ) ) {
20
  return false;
21
  }
22
 
42
 
43
  // check GET variables
44
  if ( !empty($_GET) ) {
45
+ // set regex of analytics campaign tags that shall not prevent caching
46
+ if ( !empty($settings['incl_attributes']) ) {
47
+ $attributes_regex = $settings['incl_attributes'];
48
+ } else {
49
+ $attributes_regex = '/^utm_(source|medium|campaign|term|content)$/';
50
+ }
51
+ // prevent cache use if there is any GET variable not covered by the campaign tag regex
52
+ if ( sizeof( preg_grep( $attributes_regex, array_keys( $_GET ), PREG_GREP_INVERT ) ) > 0 ) {
53
+ return false;
54
+ }
55
  }
56
 
57
  // check cookie values
88
 
89
  // check if timeout has been reached
90
  if ( $settings["cache_timeout"] <= $now ) {
91
+ @unlink($path_html);
92
+ @unlink($path_gzip);
93
+ @unlink($path_webp_html);
94
+ @unlink($path_webp_gzip);
95
  return false;
96
  }
97
  }
cache-enabler.php CHANGED
@@ -86,3 +86,10 @@ function cache_autoload($class) {
86
  );
87
  }
88
  }
 
 
 
 
 
 
 
86
  );
87
  }
88
  }
89
+
90
+ // Load the WP-CLI command.
91
+ if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI')) {
92
+ require_once CE_DIR . '/inc/cache_enabler_cli.class.php';
93
+
94
+ WP_CLI::add_command('cache-enabler', 'Cache_Enabler_CLI');
95
+ }
inc/cache_enabler.class.php CHANGED
@@ -851,7 +851,7 @@ final class Cache_Enabler {
851
  return;
852
  }
853
 
854
- // add admin purge link
855
  $wp_admin_bar->add_menu(
856
  array(
857
  'id' => 'clear-cache',
@@ -863,7 +863,7 @@ final class Cache_Enabler {
863
  );
864
 
865
  if ( ! is_admin() ) {
866
- // add admin purge link
867
  $wp_admin_bar->add_menu(
868
  array(
869
  'id' => 'clear-url-cache',
@@ -1184,7 +1184,7 @@ final class Cache_Enabler {
1184
  return;
1185
  }
1186
 
1187
- // purge cache if clean post on update
1188
  if ( ! isset($_POST['_clear_post_cache_on_update']) ) {
1189
 
1190
  // clear complete cache if option enabled
@@ -1216,7 +1216,7 @@ final class Cache_Enabler {
1216
  $clear_post_cache
1217
  );
1218
 
1219
- // purge complete cache or specific post
1220
  if ( $clear_post_cache ) {
1221
  self::clear_page_cache_by_post_id( $post_ID );
1222
  } else {
851
  return;
852
  }
853
 
854
+ // add admin clear link
855
  $wp_admin_bar->add_menu(
856
  array(
857
  'id' => 'clear-cache',
863
  );
864
 
865
  if ( ! is_admin() ) {
866
+ // add admin clear link
867
  $wp_admin_bar->add_menu(
868
  array(
869
  'id' => 'clear-url-cache',
1184
  return;
1185
  }
1186
 
1187
+ // clear cache if clean post on update
1188
  if ( ! isset($_POST['_clear_post_cache_on_update']) ) {
1189
 
1190
  // clear complete cache if option enabled
1216
  $clear_post_cache
1217
  );
1218
 
1219
+ // clear complete cache or specific post
1220
  if ( $clear_post_cache ) {
1221
  self::clear_page_cache_by_post_id( $post_ID );
1222
  } else {
inc/cache_enabler_cli.class.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Interact with Cache Enabler.
4
+ */
5
+ class Cache_Enabler_CLI {
6
+
7
+ /**
8
+ * Clear the page cache.
9
+ *
10
+ * ## OPTIONS
11
+ *
12
+ * [--ids=<id>]
13
+ * : Clear the cache for given post ID(s). Separate multiple IDs with commas.
14
+ *
15
+ * [--urls=<url>]
16
+ * : Clear the cache for the given URL(s). Separate multiple URLs with commas.
17
+ *
18
+ * ## EXAMPLES
19
+ *
20
+ * # Clear all page caches
21
+ * wp cache-enabler clear
22
+ *
23
+ * # Clear the cache for object IDs 1, 2, and 3
24
+ * wp cache-enabler clear --ids=1,2,3
25
+ *
26
+ * # Clear the cache for a particular URL
27
+ * wp cache-enabler clear --urls=https://example.com/about-us
28
+ *
29
+ * @alias clear
30
+ */
31
+ public function clear( $args, $assoc_args ) {
32
+ $assoc_args = wp_parse_args(
33
+ $assoc_args,
34
+ array(
35
+ 'ids' => '',
36
+ 'urls' => '',
37
+ )
38
+ );
39
+
40
+ // clear everything if we aren't given IDs and/or URLs.
41
+ if ( empty( $assoc_args['ids'] ) && empty( $assoc_args['urls'] ) ) {
42
+ Cache_Enabler::clear_total_cache();
43
+
44
+ return WP_CLI::success( esc_html__( 'The page cache has been cleared.', 'cache-enabler' ) );
45
+ }
46
+
47
+ // clear specific IDs and/or URLs.
48
+ array_map( 'Cache_Enabler::clear_page_cache_by_post_id', explode( ',', $assoc_args['ids'] ) );
49
+ array_map( 'Cache_Enabler::clear_page_cache_by_url', explode( ',', $assoc_args['urls'] ) );
50
+
51
+ WP_CLI::success( 'The requested caches have been cleared.', 'cache-enabler' );
52
+ }
53
+ }
inc/cache_enabler_disk.class.php CHANGED
@@ -284,10 +284,10 @@ final class Cache_Enabler_Disk {
284
  // create webp supported files
285
  if ($options['webp']) {
286
  // magic regex rule
287
- $regex_rule = '#(?<=(?:(ref|src|set)=[\"\']))(?:http[s]?[^\"\']+)(\.png|\.jp[e]?g)(?:[^\"\']+)?(?=[\"\')])#';
288
 
289
  // call the webp converter callback
290
- $converted_data = preg_replace_callback($regex_rule,'self::_convert_webp',$data);
291
 
292
  self::_create_file( self::_file_webp_html(), $converted_data.$cache_signature." (webp) -->" );
293
 
@@ -351,10 +351,13 @@ final class Cache_Enabler_Disk {
351
  }
352
 
353
  // get dir data
354
- $objects = array_diff(
355
- scandir($dir),
356
- array('..', '.')
357
- );
 
 
 
358
 
359
  if ( empty($objects) ) {
360
  return;
@@ -368,7 +371,7 @@ final class Cache_Enabler_Disk {
368
  if ( is_dir($object) ) {
369
  self::_clear_dir($object);
370
  } else {
371
- unlink($object);
372
  }
373
  }
374
 
284
  // create webp supported files
285
  if ($options['webp']) {
286
  // magic regex rule
287
+ $regex_rule = '#(?<=(?:(ref|src|set)=[\"\']))(?:[^\"\']+)(\.png|\.jp[e]?g)(?:[^\"\']+)?(?=[\"\')])#';
288
 
289
  // call the webp converter callback
290
+ $converted_data = apply_filters('cache_enabler_disk_webp_converted_data', preg_replace_callback($regex_rule,'self::_convert_webp',$data));
291
 
292
  self::_create_file( self::_file_webp_html(), $converted_data.$cache_signature." (webp) -->" );
293
 
351
  }
352
 
353
  // get dir data
354
+ $data_dir = @scandir($dir);
355
+ if(gettype($data_dir) === 'array') {
356
+ $objects = array_diff(
357
+ $data_dir,
358
+ array('..', '.')
359
+ );
360
+ }
361
 
362
  if ( empty($objects) ) {
363
  return;
371
  if ( is_dir($object) ) {
372
  self::_clear_dir($object);
373
  } else {
374
+ @unlink($object);
375
  }
376
  }
377
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: keycdn
3
  Tags: cache, caching, wordpress cache, wp cache, performance, gzip, webp, http2
4
  Requires at least: 4.6
5
- Tested up to: 5.1
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -22,7 +22,8 @@ The Cache Enabler plugin creates static HTML files and stores them on the server
22
  = Features =
23
  * Efficient and fast disk cache engine
24
  * Automated and/or manual clearing of the cache
25
- * Manually purge the cache of specific pages
 
26
  * Display of the actual cache size in your dashboard
27
  * Minification of HTML and inline JavaScript
28
  * WordPress multisite support
@@ -44,6 +45,18 @@ The Wordpress Cache Enabler has the ability to create 2 cached files. One is pla
44
  When combined with Optimus, the Wordpress Cache Enabler allows you to easily deliver WebP images. The plugin will check your upload directory for any JPG or PNG images that have an equivalent WebP file. If there is, the URI of these image will be cached in a WebP static file by Cache Enabler. It is not required for all images to be converted to WebP when the "Create an additional cached version for WebP image support" option is enabled. This will not break any images that are not in WebP format. The plugin will deliver images that do have a WebP equivalent and will fall back to the JPG or PNG format for images that don't.
45
 
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  = Website =
48
  * [WordPress Cache Enabler - Documentation](https://www.keycdn.com/support/wordpress-cache-enabler-plugin/ "WordPress Cache Enabler - Documentation")
49
 
@@ -68,6 +81,12 @@ When combined with Optimus, the Wordpress Cache Enabler allows you to easily del
68
 
69
  == Changelog ==
70
 
 
 
 
 
 
 
71
  = 1.3.4 =
72
  * Reverted change to page specific as new default
73
 
2
  Contributors: keycdn
3
  Tags: cache, caching, wordpress cache, wp cache, performance, gzip, webp, http2
4
  Requires at least: 4.6
5
+ Tested up to: 5.3
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
22
  = Features =
23
  * Efficient and fast disk cache engine
24
  * Automated and/or manual clearing of the cache
25
+ * Manually clear the cache of specific pages
26
+ * WP CLI cache clearing
27
  * Display of the actual cache size in your dashboard
28
  * Minification of HTML and inline JavaScript
29
  * WordPress multisite support
45
  When combined with Optimus, the Wordpress Cache Enabler allows you to easily deliver WebP images. The plugin will check your upload directory for any JPG or PNG images that have an equivalent WebP file. If there is, the URI of these image will be cached in a WebP static file by Cache Enabler. It is not required for all images to be converted to WebP when the "Create an additional cached version for WebP image support" option is enabled. This will not break any images that are not in WebP format. The plugin will deliver images that do have a WebP equivalent and will fall back to the JPG or PNG format for images that don't.
46
 
47
 
48
+ = WP CLI =
49
+
50
+ * Clear all page caches
51
+ `wp cache-enabler clear`
52
+
53
+ * Clear the cache for object IDs 1, 2, and 3
54
+ `wp cache-enabler clear --ids=1,2,3`
55
+
56
+ * Clear the cache for a particular URL
57
+ `wp cache-enabler clear --urls=https://example.com/about-us`
58
+
59
+
60
  = Website =
61
  * [WordPress Cache Enabler - Documentation](https://www.keycdn.com/support/wordpress-cache-enabler-plugin/ "WordPress Cache Enabler - Documentation")
62
 
81
 
82
  == Changelog ==
83
 
84
+ = 1.3.5 =
85
+ * WP CLI cache clearing (Thanks to Steve Grunwell)
86
+ * Added cache_enabler_disk_webp_converted_data filter
87
+ * Improved WebP URL conversion
88
+ * Fixed advanced cache issue
89
+
90
  = 1.3.4 =
91
  * Reverted change to page specific as new default
92