Asset CleanUp: Page Speed Booster - Version 1.3.2.9

Version Description

  • New Feature: Enable Minify CSS/JS on the fly when admin is logged in (for debugging purposes) - via /?wpacu_css_minify
  • Updated "Tools" -> "System Info": Has database information related to the Asset CleanUp's entries
  • Option to override "administrator" (default) role, in order to acesss plugin's pages
  • Do not trigger Asset CleanUp Pro on REST Requests, WPBakery Page Builder Edit Mode, Brizy Page Builder Edit Mode
  • Avoid notice errors if some "SG Optimizer" features are enabled
  • Minify CSS: Compatibility with "Simple Custom CSS" plugin
  • Match sidebar and top bar menus; Allow unloading of CSS/JS on the fly (via URI request) for debugging purposes; Added coloured left border for assets that had their position changed to easily distinguish them
  • New Feature: Ignore dependency rule and keep the "children" loaded
  • New Feature: CSS/JS "Notes" (useful to remember why you have unloaded or decided to keep a specific file)
  • Bug Fix: Posts' Metas (e.g. load exceptions) were not imported
  • Bug Fix: Make sure specific elements from "Site-Wide Common Unloads" are properly imported/exported
Download this release

Release Info

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

Code changes from version 1.3.2.8 to 1.3.2.9

classes/CleanUp.php CHANGED
@@ -54,13 +54,10 @@ class CleanUp
54
  // <link rel='shortlink' href="https://yourdomain.com/?p=1">
55
  remove_action('wp_head', 'wp_shortlink_wp_head');
56
 
57
- // For some reason, in some WP installs, it's not enough to just use the "remove_action" function
58
- add_action('wp_loaded', function () {
59
- ob_start(function($htmlSource) {
60
- return self::cleanRelShortLink($htmlSource);
61
- });
62
- }, PHP_INT_MAX);
63
- }
64
 
65
  // Remove "Post's Relational Links"?
66
  if ($settings['remove_posts_rel_links'] == 1) {
@@ -399,30 +396,6 @@ class CleanUp
399
  return $htmlSource;
400
  }
401
 
402
- /**
403
- * @param $htmlSource
404
- *
405
- * @return mixed
406
- */
407
- public function cleanRelShortLink($htmlSource)
408
- {
409
- $regExpPattern = '#<link[^>]*shortlink[^>]*(>)#Usmi';
410
-
411
- preg_match_all($regExpPattern, $htmlSource, $matchedLinks, PREG_SET_ORDER);
412
-
413
- if (! isset($matchedLinks[0][0])) {
414
- return $htmlSource;
415
- }
416
-
417
- $linkTag = $matchedLinks[0][0];
418
-
419
- if (stripos($linkTag, '<link') === 0 && substr($linkTag, -1) === '>' && strip_tags($linkTag) === '') {
420
- $htmlSource = str_replace($matchedLinks[0][0], '', $htmlSource);
421
- }
422
-
423
- return $htmlSource;
424
- }
425
-
426
  /**
427
  *
428
  */
54
  // <link rel='shortlink' href="https://yourdomain.com/?p=1">
55
  remove_action('wp_head', 'wp_shortlink_wp_head');
56
 
57
+ // link: <https://yourdomainname.com/wp-json/>; rel="https://api.w.org/", <https://yourdomainname.com/?p=[post_id_here]>; rel=shortlink
58
+ remove_action('template_redirect', 'wp_shortlink_header', 11);
59
+
60
+ }
 
 
 
61
 
62
  // Remove "Post's Relational Links"?
63
  if ($settings['remove_posts_rel_links'] == 1) {
396
  return $htmlSource;
397
  }
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  /**
400
  *
401
  */
classes/Main.php CHANGED
@@ -249,9 +249,11 @@ class Main
249
  add_action( 'wp_print_footer_scripts', array( $this, 'filterStyles' ), 1 );
250
  }
251
 
252
- add_action( 'admin_footer', array( $this, 'ajaxFetchActivePluginsJsFooterCode' ) );
253
- add_action( 'wp_ajax_' . WPACU_PLUGIN_ID . '_fetch_active_plugins_icons',
254
- array( $this, 'ajaxFetchActivePluginsIcons' ) );
 
 
255
 
256
  $this->wpacuHtmlNoticeForAdmin();
257
  }
249
  add_action( 'wp_print_footer_scripts', array( $this, 'filterStyles' ), 1 );
