Asset CleanUp: Page Speed Booster - Version 1.2.4.3

Version Description

  • Bug Fix: PHP versions < 5.4 triggered errors
Download this release

Release Info

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

Code changes from version 1.2.4.2 to 1.2.4.3

README.md DELETED
@@ -1,2 +0,0 @@
1
- # wp-asset-clean-up
2
- WordPress Plugin: Make your Website Load FASTER by preventing specific scripts (.JS) and styles (.CSS) from loading on pages/posts and home page
 
 
assets/script.js CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * WP Asset CleanUp
3
  */
4
  jQuery(document).ready(function($) {
5
  //
1
  /**
2
+ * WP Asset Clean Up
3
  */
4
  jQuery(document).ready(function($) {
5
  //
classes/GlobalRules.php CHANGED
@@ -84,8 +84,10 @@ class GlobalRules
84
  */
85
  public function update()
86
  {
 
 
87
  if ($this->wpacuFor === 'everywhere') {
88
- $removed = (new Update)->removeEverywhereUnloads();
89
 
90
  if ($removed) {
91
  add_action('admin_notices', array($this, 'noticeGlobalsRemoved'));
@@ -93,7 +95,7 @@ class GlobalRules
93
  }
94
 
95
  if ($this->wpacuFor === 'post_types') {
96
- $removed = (new Update)->removeBulkUnloads($this->wpacuPostType);
97
 
98
  if ($removed) {
99
  add_action('admin_notices', array($this, 'noticePostTypesRemoved'));
84
  */
85
  public function update()
86
  {
87
+ $wpacuUpdate = new Update;
88
+
89
  if ($this->wpacuFor === 'everywhere') {
90
+ $removed = $wpacuUpdate->removeEverywhereUnloads();
91
 
92
  if ($removed) {
93
  add_action('admin_notices', array($this, 'noticeGlobalsRemoved'));
95
  }
96
 
97
  if ($this->wpacuFor === 'post_types') {
98
+ $removed = $wpacuUpdate->removeBulkUnloads($this->wpacuPostType);
99
 
100
  if ($removed) {
101
  add_action('admin_notices', array($this, 'noticePostTypesRemoved'));
classes/HomePage.php CHANGED
@@ -18,7 +18,7 @@ class HomePage
18
  public function __construct()
19
  {
20
  $this->data['nonce_name'] = WPACU_PLUGIN_NAME.'_settings';
21
- $this->data['show_on_front'] = get_option('show_on_front');
22
 
23
  $isHomePageEdit = (isset($_GET['page']) && $_GET['page'] == WPACU_PLUGIN_NAME.'_home_page');
24
 
@@ -64,7 +64,8 @@ class HomePage
64
  ? $_POST[$this->data['nonce_name']] : '';
65
 
66
  if (is_array($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
67
- (new Update)->updateFrontPage($wpacuNoLoadAssets);
 
68
  }
69
 
70
  $this->data['nonce_value'] = wp_create_nonce($this->data['nonce_name']);
18
  public function __construct()
19
  {
20
  $this->data['nonce_name'] = WPACU_PLUGIN_NAME.'_settings';
21
+ $this->data['show_on_front'] = Misc::getShowOnFront();
22
 
23
  $isHomePageEdit = (isset($_GET['page']) && $_GET['page'] == WPACU_PLUGIN_NAME.'_home_page');
24
 
64
  ? $_POST[$this->data['nonce_name']] : '';
65
 
66
  if (is_array($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
67
+ $wpacuUpdate = new Update;
68
+ $wpacuUpdate->updateFrontPage($wpacuNoLoadAssets);
69
  }
70
 
71
  $this->data['nonce_value'] = wp_create_nonce($this->data['nonce_name']);
classes/Main.php CHANGED
@@ -30,7 +30,7 @@ class Main
30
  /**
31
  * @var array
32
  */
33
- public $loadExceptions = array();
34
 
35
  /**
36
  * @var
@@ -92,7 +92,7 @@ class Main
92
  // Fetch the page in the background to see what scripts/styles are already loading
93
  if (isset($_POST[WPACU_PLUGIN_NAME.'_load']) || $this->frontendShow) {
94
  if (isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
95
- add_filter('show_admin_bar', '__return_false'); // not relevant
96
  }
97
 
98
  add_action('wp_head', array($this, 'saveFooterAssets'), 100000000);
@@ -131,7 +131,7 @@ class Main
131
  if (! isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
132
  $this->globalUnloaded = $this->getGlobalUnload();
133
 
134
- if (!is_singular() && !is_front_page()) {
135
  return;
136
  }
137
 
@@ -139,7 +139,7 @@ class Main
139
 
140
  $postId = isset($post->ID) ? $post->ID : '';
141
 
142
- $type = (is_front_page()) ? 'front_page' : 'post';
143
 
144
  if (is_singular()) {
145
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
@@ -211,7 +211,7 @@ class Main
211
  return;
212
  }
213
 
214
- $nonAssetConfigPage = (!is_singular() && !is_front_page());
215
 
216
  // It looks like the page loaded is neither a post, page or the front-page
217
  // We'll see if there are assets unloaded globally and unload them
@@ -311,7 +311,7 @@ class Main
311
  return;
312
  }
313
 
314
- $nonAssetConfigPage = (!is_singular() && !is_front_page());
315
 
316
  // It looks like the page loaded is neither a post, page or the front-page
317
  // We'll see if there are assets unloaded globally and unload them
@@ -404,23 +404,24 @@ class Main
404
  /**
405
  * @param string $type
406
  * @param string $postId
407
- * @return array|mixed|object|void
408
  */
409
  public function getLoadExceptions($type = 'post', $postId = '')
410
  {
 
 
411
  if ($type == 'post' && !$postId) {
412
  // $postId needs to have a value if $type is a 'post' type
413
- return false;
414
  }
415
 
416
  if (! in_array($type, array('post', 'front_page'))) {
417
  // Invalid request
418
- return false;
419
  }
420
 
421
  // Default
422
  $exceptionsListJson = '';
423
- $exceptionsListEmpty = $exceptionsList = array('styles' => array(), 'scripts' => array());
424
 
425
  $homepageClass = new HomePage;
426
 
@@ -443,7 +444,7 @@ class Main
443
  $exceptionsList = json_decode($exceptionsListJson, true);
444
 
445
  if (json_last_error() != JSON_ERROR_NONE) {
446
- $exceptionsList = $exceptionsListEmpty;
447
  }
448
  }
449
 
@@ -550,6 +551,8 @@ class Main
550
  $stylesBeforeUnload = $this->wpStyles;
551
  $scriptsBeforeUnload = $this->wpScripts;
552
 
 
 
553
  global $wp_scripts, $wp_styles;
554
 
555
  $list = array();
@@ -704,7 +707,7 @@ class Main
704
 
705
  $data['global_unload'] = $this->globalUnloaded;
706
 
707
- $type = (is_front_page()) ? 'front_page' : 'post';
708
  $postId = $post->ID;
709
 
710
  $data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
@@ -944,7 +947,7 @@ class Main
944
 
945
  /**
946
  * @param int $postId
947
- * @return array|mixed|string|void
948
  */
949
  public function getAssetsUnloaded($postId = 0)
950
  {
30
  /**
31
  * @var array
32
  */
33
+ public $loadExceptions = array('styles' => array(), 'scripts' => array());
34
 
35
  /**
36
  * @var
92
  // Fetch the page in the background to see what scripts/styles are already loading
93
  if (isset($_POST[WPACU_PLUGIN_NAME.'_load']) || $this->frontendShow) {
94
  if (isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
95
+ Misc::noAdminBarLoad();
96
  }
97
 
98
  add_action('wp_head', array($this, 'saveFooterAssets'), 100000000);
131
  if (! isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
132
  $this->globalUnloaded = $this->getGlobalUnload();
133
 
134
+ if (! is_singular() && ! Misc::isHomePage()) {
135
  return;
136
  }
137
 
139
 
140
  $postId = isset($post->ID) ? $post->ID : '';
141
 
142
+ $type = (Misc::isHomePage()) ? 'front_page' : 'post';
143
 
144
  if (is_singular()) {
145
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
211
  return;
212
  }
213
 
214
+ $nonAssetConfigPage = (! is_singular() && ! Misc::getShowOnFront());
215
 
216
  // It looks like the page loaded is neither a post, page or the front-page
217
  // We'll see if there are assets unloaded globally and unload them
311
  return;
312
  }
313
 
314
+ $nonAssetConfigPage = (! is_singular() && ! Misc::getShowOnFront());
315
 
316
  // It looks like the page loaded is neither a post, page or the front-page
317
  // We'll see if there are assets unloaded globally and unload them
404
  /**
405
  * @param string $type
406
  * @param string $postId
407
+ * @return array|mixed|object
408
  */
409
  public function getLoadExceptions($type = 'post', $postId = '')
410
  {
411
+ $exceptionsListDefault = $exceptionsList = $this->loadExceptions;
412
+
413
  if ($type == 'post' && !$postId) {
414
  // $postId needs to have a value if $type is a 'post' type
415
+ return $exceptionsListDefault;
416
  }
417
 
418
  if (! in_array($type, array('post', 'front_page'))) {
419
  // Invalid request
420
+ return $exceptionsListDefault;
421
  }
422
 
423
  // Default
424
  $exceptionsListJson = '';
 
425
 
426
  $homepageClass = new HomePage;
427
 
444
  $exceptionsList = json_decode($exceptionsListJson, true);
445
 
446
  if (json_last_error() != JSON_ERROR_NONE) {
447
+ $exceptionsList = $exceptionsListDefault;
448
  }
449
  }
450
 
551
  $stylesBeforeUnload = $this->wpStyles;
552
  $scriptsBeforeUnload = $this->wpScripts;
553
 
554
+
555
+
556
  global $wp_scripts, $wp_styles;
557
 
558
  $list = array();
707
 
708
  $data['global_unload'] = $this->globalUnloaded;
709
 
710
+ $type = Misc::getShowOnFront() ? 'front_page' : 'post';
711
  $postId = $post->ID;
712
 
713
  $data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
947
 
948
  /**
949
  * @param int $postId
950
+ * @return array|mixed|string
951
  */
952
  public function getAssetsUnloaded($postId = 0)
953
  {
classes/Misc.php CHANGED
@@ -8,6 +8,21 @@ namespace WpAssetCleanUp;
8
  */
9
  class Misc
10
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  /**
12
  * @param $string
13
  * @param $start
@@ -51,11 +66,11 @@ class Misc
51
 
52
  /**
53
  * @param $postId
54
- * @return false|mixed|string|void
55
  */
56
  public static function getPostUrl($postId)
57
  {
58
- if (is_front_page()) {
59
  return get_option('siteurl');
60
  }
61
 
@@ -80,4 +95,40 @@ class Misc
80
 
81
  return $postUrl;
82
  }
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  */
9
  class Misc
10
  {
11
+ /**
12
+ * Misc constructor.
13
+ */
14
+ public function __construct()
15
+ {
16
+ if (isset($_REQUEST['wpacuNoAdminBar'])) {
17
+ Misc::noAdminBarLoad();
18
+ }
19
+ }
20
+
21
+ /**
22
+ * @var
23
+ */
24
+ public static $showOnFront;
25
+
26
  /**
27
  * @param $string
28
  * @param $start
66
 
67
  /**
68
  * @param $postId
69
+ * @return false|mixed|string
70
  */
71
  public static function getPostUrl($postId)
72
  {
73
+ if (self::isHomePage()) {
74
  return get_option('siteurl');
75
  }
76
 
95
 
96
  return $postUrl;
97
  }
98
+
99
+ /**
100
+ * @return mixed
101
+ */
102
+ public static function isHomePage()
103
+ {
104
+ $homePage = false;
105
+
106
+ if (self::$showOnFront === 'page') {
107
+ $homePage = is_front_page();
108
+ } elseif (self::$showOnFront === 'posts') {
109
+ $homePage = is_home();
110
+ }
111
+
112
+ return apply_filters('wpacu_home_page', $homePage);
113
+ }
114
+
115
+ /**
116
+ * @return mixed
117
+ */
118
+ public static function getShowOnFront()
119
+ {
120
+ if (! self::$showOnFront) {
121
+ self::$showOnFront = get_option('show_on_front');
122
+ }
123
+
124
+ return self::$showOnFront;
125
+ }
126
+
127
+ /**
128
+ *
129
+ */
130
+ public static function noAdminBarLoad()
131
+ {
132
+ add_filter('show_admin_bar', '__return_false');
133
+ }
134
+ }
classes/Update.php CHANGED
@@ -64,7 +64,7 @@ class Update
64
  );
65
  }
66
 
67
- if (is_front_page()) {
68
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
69
  ? $_POST[WPACU_PLUGIN_NAME] : array();
70
 
64
  );
65
  }
66
 
67
+ if (Misc::isHomePage()) {
68
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
69
  ? $_POST[WPACU_PLUGIN_NAME] : array();
70
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WP Asset CleanUp ===
2
  Contributors: gabelivan
3
  Tags: speed, pagespeed, dequeue style, dequeue script, unload style, unload script, fast
4
- Donate link: http://www.gabelivan.com/donate/
5
  Requires at least: 4.0
6
- Tested up to: 4.7
7
- Stable tag: 1.2.4.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
@@ -92,6 +92,9 @@ If that's the case, then it's advisable to consult with a developer (ideally the
92
  4. Scripts (.JS) are selected for site-wide unload
93
 
94
  == Changelog ==
 
 
 
95
  = 1.2.4.2 =
96
  * Now styles that are loaded in the BODY section of the page are unloaded (if selected); Sometimes, in special cases, within "wp_footer" action (or other similar one such as "get_footer"), wp_enqueue_style is called
97
 
1
  === WP Asset CleanUp ===
2
  Contributors: gabelivan
3
  Tags: speed, pagespeed, dequeue style, dequeue script, unload style, unload script, fast
4
+ Donate link: https://www.gabelivan.com/donate/
5
  Requires at least: 4.0
6
+ Tested up to: 4.7.1
7
+ Stable tag: 1.2.4.3
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
92
  4. Scripts (.JS) are selected for site-wide unload
93
 
94
  == Changelog ==
95
+ = 1.2.4.3 =
96
+ * Bug Fix: PHP versions < 5.4 triggered errors
97
+
98
  = 1.2.4.2 =
99
  * Now styles that are loaded in the BODY section of the page are unloaded (if selected); Sometimes, in special cases, within "wp_footer" action (or other similar one such as "get_footer"), wp_enqueue_style is called
100
 
templates/meta-box-loaded.php CHANGED
@@ -205,7 +205,7 @@ if (! empty($data['all']['styles'])) {
205
  <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
206
  name="wpacu_styles_load_it[]"
207
  value="<?php echo $obj->handle; ?>"/>
208
- Load it on this page (make exception<?php if (! $isGlobalRule) { echo ' IF any unload rule is applied'; } ?>)</label>
209
  </li>
210
  </ul>
211
  <?php
@@ -441,7 +441,7 @@ if (! empty($data['all']['scripts'])) {
441
  name="wpacu_scripts_load_it[]"
442
  <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
443
  value="<?php echo $obj->handle; ?>" />
444
- Load it on this page (make exception<?php if (! $isGlobalRule) { echo ' IF any unload rule is applied'; } ?>)</label>
445
  </li>
446
  </ul>
447
  <?php
205
  <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
206
  name="wpacu_styles_load_it[]"
207
  value="<?php echo $obj->handle; ?>"/>
208
+ Load it on this page (make exception<?php if (! $isGlobalRule) { echo ' * works only IF any of two rules above are selected'; } ?>)</label>
209
  </li>
210
  </ul>
211
  <?php
441
  name="wpacu_scripts_load_it[]"
442
  <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
443
  value="<?php echo $obj->handle; ?>" />
444
+ Load it on this page (make exception<?php if (! $isGlobalRule) { echo ' * works only IF any of two rules above are selected'; } ?>)</label>
445
  </li>
446
  </ul>
447
  <?php
templates/settings-home-page.php CHANGED
@@ -45,7 +45,7 @@ if ($data['show_on_front'] === 'page') {
45
 
46
  <p><?php _e('Here you can manage the assets that are not loading for the home page. It is only applicable if "Front page displays" is set to "Your latest posts" (in "Settings" -&gt; "Reading"). When you edit a page/post (e.g. "Posts" -&gt; "All Posts", "Pages" -&gt; "All Pages" etc.), you will see the list inside a meta box.', WPACU_PLUGIN_NAME); ?></p>
47
 
48
- <p>The plugin uses <a target="_blank" href="https://codex.wordpress.org/Function_Reference/is_front_page">is_front_page()</a> WordPress function to check if the visitor is on the home page. Note that the setting will also apply to pages such as <code>/page/2</code> <code>page/3</code> etc. in case the latest blog posts are paginated.</p>
49
 
50
  <div id="wpacu_meta_box_content">
51
  <img src="<?php echo admin_url(); ?>/images/spinner.gif" align="top" width="20" height="20" alt="" />&nbsp;
45
 
46
  <p><?php _e('Here you can manage the assets that are not loading for the home page. It is only applicable if "Front page displays" is set to "Your latest posts" (in "Settings" -&gt; "Reading"). When you edit a page/post (e.g. "Posts" -&gt; "All Posts", "Pages" -&gt; "All Pages" etc.), you will see the list inside a meta box.', WPACU_PLUGIN_NAME); ?></p>
47
 
48
+ <p>The plugin uses <a target="_blank" href="https://codex.wordpress.org/Function_Reference/is_front_page">is_front_page()</a> and <a href="https://codex.wordpress.org/Conditional_Tags#The_Main_Page">is_home()</a> WordPress functions to check if the visitor is on the home page. Note that the setting will also apply to pages such as <code>/page/2</code> <code>page/3</code> etc. in case the latest blog posts are paginated.</p>
49
 
50
  <div id="wpacu_meta_box_content">
51
  <img src="<?php echo admin_url(); ?>/images/spinner.gif" align="top" width="20" height="20" alt="" />&nbsp;
wpacu-load.php CHANGED
@@ -40,7 +40,8 @@ WpAssetCleanUp\Main::instance();
40
  new \WpAssetCleanUp\OwnAssets;
41
 
42
  // Add / Update / Remove Settings
43
- (new WpAssetCleanUp\Update)->init();
 
44
 
45
  // Settings
46
  new WpAssetCleanUp\Settings;
@@ -48,5 +49,8 @@ new WpAssetCleanUp\Settings;
48
  // HomePage
49
  new WpAssetCleanUp\HomePage;
50
 
 
 
 
51
  // Menu
52
  new \WpAssetCleanUp\Menu;
40
  new \WpAssetCleanUp\OwnAssets;
41
 
42
  // Add / Update / Remove Settings
43
+ $wpacuUpdate = new WpAssetCleanUp\Update;
44
+ $wpacuUpdate->init();
45
 
46
  // Settings
47
  new WpAssetCleanUp\Settings;
49
  // HomePage
50
  new WpAssetCleanUp\HomePage;
51
 
52
+ // Various functions
53
+ new WpAssetCleanUp\Misc;
54
+
55
  // Menu
56
  new \WpAssetCleanUp\Menu;
wpacu.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  * Plugin Name: WP Asset CleanUp
4
  * Plugin URI: http://www.bitrepository.com/remove-unused-scripts-styles-wordpress-pages.html
5
- * Version: 1.2.4.2
6
  * Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages that you don't need
7
  * Author: Gabriel Livan
8
  * Author URI: http://www.gabelivan.com/
2
  /*
3
  * Plugin Name: WP Asset CleanUp
4
  * Plugin URI: http://www.bitrepository.com/remove-unused-scripts-styles-wordpress-pages.html
5
+ * Version: 1.2.4.3
6
  * Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages that you don't need
7
  * Author: Gabriel Livan
8
  * Author URI: http://www.gabelivan.com/