Cache Enabler – WordPress Cache - Version 1.8.6

Version Description

  • Add cache_enabler_settings_before_validation filter hook (#298)
  • Add additional validation when creating cached files (#299)
  • Add type casts to several filter hooks (#299)
  • Update requirements check notices (#300)
  • Update advanced-cache.php drop-in file handling (#297)
Download this release

Release Info

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

Code changes from version 1.8.5 to 1.8.6

advanced-cache.php CHANGED
@@ -3,11 +3,12 @@
3
  * The advanced-cache.php drop-in file for Cache Enabler.
4
  *
5
  * The advanced-cache.php creation method uses this during the disk setup and
6
- * requirements check. You can copy this file to the wp-content directory and
7
- * edit the $cache_enabler_constants_file value as needed.
 
8
  *
9
  * @since 1.2.0
10
- * @change 1.8.0
11
  */
12
 
13
  if ( ! defined( 'ABSPATH' ) ) {
@@ -30,4 +31,6 @@ if ( file_exists( $cache_enabler_constants_file ) ) {
30
  Cache_Enabler_Engine::start_buffering();
31
  }
32
  }
 
 
33
  }
3
  * The advanced-cache.php drop-in file for Cache Enabler.
4
  *
5
  * The advanced-cache.php creation method uses this during the disk setup and
6
+ * requirements check. You can copy this file to the wp-content directory and edit
7
+ * the $cache_enabler_constants_file value as needed. It will be deleted if stale
8
+ * or abandoned.
9
  *
10
  * @since 1.2.0
11
+ * @change 1.8.6
12
  */
13
 
14
  if ( ! defined( 'ABSPATH' ) ) {
31
  Cache_Enabler_Engine::start_buffering();
32
  }
33
  }
34
+ } elseif ( __DIR__ === WP_CONTENT_DIR ) {
35
+ @unlink( __FILE__ );
36
  }
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.8.5
10
  */
11
 
12
  /*
6
  Author: KeyCDN
7
  Author URI: https://www.keycdn.com
8
  License: GPLv2 or later
9
+ Version: 1.8.6
10
  */
11
 
12
  /*
constants.php CHANGED
@@ -6,15 +6,16 @@
6
  */
7
 
8
  $cache_enabler_constants = array(
9
- 'CACHE_ENABLER_VERSION' => '1.8.5',
10
- 'CACHE_ENABLER_MIN_PHP' => '5.6',
11
- 'CACHE_ENABLER_MIN_WP' => '5.5',
12
- 'CACHE_ENABLER_DIR' => __DIR__,
13
- 'CACHE_ENABLER_FILE' => __DIR__ . '/cache-enabler.php',
14
- 'CACHE_ENABLER_BASE' => ( function_exists( 'wp_normalize_path' ) ) ? plugin_basename( __DIR__ . '/cache-enabler.php' ) : null,
15
- 'CACHE_ENABLER_CACHE_DIR' => WP_CONTENT_DIR . '/cache/cache-enabler', // Without a trailing slash.
16
- 'CACHE_ENABLER_SETTINGS_DIR' => WP_CONTENT_DIR . '/settings/cache-enabler', // Without a trailing slash.
17
- 'CACHE_ENABLER_INDEX_FILE' => ABSPATH . 'index.php',
 
18
  );
19
 
20
  foreach ( $cache_enabler_constants as $cache_enabler_constant_name => $cache_enabler_constant_value ) {
6
  */
7
 
8
  $cache_enabler_constants = array(
9
+ 'CACHE_ENABLER_VERSION' => '1.8.6',
10
+ 'CACHE_ENABLER_MIN_PHP' => '5.6',
11
+ 'CACHE_ENABLER_MIN_WP' => '5.1',
12
+ 'CACHE_ENABLER_DIR' => __DIR__,
13
+ 'CACHE_ENABLER_FILE' => __DIR__ . '/cache-enabler.php',
14
+ 'CACHE_ENABLER_BASE' => ( function_exists( 'wp_normalize_path' ) ) ? plugin_basename( __DIR__ . '/cache-enabler.php' ) : null,
15
+ 'CACHE_ENABLER_CACHE_DIR' => WP_CONTENT_DIR . '/cache/cache-enabler', // Without a trailing slash.
16
+ 'CACHE_ENABLER_SETTINGS_DIR' => WP_CONTENT_DIR . '/settings/cache-enabler', // Without a trailing slash.
17
+ 'CACHE_ENABLER_CONSTANTS_FILE' => __FILE__,
18
+ 'CACHE_ENABLER_INDEX_FILE' => ABSPATH . 'index.php',
19
  );
20
 
21
  foreach ( $cache_enabler_constants as $cache_enabler_constant_name => $cache_enabler_constant_value ) {
inc/cache_enabler.class.php CHANGED
@@ -341,7 +341,7 @@ final class Cache_Enabler {
341
  * is activated, but in this case even if the backend was not truly updated.
342
  *
343
  * @since 1.5.0
344
- * @change 1.8.0
345
  *
346
  * @return array The new or current option value.
347
  */
@@ -357,8 +357,6 @@ final class Cache_Enabler {
357
 
358
  $old_value = get_option( 'cache_enabler', array() );
359
  $value = self::upgrade_settings( $old_value );
360
- $value = wp_parse_args( self::get_default_settings( 'system' ), $value );
361
- $value = wp_parse_args( $value, self::get_default_settings() );
362
  $value = self::validate_settings( $value );
363
 
364
  update_option( 'cache_enabler', $value );
@@ -957,24 +955,53 @@ final class Cache_Enabler {
957
  * Get the default plugin settings.
958
  *
959
  * @since 1.5.0
960
- * @change 1.8.0
 
961
  *
962
- * @param string $settings_type (Optional) The default 'system' settings or all default settings if empty.
 
963
  * @return array Default plugin settings.
964
  */
965
- private static function get_default_settings( $settings_type = null ) {
 
 
 
 
 
 
 
 
 
 
966
 
967
- $system_default_settings = array(
 
 
 
 
 
 
 
 
 
968
  'version' => (string) CACHE_ENABLER_VERSION,
969
  'use_trailing_slashes' => (int) ( substr( get_option( 'permalink_structure' ), -1, 1 ) === '/' ),
970
  'permalink_structure' => (string) self::get_permalink_structure(), // Deprecated in 1.8.0.
971
  );
972
 
973
- if ( $settings_type === 'system' ) {
974
- return $system_default_settings;
975
- }
 
 
 
 
 
 
 
 
976
 
977
- $user_default_settings = array(
978
  'cache_expires' => 0,
979
  'cache_expiry_time' => 0,
980
  'clear_site_cache_on_saved_post' => 0,
@@ -993,9 +1020,7 @@ final class Cache_Enabler {
993
  'excluded_cookies' => '',
994
  );
995
 
996
- $default_settings = wp_parse_args( $user_default_settings, $system_default_settings );
997
-
998
- return $default_settings;
999
  }
1000
 
1001
  /**
@@ -1028,7 +1053,8 @@ final class Cache_Enabler {
1028
  * This runs when self::update_backend() is called. An empty replacement value
1029
  * means the setting will be removed.
1030
  *
1031
- * @since 1.8.0
 
1032
  *
1033
  * @param array $settings Plugin settings.
1034
  * @return array The plugin settings after maybe being upgraded.
@@ -1053,6 +1079,7 @@ final class Cache_Enabler {
1053
  $settings_names = array(
1054
  // 1.4.0
1055
  'excl_regexp' => 'excluded_page_paths',
 
1056
 
1057
  // 1.5.0
1058
  'expires' => 'cache_expiry_time',
@@ -2235,7 +2262,7 @@ final class Cache_Enabler {
2235
  * Check plugin's requirements.
2236
  *
2237
  * @since 1.1.0
2238
- * @change 1.8.1
2239
  *
2240
  * @global string $wp_version WordPress version.
2241
  */
@@ -2276,12 +2303,12 @@ final class Cache_Enabler {
2276
  printf(
2277
  '<div class="notice notice-warning"><p>%s</p></div>',
2278
  sprintf(
2279
- // translators: 1. Cache Enabler 2. advanced-cache.php 3. wp-content/plugins/cache-enabler 4. wp-content
2280
  esc_html__( '%1$s was unable to create the required %2$s drop-in file. You can manually create it by locating the sample file in the %3$s directory, editing it as needed, and then saving it in the %4$s directory.', 'cache-enabler' ),
2281
  '<strong>Cache Enabler</strong>',
2282
  '<code>advanced-cache.php</code>',
2283
- '<code>' . str_replace( ABSPATH, '', CACHE_ENABLER_DIR ) . '</code>',
2284
- '<code>' . basename( WP_CONTENT_DIR ) . '</code>'
2285
  )
2286
  );
2287
  }
@@ -2326,11 +2353,11 @@ final class Cache_Enabler {
2326
  printf(
2327
  '<div class="notice notice-warning"><p>%s</p></div>',
2328
  sprintf(
2329
- // translators: 1. Cache Enabler 2. 755 3. wp-content/cache 4. file permissions
2330
  esc_html__( '%1$s requires write permissions %2$s in the %3$s directory. Please change the %4$s.', 'cache-enabler' ),
2331
  '<strong>Cache Enabler</strong>',
2332
  '<code>755</code>',
2333
- '<code>' . str_replace( ABSPATH, '', $parent_dir ) . '</code>',
2334
  sprintf(
2335
  '<a href="%s" target="_blank" rel="nofollow noopener">%s</a>',
2336
  'https://wordpress.org/support/article/changing-file-permissions/',
@@ -2452,14 +2479,29 @@ final class Cache_Enabler {
2452
  * Validate plugin settings.
2453
  *
2454
  * @since 1.0.0
2455
- * @change 1.8.0
2456
  *
2457
  * @param array $settings Plugin settings.
2458
  * @return array Validated plugin settings.
2459
  */
2460
  public static function validate_settings( $settings ) {
2461
 
2462
- $validated_settings = array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2463
  'cache_expires' => (int) ( ! empty( $settings['cache_expires'] ) ),
2464
  'cache_expiry_time' => absint( $settings['cache_expiry_time'] ),
2465
  'clear_site_cache_on_saved_post' => (int) ( ! empty( $settings['clear_site_cache_on_saved_post'] ) ),
@@ -2476,9 +2518,7 @@ final class Cache_Enabler {
2476
  'excluded_page_paths' => (string) self::validate_regex( $settings['excluded_page_paths'] ),
2477
  'excluded_query_strings' => (string) self::validate_regex( $settings['excluded_query_strings'] ),
2478
  'excluded_cookies' => (string) self::validate_regex( $settings['excluded_cookies'] ),
2479
- );
2480
-
2481
- $validated_settings = wp_parse_args( $validated_settings, self::get_default_settings( 'system' ) );
2482
 
2483
  if ( ! empty( $settings['clear_site_cache_on_saved_settings'] ) ) {
2484
  self::clear_site_cache();
341
  * is activated, but in this case even if the backend was not truly updated.
342
  *
343
  * @since 1.5.0
344
+ * @change 1.8.6
345
  *
346
  * @return array The new or current option value.
347
  */
357
 
358
  $old_value = get_option( 'cache_enabler', array() );
359
  $value = self::upgrade_settings( $old_value );
 
 
360
  $value = self::validate_settings( $value );
361
 
362
  update_option( 'cache_enabler', $value );
955
  * Get the default plugin settings.
956
  *
957
  * @since 1.5.0
958
+ * @since 1.8.6 The `$settings_type` parameter was updated to also accept 'user'.
959
+ * @change 1.8.6
960
  *
961
+ * @param string $settings_type (Optional) The default plugin 'system' or 'user' settings, all default plugin
962
+ * settings otherwise.
963
  * @return array Default plugin settings.
964
  */
965
+ private static function get_default_settings( $settings_type = '' ) {
966
+
967
+ switch ( $settings_type ) {
968
+ case 'system':
969
+ return self::get_default_system_settings();
970
+ case 'user':
971
+ return self::get_default_user_settings();
972
+ default:
973
+ return wp_parse_args( self::get_default_user_settings(), self::get_default_system_settings() );
974
+ }
975
+ }
976
 
977
+ /**
978
+ * Get the default plugin system settings.
979
+ *
980
+ * @since 1.8.6
981
+ *
982
+ * @return array Default plugin system settings.
983
+ */
984
+ private static function get_default_system_settings() {
985
+
986
+ $default_system_settings = array(
987
  'version' => (string) CACHE_ENABLER_VERSION,
988
  'use_trailing_slashes' => (int) ( substr( get_option( 'permalink_structure' ), -1, 1 ) === '/' ),
989
  'permalink_structure' => (string) self::get_permalink_structure(), // Deprecated in 1.8.0.
990
  );
991
 
992
+ return $default_system_settings;
993
+ }
994
+
995
+ /**
996
+ * Get the default plugin user settings.
997
+ *
998
+ * @since 1.8.6
999
+ *
1000
+ * @return array Default plugin user settings.
1001
+ */
1002
+ private static function get_default_user_settings() {
1003
 
1004
+ $default_user_settings = array(
1005
  'cache_expires' => 0,
1006
  'cache_expiry_time' => 0,
1007
  'clear_site_cache_on_saved_post' => 0,
1020
  'excluded_cookies' => '',
1021
  );
1022
 
1023
+ return $default_user_settings;
 
 
1024
  }
1025
 
1026
  /**
1053
  * This runs when self::update_backend() is called. An empty replacement value
1054
  * means the setting will be removed.
1055
  *
1056
+ * @since 1.8.0
1057
+ * @change 1.8.6
1058
  *
1059
  * @param array $settings Plugin settings.
1060
  * @return array The plugin settings after maybe being upgraded.
1079
  $settings_names = array(
1080
  // 1.4.0
1081
  'excl_regexp' => 'excluded_page_paths',
1082
+ 'incl_attributes' => '',
1083
 
1084
  // 1.5.0
1085
  'expires' => 'cache_expiry_time',
2262
  * Check plugin's requirements.
2263
  *
2264
  * @since 1.1.0
2265
+ * @change 1.8.6
2266
  *
2267
  * @global string $wp_version WordPress version.
2268
  */
2303
  printf(
2304
  '<div class="notice notice-warning"><p>%s</p></div>',
2305
  sprintf(
2306
+ // translators: 1. Cache Enabler 2. advanced-cache.php 3. /path/to/wp-content/plugins/cache-enabler 4. /path/to/wp-content
2307
  esc_html__( '%1$s was unable to create the required %2$s drop-in file. You can manually create it by locating the sample file in the %3$s directory, editing it as needed, and then saving it in the %4$s directory.', 'cache-enabler' ),
2308
  '<strong>Cache Enabler</strong>',
2309
  '<code>advanced-cache.php</code>',
2310
+ '<code>' . CACHE_ENABLER_DIR . '</code>',
2311
+ '<code>' . WP_CONTENT_DIR . '</code>'
2312
  )
2313
  );
2314
  }
2353
  printf(
2354
  '<div class="notice notice-warning"><p>%s</p></div>',
2355
  sprintf(
2356
+ // translators: 1. Cache Enabler 2. 755 3. /path/to/wp-content/cache 4. file permissions
2357
  esc_html__( '%1$s requires write permissions %2$s in the %3$s directory. Please change the %4$s.', 'cache-enabler' ),
2358
  '<strong>Cache Enabler</strong>',
2359
  '<code>755</code>',
2360
+ '<code>' . $parent_dir . '</code>',
2361
  sprintf(
2362
  '<a href="%s" target="_blank" rel="nofollow noopener">%s</a>',
2363
  'https://wordpress.org/support/article/changing-file-permissions/',
2479
  * Validate plugin settings.
2480
  *
2481
  * @since 1.0.0
2482
+ * @change 1.8.6
2483
  *
2484
  * @param array $settings Plugin settings.
2485
  * @return array Validated plugin settings.
2486
  */
2487
  public static function validate_settings( $settings ) {
2488
 
2489
+ /**
2490
+ * Filters the plugin settings before being validated and added or maybe updated.
2491
+ *
2492
+ * This can be an empty array or not contain all plugin settings. It will depend
2493
+ * on if the plugin was just installed, the plugin version being upgraded from, or
2494
+ * the form submitted in the plugin settings page. The plugin system settings are
2495
+ * protected and cannot be overwritten.
2496
+ *
2497
+ * @since 1.8.6
2498
+ *
2499
+ * @param array $settings Plugin settings.
2500
+ */
2501
+ $settings = (array) apply_filters( 'cache_enabler_settings_before_validation', $settings );
2502
+ $settings = wp_parse_args( $settings, self::get_default_settings( 'user' ) );
2503
+
2504
+ $validated_settings = wp_parse_args( array(
2505
  'cache_expires' => (int) ( ! empty( $settings['cache_expires'] ) ),
2506
  'cache_expiry_time' => absint( $settings['cache_expiry_time'] ),
2507
  'clear_site_cache_on_saved_post' => (int) ( ! empty( $settings['clear_site_cache_on_saved_post'] ) ),
2518
  'excluded_page_paths' => (string) self::validate_regex( $settings['excluded_page_paths'] ),
2519
  'excluded_query_strings' => (string) self::validate_regex( $settings['excluded_query_strings'] ),
2520
  'excluded_cookies' => (string) self::validate_regex( $settings['excluded_cookies'] ),
2521
+ ), self::get_default_settings( 'system' ) );
 
 
2522
 
2523
  if ( ! empty( $settings['clear_site_cache_on_saved_settings'] ) ) {
2524
  self::clear_site_cache();
inc/cache_enabler_disk.class.php CHANGED
@@ -61,7 +61,7 @@ final class Cache_Enabler_Disk {
61
  * Create a static HTML file from the page contents received from the cache engine.
62
  *
63
  * @since 1.5.0
64
- * @change 1.7.0
65
  *
66
  * @param string $page_contents Page contents from the cache engine as raw HTML.
67
  */
@@ -74,8 +74,8 @@ final class Cache_Enabler_Disk {
74
  *
75
  * @param string $page_contents Page contents from the cache engine as raw HTML.
76
  */
77
- $page_contents = apply_filters( 'cache_enabler_page_contents_before_store', $page_contents );
78
- $page_contents = apply_filters_deprecated( 'cache_enabler_before_store', array( $page_contents ), '1.6.0', 'cache_enabler_page_contents_before_store' );
79
 
80
  self::create_cache_file( $page_contents );
81
  }
@@ -274,12 +274,16 @@ final class Cache_Enabler_Disk {
274
  * Create the advanced-cache.php drop-in file.
275
  *
276
  * @since 1.8.0
277
- * @change 1.8.4
278
  *
279
  * @return string|bool Path to the created file, false on failure.
280
  */
281
  public static function create_advanced_cache_file() {
282
 
 
 
 
 
283
  $advanced_cache_sample_file = CACHE_ENABLER_DIR . '/advanced-cache.php';
284
 
285
  if ( ! is_readable( $advanced_cache_sample_file ) ) {
@@ -288,13 +292,12 @@ final class Cache_Enabler_Disk {
288
 
289
  $advanced_cache_file = WP_CONTENT_DIR . '/advanced-cache.php';
290
  $advanced_cache_file_contents = file_get_contents( $advanced_cache_sample_file );
291
- $advanced_cache_file_contents = str_replace( '/your/path/to/wp-content/plugins/cache-enabler', CACHE_ENABLER_DIR, $advanced_cache_file_contents );
292
 
293
- if ( ! is_writable( dirname( $advanced_cache_file ) ) ) {
294
- return false;
295
- }
296
 
297
- $advanced_cache_file_created = file_put_contents( $advanced_cache_file, $advanced_cache_file_contents, LOCK_EX );
 
298
 
299
  return ( $advanced_cache_file_created === false ) ? false : $advanced_cache_file;
300
  }
@@ -303,7 +306,7 @@ final class Cache_Enabler_Disk {
303
  * Create a static HTML file.
304
  *
305
  * @since 1.5.0
306
- * @change 1.8.0
307
  *
308
  * @param string $page_contents Page contents from the cache engine as raw HTML.
309
  */
@@ -327,6 +330,10 @@ final class Cache_Enabler_Disk {
327
  $page_contents = self::converter( $page_contents );
328
  }
329
 
 
 
 
 
330
  switch ( substr( $new_cache_file_name, -2, 2 ) ) {
331
  case 'br':
332
  $page_contents = brotli_compress( $page_contents );
@@ -1255,7 +1262,7 @@ final class Cache_Enabler_Disk {
1255
  * and will attempt to update any existing directories accordingly.
1256
  *
1257
  * @since 1.7.0
1258
- * @change 1.7.2
1259
  *
1260
  * @param string $dir Directory path to create.
1261
  * @return bool True if the directory either already exists or was created *and* has the
@@ -1271,7 +1278,7 @@ final class Cache_Enabler_Disk {
1271
  * @param int $mode Mode that defines the access permissions for the created directory. The mode
1272
  * must be an octal number, which means it should have a leading zero. Default is 0755.
1273
  */
1274
- $mode_octal = apply_filters( 'cache_enabler_mkdir_mode', 0755 );
1275
  $mode_string = decoct( $mode_octal ); // Get the last three digits (e.g. '755').
1276
  $parent_dir = dirname( $dir );
1277
  $fs = self::get_filesystem();
@@ -1411,7 +1418,7 @@ final class Cache_Enabler_Disk {
1411
  * This handles converting inline image URLs for the WebP cache version.
1412
  *
1413
  * @since 1.7.0
1414
- * @change 1.8.0
1415
  *
1416
  * @param string $page_contents Page contents from the cache engine as raw HTML.
1417
  * @return string Page contents after maybe being converted.
@@ -1450,8 +1457,8 @@ final class Cache_Enabler_Disk {
1450
  *
1451
  * @param string $page_contents Page contents from the cache engine as raw HTML.
1452
  */
1453
- $converted_page_contents = apply_filters( 'cache_enabler_page_contents_after_webp_conversion', preg_replace_callback( $image_urls_regex, 'self::convert_webp', $page_contents ) );
1454
- $converted_page_contents = apply_filters_deprecated( 'cache_enabler_disk_webp_converted_data', array( $converted_page_contents ), '1.6.0', 'cache_enabler_page_contents_after_webp_conversion' );
1455
 
1456
  return $converted_page_contents;
1457
  }
61
  * Create a static HTML file from the page contents received from the cache engine.
62
  *
63
  * @since 1.5.0
64
+ * @change 1.8.6
65
  *
66
  * @param string $page_contents Page contents from the cache engine as raw HTML.
67
  */
74
  *
75
  * @param string $page_contents Page contents from the cache engine as raw HTML.
76
  */
77
+ $page_contents = (string) apply_filters( 'cache_enabler_page_contents_before_store', $page_contents );
78
+ $page_contents = (string) apply_filters_deprecated( 'cache_enabler_before_store', array( $page_contents ), '1.6.0', 'cache_enabler_page_contents_before_store' );
79
 
80
  self::create_cache_file( $page_contents );
81
  }
274
  * Create the advanced-cache.php drop-in file.
275
  *
276
  * @since 1.8.0
277
+ * @change 1.8.6
278
  *
279
  * @return string|bool Path to the created file, false on failure.
280
  */
281
  public static function create_advanced_cache_file() {
282
 
283
+ if ( ! is_writable( WP_CONTENT_DIR ) ) {
284
+ return false;
285
+ }
286
+
287
  $advanced_cache_sample_file = CACHE_ENABLER_DIR . '/advanced-cache.php';
288
 
289
  if ( ! is_readable( $advanced_cache_sample_file ) ) {
292
 
293
  $advanced_cache_file = WP_CONTENT_DIR . '/advanced-cache.php';
294
  $advanced_cache_file_contents = file_get_contents( $advanced_cache_sample_file );
 
295
 
296
+ $search = '/your/path/to/wp-content/plugins/cache-enabler/constants.php';
297
+ $replace = CACHE_ENABLER_CONSTANTS_FILE;
 
298
 
299
+ $advanced_cache_file_contents = str_replace( $search, $replace, $advanced_cache_file_contents );
300
+ $advanced_cache_file_created = file_put_contents( $advanced_cache_file, $advanced_cache_file_contents, LOCK_EX );
301
 
302
  return ( $advanced_cache_file_created === false ) ? false : $advanced_cache_file;
303
  }
306
  * Create a static HTML file.
307
  *
308
  * @since 1.5.0
309
+ * @change 1.8.6
310
  *
311
  * @param string $page_contents Page contents from the cache engine as raw HTML.
312
  */
330
  $page_contents = self::converter( $page_contents );
331
  }
332
 
333
+ if ( ! Cache_Enabler_Engine::is_cacheable( $page_contents ) ) {
334
+ return; // Filter, HTML minification, or WebP conversion failed.
335
+ }
336
+
337
  switch ( substr( $new_cache_file_name, -2, 2 ) ) {
338
  case 'br':
339
  $page_contents = brotli_compress( $page_contents );
1262
  * and will attempt to update any existing directories accordingly.
1263
  *
1264
  * @since 1.7.0
1265
+ * @change 1.8.6
1266
  *
1267
  * @param string $dir Directory path to create.
1268
  * @return bool True if the directory either already exists or was created *and* has the
1278
  * @param int $mode Mode that defines the access permissions for the created directory. The mode
1279
  * must be an octal number, which means it should have a leading zero. Default is 0755.
1280
  */
1281
+ $mode_octal = (int) apply_filters( 'cache_enabler_mkdir_mode', 0755 );
1282
  $mode_string = decoct( $mode_octal ); // Get the last three digits (e.g. '755').
1283
  $parent_dir = dirname( $dir );
1284
  $fs = self::get_filesystem();
1418
  * This handles converting inline image URLs for the WebP cache version.
1419
  *
1420
  * @since 1.7.0
1421
+ * @change 1.8.6
1422
  *
1423
  * @param string $page_contents Page contents from the cache engine as raw HTML.
1424
  * @return string Page contents after maybe being converted.
1457
  *
1458
  * @param string $page_contents Page contents from the cache engine as raw HTML.
1459
  */
1460
+ $converted_page_contents = (string) apply_filters( 'cache_enabler_page_contents_after_webp_conversion', preg_replace_callback( $image_urls_regex, 'self::convert_webp', $page_contents ) );
1461
+ $converted_page_contents = (string) apply_filters_deprecated( 'cache_enabler_disk_webp_converted_data', array( $converted_page_contents ), '1.6.0', 'cache_enabler_page_contents_after_webp_conversion' );
1462
 
1463
  return $converted_page_contents;
1464
  }
inc/cache_enabler_engine.class.php CHANGED
@@ -210,12 +210,16 @@ final class Cache_Enabler_Engine {
210
  * Whether the contents from the output buffer can be cached.
211
  *
212
  * @since 1.5.0
213
- * @change 1.8.0
214
  *
215
  * @param string $contents Contents from the output buffer.
216
  * @return bool True if contents from the output buffer are cacheable, false if not.
217
  */
218
- private static function is_cacheable( $contents ) {
 
 
 
 
219
 
220
  $has_html_tag = ( stripos( $contents, '<html' ) !== false );
221
  $has_html5_doctype = preg_match( '/^<!DOCTYPE.+html\s*>/i', ltrim( $contents ) );
210
  * Whether the contents from the output buffer can be cached.
211
  *
212
  * @since 1.5.0
213
+ * @change 1.8.6
214
  *
215
  * @param string $contents Contents from the output buffer.
216
  * @return bool True if contents from the output buffer are cacheable, false if not.
217
  */
218
+ public static function is_cacheable( $contents ) {
219
+
220
+ if ( ! is_string( $contents ) ) {
221
+ return false;
222
+ }
223
 
224
  $has_html_tag = ( stripos( $contents, '<html' ) !== false );
225
  $has_html5_doctype = preg_match( '/^<!DOCTYPE.+html\s*>/i', ltrim( $contents ) );
readme.txt CHANGED
@@ -55,6 +55,13 @@ Cache Enabler captures page contents and saves it as a static HTML file on the s
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
 
58
  = 1.8.5 =
59
  * Update required WordPress version from 5.5 to 5.1 (#295)
60
  * Fix plugin upgrade process when disk settings are outdated and a frontend page is requested (#295)
55
 
56
  == Changelog ==
57
 
58
+ = 1.8.6 =
59
+ * Add `cache_enabler_settings_before_validation` filter hook (#298)
60
+ * Add additional validation when creating cached files (#299)
61
+ * Add type casts to several filter hooks (#299)
62
+ * Update requirements check notices (#300)
63
+ * Update `advanced-cache.php` drop-in file handling (#297)
64
+
65
  = 1.8.5 =
66
  * Update required WordPress version from 5.5 to 5.1 (#295)
67
  * Fix plugin upgrade process when disk settings are outdated and a frontend page is requested (#295)