Cache Enabler – WordPress Cache - Version 1.4.7

Version Description

  • Update getting wp-config.php if one level above installation (#106)
  • Add clear types for strict cache clearing (#110)
  • Fix advanced cache settings recognition for subdirectory multisite networks
  • Fix WP-CLI clear command for post IDs (#110)
  • Fix scheme-based caching for NGINX/PHP-FPM (#109)
  • Fix trailing slash handling
Download this release

Release Info

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

Code changes from version 1.4.6 to 1.4.7

advanced-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  * Cache Enabler advanced cache
4
  *
5
  * @since 1.2.0
6
- * @change 1.4.2
7
  */
8
 
9
  // check if request method is GET
@@ -12,10 +12,10 @@ if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || $_SERVER['REQUEST_METHOD'] !== 'GE
12
  }
13
 
14
  // base path
15
- $path = _ce_file_path();
16
 
17
  // scheme
18
- $scheme = ( ( isset( $_SERVER['HTTPS'] ) && ! empty( $_SERVER['HTTPS'] ) ) || $_SERVER['SERVER_PORT'] === '443' ) ? 'https' : 'http';
19
 
20
  // path to cached variants
21
  $path_html = $path . $scheme . '-index.html';
@@ -152,8 +152,8 @@ readfile( $path_html );
152
  exit;
153
 
154
 
155
- // generate cache path
156
- function _ce_file_path( $path = null ) {
157
 
158
  $path = sprintf(
159
  '%s%s%s%s',
@@ -164,12 +164,12 @@ function _ce_file_path( $path = null ) {
164
  PHP_URL_HOST
165
  ),
166
  parse_url(
167
- ( $path ) ? $path : $_SERVER['REQUEST_URI'],
168
  PHP_URL_PATH
169
  )
170
  );
171
 
172
- if ( is_file( $path ) > 0 ) {
173
  header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404 );
174
  exit;
175
  }
@@ -182,11 +182,17 @@ function _ce_file_path( $path = null ) {
182
 
183
  // get blog path
184
  function _get_blog_path() {
185
- $path = $_SERVER['REQUEST_URI'];
186
 
187
- $path = explode( '/', $path, 3 );
 
 
188
 
189
- return '-' . $path[1];
 
 
 
 
 
190
  }
191
 
192
  // read settings file
3
  * Cache Enabler advanced cache
4
  *
5
  * @since 1.2.0
6
+ * @change 1.4.7
7
  */
8
 
9
  // check if request method is GET
12
  }
13
 
14
  // base path
15
+ $path = _file_path();
16
 
17
  // scheme
18
+ $scheme = ( ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) || $_SERVER['SERVER_PORT'] === '443' ) ? 'https' : 'http';
19
 
20
  // path to cached variants
21
  $path_html = $path . $scheme . '-index.html';
152
  exit;
153
 
154
 
155
+ // get cached file path
156
+ function _file_path() {
157
 
158
  $path = sprintf(
159
  '%s%s%s%s',
164
  PHP_URL_HOST
165
  ),
166
  parse_url(
167
+ $_SERVER['REQUEST_URI'],
168
  PHP_URL_PATH
169
  )
170
  );
171
 
172
+ if ( is_file( $path ) ) {
173
  header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404 );
174
  exit;
175
  }
182
 
183
  // get blog path
184
  function _get_blog_path() {
 
185
 
186
+ // get blog path
187
+ $path = explode( '/', $_SERVER['REQUEST_URI'], 3 );
188
+ $path = $path[1];
189
 
190
+ // check if blog path is empty
191
+ if ( ! empty( $path ) ) {
192
+ $path = '-' . $path;
193
+ }
194
+
195
+ return $path;
196
  }
197
 
198
  // read settings file
cache-enabler.php CHANGED
@@ -6,7 +6,7 @@ Description: Simple and fast WordPress disk caching plugin.
6
  Author: KeyCDN
7
  Author URI: https://www.keycdn.com
8
  License: GPLv2 or later
9
- Version: 1.4.6
10
  */
11
 
12
  /*
6
  Author: KeyCDN
7
  Author URI: https://www.keycdn.com
8
  License: GPLv2 or later
9
+ Version: 1.4.7
10
  */
11
 
12
  /*
inc/cache_enabler.class.php CHANGED
@@ -445,19 +445,25 @@ final class Cache_Enabler {
445
  * set or unset WP_CACHE constant
446
  *
447
  * @since 1.1.1
448
- * @change 1.4.5
449
  *
450
  * @param boolean $wp_cache_value true to set WP_CACHE constant in wp-config.php, false to unset
451
  */
452
 
453
  private static function _set_wp_cache( $wp_cache_value = true ) {
454
 
455
- // get wp-config.php file
456
- $wp_config_file = ABSPATH . 'wp-config.php';
 
 
 
 
 
 
457
 
458
- // check if wp-config.php file exists
459
- if ( file_exists( $wp_config_file ) && is_writable( $wp_config_file ) ) {
460
- // get wp-config.php as array
461
  $wp_config = file( $wp_config_file );
462
 
463
  // set Cache Enabler line
@@ -489,7 +495,7 @@ final class Cache_Enabler {
489
  array_unshift( $wp_config, "<?php\r\n", $wp_cache_ce_line );
490
  }
491
 
492
- // write wp-config.php file
493
  $fh = @fopen( $wp_config_file, 'w' );
494
  foreach( $wp_config as $ln ) {
495
  @fwrite( $fh, $ln );
@@ -1218,16 +1224,26 @@ final class Cache_Enabler {
1218
  * clear page cache by post ID
1219
  *
1220
  * @since 1.0.0
1221
- * @change 1.4.0
1222
  *
1223
- * @param integer $post_id post ID
1224
  */
1225
 
1226
  public static function clear_page_cache_by_post_id( $post_id ) {
1227
 
 
 
 
 
 
1228
  // validate integer
1229
  if ( ! is_int( $post_id ) ) {
1230
- return;
 
 
 
 
 
1231
  }
1232
 
1233
  // clear page cache
@@ -1239,36 +1255,29 @@ final class Cache_Enabler {
1239
  * clear page cache by URL
1240
  *
1241
  * @since 1.0.0
1242
- * @change 1.4.3
1243
  *
1244
- * @param string $url URL of a page
 
1245
  */
1246
 
1247
- public static function clear_page_cache_by_url( $url ) {
1248
 
1249
- // validate string
1250
- if ( ! is_string( $url ) ) {
1251
  return;
1252
  }
1253
 
1254
- // get home page URL
1255
- $home_page_url = get_site_url( null, '/' );
1256
-
1257
- // check if URL is the home page
1258
- if ( $url === $home_page_url ) {
1259
- self::clear_home_page_cache();
1260
- } else {
1261
- call_user_func(
1262
- array(
1263
- self::$disk,
1264
- 'delete_asset',
1265
- ),
1266
- $url
1267
- );
1268
  }
1269
 
 
 
 
1270
  // clear cache by URL post hook
1271
- do_action( 'ce_action_cache_by_url_cleared' );
1272
  }
1273
 
1274
 
@@ -1276,17 +1285,13 @@ final class Cache_Enabler {
1276
  * clear home page cache
1277
  *
1278
  * @since 1.0.7
1279
- * @change 1.2.3
1280
  */
1281
 
1282
  public static function clear_home_page_cache() {
1283
 
1284
- call_user_func(
1285
- array(
1286
- self::$disk,
1287
- 'clear_home',
1288
- )
1289
- );
1290
 
1291
  // clear home page cache post hook
1292
  do_action( 'ce_action_home_page_cache_cleared' );
@@ -1297,9 +1302,9 @@ final class Cache_Enabler {
1297
  * clear blog ID cache
1298
  *
1299
  * @since 1.4.0
1300
- * @change 1.4.6
1301
  *
1302
- * @param integer $blog_id blog ID
1303
  */
1304
 
1305
  public static function clear_blog_id_cache( $blog_id ) {
@@ -1311,7 +1316,12 @@ final class Cache_Enabler {
1311
 
1312
  // validate integer
1313
  if ( ! is_int( $blog_id ) ) {
1314
- return;
 
 
 
 
 
1315
  }
1316
 
1317
  // set clear URL
@@ -1320,7 +1330,7 @@ final class Cache_Enabler {
1320
  // network with subdomain configuration
1321
  if ( is_subdomain_install() ) {
1322
  // clear main site or subsite cache
1323
- self::clear_page_cache_by_url( $clear_url );
1324
  // network with subdirectory configuration
1325
  } else {
1326
  // get blog path
@@ -1344,7 +1354,7 @@ final class Cache_Enabler {
1344
  // if cached page belongs to main site
1345
  if ( ! in_array( $page_path, $blog_paths ) ) {
1346
  // clear page cache
1347
- self::clear_page_cache_by_url( $clear_url . $page_path );
1348
  }
1349
  }
1350
 
@@ -1353,7 +1363,7 @@ final class Cache_Enabler {
1353
  // subsite
1354
  } else {
1355
  // clear subsite cache
1356
- self::clear_page_cache_by_url( $clear_url );
1357
  }
1358
  }
1359
  }
@@ -1412,6 +1422,33 @@ final class Cache_Enabler {
1412
  }
1413
 
1414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1415
  /**
1416
  * check if mobile
1417
  *
@@ -1457,7 +1494,7 @@ final class Cache_Enabler {
1457
  * check to bypass the cache
1458
  *
1459
  * @since 1.0.0
1460
- * @change 1.4.6
1461
  *
1462
  * @return boolean true if exception, false otherwise
1463
  *
@@ -1482,7 +1519,7 @@ final class Cache_Enabler {
1482
  }
1483
 
1484
  // check conditional tags
1485
- if ( self::_is_wp_cache_disabled() || self::_is_index() || is_search() || self::_is_sitemap() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required() ) {
1486
  return true;
1487
  }
1488
 
@@ -1678,7 +1715,7 @@ final class Cache_Enabler {
1678
 
1679
  public static function set_cache( $data ) {
1680
 
1681
- // check if empty
1682
  if ( empty( $data ) ) {
1683
  return '';
1684
  }
@@ -1686,13 +1723,7 @@ final class Cache_Enabler {
1686
  $data = apply_filters( 'cache_enabler_before_store', $data );
1687
 
1688
  // store as asset
1689
- call_user_func(
1690
- array(
1691
- self::$disk,
1692
- 'store_asset',
1693
- ),
1694
- self::_minify_cache( $data )
1695
- );
1696
 
1697
  return $data;
1698
  }
@@ -1713,12 +1744,7 @@ final class Cache_Enabler {
1713
  }
1714
 
1715
  // get asset cache status
1716
- $cached = call_user_func(
1717
- array(
1718
- self::$disk,
1719
- 'check_asset',
1720
- )
1721
- );
1722
 
1723
  // check if cache is empty
1724
  if ( empty( $cached ) ) {
@@ -1727,12 +1753,7 @@ final class Cache_Enabler {
1727
  }
1728
 
1729
  // get cache expiry status
1730
- $expired = call_user_func(
1731
- array(
1732
- self::$disk,
1733
- 'check_expiry',
1734
- )
1735
- );
1736
 
1737
  // check if cache has expired
1738
  if ( $expired ) {
@@ -1741,12 +1762,7 @@ final class Cache_Enabler {
1741
  }
1742
 
1743
  // return cached asset
1744
- call_user_func(
1745
- array(
1746
- self::$disk,
1747
- 'get_asset',
1748
- )
1749
- );
1750
  }
1751
 
1752
 
445
  * set or unset WP_CACHE constant
446
  *
447
  * @since 1.1.1
448
+ * @change 1.4.7
449
  *
450
  * @param boolean $wp_cache_value true to set WP_CACHE constant in wp-config.php, false to unset
451
  */
452
 
453
  private static function _set_wp_cache( $wp_cache_value = true ) {
454
 
455
+ // get config file
456
+ if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
457
+ // config file resides in ABSPATH
458
+ $wp_config_file = ABSPATH . 'wp-config.php';
459
+ } elseif ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
460
+ // config file resides one level above ABSPATH but is not part of another installation
461
+ $wp_config_file = dirname( ABSPATH ) . '/wp-config.php';
462
+ }
463
 
464
+ // check if config file can be written to
465
+ if ( is_writable( $wp_config_file ) ) {
466
+ // get config file as array
467
  $wp_config = file( $wp_config_file );
468
 
469
  // set Cache Enabler line
495
  array_unshift( $wp_config, "<?php\r\n", $wp_cache_ce_line );
496
  }
497
 
498
+ // write config file
499
  $fh = @fopen( $wp_config_file, 'w' );
500
  foreach( $wp_config as $ln ) {
501
  @fwrite( $fh, $ln );
1224
  * clear page cache by post ID
1225
  *
1226
  * @since 1.0.0
1227
+ * @change 1.4.7
1228
  *
1229
+ * @param integer|string $post_id post ID
1230
  */
1231
 
1232
  public static function clear_page_cache_by_post_id( $post_id ) {
1233
 
1234
+ // check if post ID is empty
1235
+ if ( empty( $post_id ) ) {
1236
+ return;
1237
+ }
1238
+
1239
  // validate integer
1240
  if ( ! is_int( $post_id ) ) {
1241
+ // if string try to convert to integer
1242
+ $post_id = (int) $post_id;
1243
+ // conversion failed
1244
+ if ( ! $post_id ) {
1245
+ return;
1246
+ }
1247
  }
1248
 
1249
  // clear page cache
1255
  * clear page cache by URL
1256
  *
1257
  * @since 1.0.0
1258
+ * @change 1.4.7
1259
  *
1260
+ * @param string $clear_url full or relative URL of a page
1261
+ * @param string $clear_type clear all specific `page` variants or the entire `dir`
1262
  */
1263
 
1264
+ public static function clear_page_cache_by_url( $clear_url, $clear_type = 'page' ) {
1265
 
1266
+ // check if clear URL is empty
1267
+ if ( empty( $clear_url ) ) {
1268
  return;
1269
  }
1270
 
1271
+ // validate string
1272
+ if ( ! is_string( $clear_url ) ) {
1273
+ return;
 
 
 
 
 
 
 
 
 
 
 
1274
  }
1275
 
1276
+ // clear URL
1277
+ call_user_func( array( self::$disk, 'delete_asset' ), $clear_url, $clear_type );
1278
+
1279
  // clear cache by URL post hook
1280
+ do_action( 'ce_action_cache_by_url_cleared', $clear_url );
1281
  }
1282
 
1283
 
1285
  * clear home page cache
1286
  *
1287
  * @since 1.0.7
1288
+ * @change 1.4.7
1289
  */
1290
 
1291
  public static function clear_home_page_cache() {
1292
 
1293
+ // clear home page cache
1294
+ self::clear_page_cache_by_url( get_site_url() );
 
 
 
 
1295
 
1296
  // clear home page cache post hook
1297
  do_action( 'ce_action_home_page_cache_cleared' );
1302
  * clear blog ID cache
1303
  *
1304
  * @since 1.4.0
1305
+ * @change 1.4.7
1306
  *
1307
+ * @param integer|string $blog_id blog ID
1308
  */
1309
 
1310
  public static function clear_blog_id_cache( $blog_id ) {
1316
 
1317
  // validate integer
1318
  if ( ! is_int( $blog_id ) ) {
1319
+ // if string try to convert to integer
1320
+ $blog_id = (int) $blog_id;
1321
+ // conversion failed
1322
+ if ( ! $blog_id ) {
1323
+ return;
1324
+ }
1325
  }
1326
 
1327
  // set clear URL
1330
  // network with subdomain configuration
1331
  if ( is_subdomain_install() ) {
1332
  // clear main site or subsite cache
1333
+ self::clear_page_cache_by_url( $clear_url, 'dir' );
1334
  // network with subdirectory configuration
1335
  } else {
1336
  // get blog path
1354
  // if cached page belongs to main site
1355
  if ( ! in_array( $page_path, $blog_paths ) ) {
1356
  // clear page cache
1357
+ self::clear_page_cache_by_url( $clear_url . $page_path, 'dir' );
1358
  }
1359
  }
1360
 
1363
  // subsite
1364
  } else {
1365
  // clear subsite cache
1366
+ self::clear_page_cache_by_url( $clear_url, 'dir' );
1367
  }
1368
  }
1369
  }
1422
  }
1423
 
1424
 
1425
+
1426
+
1427
+ /**
1428
+ * check if trailing slash redirect
1429
+ *
1430
+ * @since 1.4.7
1431
+ * @change 1.4.7
1432
+ *
1433
+ * @return boolean true if a redirect is required, false otherwise
1434
+ */
1435
+
1436
+ private static function _is_trailing_slash_redirect() {
1437
+
1438
+ // check if trailing slash is set and missing
1439
+ if ( self::permalink_structure_has_trailing_slash() ) {
1440
+ if ( ! preg_match( '/\/(|\?.*)$/', $_SERVER['REQUEST_URI'] ) ) {
1441
+ return true;
1442
+ }
1443
+ // if trailing slash is not set and appended
1444
+ } elseif ( preg_match( '/(?!^)\/(|\?.*)$/', $_SERVER['REQUEST_URI'] ) ) {
1445
+ return true;
1446
+ }
1447
+
1448
+ return false;
1449
+ }
1450
+
1451
+
1452
  /**
1453
  * check if mobile
1454
  *
1494
  * check to bypass the cache
1495
  *
1496
  * @since 1.0.0
1497
+ * @change 1.4.7
1498
  *
1499
  * @return boolean true if exception, false otherwise
1500
  *
1519
  }
1520
 
1521
  // check conditional tags
1522
+ if ( self::_is_wp_cache_disabled() || self::_is_index() || self::_is_sitemap() || self::_is_trailing_slash_redirect() || is_search() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required() ) {
1523
  return true;
1524
  }
1525
 
1715
 
1716
  public static function set_cache( $data ) {
1717
 
1718
+ // check if page is empty
1719
  if ( empty( $data ) ) {
1720
  return '';
1721
  }
1723
  $data = apply_filters( 'cache_enabler_before_store', $data );
1724
 
1725
  // store as asset
1726
+ call_user_func( array( self::$disk, 'store_asset' ), self::_minify_cache( $data ) );
 
 
 
 
 
 
1727
 
1728
  return $data;
1729
  }
1744
  }
1745
 
1746
  // get asset cache status
1747
+ $cached = call_user_func( array( self::$disk, 'check_asset' ) );
 
 
 
 
 
1748
 
1749
  // check if cache is empty
1750
  if ( empty( $cached ) ) {
1753
  }
1754
 
1755
  // get cache expiry status
1756
+ $expired = call_user_func( array( self::$disk, 'check_expiry' ) );
 
 
 
 
 
1757
 
1758
  // check if cache has expired
1759
  if ( $expired ) {
1762
  }
1763
 
1764
  // return cached asset
1765
+ call_user_func( array( self::$disk, 'get_asset' ) );
 
 
 
 
 
1766
  }
1767
 
1768
 
inc/cache_enabler_disk.class.php CHANGED
@@ -116,20 +116,27 @@ final class Cache_Enabler_Disk {
116
  * delete asset
117
  *
118
  * @since 1.0.0
119
- * @change 1.0.0
120
  *
121
- * @param string $url URL of cached asset
 
122
  */
123
 
124
- public static function delete_asset( $url ) {
125
 
126
- // check if URL is empty
127
- if ( empty( $url ) ) {
128
- wp_die( 'URL is empty.' );
129
- }
 
130
 
131
- // delete
132
- self::_clear_dir( self::_file_path( $url ) );
 
 
 
 
 
133
  }
134
 
135
 
@@ -147,27 +154,6 @@ final class Cache_Enabler_Disk {
147
  }
148
 
149
 
150
- /**
151
- * clear home cache
152
- *
153
- * @since 1.0.7
154
- * @change 1.4.0
155
- */
156
-
157
- public static function clear_home() {
158
-
159
- $path = sprintf(
160
- '%s%s%s%s',
161
- CE_CACHE_DIR,
162
- DIRECTORY_SEPARATOR,
163
- preg_replace( '#^https?://#', '', get_option( 'siteurl' ) ),
164
- DIRECTORY_SEPARATOR
165
- );
166
-
167
- array_map( 'unlink', glob( $path . self::FILE_GLOB ) );
168
- }
169
-
170
-
171
  /**
172
  * get asset
173
  *
@@ -328,7 +314,7 @@ final class Cache_Enabler_Disk {
328
  * clear directory
329
  *
330
  * @since 1.0.0
331
- * @change 1.0.0
332
  *
333
  * @param string $dir directory
334
  */
@@ -344,16 +330,24 @@ final class Cache_Enabler_Disk {
344
  }
345
 
346
  // get directory data
347
- $data_dir = @scandir( $dir );
348
- if( gettype( $data_dir ) === 'array' ) {
349
- $objects = array_diff(
350
- $data_dir,
351
- array( '..', '.' )
352
- );
353
- }
354
 
355
- // check if empty
356
  if ( empty( $objects ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  return;
358
  }
359
 
@@ -369,7 +363,7 @@ final class Cache_Enabler_Disk {
369
  }
370
  }
371
 
372
- // delete
373
  @rmdir( $dir );
374
 
375
  // clears file status cache
@@ -389,17 +383,15 @@ final class Cache_Enabler_Disk {
389
 
390
  public static function cache_size( $dir = '.' ) {
391
 
392
- // check if not directory
393
  if ( ! is_dir( $dir ) ) {
394
  return;
395
  }
396
 
397
  // get directory data
398
- $objects = array_diff(
399
- scandir( $dir ),
400
- array( '..', '.' )
401
- );
402
 
 
403
  if ( empty( $objects ) ) {
404
  return;
405
  }
@@ -423,10 +415,10 @@ final class Cache_Enabler_Disk {
423
 
424
 
425
  /**
426
- * cache path
427
  *
428
  * @since 1.0.0
429
- * @change 1.4.5
430
  *
431
  * @param string $path URI or permalink
432
  * @return string $diff path to cached file
@@ -448,7 +440,7 @@ final class Cache_Enabler_Disk {
448
  )
449
  );
450
 
451
- if ( is_file( $path ) > 0 ) {
452
  wp_die( 'Path is not valid.' );
453
  }
454
 
@@ -460,14 +452,14 @@ final class Cache_Enabler_Disk {
460
  * get file scheme
461
  *
462
  * @since 1.4.0
463
- * @change 1.4.2
464
  *
465
  * @return string https or http
466
  */
467
 
468
  private static function _file_scheme() {
469
 
470
- return ( ( isset( $_SERVER['HTTPS'] ) && ! empty( $_SERVER['HTTPS'] ) ) || $_SERVER['SERVER_PORT'] === '443' ) ? 'https' : 'http';
471
  }
472
 
473
 
@@ -567,6 +559,28 @@ final class Cache_Enabler_Disk {
567
  }
568
 
569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
570
  /**
571
  * read settings file
572
  *
116
  * delete asset
117
  *
118
  * @since 1.0.0
119
+ * @change 1.4.7
120
  *
121
+ * @param string $clear_url full or relative URL of a page
122
+ * @param string $clear_type if `dir` clear the entire directory
123
  */
124
 
125
+ public static function delete_asset( $clear_url, $clear_type ) {
126
 
127
+ // get directory
128
+ $dir = self::_file_path( $clear_url );
129
+
130
+ // delete all cached variants in directory
131
+ array_map( 'unlink', glob( $dir . self::FILE_GLOB ) );
132
 
133
+ // get directory data
134
+ $objects = self::_get_dir( $dir );
135
+
136
+ // check if directory is now empty or if it needs to be cleared anyways
137
+ if ( empty( $objects ) || $clear_type === 'dir' ) {
138
+ self::_clear_dir( $dir );
139
+ }
140
  }
141
 
142
 
154
  }
155
 
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  /**
158
  * get asset
159
  *
314
  * clear directory
315
  *
316
  * @since 1.0.0
317
+ * @change 1.4.7
318
  *
319
  * @param string $dir directory
320
  */
330
  }
331
 
332
  // get directory data
333
+ $objects = self::_get_dir( $dir );
 
 
 
 
 
 
334
 
335
+ // check if directory is empty
336
  if ( empty( $objects ) ) {
337
+ // delete empty directory
338
+ @rmdir( $dir );
339
+
340
+ // get parent directory
341
+ $parent_dir = preg_replace( '/\/[^\/]+$/', '', $dir );
342
+
343
+ // get parent directory data
344
+ $parent_objects = self::_get_dir( $parent_dir );
345
+
346
+ // check if parent directory is also empty
347
+ if ( empty( $parent_objects ) ) {
348
+ self::_clear_dir( $parent_dir );
349
+ }
350
+
351
  return;
352
  }
353
 
363
  }
364
  }
365
 
366
+ // delete directory
367
  @rmdir( $dir );
368
 
369
  // clears file status cache
383
 
384
  public static function cache_size( $dir = '.' ) {
385
 
386
+ // check if directory
387
  if ( ! is_dir( $dir ) ) {
388
  return;
389
  }
390
 
391
  // get directory data
392
+ $objects = self::_get_dir( $dir );
 
 
 
393
 
394
+ // check if empty
395
  if ( empty( $objects ) ) {
396
  return;
397
  }
415
 
416
 
417
  /**
418
+ * get cached file path
419
  *
420
  * @since 1.0.0
421
+ * @change 1.4.7
422
  *
423
  * @param string $path URI or permalink
424
  * @return string $diff path to cached file
440
  )
441
  );
442
 
443
+ if ( is_file( $path ) ) {
444
  wp_die( 'Path is not valid.' );
445
  }
446
 
452
  * get file scheme
453
  *
454
  * @since 1.4.0
455
+ * @change 1.4.7
456
  *
457
  * @return string https or http
458
  */
459
 
460
  private static function _file_scheme() {
461
 
462
+ return ( ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) || $_SERVER['SERVER_PORT'] === '443' ) ? 'https' : 'http';
463
  }
464
 
465
 
559
  }
560
 
561
 
562
+ /**
563
+ * get directory data
564
+ *
565
+ * @since 1.4.7
566
+ * @change 1.4.7
567
+ *
568
+ * @param string $dir directory path
569
+ * @return array $objects directory objects
570
+ */
571
+
572
+ private static function _get_dir( $dir ) {
573
+
574
+ // scan directory
575
+ $data_dir = @scandir( $dir );
576
+
577
+ if ( is_array( $data_dir ) ) {
578
+ $objects = array_diff( $data_dir, array( '..', '.' ) );
579
+ return $objects;
580
+ }
581
+ }
582
+
583
+
584
  /**
585
  * read settings file
586
  *
readme.txt CHANGED
@@ -81,6 +81,14 @@ When combined with Optimus, the WordPress Cache Enabler allows you to easily del
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
 
 
84
  = 1.4.6 =
85
  * Add cache bypass method for sitemaps (#104)
86
  * Fix cache clearing for subdirectory multisite networks (#103)
81
 
82
  == Changelog ==
83
 
84
+ = 1.4.7 =
85
+ * Update getting wp-config.php if one level above installation (#106)
86
+ * Add clear types for strict cache clearing (#110)
87
+ * Fix advanced cache settings recognition for subdirectory multisite networks
88
+ * Fix WP-CLI clear command for post IDs (#110)
89
+ * Fix scheme-based caching for NGINX/PHP-FPM (#109)
90
+ * Fix trailing slash handling
91
+
92
  = 1.4.6 =
93
  * Add cache bypass method for sitemaps (#104)
94
  * Fix cache clearing for subdirectory multisite networks (#103)