250
  }
251
 
252
+ // Only trigger it within the Dashboard when an Asset CleanUp page is accessed and the transient is non-existent or expired
253
+ if (is_admin() && (isset($_GET['page']) && strpos($_GET['page'], WPACU_PLUGIN_ID . '_') === 0) && ! get_transient('wpacu_active_plugins_icons')) {
254
+ add_action('admin_footer', array($this, 'ajaxFetchActivePluginsJsFooterCode'));
255
+ add_action('wp_ajax_' . WPACU_PLUGIN_ID . '_fetch_active_plugins_icons', array($this, 'ajaxFetchActivePluginsIcons'));
256
+ }
257
 
258
  $this->wpacuHtmlNoticeForAdmin();
259
  }
classes/Misc.php CHANGED
@@ -484,11 +484,16 @@ class Misc
484
  }
485
 
486
  foreach ($allActivePlugins as $activePlugin) {
487
- if (strpos($activePlugin, '/') === false) {
488
  continue;
489
  }
490
 
491
  list($pluginSlug) = explode('/', $activePlugin);
 
 
 
 
 
492
 
493
  // Avoid the calls to WordPress.org as much as possible
494
  // as it would decrease the resources and timing to fetch the data we need
484
  }
485
 
486
  foreach ($allActivePlugins as $activePlugin) {
487
+ if (! is_string($activePlugin) || strpos($activePlugin, '/') === false) {
488
  continue;
489
  }
490
 
491
  list($pluginSlug) = explode('/', $activePlugin);
492
+ $pluginSlug = trim($pluginSlug);
493
+
494
+ if (! $pluginSlug) {
495
+ continue;
496
+ }
497
 
498
  // Avoid the calls to WordPress.org as much as possible
499
  // as it would decrease the resources and timing to fetch the data we need
classes/OptimiseAssets/MinifyCss.php CHANGED
@@ -34,9 +34,13 @@ class MinifyCss
34
  $cssMinifyList = array();
35
 
36
  // [Start] Collect for caching
37
- foreach ($wp_styles->done as $handle) {
38
- if (isset($wp_styles->registered[$handle])) {
39
- $value = $wp_styles->registered[$handle];
 
 
 
 
40
  $minifyValues = $this->maybeMinifyIt($value);
41
 
42
  if (! empty($minifyValues)) {
@@ -74,6 +78,10 @@ class MinifyCss
74
 
75
  preg_match_all($regExpPattern, OptimizeCommon::cleanerHtmlSource($htmlSource), $matchesSourcesFromTags, PREG_SET_ORDER);
76
 
 
 
 
 
77
  foreach ($matchesSourcesFromTags as $matches) {
78
  $linkSourceTag = $matches[0];
79
 
34
  $cssMinifyList = array();
35
 
36
  // [Start] Collect for caching
37
+ $wpStylesDone = $wp_styles->done;
38
+ $wpStylesRegistered = $wp_styles->registered;
39
+
40
+ foreach ($wpStylesDone as $handle) {
41
+ if (isset($wpStylesRegistered[$handle])) {
42
+ $value = $wpStylesRegistered[$handle];
43
+
44
  $minifyValues = $this->maybeMinifyIt($value);
45
 
46
  if (! empty($minifyValues)) {
78
 
79
  preg_match_all($regExpPattern, OptimizeCommon::cleanerHtmlSource($htmlSource), $matchesSourcesFromTags, PREG_SET_ORDER);
80
 
81
+ if (empty($matchesSourcesFromTags)) {
82
+ return $htmlSource;
83
+ }
84
+
85
  foreach ($matchesSourcesFromTags as $matches) {
86
  $linkSourceTag = $matches[0];
87
 
classes/OptimiseAssets/OptimizeCommon.php CHANGED
@@ -527,6 +527,16 @@ class OptimizeCommon
527
  return $wpContentUrl;
528
  }
529
 
 
 
 
 
 
 
 
 
 
 
530
  /**
531
  * URLs with query strings are not loading Optimised Assets (e.g. combine CSS files into one file)
532
  * However, there are exceptions such as the ones below (preview, debugging purposes)
527
  return $wpContentUrl;
528
  }
529
 
530
+ /**
531
+ * @param $assetContent
532
+ *
533
+ * @return mixed
534
+ */
535
+ public static function stripSourceMap($assetContent)
536
+ {
537
+ return str_replace('# sourceMappingURL=', '# From Source Map: ', $assetContent);
538
+ }
539
+
540
  /**
541
  * URLs with query strings are not loading Optimised Assets (e.g. combine CSS files into one file)
542
  * However, there are exceptions such as the ones below (preview, debugging purposes)
classes/OptimiseAssets/OptimizeCss.php CHANGED
@@ -98,7 +98,7 @@ class OptimizeCss
98
  // Fetch the DOM, and then set a new transient
99
  $documentForCSS = new \DOMDocument();
100
 
101
- libxml_use_internal_errors( true );
102
  $documentForCSS->loadHTML( $htmlSource );
103
 
104
  $storageJsonContents = array();
@@ -349,19 +349,24 @@ HTML;
349
  );
350
  }
351
 
352
- $assetContent = @file_get_contents($localAssetsPath);
353
 
354
- if ($assetContent) {
355
  // Do not combine it if it contains "@import"
356
- if (stripos($assetContent, '@import') !== false) {
357
  unset($localAssetsPaths[$assetHref]);
358
  $linkHrefKey = array_search($assetHref, $linkHrefs);
359
  unset($linkHrefs[$linkHrefKey]);
360
  continue;
361
  }
362
 
 
 
 
 
 
363
  $finalAssetsContents .= '/*** Source: '.str_replace(ABSPATH, '/', $localAssetsPath)." ***/\n";
364
- $finalAssetsContents .= self::maybeFixCssBackgroundUrls($assetContent, $pathToAssetDir . '/') . "\n\n";
365
  }
366
  }
367
 
98
  // Fetch the DOM, and then set a new transient
99
  $documentForCSS = new \DOMDocument();
100
 
101
+ libxml_use_internal_errors(true);
102
  $documentForCSS->loadHTML( $htmlSource );
103
 
104
  $storageJsonContents = array();
349
  );
350
  }
351
 
352
+ $cssContent = @file_get_contents($localAssetsPath);
353
 
354
+ if ($cssContent) {
355
  // Do not combine it if it contains "@import"
356
+ if (stripos($cssContent, '@import') !== false) {
357
  unset($localAssetsPaths[$assetHref]);
358
  $linkHrefKey = array_search($assetHref, $linkHrefs);
359
  unset($linkHrefs[$linkHrefKey]);
360
  continue;
361
  }
362
 
363
+ // Does it have a source map? Strip it
364
+ if (strpos($cssContent, 'sourceMappingURL') !== false) {
365
+ $cssContent = OptimizeCommon::stripSourceMap($cssContent);
366
+ }
367
+
368
  $finalAssetsContents .= '/*** Source: '.str_replace(ABSPATH, '/', $localAssetsPath)." ***/\n";
369
+ $finalAssetsContents .= self::maybeFixCssBackgroundUrls($cssContent, $pathToAssetDir . '/') . "\n\n";
370
  }
371
  }
372
 
classes/OptimiseAssets/OptimizeJs.php CHANGED
@@ -482,6 +482,11 @@ HTML;
482
  $jsContent = @file_get_contents($localAssetsPath);
483
 
484
  if ($jsContent) {
 
 
 
 
 
485
  $finalJsContentsIndex = 1;
486
 
487
  $finalJsContentsGroupsArray[$finalJsContentsIndex][] = '/*** Source: '.str_replace(ABSPATH, '/', $localAssetsPath)." ***/\n" . self::maybeDoJsFixes($jsContent, $pathToAssetDir . '/') . "\n\n";
482
  $jsContent = @file_get_contents($localAssetsPath);
483
 
484
  if ($jsContent) {
485
+ // Does it have a source map? Strip it
486
+ if (strpos($jsContent, 'sourceMappingURL') !== false) {
487
+ $jsContent = OptimizeCommon::stripSourceMap($jsContent);
488
+ }
489
+
490
  $finalJsContentsIndex = 1;
491
 
492
  $finalJsContentsGroupsArray[$finalJsContentsIndex][] = '/*** Source: '.str_replace(ABSPATH, '/', $localAssetsPath)." ***/\n" . self::maybeDoJsFixes($jsContent, $pathToAssetDir . '/') . "\n\n";
early-triggers.php CHANGED
@@ -29,6 +29,11 @@ if (! function_exists('assetCleanUpNoLoad')) {
29
  return true;
30
  }
31
 
 
 
 
 
 
32
  // "Oxygen" plugin: Edit Mode
33
  if (isset($_GET['ct_builder'], $_GET['ct_inner']) && $_GET['ct_builder'] === 'true' && $_GET['ct_inner'] === 'true') {
34
  return true;
@@ -44,11 +49,18 @@ if (! function_exists('assetCleanUpNoLoad')) {
44
  return true;
45
  }
46
 
47
- // Thrive Architect
48
  if (isset($_GET['action'], $_GET['tve']) && $_GET['action'] === 'architect' && $_GET['tve'] === 'true' && is_admin()) {
49
  return true;
50
  }
51
 
 
 
 
 
 
 
 
52
  // Page Builder by SiteOrigin
53
  if (isset($_GET['action'], $_GET['so_live_editor']) && $_GET['action'] === 'edit' && $_GET['so_live_editor'] && is_admin()) {
54
  return true;
@@ -77,7 +89,7 @@ if (! function_exists('assetCleanUpNoLoad')) {
77
  }
78
 
79
  // REST Request
80
- if ((strpos($_SERVER['REQUEST_URI'], '/wp-json/wp/v2/') !== false) || (defined('REST_REQUEST') && REST_REQUEST)) {
81
  return true;
82
  }
83
 
29
  return true;
30
  }
31
 
32
+ // "Elementor" plugin: Do not trigger the plugin on AJAX calls
33
+ if (isset($_POST['action']) && (strpos($_POST['action'], 'elementor_') === 0) && (! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')) {
34
+ return true;
35
+ }
36
+
37
  // "Oxygen" plugin: Edit Mode
38
  if (isset($_GET['ct_builder'], $_GET['ct_inner']) && $_GET['ct_builder'] === 'true' && $_GET['ct_inner'] === 'true') {
39
  return true;
49
  return true;
50
  }
51
 
52
+ // Thrive Architect (Dashboard)
53
  if (isset($_GET['action'], $_GET['tve']) && $_GET['action'] === 'architect' && $_GET['tve'] === 'true' && is_admin()) {
54
  return true;
55
  }
56
 
57
+ // Thrive Architect (iFrame)
58
+ $tveFrameFlag = defined('TVE_FRAME_FLAG') ? TVE_FRAME_FLAG : 'tcbf';
59
+
60
+ if (isset($_GET['tve'], $_GET[$tveFrameFlag]) && $_GET['tve'] === 'true') {
61
+ return true;
62
+ }
63
+
64
  // Page Builder by SiteOrigin
65
  if (isset($_GET['action'], $_GET['so_live_editor']) && $_GET['action'] === 'edit' && $_GET['so_live_editor'] && is_admin()) {
66
  return true;
89
  }
90
 
91
  // REST Request
92
+ if ((defined('REST_REQUEST') && REST_REQUEST) || (strpos($_SERVER['REQUEST_URI'], '/wp-json/wp/v2/') !== false)) {
93
  return true;
94
  }
95
 
freemius/templates/forms/deactivation/form.php CHANGED
@@ -31,10 +31,10 @@
31
  } else {
32
  $reason_internal_message = '';
33
  }
34
-
35
  $reason_input_type = ( ! empty( $reason['input_type'] ) ? $reason['input_type'] : '' );
36
  $reason_input_placeholder = ( ! empty( $reason['input_placeholder'] ) ? $reason['input_placeholder'] : '' );
37
-
38
  $reason_list_item_html = <<< HTML
39
  <li class="{$list_item_classes}"
40
  data-input-type="{$reason_input_type}"
@@ -182,7 +182,7 @@ HTML;
182
  *
183
  * @author Leo Fajardo (@leorw)
184
  * @since 1.2.2
185
- *
186
  * @since 1.2.2.7 Don't trigger the deactivation feedback form if activating the premium version of the theme.
187
  */
188
  ?>
@@ -344,7 +344,7 @@ HTML;
344
  if (_parent.hasClass('has-input')) {
345
  var inputType = _parent.data('input-type'),
346
  inputPlaceholder = _parent.data('input-placeholder'),
347
- reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" maxlength="128" />' : '<textarea rows="5" maxlength="128"></textarea>' ) + '</div>';
348
 
349
  _parent.append($(reasonInputHtml));
350
  _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
31
  } else {
32
  $reason_internal_message = '';
33
  }
34
+
35
  $reason_input_type = ( ! empty( $reason['input_type'] ) ? $reason['input_type'] : '' );
36
  $reason_input_placeholder = ( ! empty( $reason['input_placeholder'] ) ? $reason['input_placeholder'] : '' );
37
+
38
  $reason_list_item_html = <<< HTML
39
  <li class="{$list_item_classes}"
40
  data-input-type="{$reason_input_type}"
182
  *
183
  * @author Leo Fajardo (@leorw)
184
  * @since 1.2.2
185
+ *
186
  * @since 1.2.2.7 Don't trigger the deactivation feedback form if activating the premium version of the theme.
187
  */
188
  ?>
344
  if (_parent.hasClass('has-input')) {
345
  var inputType = _parent.data('input-type'),
346
  inputPlaceholder = _parent.data('input-placeholder'),
347
+ reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
348
 
349
  _parent.append($(reasonInputHtml));
350
  _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: gabelivan
3
  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.2
7
- Stable tag: 1.3.2.8
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
@@ -154,6 +154,19 @@ With the recently released "Test Mode" feature, you can safely unload assets on
154
  4. Homepage CSS & JS Management (List sorted by location)
155
 
156
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  = 1.3.2.8 =
158
  * "Import & Export" added under "Tools" For Settings & Load/Unload Rules
159
  * "General & Files Management" -> "Assets List Layout" - 2 new options: Group by dependencies & Group by loaded/unloaded status
3
  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.2.1
7
+ Stable tag: 1.3.2.9
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
154
  4. Homepage CSS & JS Management (List sorted by location)
155
 
156
  == Changelog ==
157
+ = 1.3.2.9 =
158
+ * New Feature: Enable Minify CSS/JS on the fly when admin is logged in (for debugging purposes) - via /?wpacu_css_minify
159
+ * Updated "Tools" -> "System Info": Has database information related to the Asset CleanUp's entries
160
+ * Option to override "administrator" (default) role, in order to acesss plugin's pages
161
+ * Do not trigger Asset CleanUp Pro on REST Requests, WPBakery Page Builder Edit Mode, Brizy Page Builder Edit Mode
162
+ * Avoid notice errors if some "SG Optimizer" features are enabled
163
+ * Minify CSS: Compatibility with "Simple Custom CSS" plugin
164
+ * Match sidebar and top bar menus; Allow unloading of CSS/JS on the fly (via URI request) for debugging purposes; Added coloured left border for assets that had their position changed to easily distinguish them
165
+ * New Feature: Ignore dependency rule and keep the "children" loaded
166
+ * New Feature: CSS/JS "Notes" (useful to remember why you have unloaded or decided to keep a specific file)
167
+ * Bug Fix: Posts' Metas (e.g. load exceptions) were not imported
168
+ * Bug Fix: Make sure specific elements from "Site-Wide Common Unloads" are properly imported/exported
169
+
170
  = 1.3.2.8 =
171
  * "Import & Export" added under "Tools" For Settings & Load/Unload Rules
172
  * "General & Files Management" -> "Assets List Layout" - 2 new options: Group by dependencies & Group by loaded/unloaded status
wpacu.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  * Plugin Name: Asset CleanUp: Page Speed Booster
4
  * Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
5
- * Version: 1.3.2.8
6
  * Description: Unload Chosen Scripts & Styles from Posts/Pages to reduce HTTP Requests, Combine/Minify CSS/JS files
7
  * Author: Gabriel Livan
8
  * Author URI: http://gabelivan.com/
@@ -10,7 +10,7 @@
10
  * Domain Path: /languages
11
  */
12
 
13
- define('WPACU_PLUGIN_VERSION', '1.3.2.8');
14
 
15
  // Exit if accessed directly
16
  if (! defined('ABSPATH')) {
2
  /*
3
  * Plugin Name: Asset CleanUp: Page Speed Booster
4
  * Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
5
+ * Version: 1.3.2.9
6
  * Description: Unload Chosen Scripts & Styles from Posts/Pages to reduce HTTP Requests, Combine/Minify CSS/JS files
7
  * Author: Gabriel Livan
8
  * Author URI: http://gabelivan.com/
10
  * Domain Path: /languages
11
  */
12
 
13
+ define('WPACU_PLUGIN_VERSION', '1.3.2.9');
14
 
15
  // Exit if accessed directly
16
  if (! defined('ABSPATH')) {