Cache Enabler – WordPress Cache - Version 1.6.1

Version Description

  • Update requirement checks (#186)
  • Update cache clearing behavior for comment actions (#185)
  • Update HTML minification to remove CSS and JavaScript comments (#184)
  • Update site cache clearing behavior for multisite networks to ensure cache cleared action hooks are fired when using WP-CLI or clear cache action hooks (#180)
  • Add cache_enabler_convert_webp_attributes and cache_enabler_convert_webp_ignore_query_strings filter hooks (#183)
  • Fix cache clearing behavior on WooCommerce stock update (#179)
Download this release

Release Info

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

Code changes from version 1.6.0 to 1.6.1

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.6.0
10
  */
11
 
12
  /*
@@ -32,7 +32,8 @@ if ( ! defined( 'ABSPATH' ) ) {
32
  }
33
 
34
  // constants
35
- define( 'CE_VERSION', '1.6.0' );
 
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.6.1
10
  */
11
 
12
  /*
32
  }
33
 
34
  // constants
35
+ define( 'CE_VERSION', '1.6.1' );
36
+ define( 'CE_MIN_PHP', '5.6' );
37
  define( 'CE_MIN_WP', '5.1' );
38
  define( 'CE_FILE', __FILE__ );
39
  define( 'CE_BASE', plugin_basename( __FILE__ ) );
inc/cache_enabler.class.php CHANGED
@@ -50,7 +50,7 @@ final class Cache_Enabler {
50
  * constructor
51
  *
52
  * @since 1.0.0
53
- * @change 1.6.0
54
  */
55
 
56
  public function __construct() {
@@ -86,6 +86,10 @@ final class Cache_Enabler {
86
 
87
  // third party clear cache hooks
88
  add_action( 'autoptimize_action_cachepurged', array( __CLASS__, 'clear_complete_cache' ) );
 
 
 
 
89
 
90
  // multisite hooks
91
  add_action( 'wp_initialize_site', array( __CLASS__, 'install_later' ) );
@@ -233,13 +237,13 @@ final class Cache_Enabler {
233
  return;
234
  }
235
 
236
- // switch to blog
237
  switch_to_blog( (int) $new_site->blog_id );
238
 
239
  // add backend requirements, triggering the settings file to be created
240
  self::update_backend();
241
 
242
- // restore blog
243
  restore_current_blog();
244
  }
245
 
@@ -568,7 +572,7 @@ final class Cache_Enabler {
568
  * get default settings
569
  *
570
  * @since 1.0.0
571
- * @change 1.6.0
572
  *
573
  * @param string $settings_type default `system` settings
574
  * @return array $system_default_settings|$default_settings only default system settings or all default settings
@@ -589,7 +593,7 @@ final class Cache_Enabler {
589
  'cache_expires' => 0,
590
  'cache_expiry_time' => 0,
591
  'clear_site_cache_on_saved_post' => 0,
592
- 'clear_site_cache_on_new_comment' => 0,
593
  'clear_site_cache_on_changed_plugin' => 0,
594
  'compress_cache' => 0,
595
  'convert_image_urls_to_webp' => 0,
@@ -612,7 +616,7 @@ final class Cache_Enabler {
612
  * convert settings to new structure
613
  *
614
  * @since 1.5.0
615
- * @change 1.6.0
616
  *
617
  * @param array $settings settings
618
  * @return array $settings converted settings if applicable, unchanged otherwise
@@ -644,7 +648,7 @@ final class Cache_Enabler {
644
  'expires' => 'cache_expiry_time',
645
  'new_post' => 'clear_site_cache_on_saved_post',
646
  'update_product_stock' => '', // deprecated
647
- 'new_comment' => 'clear_site_cache_on_new_comment',
648
  'clear_on_upgrade' => 'clear_site_cache_on_changed_plugin',
649
  'compress' => 'compress_cache',
650
  'webp' => 'convert_image_urls_to_webp',
@@ -655,8 +659,11 @@ final class Cache_Enabler {
655
 
656
  // 1.6.0
657
  'clear_complete_cache_on_saved_post' => 'clear_site_cache_on_saved_post',
658
- 'clear_complete_cache_on_new_comment' => 'clear_site_cache_on_new_comment',
659
  'clear_complete_cache_on_changed_plugin' => 'clear_site_cache_on_changed_plugin',
 
 
 
660
  );
661
 
662
  foreach ( $settings_names as $old_name => $new_name ) {
@@ -1046,7 +1053,7 @@ final class Cache_Enabler {
1046
  // if new approved comment is posted
1047
  if ( $comment_approved === 1 ) {
1048
  // if setting enabled clear site cache
1049
- if ( Cache_Enabler_Engine::$settings['clear_site_cache_on_new_comment'] ) {
1050
  self::clear_site_cache();
1051
  // clear page cache otherwise
1052
  } else {
@@ -1060,7 +1067,7 @@ final class Cache_Enabler {
1060
  * edit comment hook
1061
  *
1062
  * @since 1.0.0
1063
- * @change 1.6.0
1064
  *
1065
  * @param integer $comment_id comment ID
1066
  * @param array $comment_data comment data
@@ -1072,7 +1079,13 @@ final class Cache_Enabler {
1072
 
1073
  // if approved comment is edited
1074
  if ( $comment_approved === 1 ) {
1075
- self::clear_page_cache_by_post_id( get_comment( $comment_id )->comment_post_ID );
 
 
 
 
 
 
1076
  }
1077
  }
1078
 
@@ -1081,7 +1094,7 @@ final class Cache_Enabler {
1081
  * transition comment status hook
1082
  *
1083
  * @since 1.0.0
1084
- * @change 1.6.0
1085
  *
1086
  * @param integer|string $new_status new comment status
1087
  * @param integer|string $old_status old comment status
@@ -1092,11 +1105,39 @@ final class Cache_Enabler {
1092
 
1093
  // if comment status has changed from or to approved
1094
  if ( $old_status === 'approved' || $new_status === 'approved' ) {
1095
- self::clear_page_cache_by_post_id( $comment->comment_post_ID );
 
 
 
 
 
 
1096
  }
1097
  }
1098
 
1099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1100
  /**
1101
  * clear complete cache
1102
  *
@@ -1160,7 +1201,7 @@ final class Cache_Enabler {
1160
  if ( $post->post_type === 'post' ) {
1161
  // clear author archives
1162
  self::clear_author_archives_cache_by_user_id( $post->post_author );
1163
- // date archives
1164
  self::clear_date_archives_cache_by_post_id( $post->ID );
1165
  }
1166
  }
@@ -1314,7 +1355,7 @@ final class Cache_Enabler {
1314
  * clear site cache by blog ID
1315
  *
1316
  * @since 1.4.0
1317
- * @change 1.6.0
1318
  *
1319
  * @param integer|string $blog_id blog ID
1320
  * @param boolean $delete_cache_size_transient whether or not the cache size transient should be deleted
@@ -1337,11 +1378,16 @@ final class Cache_Enabler {
1337
  return;
1338
  }
1339
 
 
 
 
 
 
1340
  // disable page cache cleared hook
1341
  self::$fire_page_cache_cleared_hook = false;
1342
 
1343
  // get site URL
1344
- $site_url = get_home_url( $blog_id );
1345
 
1346
  // get site objects
1347
  $site_objects = Cache_Enabler_Disk::get_site_objects( $site_url );
@@ -1356,13 +1402,12 @@ final class Cache_Enabler {
1356
 
1357
  // delete cache size transient
1358
  if ( $delete_cache_size_transient ) {
1359
- if ( is_multisite() ) {
1360
- switch_to_blog( $blog_id );
1361
- delete_transient( self::get_cache_size_transient_name() );
1362
- restore_current_blog();
1363
- } else {
1364
- delete_transient( self::get_cache_size_transient_name() );
1365
- }
1366
  }
1367
  }
1368
 
@@ -1402,7 +1447,7 @@ final class Cache_Enabler {
1402
  * check plugin requirements
1403
  *
1404
  * @since 1.1.0
1405
- * @change 1.6.0
1406
  */
1407
 
1408
  public static function requirements_check() {
@@ -1412,26 +1457,54 @@ final class Cache_Enabler {
1412
  return;
1413
  }
1414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1415
  // check WordPress version
1416
  if ( version_compare( $GLOBALS['wp_version'], CE_MIN_WP . 'alpha', '<' ) ) {
1417
  echo sprintf(
1418
  '<div class="notice notice-error"><p>%s</p></div>',
1419
  sprintf(
1420
  // translators: 1. Cache Enabler 2. WordPress version (e.g. 5.1)
1421
- esc_html__( 'The %1$s plugin is optimized for WordPress %2$s. Please disable the plugin or upgrade your WordPress installation (recommended).', 'cache-enabler' ),
1422
  '<strong>Cache Enabler</strong>',
1423
  CE_MIN_WP
1424
  )
1425
  );
1426
  }
1427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1428
  // check permalink structure
1429
  if ( Cache_Enabler_Engine::$settings['permalink_structure'] === 'plain' && current_user_can( 'manage_options' ) ) {
1430
  echo sprintf(
1431
- '<div class="notice notice-error"><p>%s</p></div>',
1432
  sprintf(
1433
  // translators: 1. Cache Enabler 2. Permalink Settings
1434
- esc_html__( 'The %1$s plugin requires a custom permalink structure to start caching properly. Please enable a custom structure in the %2$s.', 'cache-enabler' ),
1435
  '<strong>Cache Enabler</strong>',
1436
  sprintf(
1437
  '<a href="%s">%s</a>',
@@ -1442,13 +1515,13 @@ final class Cache_Enabler {
1442
  );
1443
  }
1444
 
1445
- // check permissions
1446
- if ( file_exists( Cache_Enabler_Disk::$cache_dir ) && ! is_writable( Cache_Enabler_Disk::$cache_dir ) ) {
1447
  echo sprintf(
1448
- '<div class="notice notice-error"><p>%s</p></div>',
1449
  sprintf(
1450
  // translators: 1. Cache Enabler 2. 755 3. wp-content/cache 4. file permissions
1451
- esc_html__( 'The %1$s plugin requires write permissions %2$s in %3$s. Please change the %4$s.', 'cache-enabler' ),
1452
  '<strong>Cache Enabler</strong>',
1453
  '<code>755</code>',
1454
  '<code>wp-content/cache</code>',
@@ -1464,10 +1537,10 @@ final class Cache_Enabler {
1464
  // check Autoptimize HTML optimization
1465
  if ( defined( 'AUTOPTIMIZE_PLUGIN_DIR' ) && Cache_Enabler_Engine::$settings['minify_html'] && get_option( 'autoptimize_html', '' ) !== '' ) {
1466
  echo sprintf(
1467
- '<div class="notice notice-error"><p>%s</p></div>',
1468
  sprintf(
1469
  // translators: 1. Autoptimize 2. Cache Enabler Settings
1470
- esc_html__( 'The %1$s plugin HTML optimization is enabled. Please disable HTML minification in the %2$s.', 'cache-enabler' ),
1471
  '<strong>Autoptimize</strong>',
1472
  sprintf(
1473
  '<a href="%s">%s</a>',
@@ -1541,7 +1614,7 @@ final class Cache_Enabler {
1541
  * validate settings
1542
  *
1543
  * @since 1.0.0
1544
- * @change 1.6.0
1545
  *
1546
  * @param array $settings user defined settings
1547
  * @return array $validated_settings validated settings
@@ -1558,7 +1631,7 @@ final class Cache_Enabler {
1558
  'cache_expires' => (int) ( ! empty( $settings['cache_expires'] ) ),
1559
  'cache_expiry_time' => (int) @$settings['cache_expiry_time'],
1560
  'clear_site_cache_on_saved_post' => (int) ( ! empty( $settings['clear_site_cache_on_saved_post'] ) ),
1561
- 'clear_site_cache_on_new_comment' => (int) ( ! empty( $settings['clear_site_cache_on_new_comment'] ) ),
1562
  'clear_site_cache_on_changed_plugin' => (int) ( ! empty( $settings['clear_site_cache_on_changed_plugin'] ) ),
1563
  'compress_cache' => (int) ( ! empty( $settings['compress_cache'] ) ),
1564
  'convert_image_urls_to_webp' => (int) ( ! empty( $settings['convert_image_urls_to_webp'] ) ),
@@ -1587,7 +1660,7 @@ final class Cache_Enabler {
1587
  * settings page
1588
  *
1589
  * @since 1.0.0
1590
- * @change 1.6.0
1591
  */
1592
 
1593
  public static function settings_page() {
@@ -1604,10 +1677,12 @@ final class Cache_Enabler {
1604
  printf(
1605
  '<div class="notice notice-warning"><p>%s</p></div>',
1606
  sprintf(
1607
- // translators: 1. define( 'WP_CACHE', true ); 2. wp-config.php
1608
- esc_html__( 'Caching is disabled because %1$s is not set in the %2$s file.', 'cache-enabler' ),
 
1609
  "<code>define( 'WP_CACHE', true );</code>",
1610
- '<code>wp-config.php</code>'
 
1611
  )
1612
  );
1613
  }
@@ -1658,16 +1733,16 @@ final class Cache_Enabler {
1658
 
1659
  <br />
1660
 
1661
- <label for="clear_site_cache_on_new_comment">
1662
- <input name="cache_enabler[clear_site_cache_on_new_comment]" type="checkbox" id="clear_site_cache_on_new_comment" value="1" <?php checked( '1', Cache_Enabler_Engine::$settings['clear_site_cache_on_new_comment'] ); ?> />
1663
- <?php esc_html_e( 'Clear the site cache if a new comment has been posted (instead of only the page cache).', 'cache-enabler' ); ?>
1664
  </label>
1665
 
1666
  <br />
1667
 
1668
  <label for="clear_site_cache_on_changed_plugin">
1669
  <input name="cache_enabler[clear_site_cache_on_changed_plugin]" type="checkbox" id="clear_site_cache_on_changed_plugin" value="1" <?php checked( '1', Cache_Enabler_Engine::$settings['clear_site_cache_on_changed_plugin'] ); ?> />
1670
- <?php esc_html_e( 'Clear the site cache if any plugin has been activated, updated, or deactivated.', 'cache-enabler' ); ?>
1671
  </label>
1672
 
1673
  <br />
50
  * constructor
51
  *
52
  * @since 1.0.0
53
+ * @change 1.6.1
54
  */
55
 
56
  public function __construct() {
86
 
87
  // third party clear cache hooks
88
  add_action( 'autoptimize_action_cachepurged', array( __CLASS__, 'clear_complete_cache' ) );
89
+ add_action( 'woocommerce_product_set_stock', array( __CLASS__, 'on_woocommerce_stock_update' ) );
90
+ add_action( 'woocommerce_variation_set_stock', array( __CLASS__, 'on_woocommerce_stock_update' ) );
91
+ add_action( 'woocommerce_product_set_stock_status', array( __CLASS__, 'on_woocommerce_stock_update' ) );
92
+ add_action( 'woocommerce_variation_set_stock_status', array( __CLASS__, 'on_woocommerce_stock_update' ) );
93
 
94
  // multisite hooks
95
  add_action( 'wp_initialize_site', array( __CLASS__, 'install_later' ) );
237
  return;
238
  }
239
 
240
+ // switch to new site
241
  switch_to_blog( (int) $new_site->blog_id );
242
 
243
  // add backend requirements, triggering the settings file to be created
244
  self::update_backend();
245
 
246
+ // restore current blog from before new site
247
  restore_current_blog();
248
  }
249
 
572
  * get default settings
573
  *
574
  * @since 1.0.0
575
+ * @change 1.6.1
576
  *
577
  * @param string $settings_type default `system` settings
578
  * @return array $system_default_settings|$default_settings only default system settings or all default settings
593
  'cache_expires' => 0,
594
  'cache_expiry_time' => 0,
595
  'clear_site_cache_on_saved_post' => 0,
596
+ 'clear_site_cache_on_saved_comment' => 0,
597
  'clear_site_cache_on_changed_plugin' => 0,
598
  'compress_cache' => 0,
599
  'convert_image_urls_to_webp' => 0,
616
  * convert settings to new structure
617
  *
618
  * @since 1.5.0
619
+ * @change 1.6.1
620
  *
621
  * @param array $settings settings
622
  * @return array $settings converted settings if applicable, unchanged otherwise
648
  'expires' => 'cache_expiry_time',
649
  'new_post' => 'clear_site_cache_on_saved_post',
650
  'update_product_stock' => '', // deprecated
651
+ 'new_comment' => 'clear_site_cache_on_saved_comment',
652
  'clear_on_upgrade' => 'clear_site_cache_on_changed_plugin',
653
  'compress' => 'compress_cache',
654
  'webp' => 'convert_image_urls_to_webp',
659
 
660
  // 1.6.0
661
  'clear_complete_cache_on_saved_post' => 'clear_site_cache_on_saved_post',
662
+ 'clear_complete_cache_on_new_comment' => 'clear_site_cache_on_saved_comment',
663
  'clear_complete_cache_on_changed_plugin' => 'clear_site_cache_on_changed_plugin',
664
+
665
+ // 1.6.1
666
+ 'clear_site_cache_on_new_comment' => 'clear_site_cache_on_saved_comment',
667
  );
668
 
669
  foreach ( $settings_names as $old_name => $new_name ) {
1053
  // if new approved comment is posted
1054
  if ( $comment_approved === 1 ) {
1055
  // if setting enabled clear site cache
1056
+ if ( Cache_Enabler_Engine::$settings['clear_site_cache_on_saved_comment'] ) {
1057
  self::clear_site_cache();
1058
  // clear page cache otherwise
1059
  } else {
1067
  * edit comment hook
1068
  *
1069
  * @since 1.0.0
1070
+ * @change 1.6.1
1071
  *
1072
  * @param integer $comment_id comment ID
1073
  * @param array $comment_data comment data
1079
 
1080
  // if approved comment is edited
1081
  if ( $comment_approved === 1 ) {
1082
+ // if setting enabled clear site cache
1083
+ if ( Cache_Enabler_Engine::$settings['clear_site_cache_on_saved_comment'] ) {
1084
+ self::clear_site_cache();
1085
+ // clear page cache otherwise
1086
+ } else {
1087
+ self::clear_page_cache_by_post_id( get_comment( $comment_id )->comment_post_ID );
1088
+ }
1089
  }
1090
  }
1091
 
1094
  * transition comment status hook
1095
  *
1096
  * @since 1.0.0
1097
+ * @change 1.6.1
1098
  *
1099
  * @param integer|string $new_status new comment status
1100
  * @param integer|string $old_status old comment status
1105
 
1106
  // if comment status has changed from or to approved
1107
  if ( $old_status === 'approved' || $new_status === 'approved' ) {
1108
+ // if setting enabled clear site cache
1109
+ if ( Cache_Enabler_Engine::$settings['clear_site_cache_on_saved_comment'] ) {
1110
+ self::clear_site_cache();
1111
+ // clear page cache otherwise
1112
+ } else {
1113
+ self::clear_page_cache_by_post_id( $comment->comment_post_ID );
1114
+ }
1115
  }
1116
  }
1117
 
1118
 
1119
+ /**
1120
+ * WooCommerce stock hooks
1121
+ *
1122
+ * @since 1.3.0
1123
+ * @change 1.6.1
1124
+ *
1125
+ * @param integer|WC_Product $product product ID or product instance
1126
+ */
1127
+
1128
+ public static function on_woocommerce_stock_update( $product ) {
1129
+
1130
+ // get product ID
1131
+ if ( is_int( $product ) ) {
1132
+ $product_id = $product;
1133
+ } else {
1134
+ $product_id = $product->get_id();
1135
+ }
1136
+
1137
+ self::clear_cache_on_post_save( $product_id );
1138
+ }
1139
+
1140
+
1141
  /**
1142
  * clear complete cache
1143
  *
1201
  if ( $post->post_type === 'post' ) {
1202
  // clear author archives
1203
  self::clear_author_archives_cache_by_user_id( $post->post_author );
1204
+ // clear date archives
1205
  self::clear_date_archives_cache_by_post_id( $post->ID );
1206
  }
1207
  }
1355
  * clear site cache by blog ID
1356
  *
1357
  * @since 1.4.0
1358
+ * @change 1.6.1
1359
  *
1360
  * @param integer|string $blog_id blog ID
1361
  * @param boolean $delete_cache_size_transient whether or not the cache size transient should be deleted
1378
  return;
1379
  }
1380
 
1381
+ // ensure site cache being cleared is current blog
1382
+ if ( is_multisite() ) {
1383
+ switch_to_blog( $blog_id );
1384
+ }
1385
+
1386
  // disable page cache cleared hook
1387
  self::$fire_page_cache_cleared_hook = false;
1388
 
1389
  // get site URL
1390
+ $site_url = home_url();
1391
 
1392
  // get site objects
1393
  $site_objects = Cache_Enabler_Disk::get_site_objects( $site_url );
1402
 
1403
  // delete cache size transient
1404
  if ( $delete_cache_size_transient ) {
1405
+ delete_transient( self::get_cache_size_transient_name() );
1406
+ }
1407
+
1408
+ // restore current blog from before site cache being cleared
1409
+ if ( is_multisite() ) {
1410
+ restore_current_blog();
 
1411
  }
1412
  }
1413
 
1447
  * check plugin requirements
1448
  *
1449
  * @since 1.1.0
1450
+ * @change 1.6.1
1451
  */
1452
 
1453
  public static function requirements_check() {
1457
  return;
1458
  }
1459
 
1460
+ // check PHP version
1461
+ if ( version_compare( PHP_VERSION, CE_MIN_PHP, '<' ) ) {
1462
+ echo sprintf(
1463
+ '<div class="notice notice-error"><p>%s</p></div>',
1464
+ sprintf(
1465
+ // translators: 1. Cache Enabler 2. PHP version (e.g. 5.6)
1466
+ esc_html__( '%1$s requires PHP %2$s or higher to function properly. Please update PHP or disable the plugin.', 'cache-enabler' ),
1467
+ '<strong>Cache Enabler</strong>',
1468
+ CE_MIN_PHP
1469
+ )
1470
+ );
1471
+ }
1472
+
1473
  // check WordPress version
1474
  if ( version_compare( $GLOBALS['wp_version'], CE_MIN_WP . 'alpha', '<' ) ) {
1475
  echo sprintf(
1476
  '<div class="notice notice-error"><p>%s</p></div>',
1477
  sprintf(
1478
  // translators: 1. Cache Enabler 2. WordPress version (e.g. 5.1)
1479
+ esc_html__( '%1$s requires WordPress %2$s or higher to function properly. Please update WordPress or disable the plugin.', 'cache-enabler' ),
1480
  '<strong>Cache Enabler</strong>',
1481
  CE_MIN_WP
1482
  )
1483
  );
1484
  }
1485
 
1486
+ // check advanced-cache.php drop-in
1487
+ if ( ! file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) {
1488
+ echo sprintf(
1489
+ '<div class="notice notice-warning"><p>%s</p></div>',
1490
+ sprintf(
1491
+ // translators: 1. Cache Enabler 2. advanced-cache.php 3. wp-content/plugins/cache-enabler 4. wp-content
1492
+ esc_html__( '%1$s requires the %2$s drop-in. Please deactivate and then activate the plugin to automatically copy this file or manually copy it from the %3$s directory to the %4$s directory.', 'cache-enabler' ),
1493
+ '<strong>Cache Enabler</strong>',
1494
+ '<code>advanced-cache.php</code>',
1495
+ '<code>wp-content/plugins/cache-enabler</code>',
1496
+ '<code>wp-content</code>'
1497
+ )
1498
+ );
1499
+ }
1500
+
1501
  // check permalink structure
1502
  if ( Cache_Enabler_Engine::$settings['permalink_structure'] === 'plain' && current_user_can( 'manage_options' ) ) {
1503
  echo sprintf(
1504
+ '<div class="notice notice-warning"><p>%s</p></div>',
1505
  sprintf(
1506
  // translators: 1. Cache Enabler 2. Permalink Settings
1507
+ esc_html__( '%1$s requires a custom permalink structure. Please enable a custom structure in the %2$s.', 'cache-enabler' ),
1508
  '<strong>Cache Enabler</strong>',
1509
  sprintf(
1510
  '<a href="%s">%s</a>',
1515
  );
1516
  }
1517
 
1518
+ // check file permissions
1519
+ if ( file_exists( dirname( Cache_Enabler_Disk::$cache_dir ) ) && ! is_writable( dirname( Cache_Enabler_Disk::$cache_dir ) ) ) {
1520
  echo sprintf(
1521
+ '<div class="notice notice-warning"><p>%s</p></div>',
1522
  sprintf(
1523
  // translators: 1. Cache Enabler 2. 755 3. wp-content/cache 4. file permissions
1524
+ esc_html__( '%1$s requires write permissions %2$s in the %3$s directory. Please change the %4$s.', 'cache-enabler' ),
1525
  '<strong>Cache Enabler</strong>',
1526
  '<code>755</code>',
1527
  '<code>wp-content/cache</code>',
1537
  // check Autoptimize HTML optimization
1538
  if ( defined( 'AUTOPTIMIZE_PLUGIN_DIR' ) && Cache_Enabler_Engine::$settings['minify_html'] && get_option( 'autoptimize_html', '' ) !== '' ) {
1539
  echo sprintf(
1540
+ '<div class="notice notice-warning"><p>%s</p></div>',
1541
  sprintf(
1542
  // translators: 1. Autoptimize 2. Cache Enabler Settings
1543
+ esc_html__( '%1$s HTML optimization is enabled. Please disable HTML minification in the %2$s.', 'cache-enabler' ),
1544
  '<strong>Autoptimize</strong>',
1545
  sprintf(
1546
  '<a href="%s">%s</a>',
1614
  * validate settings
1615
  *
1616
  * @since 1.0.0
1617
+ * @change 1.6.1
1618
  *
1619
  * @param array $settings user defined settings
1620
  * @return array $validated_settings validated settings
1631
  'cache_expires' => (int) ( ! empty( $settings['cache_expires'] ) ),
1632
  'cache_expiry_time' => (int) @$settings['cache_expiry_time'],
1633
  'clear_site_cache_on_saved_post' => (int) ( ! empty( $settings['clear_site_cache_on_saved_post'] ) ),
1634
+ 'clear_site_cache_on_saved_comment' => (int) ( ! empty( $settings['clear_site_cache_on_saved_comment'] ) ),
1635
  'clear_site_cache_on_changed_plugin' => (int) ( ! empty( $settings['clear_site_cache_on_changed_plugin'] ) ),
1636
  'compress_cache' => (int) ( ! empty( $settings['compress_cache'] ) ),
1637
  'convert_image_urls_to_webp' => (int) ( ! empty( $settings['convert_image_urls_to_webp'] ) ),
1660
  * settings page
1661
  *
1662
  * @since 1.0.0
1663
+ * @change 1.6.1
1664
  */
1665
 
1666
  public static function settings_page() {
1677
  printf(
1678
  '<div class="notice notice-warning"><p>%s</p></div>',
1679
  sprintf(
1680
+ // translators: 1. Cache Enabler 2. define( 'WP_CACHE', true ); 3. wp-config.php 4. require_once ABSPATH . 'wp-settings.php';
1681
+ esc_html__( '%1$s requires %2$s to be set. Please set this in the %3$s file (must be before %4$s).', 'cache-enabler' ),
1682
+ '<strong>Cache Enabler</strong>',
1683
  "<code>define( 'WP_CACHE', true );</code>",
1684
+ '<code>wp-config.php</code>',
1685
+ "<code>require_once ABSPATH . 'wp-settings.php';</code>"
1686
  )
1687
  );
1688
  }
1733
 
1734
  <br />
1735
 
1736
+ <label for="clear_site_cache_on_saved_comment">
1737
+ <input name="cache_enabler[clear_site_cache_on_saved_comment]" type="checkbox" id="clear_site_cache_on_saved_comment" value="1" <?php checked( '1', Cache_Enabler_Engine::$settings['clear_site_cache_on_saved_comment'] ); ?> />
1738
+ <?php esc_html_e( 'Clear the site cache if a comment has been posted, updated, spammed, or trashed (instead of only the page cache).', 'cache-enabler' ); ?>
1739
  </label>
1740
 
1741
  <br />
1742
 
1743
  <label for="clear_site_cache_on_changed_plugin">
1744
  <input name="cache_enabler[clear_site_cache_on_changed_plugin]" type="checkbox" id="clear_site_cache_on_changed_plugin" value="1" <?php checked( '1', Cache_Enabler_Engine::$settings['clear_site_cache_on_changed_plugin'] ); ?> />
1745
+ <?php esc_html_e( 'Clear the site cache if a plugin has been activated, updated, or deactivated.', 'cache-enabler' ); ?>
1746
  </label>
1747
 
1748
  <br />
inc/cache_enabler_cli.class.php CHANGED
@@ -29,14 +29,14 @@ class Cache_Enabler_CLI {
29
  *
30
  * # Clear all pages cache.
31
  * $ wp cache-enabler clear
32
- * Success: Cache cleared.
33
  *
34
  * # Clear the page cache for post IDs 1, 2, and 3.
35
  * $ wp cache-enabler clear --ids=1,2,3
36
  * Success: Pages cache cleared.
37
  *
38
  * # Clear the page cache for a particular URL.
39
- * $ wp cache-enabler clear --urls=https://example.com/about-us
40
  * Success: Page cache cleared.
41
  *
42
  * # Clear all pages cache for sites with blog IDs 1, 2, and 3.
29
  *
30
  * # Clear all pages cache.
31
  * $ wp cache-enabler clear
32
+ * Success: Site cache cleared.
33
  *
34
  * # Clear the page cache for post IDs 1, 2, and 3.
35
  * $ wp cache-enabler clear --ids=1,2,3
36
  * Success: Pages cache cleared.
37
  *
38
  * # Clear the page cache for a particular URL.
39
+ * $ wp cache-enabler clear --urls=https://www.example.com/about-us/
40
  * Success: Page cache cleared.
41
  *
42
  * # Clear all pages cache for sites with blog IDs 1, 2, and 3.
inc/cache_enabler_disk.class.php CHANGED
@@ -111,7 +111,7 @@ final class Cache_Enabler_Disk {
111
  * @since 1.0.0
112
  * @change 1.5.0
113
  *
114
- * @param string $page_contents content of a page from the output buffer
115
  */
116
 
117
  public static function cache_page( $page_contents ) {
@@ -361,9 +361,9 @@ final class Cache_Enabler_Disk {
361
  * create files for cache
362
  *
363
  * @since 1.0.0
364
- * @change 1.6.0
365
  *
366
- * @param string $page_contents content of a page from the output buffer
367
  */
368
 
369
  private static function create_cache_files( $page_contents ) {
@@ -393,8 +393,19 @@ final class Cache_Enabler_Disk {
393
 
394
  // create WebP supported files
395
  if ( Cache_Enabler_Engine::$settings['convert_image_urls_to_webp'] ) {
 
 
 
 
 
 
396
  // magic regex rule
397
- $image_urls_regex = '#(?:(?:(src|srcset|data-[^=]+)\s*=|(url)\()\s*[\'\"]?\s*)\K(?:[^\?\"\'\s>]+)(?:\.jpe?g|\.png)(?:\s\d+[wx][^\"\'>]*)?(?=\/?[\"\'\s\)>])(?=[^<{]*(?:\)[^<{]*\}|>))#i';
 
 
 
 
 
398
 
399
  // page contents after WebP conversion hook
400
  $converted_page_contents = apply_filters( 'cache_enabler_page_contents_after_webp_conversion', preg_replace_callback( $image_urls_regex, 'self::convert_webp', $page_contents ) );
@@ -424,7 +435,7 @@ final class Cache_Enabler_Disk {
424
  * @change 1.5.0
425
  *
426
  * @param string $file_path file path
427
- * @param string $page_contents content of a page from the output buffer
428
  */
429
 
430
  private static function create_cache_file( $file_path, $page_contents ) {
@@ -1016,15 +1027,15 @@ final class Cache_Enabler_Disk {
1016
  * minify HTML
1017
  *
1018
  * @since 1.0.0
1019
- * @change 1.6.0
1020
  *
1021
- * @param string $page_contents content of a page from the output buffer
1022
  * @return string $minified_html|$page_contents minified page contents if applicable, unchanged otherwise
1023
  */
1024
 
1025
  private static function minify_html( $page_contents ) {
1026
 
1027
- // check if disabled
1028
  if ( ! Cache_Enabler_Engine::$settings['minify_html'] ) {
1029
  return $page_contents;
1030
  }
@@ -1040,7 +1051,7 @@ final class Cache_Enabler_Disk {
1040
  // deprecated HTML tags to ignore hook
1041
  $ignore_tags = (array) apply_filters_deprecated( 'cache_minify_ignore_tags', array( $ignore_tags ), '1.6.0', 'cache_enabler_minify_html_ignore_tags' );
1042
 
1043
- // if selected exclude inline CSS and JavaScript
1044
  if ( ! Cache_Enabler_Engine::$settings['minify_inline_css_js'] ) {
1045
  array_push( $ignore_tags, 'style', 'script' );
1046
  }
@@ -1051,19 +1062,25 @@ final class Cache_Enabler_Disk {
1051
  }
1052
 
1053
  // stringify
1054
- $ignore_regex = implode( '|', $ignore_tags );
 
 
 
 
 
 
 
 
 
 
 
 
1055
 
1056
- // regex minification
1057
  $minified_html = preg_replace(
1058
- array(
1059
- '/<!--[^\[><](.*?)-->/s',
1060
- '#(?ix)(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:' . $ignore_regex . ')\b))*+)(?:<(?>' . $ignore_regex . ')\b|\z))#',
1061
- ),
1062
- array(
1063
- '',
1064
- ' ',
1065
- ),
1066
- $page_contents
1067
  );
1068
 
1069
  // something went wrong
111
  * @since 1.0.0
112
  * @change 1.5.0
113
  *
114
+ * @param string $page_contents contents of a page from the output buffer
115
  */
116
 
117
  public static function cache_page( $page_contents ) {
361
  * create files for cache
362
  *
363
  * @since 1.0.0
364
+ * @change 1.6.1
365
  *
366
+ * @param string $page_contents contents of a page from the output buffer
367
  */
368
 
369
  private static function create_cache_files( $page_contents ) {
393
 
394
  // create WebP supported files
395
  if ( Cache_Enabler_Engine::$settings['convert_image_urls_to_webp'] ) {
396
+ // attributes to convert during WebP conversion hook
397
+ $attributes = (array) apply_filters( 'cache_enabler_convert_webp_attributes', array( 'src', 'srcset', 'data-[^=]+' ) );
398
+
399
+ // stringify
400
+ $attributes_regex = implode( '|', $attributes );
401
+
402
  // magic regex rule
403
+ $image_urls_regex = '#(?:(?:(' . $attributes_regex . ')\s*=|(url)\()\s*[\'\"]?\s*)\K(?:[^\?\"\'\s>]+)(?:\.jpe?g|\.png)(?:\s\d+[wx][^\"\'>]*)?(?=\/?[\"\'\s\)>])(?=[^<{]*(?:\)[^<{]*\}|>))#i';
404
+
405
+ // ignore query strings during WebP conversion hook
406
+ if ( ! apply_filters( 'cache_enabler_convert_webp_ignore_query_strings', true ) ) {
407
+ $image_urls_regex = '#(?:(?:(' . $attributes_regex . ')\s*=|(url)\()\s*[\'\"]?\s*)\K(?:[^\"\'\s>]+)(?:\.jpe?g|\.png)(?:\s\d+[wx][^\"\'>]*)?(?=\/?[\?\"\'\s\)>])(?=[^<{]*(?:\)[^<{]*\}|>))#i';
408
+ }
409
 
410
  // page contents after WebP conversion hook
411
  $converted_page_contents = apply_filters( 'cache_enabler_page_contents_after_webp_conversion', preg_replace_callback( $image_urls_regex, 'self::convert_webp', $page_contents ) );
435
  * @change 1.5.0
436
  *
437
  * @param string $file_path file path
438
+ * @param string $page_contents contents of a page from the output buffer
439
  */
440
 
441
  private static function create_cache_file( $file_path, $page_contents ) {
1027
  * minify HTML
1028
  *
1029
  * @since 1.0.0
1030
+ * @change 1.6.1
1031
  *
1032
+ * @param string $page_contents contents of a page from the output buffer
1033
  * @return string $minified_html|$page_contents minified page contents if applicable, unchanged otherwise
1034
  */
1035
 
1036
  private static function minify_html( $page_contents ) {
1037
 
1038
+ // check if setting is enabled
1039
  if ( ! Cache_Enabler_Engine::$settings['minify_html'] ) {
1040
  return $page_contents;
1041
  }
1051
  // deprecated HTML tags to ignore hook
1052
  $ignore_tags = (array) apply_filters_deprecated( 'cache_minify_ignore_tags', array( $ignore_tags ), '1.6.0', 'cache_enabler_minify_html_ignore_tags' );
1053
 
1054
+ // if setting selected exclude inline CSS and JavaScript
1055
  if ( ! Cache_Enabler_Engine::$settings['minify_inline_css_js'] ) {
1056
  array_push( $ignore_tags, 'style', 'script' );
1057
  }
1062
  }
1063
 
1064
  // stringify
1065
+ $ignore_tags_regex = implode( '|', $ignore_tags );
1066
+
1067
+ // remove HTML comments
1068
+ $minified_html = preg_replace( '#<!--[^\[><].*?-->#s', '', $page_contents );
1069
+
1070
+ // if setting selected remove CSS and JavaScript comments
1071
+ if ( Cache_Enabler_Engine::$settings['minify_inline_css_js'] ) {
1072
+ $minified_html = preg_replace(
1073
+ '#/\*+[^\*]+\*+/|([^\'\"\\:]|^)//.*$#m',
1074
+ '$1',
1075
+ $minified_html
1076
+ );
1077
+ }
1078
 
1079
+ // minify HTML
1080
  $minified_html = preg_replace(
1081
+ '#(?>[^\S ]\s*|\s{2,})(?=[^<]*+(?:<(?!/?(?:' . $ignore_tags_regex . ')\b)[^<]*+)*+(?:<(?>' . $ignore_tags_regex . ')\b|\z))#ix',
1082
+ ' ',
1083
+ $minified_html
 
 
 
 
 
 
1084
  );
1085
 
1086
  // something went wrong
inc/cache_enabler_engine.class.php CHANGED
@@ -144,9 +144,9 @@ final class Cache_Enabler_Engine {
144
  * @since 1.0.0
145
  * @change 1.6.0
146
  *
147
- * @param string $page_contents content of a page from the output buffer
148
  * @param integer $phase bitmask of PHP_OUTPUT_HANDLER_* constants
149
- * @return string $page_contents content of a page from the output buffer
150
  */
151
 
152
  private static function end_buffering( $page_contents, $phase ) {
@@ -192,7 +192,7 @@ final class Cache_Enabler_Engine {
192
  * @since 1.5.0
193
  * @change 1.5.0
194
  *
195
- * @param string $page_contents content of a page from the output buffer
196
  * @return boolean true if page contents are cacheable, false otherwise
197
  */
198
 
144
  * @since 1.0.0
145
  * @change 1.6.0
146
  *
147
+ * @param string $page_contents contents of a page from the output buffer
148
  * @param integer $phase bitmask of PHP_OUTPUT_HANDLER_* constants
149
+ * @return string $page_contents contents of a page from the output buffer
150
  */
151
 
152
  private static function end_buffering( $page_contents, $phase ) {
192
  * @since 1.5.0
193
  * @change 1.5.0
194
  *
195
+ * @param string $page_contents contents of a page from the output buffer
196
  * @return boolean true if page contents are cacheable, false otherwise
197
  */
198
 
readme.txt CHANGED
@@ -1,85 +1,68 @@
1
- === Cache Enabler - WordPress Cache ===
2
  Contributors: keycdn
3
- Tags: cache, caching, wordpress cache, wp cache, performance, gzip, webp, http2
4
  Requires at least: 5.1
5
- Tested up to: 5.5
 
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
 
11
-
12
- A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files plus WebP support.
13
-
14
 
15
 
16
  == Description ==
17
-
18
- = WordPress Cache Engine =
19
- The Cache Enabler plugin creates static HTML files and stores them on the servers disk. The web server will deliver the static HTML file and avoids the resource intensive backend processes (core, plugins and database). This WordPress cache engine will improve the performance of your website.
20
 
21
 
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
30
- * Custom Post Type support
31
- * Expiry Directive
32
- * Support of *304 Not Modified* if the page has not modified since last cached
33
- * WebP Support (when combined with [Optimus](https://optimus.io "Optimus"))
34
- * Supports responsive images via srcset since WP 4.4
35
- * Works perfectly with [Autoptimize](https://wordpress.org/plugins/autoptimize/)
36
-
37
- > Cache Enabler is the first WP plugin to allow you to serve WebP images without JavaScript and also fully supports srcset since WP 4.4. WebP is a new image format that provides lossless and lossy compression for images on the web. WebP lossless images are [26% smaller](https://developers.google.com/speed/webp/docs/webp_lossless_alpha_study#results "webp lossless alpha study") in size compared to PNGs.
38
 
39
 
40
  = How does the caching work? =
41
- This plugin requires minimal setup time and allows you to easily take advantage of the benefits that come from using WordPress caching.
42
-
43
- The WordPress Cache Enabler has the ability to create 2 cached files. One is plain HTML and the other version is gzipped (gzip level 9). These static files are then used to deliver content faster to your users without any database lookups or gzipping as the files are already pre-compressed.
44
-
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 pages cache.
51
- `wp cache-enabler clear`
52
 
53
- * Clear the page cache for post IDs 1, 2, and 3.
54
- `wp cache-enabler clear --ids=1,2,3`
 
 
 
 
 
55
 
56
- * Clear the page cache for a particular URL.
57
- `wp cache-enabler clear --urls=https://example.com/about-us`
58
 
59
- * Clear all pages cache for sites with blog IDs 1, 2, and 3.
60
- `wp cache-enabler clear --sites=1,2,3`
61
-
62
-
63
- = Website =
64
- * [WordPress Cache Enabler - Documentation](https://www.keycdn.com/support/wordpress-cache-enabler-plugin "WordPress Cache Enabler - Documentation")
65
-
66
-
67
- = System Requirements =
68
- * PHP >=5.6
69
- * WordPress >=5.1
70
-
71
-
72
- = Contribute =
73
- * Anyone is welcome to contribute to the plugin on [GitHub](https://github.com/keycdn/cache-enabler).
74
- * Please merge (squash) all your changes into a single commit before you open a pull request.
75
 
76
 
77
  = Maintainer =
78
- * [KeyCDN](https://www.keycdn.com "KeyCDN")
79
 
80
 
81
  == Changelog ==
82
 
 
 
 
 
 
 
 
 
83
  = 1.6.0 =
84
  * Update cache clearing behavior for multisite networks when permalink structure has changed to prevent unnecessary cache clearing (#170)
85
  * Update cache clearing behavior for comment actions to prevent unnecessary cache clearing (#169)
@@ -297,4 +280,4 @@ When combined with Optimus, the WordPress Cache Enabler allows you to easily del
297
  == Screenshots ==
298
 
299
  1. Cache Enabler settings page
300
- 2. Display of the cache size in your dashboard
1
+ === Cache Enabler ===
2
  Contributors: keycdn
3
+ Tags: cache, caching, performance, gzip, webp, speed
4
  Requires at least: 5.1
5
+ Tested up to: 5.6
6
+ Requires PHP: 5.6
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
 
12
+ A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files. WebP and Gzip support included.
 
 
13
 
14
 
15
  == Description ==
16
+ Cache Enabler is a simple, yet powerful WordPress plugin that is easy to use, needs minimal configuration, and best of all helps improve site performance for a faster load time. It creates static HTML files and stores them on the server's disk. This allows the web server to deliver the static HTML files avoiding resource intensive backend processes from the WordPress core, plugins, and database lookups.
 
 
17
 
18
 
19
  = Features =
20
+ * Fast and efficient cache engine
21
+ * Automatic smart cache clearing
22
+ * Manual cache clearing
23
  * WP-CLI cache clearing
24
+ * Cache expiry
25
+ * Cache size display in the WordPress dashboard
26
+ * Minification of HTML excluding or including inline CSS and JavaScript
27
+ * WordPress multisite network support
28
+ * WebP support (convert images to WebP with [Optimus](https://optimus.io "Optimus"))
29
+ * Gzip pre-compression support
30
+ * Custom post type support
31
+ * `304 Not Modified` support
32
+ * Works perfectly with [Autoptimize](https://wordpress.org/plugins/autoptimize/) and the majority of third party plugins
 
 
33
 
34
 
35
  = How does the caching work? =
36
+ Cache Enabler captures page contents and saves it as a static HTML file on the server’s disk. Converting inline image URLs to WebP as a separate static HTML file and pre-compressing both static HTML files with Gzip is possible. The accepted static HTML file is then delivered to users without any database lookups or on the fly compression for a faster site load time.
 
 
 
 
 
 
 
37
 
 
 
38
 
39
+ = Documentation =
40
+ * [Installation](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#installation)
41
+ * [Settings](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#settings)
42
+ * [Hooks](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#hooks)
43
+ * [WP-CLI](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#wp-cli)
44
+ * [Advanced configuration](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#advanced-configuration)
45
+ * [FAQ](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#faq)
46
 
 
 
47
 
48
+ = Want to help? =
49
+ * Want to file a bug, contribute some code, or improve translations? Excellent! Check out our [GitHub issues](https://github.com/keycdn/cache-enabler) or [translations](https://translate.wordpress.org/projects/wp-plugins/cache-enabler/).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
 
52
  = Maintainer =
53
+ * [KeyCDN](https://www.keycdn.com)
54
 
55
 
56
  == Changelog ==
57
 
58
+ = 1.6.1 =
59
+ * Update requirement checks (#186)
60
+ * Update cache clearing behavior for comment actions (#185)
61
+ * Update HTML minification to remove CSS and JavaScript comments (#184)
62
+ * Update site cache clearing behavior for multisite networks to ensure cache cleared action hooks are fired when using WP-CLI or clear cache action hooks (#180)
63
+ * Add `cache_enabler_convert_webp_attributes` and `cache_enabler_convert_webp_ignore_query_strings` filter hooks (#183)
64
+ * Fix cache clearing behavior on WooCommerce stock update (#179)
65
+
66
  = 1.6.0 =
67
  * Update cache clearing behavior for multisite networks when permalink structure has changed to prevent unnecessary cache clearing (#170)
68
  * Update cache clearing behavior for comment actions to prevent unnecessary cache clearing (#169)
280
  == Screenshots ==
281
 
282
  1. Cache Enabler settings page
283
+ 2. Cache Enabler cache size in the WordPress dashboard