Asset CleanUp: Page Speed Booster - Version 1.2.9.2

Version Description

  • WooCommerce & WP Rocket Compatibility - Bug Fix: When both WooCommerce and WP Rocket are active and an administrator user is logged-in and tries to place an order, the "Sorry, your session is expired." message is returned
Download this release

Release Info

Developer gabelivan
Plugin Icon 128x128 Asset CleanUp: Page Speed Booster
Version 1.2.9.2
Comparing to
See all releases

Code changes from version 1.2.9.1 to 1.2.9.2

classes/OptimizeCss.php CHANGED
@@ -12,11 +12,6 @@ class OptimizeCss
12
*/
13
public static $relPathCssCacheDir = '/cache/asset-cleanup/css/'; // keep trailing slash at the end
14
15
- /**
16
- * @var
17
- */
18
- public $transientCssName;
19
-
20
/**
21
* @var string
22
*/
@@ -25,7 +20,12 @@ class OptimizeCss
25
/**
26
* @var float|int
27
*/
28
- public static $transientExpiresIn = 60 * 60 * 12; // 8 hours in seconds
29
30
/**
31
* OptimizeCss constructor.
@@ -36,13 +36,17 @@ class OptimizeCss
36
add_action('after_switch_theme', array($this, 'clearAllCacheTransients'));
37
38
// Is WP Rocket's page cache cleared? Clear Asset CleanUp's CSS cache files too
39
- add_action('before_rocket_clean_domain', array($this, 'clearAllCacheTransients'));
40
41
// Is the CSS cache transient deleted? Remove the cached CSS file too
42
// The action below is triggered prior to transient deletion and ONLY in the front-end view (not within the Dashboard)
43
add_action('plugins_loaded', array($this, 'afterPluginsLoaded'));
44
45
- add_action('admin_post_assetcleanup_clear_assets_cache', array($this, 'clearAllCacheTransients'));
46
}
47
48
/**
@@ -61,10 +65,11 @@ class OptimizeCss
61
}
62
}
63
64
- $this->transientCssName = self::$transientCssNamePrefix . md5( $toMdFive );
65
66
// @TODO: Remove cached CSS files after a while making sure no caching system still loads the old file
67
- //add_action( 'delete_transient_' . $this->transientCssName, array( $this, 'clearTransientCssCacheFile' ) );
68
}
69
}
70
@@ -295,7 +300,7 @@ HTML;
295
);
296
}
297
298
- $assetContent = file_get_contents($localAssetsPath);
299
300
if ($assetContent) {
301
$finalAssetsContents .= $this->maybeFixCssBackgroundUrls($assetContent, $pathToAssetDir . '/') . "\n\n";
@@ -331,7 +336,7 @@ HTML;
331
return array();
332
}
333
334
- $optionValue = get_transient($this->transientCssName);
335
336
if ($optionValue) {
337
$optionValueArray = json_decode($optionValue, ARRAY_A);
@@ -370,7 +375,7 @@ HTML;
370
)
371
);
372
373
- set_transient($this->transientCssName, $optionValue, self::$transientExpiresIn);
374
}
375
376
/**
@@ -383,7 +388,7 @@ HTML;
383
return;
384
}
385
386
- delete_transient($this->transientCssName);
387
}
388
389
/**
@@ -400,7 +405,7 @@ HTML;
400
$cssContent
401
);
402
403
- // Avoid Background URLs starting with "data" or "http" as they do not need to have the path updated
404
preg_match_all('/url\((?![\'"]?(?:data|http):)[\'"]?([^\'"\)]*)[\'"]?\)/i', $cssContent, $matches, PREG_PATTERN_ORDER);
405
406
// If it start with forward slash (/), it doesn't need fix, just skip it
@@ -521,14 +526,14 @@ HTML;
521
// Always in the front-end view
522
// Do not combine if there's a POST request as there could be assets loading conditionally
523
// that might not be needed when the page is accessed without POST, making the final CSS file larger
524
- if (is_admin() || ! empty($_POST) || array_key_exists('wpacu_no_css_combine', $_GET)) {
525
return false; // Do not combine
526
}
527
528
$pluginSettings = Main::instance()->settings;
529
530
if ($pluginSettings['test_mode']) {
531
- return false; // Do not combine anything is "Test Mode" is ON
532
}
533
534
if ($pluginSettings['combine_loaded_css'] === '') {
@@ -548,10 +553,14 @@ HTML;
548
}
549
550
/**
551
- *
552
*/
553
- public function clearAllCacheTransients()
554
{
555
global $wpdb;
556
557
// First, select all and get the combined CSS file names in order to be deleted
@@ -576,16 +585,35 @@ SQL;
576
}
577
}
578
579
- if ( wp_get_referer() ) {
580
wp_safe_redirect( wp_get_referer() );
581
}
582
}
583
584
/**
585
* Triggers in the front-end view only for the current viewed page
586
*/
587
/*
588
- public function clearTransientCssCacheFile()
589
{
590
$optionValue = get_transient($this->transientCssName);
591
12
*/
13
public static $relPathCssCacheDir = '/cache/asset-cleanup/css/'; // keep trailing slash at the end
14
15
/**
16
* @var string
17
*/
20
/**
21
* @var float|int
22
*/
23
+ private static $_transientExpiresIn = 60 * 60 * 12; // 8 hours in seconds
24
+
25
+ /**
26
+ * @var
27
+ */
28
+ private $_transientCssName;
29
30
/**
31
* OptimizeCss constructor.
36
add_action('after_switch_theme', array($this, 'clearAllCacheTransients'));
37
38
// Is WP Rocket's page cache cleared? Clear Asset CleanUp's CSS cache files too
39
+ if (array_key_exists('action', $_GET) && $_GET['action'] === 'purge_cache') {
40
+ add_action( 'before_rocket_clean_domain', array( $this, 'clearAllCacheTransients' ) );
41
+ }
42
43
// Is the CSS cache transient deleted? Remove the cached CSS file too
44
// The action below is triggered prior to transient deletion and ONLY in the front-end view (not within the Dashboard)
45
add_action('plugins_loaded', array($this, 'afterPluginsLoaded'));
46
47
+ add_action('admin_post_assetcleanup_clear_assets_cache', function() {
48
+ $this->clearAllCacheTransients(true);
49
+ });
50
}
51
52
/**
65
}
66
}
67
68
+ $this->_transientCssName = self::$transientCssNamePrefix . md5( $toMdFive );
69
70
// @TODO: Remove cached CSS files after a while making sure no caching system still loads the old file
71
+ // @TODO: Maybe adding to "Tools" page would be an option
72
+ //add_action( 'delete_transient_' . $this->transientCssName, array( $this, 'clearCssCacheFile' ) );
73
}
74
}
75
300
);
301
}
302
303
+ $assetContent = @file_get_contents($localAssetsPath);
304
305
if ($assetContent) {
306
$finalAssetsContents .= $this->maybeFixCssBackgroundUrls($assetContent, $pathToAssetDir . '/') . "\n\n";
336
return array();
337
}
338
339
+ $optionValue = get_transient($this->_transientCssName);
340
341
if ($optionValue) {
342
$optionValueArray = json_decode($optionValue, ARRAY_A);
375
)
376
);
377
378
+ set_transient($this->_transientCssName, $optionValue, self::$_transientExpiresIn);
379
}
380
381
/**
388
return;
389
}
390
391
+ delete_transient($this->_transientCssName);
392
}
393
394
/**
405
$cssContent
406
);
407
408
+ // Avoid Background URLs starting with "data" or "http" as they do not need to have a path updated
409
preg_match_all('/url\((?![\'"]?(?:data|http):)[\'"]?([^\'"\)]*)[\'"]?\)/i', $cssContent, $matches, PREG_PATTERN_ORDER);
410
411
// If it start with forward slash (/), it doesn't need fix, just skip it
526
// Always in the front-end view
527
// Do not combine if there's a POST request as there could be assets loading conditionally
528
// that might not be needed when the page is accessed without POST, making the final CSS file larger
529
+ if (! empty($_POST) || array_key_exists('wpacu_no_css_combine', $_GET) || is_admin()) {
530
return false; // Do not combine
531
}
532
533
$pluginSettings = Main::instance()->settings;
534
535
if ($pluginSettings['test_mode']) {
536
+ return false; // Do not combine anything if "Test Mode" is ON
537
}
538
539
if ($pluginSettings['combine_loaded_css'] === '') {
553
}
554
555
/**
556
+ * @param bool $redirectAfter
557
*/
558
+ public function clearAllCacheTransients($redirectAfter = false)
559
{
560
+ if ($this->doNotClearAllCache()) {
561
+ return;
562
+ }
563
+
564
global $wpdb;
565
566
// First, select all and get the combined CSS file names in order to be deleted
585
}
586
}
587
588
+ if ( $redirectAfter && wp_get_referer() ) {
589
wp_safe_redirect( wp_get_referer() );
590
}
591
}
592
593
+ /**
594
+ * Prevent clear cache function in the following situations
595
+ *
596
+ * @return bool
597
+ */
598
+ public function doNotClearAllCache()
599
+ {
600
+ // WooCommerce GET or AJAX call
601
+ if (array_key_exists('wc-ajax', $_GET) && $_GET['wc-ajax']) {
602
+ return true;
603
+ }
604
+
605
+ if (defined('WC_DOING_AJAX') && WC_DOING_AJAX === true) {
606
+ return true;
607
+ }
608
+
609
+ return false;
610
+ }
611
+
612
/**
613
* Triggers in the front-end view only for the current viewed page
614
*/
615
/*
616
+ public function clearCssCacheFile()
617
{
618
$optionValue = get_transient($this->transientCssName);
619
freemius/templates/admin-notice-gabe-bkp.php DELETED
@@ -1,74 +0,0 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
- * @since 1.0.3
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- $dismiss_text = fs_text_x_inline( 'Dismiss', 'as close a window', 'dismiss' );
14
- ?>
15
- <div<?php if ( ! empty( $VARS['id'] ) ) : ?> data-id="<?php echo $VARS['id'] ?>"<?php endif ?><?php if ( ! empty( $VARS['manager_id'] ) ) : ?> data-manager-id="<?php echo $VARS['manager_id'] ?>"<?php endif ?>
16
- <?php
17
- // [wpacu_lite]
18
- // Hide "opt-in" notice that has "We made a few tweaks to the plugin"
19
- if ($VARS['manager_id'] === 'wp-asset-clean-up' && strpos($VARS['message'], 'made a few tweaks to the plugin') !== false) {
20
- ?>
21
- style="display: none !important;"
22
- <?php
23
- }
24
-
25
- $isWpacuPage = isset($_GET['page']) && (strpos($_GET['page'], 'wpassetcleanup_') !== false);
26
-
27
- $wpacuShowNoticePluginTitle = true;
28
-
29
- if ( $VARS['id'] === 'activation_pending' ) {
30
- if ( ! $isWpacuPage ) {
31
- ?>
32
- style="display: none !important;"
33
- <?php
34
- } else {
35
- $wpacuShowNoticePluginTitle = false;
36
- }
37
- }
38
-
39
-
40
- // [/wpacu_lite]
41
- ?>
42
- class="<?php
43
- switch ( $VARS['type'] ) {
44
- case 'error':
45
- echo 'error form-invalid';
46
- break;
47
- case 'promotion':
48
- echo 'updated promotion';
49
- break;
50
- case 'update':
51
- // echo 'update-nag update';
52
- // break;
53
- case 'success':
54
- default:
55
- echo 'updated success';
56
- break;
57
- }
58
- ?> fs-notice<?php if ( ! empty( $VARS['sticky'] ) ) {
59
- echo ' fs-sticky';
60
- } ?><?php if ( ! empty( $VARS['plugin'] ) ) {
61
- echo ' fs-has-title';
62
- } ?>"><?php if ( ! empty( $VARS['plugin'] ) && $wpacuShowNoticePluginTitle ) { ?>
63
- <label class="fs-plugin-title"><?php echo $VARS['plugin'] ?></label>
64
- <?php } ?>
65
- <?php if ( ! empty( $VARS['sticky'] ) ) : ?>
66
- <div class="fs-close"><i class="dashicons dashicons-no"
67
- title="<?php echo esc_attr( $dismiss_text ) ?>"></i> <span><?php echo esc_html( $dismiss_text ) ?></span>
68
- </div>
69
- <?php endif ?>
70
- <div class="fs-notice-body">
71
- <?php if ( ! empty( $VARS['title'] ) ) : ?><b><?php echo $VARS['title'] ?></b> <?php endif ?>
72
- <?php echo $VARS['message'] ?>
73
- </div>
74
- </div>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: pagespeed, page speed, dequeue, performance, gtmetrix
4
Donate link: https://gabelivan.com/items/wp-asset-cleanup-pro/?utm_source=wp_org_lite&utm_medium=donate
5
Requires at least: 4.4
6
Tested up to: 5.0.3
7
- Stable tag: 1.2.9.1
8
License: GPLv3
9
License URI: http://www.gnu.org/licenses/gpl.html
10
@@ -46,7 +46,7 @@ Give Asset CleanUp a try! If you want to unlock more features, you can <a href="
46
* If you're planning to use the Lite version of the plugin:
47
48
1. Go to "Plugins" -> "Add New" -> "Upload Plugin" and attach the downloaded ZIP archive from the plugin's page or use the "Search plugins..." form on the right side and look for "asset cleanup"
49
- 2. Install and activate the plugin (if server's PHP version is below 5.3, it will show you an error and activation will not be made).
50
3. Edit any Page / Post / Custom Post Type and you will see a meta box called "Asset CleanUp" which will load the list of all the loaded .CSS and .JS files. Alternatively, you will be able to manage the assets list in the front-end view as well (at the bottom of the pages) if you've enabled "Manage in the Front-end?" in plugin's settings page.
51
4. To unload the assets for the home page, go to "Asset CleanUp" menu on the left panel of the Dashboard and click "Home Page".
52
@@ -58,7 +58,7 @@ Give Asset CleanUp a try! If you want to unlock more features, you can <a href="
58
== Frequently Asked Questions ==
59
= What PHP version is required for this plugin to work? =
60
61
- 5.3+ - I strongly recommend you to use PHP 7+, if you're website is compatible with it, as it's much faster and it will make a big difference in terms of back-end speed.
62
63
= How do I know if my website’s page loading speed is slow and needs improvement? =
64
There are various ways to check the speed of a website and this is in relation to the following: front-end (the part of the website visible to your visitors), back-end (PHP code, server-side optimization), hosting company, CDN (Content Delivery Network) setup, files loaded (making sure CSS, JS, Images, Fonts, and other elements are properly optimized when processed by the visitor’s browser).
@@ -131,7 +131,11 @@ With the recently released "Test Mode" feature, you can safely unload assets on
131
4. Scripts (.JS) are selected for site-wide unload
132
133
== Changelog ==
134
= 1.2.9.1 =
135
* "Combined Loaded CSS" feature (concatenates all the remaining loaded stylesheets within the HEAD section of the page and saves them into one file) to reduce HTTP requests even further
136
* Improved "Getting Started" area
137
* Made "Settings" as the default page where you (the administrator user) is redirected when activating the plugin for the first time
4
Donate link: https://gabelivan.com/items/wp-asset-cleanup-pro/?utm_source=wp_org_lite&utm_medium=donate
5
Requires at least: 4.4
6
Tested up to: 5.0.3
7
+ Stable tag: 1.2.9.2
8
License: GPLv3
9
License URI: http://www.gnu.org/licenses/gpl.html
10
46
* If you're planning to use the Lite version of the plugin:
47
48
1. Go to "Plugins" -> "Add New" -> "Upload Plugin" and attach the downloaded ZIP archive from the plugin's page or use the "Search plugins..." form on the right side and look for "asset cleanup"
49
+ 2. Install and activate the plugin (if server's PHP version is below 5.4, it will show you an error and activation will not be made).
50
3. Edit any Page / Post / Custom Post Type and you will see a meta box called "Asset CleanUp" which will load the list of all the loaded .CSS and .JS files. Alternatively, you will be able to manage the assets list in the front-end view as well (at the bottom of the pages) if you've enabled "Manage in the Front-end?" in plugin's settings page.
51
4. To unload the assets for the home page, go to "Asset CleanUp" menu on the left panel of the Dashboard and click "Home Page".
52
58
== Frequently Asked Questions ==
59
= What PHP version is required for this plugin to work? =
60
61
+ 5.4+ - I strongly recommend you to use PHP 7+, if you're website is fully compatible with it, as it's much faster than any PHP 5.* and it will make a big difference for your website's backend speed.
62
63
= How do I know if my website’s page loading speed is slow and needs improvement? =
64
There are various ways to check the speed of a website and this is in relation to the following: front-end (the part of the website visible to your visitors), back-end (PHP code, server-side optimization), hosting company, CDN (Content Delivery Network) setup, files loaded (making sure CSS, JS, Images, Fonts, and other elements are properly optimized when processed by the visitor’s browser).
131
4. Scripts (.JS) are selected for site-wide unload
132
133
== Changelog ==
134
+ = 1.2.9.2 =
135
+ * WooCommerce & WP Rocket Compatibility - Bug Fix: When both WooCommerce and WP Rocket are active and an administrator user is logged-in and tries to place an order, the "Sorry, your session is expired." message is returned
136
+
137
= 1.2.9.1 =
138
+ * PHP 5.4+ minimum required to use the plugin
139
* "Combined Loaded CSS" feature (concatenates all the remaining loaded stylesheets within the HEAD section of the page and saves them into one file) to reduce HTTP requests even further
140
* Improved "Getting Started" area
141
* Made "Settings" as the default page where you (the administrator user) is redirected when activating the plugin for the first time
wpacu.php CHANGED
@@ -2,13 +2,13 @@
2
/*
3
* Plugin Name: Asset CleanUp: Page Speed Booster
4
* Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
5
- * Version: 1.2.9.1
6
* Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages to reduce HTTP Requests and have the website load faster
7
* Author: Gabriel Livan
8
* Author URI: http://gabelivan.com/
9
*/
10
11
- define('WPACU_PLUGIN_VERSION', '1.2.9.1');
12
13
// Exit if accessed directly
14
if (! defined('ABSPATH')) {
@@ -35,9 +35,9 @@ define('WPACU_PLUGIN_BASE', plugin_basename(WPACU_PLUGIN_FILE));
35
36
define('WPACU_ADMIN_PAGE_ID_START', WPACU_PLUGIN_ID . '_settings');
37
38
- // Do not load the plugin if the PHP version is below 5.3
39
// If PHP_VERSION_ID is not defined, then PHP version is below 5.2.7, thus the plugin is not usable
40
- $wpacuWrongPhp = ((! defined('PHP_VERSION_ID')) || (defined('PHP_VERSION_ID') && PHP_VERSION_ID < 50300));
41
42
if ($wpacuWrongPhp && is_admin()) { // Dashboard
43
add_action('admin_init', 'wpAssetCleanUpWrongPhp');
@@ -61,7 +61,7 @@ if ($wpacuWrongPhp && is_admin()) { // Dashboard
61
function wpAssetCleanUpWrongPhpNotice()
62
{
63
echo '<div class="error is-dismissible"><p>'.
64
- __('<strong>'.WPACU_PLUGIN_TITLE.'</strong> requires <span style="color: green;"><strong>5.3+</strong> PHP version</span> installed. You have <strong>'.PHP_VERSION.'</strong>. If you\'re website is compatible with PHP 7+ (e.g. you can check with your developers or contact the hosting company), it\'s strongly recommended to upgrade for a better performance. The plugin has been deactivated.', WPACU_PLUGIN_TEXT_DOMAIN) .
65
'</p></div>';
66
67
if (array_key_exists('active', $_GET)) {
2
/*
3
* Plugin Name: Asset CleanUp: Page Speed Booster
4
* Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
5
+ * Version: 1.2.9.2
6
* Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages to reduce HTTP Requests and have the website load faster
7
* Author: Gabriel Livan
8
* Author URI: http://gabelivan.com/
9
*/
10
11
+ define('WPACU_PLUGIN_VERSION', '1.2.9.2');
12
13
// Exit if accessed directly
14
if (! defined('ABSPATH')) {
35
36
define('WPACU_ADMIN_PAGE_ID_START', WPACU_PLUGIN_ID . '_settings');
37
38
+ // Do not load the plugin if the PHP version is below 5.4
39
// If PHP_VERSION_ID is not defined, then PHP version is below 5.2.7, thus the plugin is not usable
40
+ $wpacuWrongPhp = ((! defined('PHP_VERSION_ID')) || (defined('PHP_VERSION_ID') && PHP_VERSION_ID < 50400));
41
42
if ($wpacuWrongPhp && is_admin()) { // Dashboard
43
add_action('admin_init', 'wpAssetCleanUpWrongPhp');
61
function wpAssetCleanUpWrongPhpNotice()
62
{
63
echo '<div class="error is-dismissible"><p>'.
64
+ __('<strong>'.WPACU_PLUGIN_TITLE.'</strong> requires <span style="color: green;"><strong>5.4+</strong> PHP version</span> installed. You have <strong>'.PHP_VERSION.'</strong>. If you\'re website is compatible with PHP 7+ (e.g. you can check with your developers or contact the hosting company), it\'s strongly recommended to upgrade for a better performance. The plugin has been deactivated.', WPACU_PLUGIN_TEXT_DOMAIN) .
65
'</p></div>';
66
67
if (array_key_exists('active', $_GET)) {