Page Optimize - Version 0.4.4

Version Description

  • Don't queue the cache cleaning WP Cron job if we aren't caching.
  • Cleanup cache if we turned caching off or directory changed.
Download this release

Release Info

Developer aidvu
Plugin Icon wp plugin Page Optimize
Version 0.4.4
Comparing to
See all releases

Code changes from version 0.4.3 to 0.4.4

Files changed (2) hide show
  1. page-optimize.php +36 -11
  2. readme.txt +14 -6
page-optimize.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Page Optimize
4
  Plugin URI: https://wordpress.org/plugins/page-optimize/
5
  Description: Optimizes JS and CSS for faster page load and render in the browser.
6
  Author: Automattic
7
- Version: 0.4.3
8
  Author URI: http://automattic.com/
9
  */
10
 
@@ -31,15 +31,25 @@ if ( isset( $_SERVER['REQUEST_URI'] ) && '/_static/' === substr( $_SERVER['REQUE
31
  exit;
32
  }
33
 
34
- function page_optimize_cache_cleanup( $file_age = DAY_IN_SECONDS ) {
35
- if ( ! is_dir( PAGE_OPTIMIZE_CACHE_DIR ) ) {
36
  return;
37
  }
38
 
 
 
 
 
 
 
 
 
 
 
39
  // Grab all files in the cache directory
40
- $cache_files = glob( PAGE_OPTIMIZE_CACHE_DIR . '/page-optimize-cache-*' );
41
 
42
- // Cleanup all files older than 24 hours
43
  foreach ( $cache_files as $cache_file ) {
44
  if ( ! is_file( $cache_file ) ) {
45
  continue;
@@ -54,9 +64,14 @@ add_action( PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB, 'page_optimize_cache_cleanup'
54
 
55
  // Unschedule cache cleanup, and purge cache directory
56
  function page_optimize_deactivate() {
57
- page_optimize_cache_cleanup( 0 /* max file age */ );
 
 
 
 
 
58
 
59
- wp_clear_scheduled_hook( PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB );
60
  }
61
  register_deactivation_hook( __FILE__, 'page_optimize_deactivate' );
62
 
@@ -236,6 +251,19 @@ function page_optimize_remove_concat_base_prefix( $original_fs_path ) {
236
  return '/page-optimize-resource-outside-base-path/' . basename( $original_fs_path );
237
  }
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  // Cases when we don't want to concat
240
  function page_optimize_bail() {
241
  // Bail if we're in customizer
@@ -257,10 +285,7 @@ function page_optimize_init() {
257
  return;
258
  }
259
 
260
- // Schedule cache cleanup on init
261
- if( ! wp_next_scheduled( PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB ) ) {
262
- wp_schedule_event( time(), 'daily', PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB );
263
- }
264
 
265
  require_once __DIR__ . '/settings.php';
266
  require_once __DIR__ . '/concat-css.php';
4
  Plugin URI: https://wordpress.org/plugins/page-optimize/
5
  Description: Optimizes JS and CSS for faster page load and render in the browser.
6
  Author: Automattic
7
+ Version: 0.4.4
8
  Author URI: http://automattic.com/
9
  */
10
 
31
  exit;
32
  }
33
 
34
+ function page_optimize_cache_cleanup( $cache_folder = false, $file_age = DAY_IN_SECONDS ) {
35
+ if ( ! is_dir( $cache_folder ) ) {
36
  return;
37
  }
38
 
39
+ // If cache is disabled when the cleanup runs, purge it
40
+ $using_cache = defined( 'PAGE_OPTIMIZE_CACHE_DIR' ) && ! empty( PAGE_OPTIMIZE_CACHE_DIR );
41
+ if ( ! $using_cache ) {
42
+ $file_age = 0;
43
+ }
44
+ // If the cache folder changed since queueing, purge it
45
+ if ( $using_cache && $cache_folder !== PAGE_OPTIMIZE_CACHE_DIR ) {
46
+ $file_age = 0;
47
+ }
48
+
49
  // Grab all files in the cache directory
50
+ $cache_files = glob( $cache_folder . '/page-optimize-cache-*' );
51
 
52
+ // Cleanup all files older than $file_age
53
  foreach ( $cache_files as $cache_file ) {
54
  if ( ! is_file( $cache_file ) ) {
55
  continue;
64
 
65
  // Unschedule cache cleanup, and purge cache directory
66
  function page_optimize_deactivate() {
67
+ $cache_folder = false;
68
+ if ( defined( 'PAGE_OPTIMIZE_CACHE_DIR' ) && ! empty( PAGE_OPTIMIZE_CACHE_DIR ) ) {
69
+ $cache_folder = PAGE_OPTIMIZE_CACHE_DIR;
70
+ }
71
+
72
+ page_optimize_cache_cleanup( $cache_folder, 0 /* max file age in seconds */ );
73
 
74
+ wp_clear_scheduled_hook( PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB, [ $cache_folder ] );
75
  }
76
  register_deactivation_hook( __FILE__, 'page_optimize_deactivate' );
77
 
251
  return '/page-optimize-resource-outside-base-path/' . basename( $original_fs_path );
252
  }
253
 
254
+ function page_optimize_schedule_cache_cleanup() {
255
+ $cache_folder = false;
256
+ if ( defined( 'PAGE_OPTIMIZE_CACHE_DIR' ) && ! empty( PAGE_OPTIMIZE_CACHE_DIR ) ) {
257
+ $cache_folder = PAGE_OPTIMIZE_CACHE_DIR;
258
+ }
259
+ $args = [ $cache_folder ];
260
+
261
+ // If caching is on, and job isn't queued for current cache folder
262
+ if( false !== $cache_folder && false === wp_next_scheduled( PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB, $args ) ) {
263
+ wp_schedule_event( time(), 'daily', PAGE_OPTIMIZE_CRON_CACHE_CLEANUP_JOB, $args );
264
+ }
265
+ }
266
+
267
  // Cases when we don't want to concat
268
  function page_optimize_bail() {
269
  // Bail if we're in customizer
285
  return;
286
  }
287
 
288
+ page_optimize_schedule_cache_cleanup();
 
 
 
289
 
290
  require_once __DIR__ . '/settings.php';
291
  require_once __DIR__ . '/concat-css.php';
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === page-optimize ===
2
  Contributors: aidvu, bpayton
3
  Tags: performance
4
  Requires at least: 5.3
5
  Tested up to: 5.3
6
  Requires PHP: 7.2
7
- Stable tag: 0.4.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -17,9 +17,7 @@ This plugin supports a few features that may improve the performance of page loa
17
  * Concatenate CSS
18
  * Concatenate JavaScript
19
  * Execution timing of non-critical scripts
20
-
21
- Notes:
22
- * Changing script execution timing can be risky and will not work well for all sites.
23
 
24
  == Installation ==
25
 
@@ -51,4 +49,14 @@ Supported query params:
51
 
52
  == Changelog ==
53
 
54
- Initial release. No changes yet. :)
 
 
 
 
 
 
 
 
 
 
1
+ === Page Optimize ===
2
  Contributors: aidvu, bpayton
3
  Tags: performance
4
  Requires at least: 5.3
5
  Tested up to: 5.3
6
  Requires PHP: 7.2
7
+ Stable tag: 0.4.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
17
  * Concatenate CSS
18
  * Concatenate JavaScript
19
  * Execution timing of non-critical scripts
20
+ * Note: Changing script execution timing can be risky and will not work well for all sites.
 
 
21
 
22
  == Installation ==
23
 
49
 
50
  == Changelog ==
51
 
52
+ = 0.4.4 =
53
+ * Don't queue the cache cleaning WP Cron job if we aren't caching.
54
+ * Cleanup cache if we turned caching off or directory changed.
55
+
56
+ = 0.4.3 =
57
+ * gzip in PHP slows stuff down a bit. Simply don't do this. Any web server can handle this better.
58
+ * also remove the output buffering, no need for that anymore
59
+ * CSS Minification can sometimes slow things down significantly. Add constant to enable/disable.
60
+
61
+ = 0.4.2 =
62
+ * Initial release. No changes yet. :)