Asset CleanUp: Page Speed Booster - Version 1.2.4.4

Version Description

  • Updated AJAX calls to work fine within the Dashboard even if mod_security Apache module is enabled as there were some problems on specific servers
  • Added "Unload on this page" text next to the first checkbox to explain its purpose better
  • Added "WP Remote Post" method to retrieve assets (in case the default "Direct" method doesn't work)
  • Enable/disable asset list loading within the Dashboard (in case one prefers to only have it within the front-end)
Download this release

Release Info

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

Code changes from version 1.2.4.3 to 1.2.4.4

assets/script.js CHANGED
@@ -10,8 +10,8 @@ jQuery(document).ready(function($) {
10
  var cbSelector = '.icheckbox_square-red', handle;
11
 
12
  $(cbSelector).iCheck({
13
- checkboxClass: 'icheckbox_square-red',
14
- increaseArea: '20%' // optional
15
  });
16
 
17
  $(cbSelector).on('ifChecked', function (event) {
@@ -149,19 +149,55 @@ jQuery(document).ready(function($) {
149
  return false; // stop if we are not on the right page (with asset list)
150
  }
151
 
152
- // Get URL
153
- var data = wpacu_object.plugin_name + '_load=1';
154
 
155
- jQuery.post(wpacu_object.post_url, data, function (contents) {
156
- var data = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  'action': wpacu_object.plugin_name + '_get_loaded_assets',
158
- 'contents': contents,
159
  'post_id': wpacu_object.post_id,
160
  'post_url': wpacu_object.post_url
161
  };
162
 
163
- jQuery.post(wpacu_object.ajax_url, data, function (response) {
164
- if (response == '') {
165
  return false;
166
  }
167
 
@@ -173,6 +209,5 @@ jQuery(document).ready(function($) {
173
 
174
  WpAssetCleanUp.load();
175
  });
176
- });
177
  });
178
-
10
  var cbSelector = '.icheckbox_square-red', handle;
11
 
12
  $(cbSelector).iCheck({
13
+ checkboxClass: 'icheckbox_square-red'
14
+ //increaseArea: '-20%' // optional
15
  });
16
 
17
  $(cbSelector).on('ifChecked', function (event) {
149
  return false; // stop if we are not on the right page (with asset list)
150
  }
151
 
152
+ var data = {};
 
153
 
154
+ if (wpacu_object.dom_get_type === 'direct') {
155
+ data[wpacu_object.plugin_name + '_load'] = 1;
156
+
157
+ $.post(wpacu_object.post_url, data, function (contents) {
158
+ var wpacuList = contents.substring(
159
+ (contents.lastIndexOf(wpacu_object.start_del) + wpacu_object.start_del.length),
160
+ contents.lastIndexOf(wpacu_object.end_del)
161
+ );
162
+
163
+ var data = {
164
+ 'action': wpacu_object.plugin_name + '_get_loaded_assets',
165
+ 'wpacu_list': wpacuList,
166
+ 'post_id': wpacu_object.post_id,
167
+ 'post_url': wpacu_object.post_url
168
+ };
169
+
170
+ if ('btoa' in window) {
171
+ // Non-Latin Characters get stripped
172
+ // We only need the content related to the assets
173
+ data.contents = window.btoa(contents.replace(/[\u0250-\ue007]/g, ''));
174
+ }
175
+
176
+ //console.log(data);
177
+
178
+ $.post(wpacu_object.ajax_url, data, function (response) {
179
+ if (!response) {
180
+ return false;
181
+ }
182
+
183
+ $('#wpacu_meta_box_content').html(response);
184
+
185
+ if ($('#wpacu_home_page_form').length > 0) {
186
+ $('#submit').show();
187
+ }
188
+
189
+ WpAssetCleanUp.load();
190
+ });
191
+ });
192
+ } else if (wpacu_object.dom_get_type === 'wp_remote_post') {
193
+ data = {
194
  'action': wpacu_object.plugin_name + '_get_loaded_assets',
 
195
  'post_id': wpacu_object.post_id,
196
  'post_url': wpacu_object.post_url
197
  };
198
 
199
+ $.post(wpacu_object.ajax_url, data, function (response) {
200
+ if (! response) {
201
  return false;
202
  }
203
 
209
 
210
  WpAssetCleanUp.load();
211
  });
212
+ }
213
  });
 
assets/script.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(document).ready(function(a){var b={load:function(){var b,c=".icheckbox_square-red";a(c).iCheck({checkboxClass:"icheckbox_square-red",increaseArea:"20%"}),a(c).on("ifChecked",function(b){a(b.target).closest("tr").addClass("wpacu_not_load")}),a(c).on("ifUnchecked",function(b){a(b.target).closest("tr").removeClass("wpacu_not_load")}),a(".wpacu_global_unload").click(function(){b=a(this).attr("data-handle"),a(this).prop("checked")?a(this).parent("label").addClass("wpacu_global_checked"):a(this).parent("label").removeClass("wpacu_global_checked")}),a(".wpacu_post_type_unload").click(function(){a(this).prop("checked")?a(this).parent("label").addClass("wpacu_post_type_unload_active"):a(this).parent("label").removeClass("wpacu_post_type_unload_active")}),a(".wpacu_load_it_option").click(function(){a(this).prop("checked")?a(this).parent("label").addClass("wpacu_global_unload_exception"):a(this).parent("label").removeClass("wpacu_global_unload_exception")})}};if(a("#wpacu_post_type_select").change(function(){a("#wpacu_post_type_form").submit()}),a(".wpacu_remove_rule").click(function(){var b=a(this).parents(".wpacu_global_rule_row");a(this).prop("checked")?b.addClass("selected"):b.removeClass("selected")}),a("#wpacu_wrap_assets").length>0&&b.load(),"undefined"==typeof wpacu_object||a("#wpacu_meta_box_content").length<1)return!1;var c=wpacu_object.plugin_name+"_load=1";jQuery.post(wpacu_object.post_url,c,function(c){var d={action:wpacu_object.plugin_name+"_get_loaded_assets",contents:c,post_id:wpacu_object.post_id,post_url:wpacu_object.post_url};jQuery.post(wpacu_object.ajax_url,d,function(c){return""!=c&&(a("#wpacu_meta_box_content").html(c),a("#wpacu_home_page_form").length>0&&a("#submit").show(),void b.load())})})});
1
+ jQuery(document).ready(function(a){var b={load:function(){var b,c=".icheckbox_square-red";a(c).iCheck({checkboxClass:"icheckbox_square-red"}),a(c).on("ifChecked",function(b){a(b.target).closest("tr").addClass("wpacu_not_load")}),a(c).on("ifUnchecked",function(b){a(b.target).closest("tr").removeClass("wpacu_not_load")}),a(".wpacu_global_unload").click(function(){b=a(this).attr("data-handle"),a(this).prop("checked")?a(this).parent("label").addClass("wpacu_global_checked"):a(this).parent("label").removeClass("wpacu_global_checked")}),a(".wpacu_post_type_unload").click(function(){a(this).prop("checked")?a(this).parent("label").addClass("wpacu_post_type_unload_active"):a(this).parent("label").removeClass("wpacu_post_type_unload_active")}),a(".wpacu_load_it_option").click(function(){a(this).prop("checked")?a(this).parent("label").addClass("wpacu_global_unload_exception"):a(this).parent("label").removeClass("wpacu_global_unload_exception")})}};if(a("#wpacu_post_type_select").change(function(){a("#wpacu_post_type_form").submit()}),a(".wpacu_remove_rule").click(function(){var b=a(this).parents(".wpacu_global_rule_row");a(this).prop("checked")?b.addClass("selected"):b.removeClass("selected")}),a("#wpacu_wrap_assets").length>0&&b.load(),"undefined"==typeof wpacu_object||a("#wpacu_meta_box_content").length<1)return!1;var c={};"direct"===wpacu_object.dom_get_type?(c[wpacu_object.plugin_name+"_load"]=1,a.post(wpacu_object.post_url,c,function(c){var d=c.substring(c.lastIndexOf(wpacu_object.start_del)+wpacu_object.start_del.length,c.lastIndexOf(wpacu_object.end_del)),e={action:wpacu_object.plugin_name+"_get_loaded_assets",wpacu_list:d,post_id:wpacu_object.post_id,post_url:wpacu_object.post_url};"btoa"in window&&(e.contents=window.btoa(c.replace(/[\u0250-\ue007]/g,""))),a.post(wpacu_object.ajax_url,e,function(c){return!!c&&(a("#wpacu_meta_box_content").html(c),a("#wpacu_home_page_form").length>0&&a("#submit").show(),void b.load())})})):"wp_remote_post"===wpacu_object.dom_get_type&&(c={action:wpacu_object.plugin_name+"_get_loaded_assets",post_id:wpacu_object.post_id,post_url:wpacu_object.post_url},a.post(wpacu_object.ajax_url,c,function(c){return!!c&&(a("#wpacu_meta_box_content").html(c),a("#wpacu_home_page_form").length>0&&a("#submit").show(),void b.load())}))});
assets/style.css DELETED
@@ -1,63 +0,0 @@
1
- tr.wpacu_not_load th, tr.wpacu_not_load td { background: #FFE1E1; }
2
-
3
- .widefat .check-column.wpacu_check { padding: 10px; }
4
-
5
- #wpacu_meta_box_content { width: 99%; }
6
- #wpacu_meta_box_content h3 { margin-left: 0; padding-left: 0; }
7
- #wpacu_meta_box_content div.wpacu_note { padding: 10px; background-color: #f5f5f5; }
8
-
9
- #wpacu_wrap_assets div.wpacu_note { padding: 10px; background-color: #f5f5f5; }
10
-
11
- #wpacu_meta_box_content div.wpacu_warning, #wpacu_wrap_assets div.wpacu_warning { border: 1px solid #cc0000; }
12
-
13
- #wpacu_meta_box_content div.wpacu_verified { padding: 10px; background-color: #f5f5f5; border-left: 1px solid #ddd; }
14
- #wpacu_meta_box_content div.wpacu_verified span { color: #0073aa; font-weight: bold; }
15
- #wpacu_meta_box_content ul.wpacu_asset_options { margin: 0; padding: 0; }
16
- #wpacu_meta_box_content ul.wpacu_asset_options li { list-style: none; display: inline-block; }
17
- #wpacu_meta_box_content ul.wpacu_asset_options label { margin-right: 20px; font-weight: normal; }
18
-
19
- /*
20
- * Asset List Styling: Front-end and Back-end
21
- */
22
- #wpacu_wrap_assets { color: #000000 !important; text-align: left; clear: both; width: 90%; padding: 20px; margin: 30px 0 0 15px; border: 1px solid #cdcdcd; z-index: 10000 !important; position: relative; background-color: white; }
23
- #wpacu_wrap_assets img { display: inline-block !important; }
24
- #wpacu_wrap_assets p { margin: 10px 0; line-height: 22px; text-align: left; }
25
- #wpacu_wrap_assets h1 { margin: 0 0 20px; font-size: 160%; text-align: left; }
26
- #wpacu_wrap_assets h3 { margin: 20px 0; font-size: 130%; }
27
-
28
- .wpacu_verified { margin: 0 0 10px 0; }
29
-
30
- .wpacu_asset_row td { padding: 10px; }
31
- .wpacu_asset_row td p { margin-bottom: 10px; word-wrap: break-word; }
32
- .wpacu_asset_row td label { cursor: pointer !important; display: inline-block !important; font-size: 100%; font-weight: normal; }
33
- .wpacu_asset_row td label span { font-size: 100% !important; }
34
- .wpacu_asset_row td.wpacu_check { width: 50px; }
35
-
36
- /* Dashboard adjust */
37
- body.wp-admin .wpacu_asset_row td.wpacu_check { width: 25px; }
38
-
39
- label.wpacu_add_global { cursor: pointer; }
40
- label.wpacu_global_checked { font-weight: bold; color: #d54e21; }
41
- label.wpacu_global_unload_exception { font-weight: bold !important; }
42
- label.wpacu_post_type_unload_active { color: #d54e21; }
43
-
44
- tr.wpacu_global_rule_row.selected { background: #e7e7e7; }
45
-
46
- .nav-tab-wrapper { border-bottom: 1px solid #ccc; width: 95%; }
47
-
48
- ul.wpacu_asset_options { margin: 0; padding: 0; }
49
- ul.wpacu_asset_options li { list-style: none; display: inline-block; }
50
- ul.wpacu_asset_options label { margin-right: 20px; font-weight: normal; }
51
- ul.wpacu_asset_options label input { margin-right: 4px; }
52
-
53
- /* Assets Table */
54
- .wp-asset-clean-up.widefat { width: 99%; }
55
-
56
- .wpacu_widefat { border: 1px solid #e5e5e5 !important; }
57
- .wpacu_widefat td { border: 1px solid #e5e5e5 !important; }
58
-
59
- .wpacu_striped > tbody > :nth-child(odd), ul.wpacu_striped > :nth-child(odd) { background-color: #f9f9f9 !important; }
60
-
61
- .wpacu_update_btn { -moz-box-shadow: inset 0 1px 0 0 #54a3f7 !important; -webkit-box-shadow: inset 0 1px 0 0 #54a3f7 !important; box-shadow: inset 0 1px 0 0 #54a3f7 !important; background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7)) !important; background: -moz-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important; background: -webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important; background: -o-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important; background: -ms-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important; background: linear-gradient(to bottom, #007dc1 5%, #0061a7 100%) !important; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0) !important; background-color: #007dc1 !important; -moz-border-radius: 3px !important; -webkit-border-radius: 3px !important; border-radius: 3px !important; border: 1px solid #124d77 !important; display: inline-block !important; cursor: pointer !important; color: #ffffff !important; font-size: 15px !important; padding: 10px 24px !important; text-decoration: none !important; text-shadow: 0 1px 0 #154682 !important; }
62
- .wpacu_update_btn:hover { background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important; background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important; background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important; background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important; background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important; background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%) !important; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0) !important; background-color: #0061a7 !important; }
63
- .wpacu_update_btn:active { position: relative !important; top: 1px !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/style.min.css CHANGED
@@ -1 +1 @@
1
- tr.wpacu_not_load td,tr.wpacu_not_load th{background:#FFE1E1}.widefat .check-column.wpacu_check{padding:10px}#wpacu_meta_box_content{width:99%}#wpacu_meta_box_content h3{margin-left:0;padding-left:0}#wpacu_meta_box_content div.wpacu_note,#wpacu_wrap_assets div.wpacu_note{padding:10px;background-color:#f5f5f5}#wpacu_meta_box_content div.wpacu_warning,#wpacu_wrap_assets div.wpacu_warning{border:1px solid #c00}#wpacu_meta_box_content div.wpacu_verified{padding:10px;background-color:#f5f5f5;border-left:1px solid #ddd}#wpacu_meta_box_content div.wpacu_verified span{color:#0073aa;font-weight:700}#wpacu_meta_box_content ul.wpacu_asset_options{margin:0;padding:0}#wpacu_meta_box_content ul.wpacu_asset_options li{list-style:none;display:inline-block}#wpacu_wrap_assets img,.wpacu_asset_row td label{display:inline-block!important}#wpacu_meta_box_content ul.wpacu_asset_options label{margin-right:20px;font-weight:400}#wpacu_wrap_assets{color:#000!important;text-align:left;clear:both;width:90%;padding:20px;margin:30px 0 0 15px;border:1px solid #cdcdcd;z-index:10000!important;position:relative;background-color:#fff}#wpacu_wrap_assets p{margin:10px 0;line-height:22px;text-align:left}#wpacu_wrap_assets h1{margin:0 0 20px;font-size:160%;text-align:left}#wpacu_wrap_assets h3{margin:20px 0;font-size:130%}.wpacu_verified{margin:0 0 10px}.wpacu_asset_row td{padding:10px}.wpacu_asset_row td p{margin-bottom:10px;word-wrap:break-word}.wpacu_asset_row td label{cursor:pointer!important;font-size:100%;font-weight:400}.wpacu_asset_row td label span{font-size:100%!important}.wpacu_asset_row td.wpacu_check{width:50px}body.wp-admin .wpacu_asset_row td.wpacu_check{width:25px}label.wpacu_add_global{cursor:pointer}label.wpacu_global_checked{font-weight:700;color:#d54e21}label.wpacu_global_unload_exception{font-weight:700!important}label.wpacu_post_type_unload_active{color:#d54e21}tr.wpacu_global_rule_row.selected{background:#e7e7e7}.nav-tab-wrapper{border-bottom:1px solid #ccc;width:95%}ul.wpacu_asset_options{margin:0;padding:0}ul.wpacu_asset_options li{list-style:none;display:inline-block}ul.wpacu_asset_options label{margin-right:20px;font-weight:400}ul.wpacu_asset_options label input{margin-right:4px}.wp-asset-clean-up.widefat{width:99%}.wpacu_widefat,.wpacu_widefat td{border:1px solid #e5e5e5!important}.wpacu_striped>tbody>:nth-child(odd),ul.wpacu_striped>:nth-child(odd){background-color:#f9f9f9!important}.wpacu_update_btn{-moz-box-shadow:inset 0 1px 0 0 #54a3f7!important;-webkit-box-shadow:inset 0 1px 0 0 #54a3f7!important;box-shadow:inset 0 1px 0 0 #54a3f7!important;background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#007dc1),color-stop(1,#0061a7))!important;background:-moz-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:-webkit-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:-o-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:-ms-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:linear-gradient(to bottom,#007dc1 5%,#0061a7 100%)!important;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7', GradientType=0)!important;background-color:#007dc1!important;-moz-border-radius:3px!important;-webkit-border-radius:3px!important;border-radius:3px!important;border:1px solid #124d77!important;display:inline-block!important;cursor:pointer!important;color:#fff!important;font-size:15px!important;padding:10px 24px!important;text-decoration:none!important;text-shadow:0 1px 0 #154682!important}.wpacu_update_btn:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#0061a7),color-stop(1,#007dc1))!important;background:-moz-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:-webkit-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:-o-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:-ms-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:linear-gradient(to bottom,#0061a7 5%,#007dc1 100%)!important;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1', GradientType=0)!important;background-color:#0061a7!important}.wpacu_update_btn:active{position:relative!important;top:1px!important}
1
+ .widefat .check-column.wpacu_check,body.toplevel_page_wpassetcleanup_settings .notice{padding:10px}tr.wpacu_not_load td,tr.wpacu_not_load th{background:#FFE1E1}#wpacu_meta_box_content{width:99%}#wpacu_meta_box_content h3{margin-left:0;padding-left:0}#wpacu_meta_box_content div.wpacu_note,#wpacu_wrap_assets div.wpacu_note{padding:10px;background-color:#f5f5f5}#wpacu_meta_box_content .dashicons.dashicons-warning{color:red}#wpacu_meta_box_content div.wpacu_warning,#wpacu_wrap_assets div.wpacu_warning{border:1px solid #c00}#wpacu_meta_box_content div.wpacu_verified{padding:10px;background-color:#f5f5f5;border-left:1px solid #ddd}#wpacu_meta_box_content div.wpacu_verified span{color:#0073aa;font-weight:700}#wpacu_meta_box_content ul.wpacu_asset_options{margin:0;padding:0}#wpacu_meta_box_content ul.wpacu_asset_options li{list-style:none;display:inline-block}#wpacu_wrap_assets img,.wpacu_asset_row td label{display:inline-block!important}#wpacu_meta_box_content ul.wpacu_asset_options label{margin-right:20px;font-weight:400}#wpacu_wrap_assets{color:#000!important;text-align:left;clear:both;width:90%;padding:20px;margin:30px 0 0 15px;border:1px solid #cdcdcd;z-index:10000!important;position:relative;background-color:#fff}#wpacu_wrap_assets p{margin:10px 0;line-height:22px;text-align:left}#wpacu_wrap_assets h1{margin:0 0 20px;font-size:160%;text-align:left}#wpacu_wrap_assets h3{margin:20px 0;font-size:130%}.wpacu_verified{margin:0 0 10px}.wpacu_asset_row td{padding:10px}.wpacu_asset_row td p{margin-bottom:10px;word-wrap:break-word}.wpacu_asset_row td label{cursor:pointer!important;font-size:100%;font-weight:400}.wpacu_asset_row td label span{font-size:100%!important}.wpacu_asset_row td.wpacu_check{width:50px}body.wp-admin .wpacu_asset_row td.wpacu_check{width:25px}label.wpacu_add_global{cursor:pointer}label.wpacu_global_checked{font-weight:700;color:#d54e21}label.wpacu_global_unload_exception{font-weight:700!important}label.wpacu_post_type_unload_active{color:#d54e21}tr.wpacu_global_rule_row.selected{background:#e7e7e7}.nav-tab-wrapper{border-bottom:1px solid #ccc;width:95%}ul.wpacu_asset_options{margin:0;padding:0}ul.wpacu_asset_options li{list-style:none;display:inline-block}ul.wpacu_asset_options label{margin-right:20px;font-weight:400}ul.wpacu_asset_options label input{margin-right:4px}.wp-asset-clean-up.widefat{width:99%}.wpacu_widefat,.wpacu_widefat td{border:1px solid #e5e5e5!important}.wpacu_striped>tbody>:nth-child(odd),ul.wpacu_striped>:nth-child(odd){background-color:#f9f9f9!important}.wpacu_update_btn{-moz-box-shadow:inset 0 1px 0 0 #54a3f7!important;-webkit-box-shadow:inset 0 1px 0 0 #54a3f7!important;box-shadow:inset 0 1px 0 0 #54a3f7!important;background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#007dc1),color-stop(1,#0061a7))!important;background:-moz-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:-webkit-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:-o-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:-ms-linear-gradient(top,#007dc1 5%,#0061a7 100%)!important;background:linear-gradient(to bottom,#007dc1 5%,#0061a7 100%)!important;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7', GradientType=0)!important;background-color:#007dc1!important;-moz-border-radius:3px!important;-webkit-border-radius:3px!important;border-radius:3px!important;border:1px solid #124d77!important;display:inline-block!important;cursor:pointer!important;color:#fff!important;font-size:15px!important;padding:10px 24px!important;text-decoration:none!important;text-shadow:0 1px 0 #154682!important;height:auto!important;line-height:normal!important}.wpacu_update_btn:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(.05,#0061a7),color-stop(1,#007dc1))!important;background:-moz-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:-webkit-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:-o-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:-ms-linear-gradient(top,#0061a7 5%,#007dc1 100%)!important;background:linear-gradient(to bottom,#0061a7 5%,#007dc1 100%)!important;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1', GradientType=0)!important;background-color:#0061a7!important}.wpacu_update_btn:active{position:relative!important;top:1px!important}
assets/style.scss CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  tr.wpacu_not_load {
2
  th, td {
3
  background: #FFE1E1;
@@ -19,6 +25,9 @@ tr.wpacu_not_load {
19
  padding: 10px;
20
  background-color: #f5f5f5;
21
  }
 
 
 
22
  }
23
 
24
  #wpacu_wrap_assets div.wpacu_note {
@@ -201,6 +210,10 @@ ul.wpacu_asset_options {
201
  padding: 10px 24px !important;
202
  text-decoration: none !important;
203
  text-shadow: 0 1px 0 #154682 !important;
 
 
 
 
204
  &:hover {
205
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important;
206
  background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
1
+ body.toplevel_page_wpassetcleanup_settings {
2
+ .notice {
3
+ padding: 10px;
4
+ }
5
+ }
6
+
7
  tr.wpacu_not_load {
8
  th, td {
9
  background: #FFE1E1;
25
  padding: 10px;
26
  background-color: #f5f5f5;
27
  }
28
+ .dashicons.dashicons-warning {
29
+ color: red;
30
+ }
31
  }
32
 
33
  #wpacu_wrap_assets div.wpacu_note {
210
  padding: 10px 24px !important;
211
  text-decoration: none !important;
212
  text-shadow: 0 1px 0 #154682 !important;
213
+
214
+ height: auto !important;
215
+ line-height: normal !important;
216
+
217
  &:hover {
218
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important;
219
  background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
classes/HomePage.php CHANGED
@@ -42,7 +42,7 @@ class HomePage
42
  }
43
  } elseif ($this->data['show_on_front'] === 'posts') {
44
  // Your latest posts
45
- $postUrl = get_option('siteurl');
46
 
47
  if (substr($postUrl, -1) != '/') {
48
  $postUrl .= '/';
@@ -70,6 +70,9 @@ class HomePage
70
 
71
  $this->data['nonce_value'] = wp_create_nonce($this->data['nonce_name']);
72
 
 
 
 
73
  Main::instance()->parseTemplate('settings-home-page', $this->data, true);
74
  }
75
  }
42
  }
43
  } elseif ($this->data['show_on_front'] === 'posts') {
44
  // Your latest posts
45
+ $postUrl = get_site_url();
46
 
47
  if (substr($postUrl, -1) != '/') {
48
  $postUrl .= '/';
70
 
71
  $this->data['nonce_value'] = wp_create_nonce($this->data['nonce_name']);
72
 
73
+ $wpacuSettings = new Settings;
74
+ $this->data['wpacu_settings'] = $wpacuSettings->getAll();
75
+
76
  Main::instance()->parseTemplate('settings-home-page', $this->data, true);
77
  }
78
  }
classes/Main.php CHANGED
@@ -10,12 +10,19 @@ class Main
10
  /**
11
  *
12
  */
13
- const STARTDEL = '@ BEGIN WPACU PLUGIN JSON @';
14
 
15
  /**
16
  *
17
  */
18
- const ENDDEL = '@ END WPACU PLUGIN JSON @';
 
 
 
 
 
 
 
19
 
20
  /**
21
  * @var array
@@ -37,11 +44,46 @@ class Main
37
  */
38
  public $fetchUrl;
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  /**
41
  * @var bool|mixed|void
42
  */
43
  public $frontendShow = false;
44
 
 
 
 
 
 
 
 
 
 
 
45
  /**
46
  * @var array
47
  */
@@ -84,10 +126,23 @@ class Main
84
  */
85
  public function __construct()
86
  {
87
- $this->frontendShow = (get_option(WPACU_PLUGIN_NAME.'_frontend_show'));
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  // Early Triggers
90
- add_action('wp', array($this, 'setVars'), 2);
 
91
 
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) {
@@ -96,7 +151,7 @@ class Main
96
  }
97
 
98
  add_action('wp_head', array($this, 'saveFooterAssets'), 100000000);
99
- add_action('wp_footer', array($this, 'printScriptsStyles'), 100000000);
100
  }
101
 
102
  // Front-end View - Unload the assets
@@ -114,38 +169,52 @@ class Main
114
  add_action('wp_print_footer_scripts', array($this, 'filterStyles'), 1);
115
  }
116
 
117
- // Send an AJAX request to get the list of loaded scripts and styles and print it nicely
118
- add_action(
119
- 'wp_ajax_'. WPACU_PLUGIN_NAME . '_get_loaded_assets',
120
- array($this, 'ajaxGetJsonListCallback')
121
- );
 
 
 
122
 
123
- add_action('add_meta_boxes', array($this, 'addMetaBox'));
 
124
  }
125
 
126
  /**
127
- *
128
  */
129
- public function setVars()
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  {
131
  if (! isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
132
  $this->globalUnloaded = $this->getGlobalUnload();
133
 
134
- if (! is_singular() && ! Misc::isHomePage()) {
135
  return;
136
  }
137
 
138
- global $post;
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);
146
  }
147
 
148
- $this->loadExceptions = $this->getLoadExceptions($type, $postId);
149
  }
150
  }
151
 
@@ -156,7 +225,7 @@ class Main
156
  {
157
  $obj = get_post_type_object($postType);
158
 
159
- if ($obj->public > 0) {
160
  add_meta_box(
161
  WPACU_PLUGIN_NAME.'_asset_list',
162
  __('WP Asset CleanUp', WPACU_PLUGIN_NAME),
@@ -169,7 +238,7 @@ class Main
169
  }
170
 
171
  /**
172
- *
173
  */
174
  public function renderMetaBoxContent()
175
  {
@@ -211,7 +280,7 @@ class Main
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
@@ -247,10 +316,10 @@ class Main
247
  }
248
  }
249
 
250
- if (is_singular()) {
251
  // Any bulk unloaded styles (e.g. for all pages belonging to a post type)? Append them
252
  if (empty($this->postTypesUnloaded)) {
253
- global $post;
254
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
255
  }
256
 
@@ -273,6 +342,8 @@ class Main
273
  }
274
  }
275
 
 
 
276
  if (empty($list)) {
277
  return;
278
  }
@@ -311,7 +382,7 @@ class Main
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
@@ -347,10 +418,10 @@ class Main
347
  }
348
  }
349
 
350
- if (is_singular()) {
351
  // Any bulk unloaded styles (e.g. for all pages belonging to a post type)? Append them
352
  if (empty($this->postTypesUnloaded)) {
353
- global $post;
354
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
355
  }
356
 
@@ -373,6 +444,8 @@ class Main
373
  }
374
  }
375
 
 
 
376
  if (empty($list)) {
377
  return;
378
  }
@@ -527,22 +600,21 @@ class Main
527
  */
528
  public function printScriptsStyles()
529
  {
530
- if (defined('DOING_AJAX') && DOING_AJAX) {
531
- // Not for AJAX calls
532
  return;
533
  }
534
 
535
- global $post;
536
-
537
- $isFrontEndView = ($this->frontendShow && current_user_can('manage_options')
538
- && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])
539
- && !is_admin());
540
- $isDashboardView = (!$isFrontEndView && isset($_POST[WPACU_PLUGIN_NAME.'_load']));
541
 
542
  if (!$isFrontEndView && !$isDashboardView) {
543
  return;
544
  }
545
 
 
 
 
546
  // This is the list of the scripts an styles that were eventually loaded
547
  // We have also the list of the ones that were unloaded
548
  // located in $this->wpScripts and $this->wpStyles
@@ -551,14 +623,12 @@ class Main
551
  $stylesBeforeUnload = $this->wpStyles;
552
  $scriptsBeforeUnload = $this->wpScripts;
553
 
554
-
555
-
556
  global $wp_scripts, $wp_styles;
557
 
558
  $list = array();
559
 
560
  $currentUnloadedAll = $currentUnloaded = (array)json_decode(
561
- $this->getAssetsUnloaded($post->ID)
562
  );
563
 
564
  // Append global unloaded assets to current (one by one) unloaded ones
@@ -575,7 +645,7 @@ class Main
575
  }
576
 
577
  // Append bulk unloaded assets to current (one by one) unloaded ones
578
- if (is_singular()) {
579
  if (! empty($this->postTypesUnloaded['styles'])) {
580
  foreach ($this->postTypesUnloaded['styles'] as $postTypeStyle) {
581
  $currentUnloadedAll['styles'][] = $postTypeStyle;
@@ -601,6 +671,10 @@ class Main
601
  WPACU_PLUGIN_NAME . '-style'
602
  );
603
 
 
 
 
 
604
  foreach ($wp_styles->done as $handle) {
605
  if ($isFrontEndView && in_array($handle, $skipStyles)) {
606
  continue;
@@ -689,30 +763,41 @@ class Main
689
 
690
  // Front-end View while admin is logged in
691
  if ($isFrontEndView) {
692
- $data = array();
 
 
 
 
693
 
694
- $data['current'] = $currentUnloaded;
 
695
 
696
- $data['all']['scripts'] = $list['scripts'];
697
- $data['all']['styles'] = $list['styles'];
698
 
699
- $this->fetchUrl = Misc::getPostUrl($post->ID);
700
 
701
- $data['fetch_url'] = $this->fetchUrl;
702
 
703
- $data['nonce_name'] = Update::NONCE_FIELD_NAME;
704
- $data['nonce_action'] = Update::NONCE_ACTION_NAME;
705
 
706
- $data = $this->alterAssetObj($data);
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);
 
 
 
 
 
 
 
 
714
 
715
- if (is_singular()) {
716
  // Current Post Type
717
  $data['post_type'] = $post->post_type;
718
 
@@ -721,12 +806,19 @@ class Main
721
  $data['post_type_unloaded'] = $this->getPostTypeUnload($data['post_type']);
722
  }
723
 
 
 
 
724
  $this->parseTemplate('settings-frontend', $data, true);
725
  } elseif ($isDashboardView) {
726
- // AJAX call from the WordPress Dashboard
727
- echo self::STARTDEL
728
  .base64_encode(json_encode($list)).
729
- self::ENDDEL;
 
 
 
 
730
  }
731
  }
732
 
@@ -740,7 +832,11 @@ class Main
740
  {
741
  define('WPACU_TPL_LOADED', true);
742
 
743
- $templateFile = dirname(__DIR__) . '/templates/' . $name . '.php';
 
 
 
 
744
 
745
  if (! file_exists($templateFile)) {
746
  wp_die('Template '.$name.' not found.');
@@ -763,22 +859,41 @@ class Main
763
  */
764
  public function ajaxGetJsonListCallback()
765
  {
766
- $contents = isset($_POST['contents']) ? $_POST['contents'] : '';
767
  $postId = isset($_POST['post_id']) ? (int)$_POST['post_id'] : '';
768
  $postUrl = isset($_POST['post_url']) ? $_POST['post_url'] : '';
769
 
770
- $json = base64_decode(
771
- Misc::extractBetween(
772
- $contents,
773
- self::STARTDEL,
774
- self::ENDDEL
775
- )
776
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
777
 
778
  $data = array();
779
 
780
  $data['all'] = (array)json_decode($json);
781
- $data['contents'] = $contents;
 
 
 
782
 
783
  $data = $this->alterAssetObj($data);
784
 
@@ -813,6 +928,9 @@ class Main
813
 
814
  $data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
815
 
 
 
 
816
  $this->parseTemplate('meta-box-loaded', $data, true);
817
 
818
  exit;
@@ -824,7 +942,7 @@ class Main
824
  */
825
  public function alterAssetObj($data)
826
  {
827
- $siteUrl = get_option('siteurl');
828
 
829
  if (! empty($data['all']['styles'])) {
830
  $data['core_styles_loaded'] = false;
@@ -871,9 +989,16 @@ class Main
871
  if (! empty($data['all']['scripts'])) {
872
  $data['core_scripts_loaded'] = false;
873
 
 
 
874
  if (isset($data['contents'])) {
 
875
  $headPart = Misc::extractBetween($data['contents'], '<head', '</head>');
876
- $bodyPart = Misc::extractBetween($data['contents'], '<body', '</body>');
 
 
 
 
877
  }
878
 
879
  foreach ($data['all']['scripts'] as $key => $obj) {
@@ -951,13 +1076,14 @@ class Main
951
  */
952
  public function getAssetsUnloaded($postId = 0)
953
  {
954
- // Post Type (Overwrites 'front' if we are in a singular post)
955
- global $post;
956
- $postId = (isset($post->ID) && is_singular()) ? $post->ID : $postId;
 
957
 
958
  if (! $this->assetsRemoved) {
959
  // For Home Page (latest blog posts)
960
- if ($postId < 1) {
961
  $this->assetsRemoved = get_option(WPACU_PLUGIN_NAME . '_front_page_no_load');
962
  return $this->assetsRemoved;
963
  } elseif ($postId > 0) {
@@ -971,4 +1097,92 @@ class Main
971
 
972
  return $this->assetsRemoved;
973
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
974
  }
10
  /**
11
  *
12
  */
13
+ const START_DEL = '@ BEGIN WPACU PLUGIN JSON @';
14
 
15
  /**
16
  *
17
  */
18
+ const END_DEL = '@ END WPACU PLUGIN JSON @';
19
+
20
+ /**
21
+ * @var string
22
+ * Can be managed in the Dashboard within the plugin's settings
23
+ * e.g. 'direct', 'wp_remote_post'
24
+ */
25
+ public static $domGetType = 'direct';
26
 
27
  /**
28
  * @var array
44
  */
45
  public $fetchUrl;
46
 
47
+ /**
48
+ * @var
49
+ */
50
+ public $isUpdateable = true;
51
+
52
+ /**
53
+ * @var bool
54
+ */
55
+ public $isWooCommerceShopPage = false;
56
+
57
+ /**
58
+ * @var int
59
+ */
60
+ public $currentPostId = 0;
61
+
62
+ /**
63
+ * @var array
64
+ */
65
+ public $currentPost = array();
66
+
67
+ /**
68
+ * @var array
69
+ */
70
+ public $vars = array();
71
+
72
  /**
73
  * @var bool|mixed|void
74
  */
75
  public $frontendShow = false;
76
 
77
+ /**
78
+ * @var bool
79
+ */
80
+ public $dashboardShow = false;
81
+
82
+ /**
83
+ * @var bool
84
+ */
85
+ public $isFrontendView = false;
86
+
87
  /**
88
  * @var array
89
  */
126
  */
127
  public function __construct()
128
  {
129
+ $wpacuSettings = new Settings();
130
+ $settings = $wpacuSettings->getAll();
131
+
132
+ $this->frontendShow = $settings['frontend_show'];
133
+ $this->dashboardShow = $settings['dashboard_show'];
134
+
135
+ if ($this->dashboardShow && $settings['dom_get_type'] != '') {
136
+ self::$domGetType = $settings['dom_get_type'];
137
+ }
138
+
139
+ if (array_key_exists(WPACU_PLUGIN_NAME.'_load', $_POST)) {
140
+ add_filter('w3tc_minify_enable', '__return_false');
141
+ }
142
 
143
  // Early Triggers
144
+ add_action('wp', array($this, 'setVarsBeforeUpdate'), 8);
145
+ add_action('wp', array($this, 'setVarsAfterAnyUpdate'), 10);
146
 
147
  // Fetch the page in the background to see what scripts/styles are already loading
148
  if (isset($_POST[WPACU_PLUGIN_NAME.'_load']) || $this->frontendShow) {
151
  }
152
 
153
  add_action('wp_head', array($this, 'saveFooterAssets'), 100000000);
154
+ add_action('wp_footer', array($this, 'printScriptsStyles'), PHP_INT_MAX);
155
  }
156
 
157
  // Front-end View - Unload the assets
169
  add_action('wp_print_footer_scripts', array($this, 'filterStyles'), 1);
170
  }
171
 
172
+ // Do not load the meta box nor do any AJAX calls
173
+ // if the asset management is not enabled for the Dashboard
174
+ if ($settings['dashboard_show'] == 1) {
175
+ // Send an AJAX request to get the list of loaded scripts and styles and print it nicely
176
+ add_action(
177
+ 'wp_ajax_'. WPACU_PLUGIN_NAME . '_get_loaded_assets',
178
+ array($this, 'ajaxGetJsonListCallback')
179
+ );
180
 
181
+ add_action('add_meta_boxes', array($this, 'addMetaBox'));
182
+ }
183
  }
184
 
185
  /**
186
+ * Priority: 8 (earliest)
187
  */
188
+ public function setVarsBeforeUpdate()
189
+ {
190
+ $this->isFrontendView = ($this->frontendShow && current_user_can('manage_options')
191
+ && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])
192
+ && !is_admin());
193
+
194
+ // it will update $this->isUpdateable;
195
+ $this->getCurrentPostId();
196
+ }
197
+
198
+ /**
199
+ * Priority: 10 (latest)
200
+ */
201
+ public function setVarsAfterAnyUpdate()
202
  {
203
  if (! isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
204
  $this->globalUnloaded = $this->getGlobalUnload();
205
 
206
+ if (! $this->isUpdateable && ! Misc::isHomePage()) {
207
  return;
208
  }
209
 
 
 
 
 
210
  $type = (Misc::isHomePage()) ? 'front_page' : 'post';
211
 
212
+ if ($this->getCurrentPost()) {
213
+ $post = $this->getCurrentPost();
214
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
215
  }
216
 
217
+ $this->loadExceptions = $this->getLoadExceptions($type, $this->currentPostId);
218
  }
219
  }
220
 
225
  {
226
  $obj = get_post_type_object($postType);
227
 
228
+ if (isset($obj->public) && $obj->public > 0) {
229
  add_meta_box(
230
  WPACU_PLUGIN_NAME.'_asset_list',
231
  __('WP Asset CleanUp', WPACU_PLUGIN_NAME),
238
  }
239
 
240
  /**
241
+ * This is triggered only in the Edit Mode Dashboard View
242
  */
243
  public function renderMetaBoxContent()
244
  {
280
  return;
281
  }
282
 
283
+ $nonAssetConfigPage = (! $this->isUpdateable && ! Misc::getShowOnFront());
284
 
285
  // It looks like the page loaded is neither a post, page or the front-page
286
  // We'll see if there are assets unloaded globally and unload them
316
  }
317
  }
318
 
319
+ if ($this->isSinglePage()) {
320
  // Any bulk unloaded styles (e.g. for all pages belonging to a post type)? Append them
321
  if (empty($this->postTypesUnloaded)) {
322
+ $post = $this->getCurrentPost();
323
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
324
  }
325
 
342
  }
343
  }
344
 
345
+ $list = apply_filters('wpacu_filter_scripts', $list);
346
+
347
  if (empty($list)) {
348
  return;
349
  }
382
  return;
383
  }
384
 
385
+ $nonAssetConfigPage = (! $this->isUpdateable && ! Misc::getShowOnFront());
386
 
387
  // It looks like the page loaded is neither a post, page or the front-page
388
  // We'll see if there are assets unloaded globally and unload them
418
  }
419
  }
420
 
421
+ if ($this->isSinglePage()) {
422
  // Any bulk unloaded styles (e.g. for all pages belonging to a post type)? Append them
423
  if (empty($this->postTypesUnloaded)) {
424
+ $post = $this->getCurrentPost();
425
  $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
426
  }
427
 
444
  }
445
  }
446
 
447
+ $list = apply_filters('wpacu_filter_styles', $list);
448
+
449
  if (empty($list)) {
450
  return;
451
  }
600
  */
601
  public function printScriptsStyles()
602
  {
603
+ // Not for WordPress AJAX calls
604
+ if (self::$domGetType === 'direct' && defined('DOING_AJAX') && DOING_AJAX) {
605
  return;
606
  }
607
 
608
+ $isFrontEndView = $this->isFrontendView;
609
+ $isDashboardView = (!$isFrontEndView && array_key_exists(WPACU_PLUGIN_NAME.'_load', $_POST));
 
 
 
 
610
 
611
  if (!$isFrontEndView && !$isDashboardView) {
612
  return;
613
  }
614
 
615
+ // Prevent plugins from altering the DOM
616
+ add_filter('w3tc_minify_enable', '__return_false');
617
+
618
  // This is the list of the scripts an styles that were eventually loaded
619
  // We have also the list of the ones that were unloaded
620
  // located in $this->wpScripts and $this->wpStyles
623
  $stylesBeforeUnload = $this->wpStyles;
624
  $scriptsBeforeUnload = $this->wpScripts;
625
 
 
 
626
  global $wp_scripts, $wp_styles;
627
 
628
  $list = array();
629
 
630
  $currentUnloadedAll = $currentUnloaded = (array)json_decode(
631
+ $this->getAssetsUnloaded($this->getCurrentPostId())
632
  );
633
 
634
  // Append global unloaded assets to current (one by one) unloaded ones
645
  }
646
 
647
  // Append bulk unloaded assets to current (one by one) unloaded ones
648
+ if ($this->isSinglePage()) {
649
  if (! empty($this->postTypesUnloaded['styles'])) {
650
  foreach ($this->postTypesUnloaded['styles'] as $postTypeStyle) {
651
  $currentUnloadedAll['styles'][] = $postTypeStyle;
671
  WPACU_PLUGIN_NAME . '-style'
672
  );
673
 
674
+ if (is_admin_bar_showing()) {
675
+ $skipStyles[] = 'dashicons';
676
+ }
677
+
678
  foreach ($wp_styles->done as $handle) {
679
  if ($isFrontEndView && in_array($handle, $skipStyles)) {
680
  continue;
763
 
764
  // Front-end View while admin is logged in
765
  if ($isFrontEndView) {
766
+ $data = array(
767
+ 'is_updateable' => true,
768
+ 'post_type' => '',
769
+ 'post_type_unloaded' => array()
770
+ );
771
 
772
+ if ($this->isUpdateable) {
773
+ $data['current'] = $currentUnloaded;
774
 
775
+ $data['all']['scripts'] = $list['scripts'];
776
+ $data['all']['styles'] = $list['styles'];
777
 
778
+ $this->fetchUrl = Misc::getPostUrl($this->getCurrentPostId());
779
 
780
+ $data['fetch_url'] = $this->fetchUrl;
781
 
782
+ $data['nonce_name'] = Update::NONCE_FIELD_NAME;
783
+ $data['nonce_action'] = Update::NONCE_ACTION_NAME;
784
 
785
+ $data = $this->alterAssetObj($data);
786
 
787
+ $data['global_unload'] = $this->globalUnloaded;
788
 
789
+ $type = Misc::getShowOnFront() ? 'front_page' : 'post';
 
790
 
791
+ $data['load_exceptions'] = $this->getLoadExceptions($type, $this->getCurrentPostId());
792
+ } else {
793
+ $data['is_updateable'] = false;
794
+ }
795
+
796
+ $data['is_woocommerce_shop_page'] = $this->isWooCommerceShopPage;
797
+
798
+ if ($this->isSinglePage()) {
799
+ $post = $this->getCurrentPost();
800
 
 
801
  // Current Post Type
802
  $data['post_type'] = $post->post_type;
803
 
806
  $data['post_type_unloaded'] = $this->getPostTypeUnload($data['post_type']);
807
  }
808
 
809
+ $data['total_styles'] = (! empty($data['all']['styles'])) ? count($data['all']['styles']) : false;
810
+ $data['total_scripts'] = (! empty($data['all']['scripts'])) ? count($data['all']['scripts']) : false;
811
+
812
  $this->parseTemplate('settings-frontend', $data, true);
813
  } elseif ($isDashboardView) {
814
+ // AJAX call (not the classic WP one) from the WP Dashboard
815
+ echo self::START_DEL
816
  .base64_encode(json_encode($list)).
817
+ self::END_DEL;
818
+
819
+ // Do not allow further processes as cache plugins such as W3 Total Cache could alter the source code
820
+ // and we need the non-minified version of the DOM (e.g. to determine the position of the elements)
821
+ exit();
822
  }
823
  }
824
 
832
  {
833
  define('WPACU_TPL_LOADED', true);
834
 
835
+ $templateFile = apply_filters(
836
+ 'wpacu_template_file', // tag
837
+ dirname(__DIR__) . '/templates/' . $name . '.php', // value
838
+ $name // extra argument
839
+ );
840
 
841
  if (! file_exists($templateFile)) {
842
  wp_die('Template '.$name.' not found.');
859
  */
860
  public function ajaxGetJsonListCallback()
861
  {
 
862
  $postId = isset($_POST['post_id']) ? (int)$_POST['post_id'] : '';
863
  $postUrl = isset($_POST['post_url']) ? $_POST['post_url'] : '';
864
 
865
+ $wpacuList = $contents = '';
866
+
867
+ if (self::$domGetType === 'direct') {
868
+ $contents = isset($_POST['contents']) ? $_POST['contents'] : '';
869
+ $wpacuList = isset($_POST['wpacu_list']) ? $_POST['wpacu_list'] : '';
870
+ } elseif (self::$domGetType === 'wp_remote_post') {
871
+ $remotePost = wp_remote_post($postUrl, array(
872
+ 'body' => array(
873
+ WPACU_PLUGIN_NAME.'_load' => 1
874
+ )
875
+ ));
876
+
877
+ $contents = isset($remotePost['body']) ? $remotePost['body'] : '';
878
+
879
+ if ($contents) {
880
+ $wpacuList = Misc::extractBetween(
881
+ $contents,
882
+ self::START_DEL,
883
+ self::END_DEL
884
+ );
885
+ }
886
+ }
887
+
888
+ $json = base64_decode($wpacuList);
889
 
890
  $data = array();
891
 
892
  $data['all'] = (array)json_decode($json);
893
+
894
+ if ($contents != '') {
895
+ $data['contents'] = base64_decode($contents);
896
+ }
897
 
898
  $data = $this->alterAssetObj($data);
899
 
928
 
929
  $data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
930
 
931
+ $data['total_styles'] = (! empty($data['all']['styles'])) ? count($data['all']['styles']) : false;
932
+ $data['total_scripts'] = (! empty($data['all']['scripts'])) ? count($data['all']['scripts']) : false;
933
+
934
  $this->parseTemplate('meta-box-loaded', $data, true);
935
 
936
  exit;
942
  */
943
  public function alterAssetObj($data)
944
  {
945
+ $siteUrl = get_site_url();
946
 
947
  if (! empty($data['all']['styles'])) {
948
  $data['core_styles_loaded'] = false;
989
  if (! empty($data['all']['scripts'])) {
990
  $data['core_scripts_loaded'] = false;
991
 
992
+ $headPart = $bodyPart = '';
993
+
994
  if (isset($data['contents'])) {
995
+ // Extract 'HEAD' part
996
  $headPart = Misc::extractBetween($data['contents'], '<head', '</head>');
997
+
998
+ // Extract 'BODY' part
999
+ $contentsAltered = str_replace($headPart, '', $data['contents']);
1000
+ $bodyDel = '<body'; // Get everything after $bodyDel
1001
+ $bodyPart = substr($data['contents'], stripos($contentsAltered, $bodyDel) + strlen($bodyDel));
1002
  }
1003
 
1004
  foreach ($data['all']['scripts'] as $key => $obj) {
1076
  */
1077
  public function getAssetsUnloaded($postId = 0)
1078
  {
1079
+ // Post Type (Overwrites 'front' - home page - if we are in a singular post)
1080
+ if ($postId == 0) {
1081
+ $postId = $this->getCurrentPostId();
1082
+ }
1083
 
1084
  if (! $this->assetsRemoved) {
1085
  // For Home Page (latest blog posts)
1086
+ if ($postId < 1 && Misc::isHomePage()) {
1087
  $this->assetsRemoved = get_option(WPACU_PLUGIN_NAME . '_front_page_no_load');
1088
  return $this->assetsRemoved;
1089
  } elseif ($postId > 0) {
1097
 
1098
  return $this->assetsRemoved;
1099
  }
1100
+
1101
+ /**
1102
+ * @return bool
1103
+ */
1104
+ public function isSinglePage()
1105
+ {
1106
+ if (is_singular() || $this->isWooCommerceShopPage) {
1107
+ return true;
1108
+ }
1109
+
1110
+ return false;
1111
+ }
1112
+
1113
+ /**
1114
+ * @return int|mixed|string
1115
+ */
1116
+ public function getCurrentPostId()
1117
+ {
1118
+ if ($this->currentPostId > 0) {
1119
+ return $this->currentPostId;
1120
+ }
1121
+
1122
+ // Are we on the `Shop` page from WooCommerce?
1123
+ // Only check option if function `is_shop` exists
1124
+ $wooCommerceShopPageId = function_exists('is_shop') ? get_option('woocommerce_shop_page_id') : 0;
1125
+
1126
+ if (function_exists('is_shop') && is_shop()) {
1127
+ $this->currentPostId = $wooCommerceShopPageId;
1128
+
1129
+ if ($this->currentPostId > 0) {
1130
+ $this->isWooCommerceShopPage = true;
1131
+ }
1132
+ } else {
1133
+ if ($wooCommerceShopPageId > 0 && Misc::isHomePage()) {
1134
+ if (strpos(get_site_url(), '://') !== false) {
1135
+ list($siteUrlAfterProtocol) = explode('://', get_site_url());
1136
+ $currentPageUrlAfterProtocol = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1137
+
1138
+ if ($siteUrlAfterProtocol != $currentPageUrlAfterProtocol && (strpos($siteUrlAfterProtocol,
1139
+ '/shop') !== false)
1140
+ ) {
1141
+ $this->vars['woo_url_not_match'] = true;
1142
+ }
1143
+ }
1144
+ }
1145
+ }
1146
+
1147
+ if (is_singular() && (! $this->currentPostId)) {
1148
+ global $post;
1149
+ $this->currentPostId = isset($post->ID) ? $post->ID : 0;
1150
+ }
1151
+
1152
+ // Undetectable? The page is not a singular one nor the home page
1153
+ // It's likely an archive, category page (WooCommerce), 404 page etc.
1154
+ if (! $this->currentPostId && ! Misc::isHomePage()) {
1155
+ $this->isUpdateable = false;
1156
+ }
1157
+
1158
+ return $this->currentPostId;
1159
+ }
1160
+
1161
+ /**
1162
+ * @return array|null|\WP_Post
1163
+ */
1164
+ public function getCurrentPost()
1165
+ {
1166
+ // Already set? Return it
1167
+ if (! empty($this->currentPost)) {
1168
+ return $this->currentPost;
1169
+ }
1170
+
1171
+ // Not set? Create and return it
1172
+ if (! $this->currentPost && $this->getCurrentPostId() > 0) {
1173
+ $this->currentPost = get_post($this->getCurrentPostId());
1174
+ return $this->currentPost;
1175
+ }
1176
+
1177
+ // Empty
1178
+ return $this->currentPost;
1179
+ }
1180
+
1181
+ /**
1182
+ * @return bool
1183
+ */
1184
+ public static function isSettingsPage()
1185
+ {
1186
+ return (array_key_exists('page', $_GET) && $_GET['page'] === WPACU_PLUGIN_NAME.'_settings');
1187
+ }
1188
  }
classes/Menu.php CHANGED
@@ -25,11 +25,11 @@ class Menu
25
 
26
  add_menu_page(
27
  __('WP Asset CleanUp', WPACU_PLUGIN_NAME),
28
- __('WP Asset CleanUp', WPACU_PLUGIN_NAME),
29
  $capability,
30
  $menuSlug,
31
- array('\WpAssetCleanUp\Settings', 'settingsPage'),
32
- plugin_dir_url(WPACU_PLUGIN_FILE).'/assets/img/icon-clean-up.png'
33
  );
34
 
35
  add_submenu_page(
25
 
26
  add_menu_page(
27
  __('WP Asset CleanUp', WPACU_PLUGIN_NAME),
28
+ __('WP Asset Clean Up', WPACU_PLUGIN_NAME),
29
  $capability,
30
  $menuSlug,
31
+ array(new Settings, 'settingsPage'),
32
+ 'dashicons-filter'
33
  );
34
 
35
  add_submenu_page(
classes/Misc.php CHANGED
@@ -70,26 +70,40 @@ class Misc
70
  */
71
  public static function getPostUrl($postId)
72
  {
 
73
  if (self::isHomePage()) {
74
- return get_option('siteurl');
 
 
 
 
 
 
75
  }
76
 
77
  if ($postId > 0) {
78
  $postUrl = get_permalink($postId);
79
  } else {
80
- $postUrl = get_option('siteurl');
81
 
82
  if (substr($postUrl, -1) != '/') {
83
  $postUrl .= '/';
84
  }
85
  }
86
 
 
 
 
 
 
 
 
 
 
87
  // If we are in the Dashboard on a HTTPS connection,
88
  // then we will make the AJAX call over HTTPS as well for the front-end
89
  // to avoid blocking
90
- $https = Misc::isHttpsSecure();
91
-
92
- if ($https && strpos($postUrl, 'http://') === 0) {
93
  $postUrl = str_ireplace('http://', 'https://', $postUrl);
94
  }
95
 
@@ -101,13 +115,15 @@ class Misc
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
  }
70
  */
71
  public static function getPostUrl($postId)
72
  {
73
+ // Was the home page detected?
74
  if (self::isHomePage()) {
75
+ if (get_site_url() != get_home_url()) {
76
+ $postUrl = get_home_url();
77
+ } else {
78
+ $postUrl = get_site_url();
79
+ }
80
+
81
+ return self::_filterPostUrl($postUrl);
82
  }
83
 
84
  if ($postId > 0) {
85
  $postUrl = get_permalink($postId);
86
  } else {
87
+ $postUrl = get_site_url();
88
 
89
  if (substr($postUrl, -1) != '/') {
90
  $postUrl .= '/';
91
  }
92
  }
93
 
94
+ return self::_filterPostUrl($postUrl);
95
+ }
96
+
97
+ /**
98
+ * @param $postUrl
99
+ * @return mixed
100
+ */
101
+ private static function _filterPostUrl($postUrl)
102
+ {
103
  // If we are in the Dashboard on a HTTPS connection,
104
  // then we will make the AJAX call over HTTPS as well for the front-end
105
  // to avoid blocking
106
+ if (Misc::isHttpsSecure() && strpos($postUrl, 'http://') === 0) {
 
 
107
  $postUrl = str_ireplace('http://', 'https://', $postUrl);
108
  }
109
 
115
  */
116
  public static function isHomePage()
117
  {
118
+ // "Your latest posts" -> sometimes it works as is_front_page(), sometimes as is_home())
119
+ // "A static page (select below)" -> In this case is_front_page() should work
120
 
121
+ // Sometimes neither of these two options are selected
122
+ // (it happens with some themes that have an incorporated page builder)
123
+ // and is_home() tends to work fine
124
+
125
+ // Both will be used to be sure the home page is detected
126
+ $homePage = (is_front_page() || is_home());
127
 
128
  return apply_filters('wpacu_home_page', $homePage);
129
  }
classes/OwnAssets.php CHANGED
@@ -21,7 +21,10 @@ class OwnAssets
21
  public function __construct()
22
  {
23
  add_action('admin_enqueue_scripts', array($this, 'stylesAndScriptsForAdmin'));
24
- add_action('wp_enqueue_scripts', array($this, 'stylesAndScriptsForPublic'));
 
 
 
25
  }
26
 
27
  /**
@@ -31,6 +34,10 @@ class OwnAssets
31
  {
32
  global $post;
33
 
 
 
 
 
34
  $page = (isset($_GET['page'])) ? $_GET['page'] : '';
35
  $getPostId = (isset($_GET['post'])) ? (int)$_GET['post'] : '';
36
 
@@ -44,7 +51,7 @@ class OwnAssets
44
  $this->loadPluginAssets = true;
45
  }
46
 
47
- if (in_array($page, array(WPACU_PLUGIN_NAME.'_home_page', WPACU_PLUGIN_NAME.'_globals'))) {
48
  $this->loadPluginAssets = true;
49
  }
50
 
@@ -62,6 +69,10 @@ class OwnAssets
62
  */
63
  public function stylesAndScriptsForPublic()
64
  {
 
 
 
 
65
  $this->enqueuePublicStyles();
66
  $this->enqueuePublicScripts();
67
  }
@@ -71,7 +82,8 @@ class OwnAssets
71
  */
72
  private function enqueueAdminStyles()
73
  {
74
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-style', plugins_url('/assets/style.min.css', WPACU_PLUGIN_FILE));
 
75
  wp_enqueue_style(WPACU_PLUGIN_NAME . '-icheck-square-red', plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE));
76
  }
77
 
@@ -114,21 +126,29 @@ class OwnAssets
114
  }
115
  }
116
 
117
- wp_register_script(WPACU_PLUGIN_NAME . '-script', plugins_url('/assets/script.min.js', WPACU_PLUGIN_FILE), array('jquery'), '1.1');
 
 
 
 
 
 
 
118
 
119
  // It can also be the front page URL
120
  $postUrl = Misc::getPostUrl($postId);
121
 
122
- $this->fetchUrl = $postUrl;
123
-
124
  wp_localize_script(
125
  WPACU_PLUGIN_NAME . '-script',
126
  'wpacu_object',
127
  array(
128
- 'plugin_name' => WPACU_PLUGIN_NAME,
129
- 'ajax_url' => admin_url('admin-ajax.php'),
130
- 'post_id' => $postId,
131
- 'post_url' => $postUrl
 
 
 
132
  )
133
  );
134
 
@@ -141,10 +161,9 @@ class OwnAssets
141
  */
142
  private function enqueuePublicStyles()
143
  {
144
- if (Main::instance()->frontendShow && current_user_can('manage_options') && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
145
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-style', plugins_url('/assets/style.min.css', WPACU_PLUGIN_FILE));
146
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-icheck-square-red', plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE));
147
- }
148
  }
149
 
150
  /**
@@ -152,9 +171,23 @@ class OwnAssets
152
  */
153
  public function enqueuePublicScripts()
154
  {
155
- if (Main::instance()->frontendShow && current_user_can('manage_options') && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
156
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
157
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-script', plugins_url('/assets/script.min.js', WPACU_PLUGIN_FILE), array('jquery'), '1.1');
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
 
 
159
  }
160
  }
21
  public function __construct()
22
  {
23
  add_action('admin_enqueue_scripts', array($this, 'stylesAndScriptsForAdmin'));
24
+
25
+ if (Main::instance()->frontendShow && (! isset($_POST[WPACU_PLUGIN_NAME.'_load']))) {
26
+ add_action('wp_enqueue_scripts', array($this, 'stylesAndScriptsForPublic'));
27
+ }
28
  }
29
 
30
  /**
34
  {
35
  global $post;
36
 
37
+ if (! current_user_can('manage_options')) {
38
+ return;
39
+ }
40
+
41
  $page = (isset($_GET['page'])) ? $_GET['page'] : '';
42
  $getPostId = (isset($_GET['post'])) ? (int)$_GET['post'] : '';
43
 
51
  $this->loadPluginAssets = true;
52
  }
53
 
54
+ if (in_array($page, array(WPACU_PLUGIN_NAME.'_settings', WPACU_PLUGIN_NAME.'_home_page', WPACU_PLUGIN_NAME.'_globals'))) {
55
  $this->loadPluginAssets = true;
56
  }
57
 
69
  */
70
  public function stylesAndScriptsForPublic()
71
  {
72
+ if (! current_user_can('manage_options')) {
73
+ return;
74
+ }
75
+
76
  $this->enqueuePublicStyles();
77
  $this->enqueuePublicScripts();
78
  }
82
  */
83
  private function enqueueAdminStyles()
84
  {
85
+ $styleRelPath = '/assets/style.min.css';
86
+ wp_enqueue_style(WPACU_PLUGIN_NAME . '-style', plugins_url($styleRelPath, WPACU_PLUGIN_FILE), array(), $this->_assetVer($styleRelPath));
87
  wp_enqueue_style(WPACU_PLUGIN_NAME . '-icheck-square-red', plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE));
88
  }
89
 
126
  }
127
  }
128
 
129
+ $scriptRelPath = '/assets/script.min.js';
130
+
131
+ wp_register_script(
132
+ WPACU_PLUGIN_NAME . '-script',
133
+ plugins_url($scriptRelPath, WPACU_PLUGIN_FILE),
134
+ array('jquery'),
135
+ $this->_assetVer($scriptRelPath)
136
+ );
137
 
138
  // It can also be the front page URL
139
  $postUrl = Misc::getPostUrl($postId);
140
 
 
 
141
  wp_localize_script(
142
  WPACU_PLUGIN_NAME . '-script',
143
  'wpacu_object',
144
  array(
145
+ 'plugin_name' => WPACU_PLUGIN_NAME,
146
+ 'dom_get_type' => Main::$domGetType,
147
+ 'start_del' => Main::START_DEL,
148
+ 'end_del' => Main::END_DEL,
149
+ 'ajax_url' => admin_url('admin-ajax.php'),
150
+ 'post_id' => $postId,
151
+ 'post_url' => $postUrl
152
  )
153
  );
154
 
161
  */
162
  private function enqueuePublicStyles()
163
  {
164
+ $styleRelPath = '/assets/style.min.css';
165
+ wp_enqueue_style(WPACU_PLUGIN_NAME . '-style', plugins_url($styleRelPath, WPACU_PLUGIN_FILE), array(), $this->_assetVer($styleRelPath));
166
+ wp_enqueue_style(WPACU_PLUGIN_NAME . '-icheck-square-red', plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE));
 
167
  }
168
 
169
  /**
171
  */
172
  public function enqueuePublicScripts()
173
  {
174
+ $scriptRelPath = '/assets/script.min.js';
175
+ wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
176
+ wp_enqueue_script(WPACU_PLUGIN_NAME . '-script', plugins_url($scriptRelPath, WPACU_PLUGIN_FILE), array('jquery'), $this->_assetVer($scriptRelPath));
177
+ }
178
+
179
+ /**
180
+ * @param $relativePath
181
+ * @return bool|false|int|string
182
+ */
183
+ private function _assetVer($relativePath)
184
+ {
185
+ $assetVer = @filemtime(dirname(WPACU_PLUGIN_FILE) . $relativePath);
186
+
187
+ if (! $assetVer) {
188
+ $assetVer = date('dmYHi');
189
  }
190
+
191
+ return $assetVer;
192
  }
193
  }
classes/Plugin.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace WpAssetCleanUp;
3
+
4
+ /**
5
+ * Class Plugin
6
+ */
7
+ class Plugin
8
+ {
9
+ /**
10
+ * Plugin constructor.
11
+ */
12
+ public function __construct()
13
+ {
14
+ register_activation_hook(WPACU_PLUGIN_FILE, array($this, 'whenActivated'));
15
+ }
16
+
17
+ /**
18
+ *
19
+ */
20
+ public function whenActivated()
21
+ {
22
+ if (! get_option(WPACU_PLUGIN_NAME.'_settings')) {
23
+ $defaultSettings = array(
24
+ 'dashboard_show' => 1,
25
+ 'dom_get_type' => 'direct'
26
+ );
27
+
28
+ $settings = new Settings();
29
+ $settings->update($defaultSettings);
30
+ }
31
+ }
32
+ }
classes/Settings.php CHANGED
@@ -7,34 +7,164 @@ namespace WpAssetCleanUp;
7
  */
8
  class Settings
9
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  /**
11
- * Settings constructor.
12
  */
13
- public function __construct()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  {
15
- add_action('admin_init', array($this, 'registerSettings'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
18
  /**
19
  *
20
  */
21
- public function registerSettings()
22
  {
23
- // Register settings
24
- register_setting('wpacu-plugin-settings-group', WPACU_PLUGIN_NAME.'_frontend_show');
25
-
26
- register_setting('wpacu-global-settings-group', WPACU_PLUGIN_NAME.'_global_styles_unload');
27
- register_setting('wpacu-global-settings-group', WPACU_PLUGIN_NAME.'_global_scripts_unload');
28
  }
29
 
30
  /**
31
  *
32
  */
33
- public static function settingsPage()
34
  {
35
- $data = array();
36
- $data['frontend_show'] = get_option(WPACU_PLUGIN_NAME.'_frontend_show');
 
 
 
 
 
 
37
 
38
  Main::instance()->parseTemplate('settings-plugin', $data, true);
39
  }
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  */
8
  class Settings
9
  {
10
+ /**
11
+ * @var array
12
+ */
13
+ public $settingsKeys = array(
14
+ 'frontend_show',
15
+ 'dashboard_show',
16
+ 'dom_get_type'
17
+ );
18
+
19
+ /**
20
+ * @var array
21
+ */
22
+ public $currentSettings = array();
23
+
24
  /**
25
+ * @var array
26
  */
27
+ public $status = array(
28
+ 'updated' => false
29
+ );
30
+
31
+ /**
32
+ *
33
+ */
34
+ public function init()
35
+ {
36
+ add_action('admin_init', array($this, 'saveSettings'), 1);
37
+
38
+ if (array_key_exists('page', $_GET) && $_GET['page'] === 'wpassetcleanup_settings') {
39
+ add_action('admin_notices', array($this, 'notices'));
40
+ }
41
+ }
42
+
43
+ /**
44
+ *
45
+ */
46
+ public function notices()
47
  {
48
+ $settings = $this->getAll();
49
+
50
+ // When all ways to manage the assets are not enabled
51
+ if ($settings['dashboard_show'] != 1 && $settings['frontend_show'] != 1) {
52
+ ?>
53
+ <div class="notice notice-warning">
54
+ <p><span style="color: #ffb900;" class="dashicons dashicons-info"></span>&nbsp;<?php _e('It looks like you have both "Manage in the Dashboard?" and "Manage in the Front-end?" inactive. The plugin works fine with any settings that were applied. However, if you want to manage the assets in any page, you need to have at least one of them active.', WPACU_PLUGIN_NAME); ?></p>
55
+ </div>
56
+ <?php
57
+ }
58
+
59
+ // After "Save changes" is clicked
60
+ if ($this->status['updated']) {
61
+ ?>
62
+ <div class="notice notice-success">
63
+ <?php _e('The settings were successfully updated.', WPACU_PLUGIN_NAME); ?>
64
+ </div>
65
+ <?php
66
+ }
67
  }
68
 
69
  /**
70
  *
71
  */
72
+ public function saveSettings()
73
  {
74
+ if (! empty($_POST) && array_key_exists('wpacu_settings_page', $_POST)) {
75
+ $data = isset($_POST[WPACU_PLUGIN_NAME.'_settings']) ? $_POST[WPACU_PLUGIN_NAME.'_settings'] : array();
76
+
77
+ $this->update($data);
78
+ }
79
  }
80
 
81
  /**
82
  *
83
  */
84
+ public function settingsPage()
85
  {
86
+ $data = $this->getAll();
87
+
88
+ foreach ($this->settingsKeys as $settingKey) {
89
+ // Special check for plugin versions < 1.2.4.4
90
+ if ($settingKey === 'frontend_show') {
91
+ $data['frontend_show'] = $this->showOnFrontEnd();
92
+ }
93
+ }
94
 
95
  Main::instance()->parseTemplate('settings-plugin', $data, true);
96
  }
97
+
98
+ /**
99
+ * @return bool
100
+ */
101
+ public function showOnFrontEnd()
102
+ {
103
+ $settings = $this->getAll();
104
+
105
+ if ($settings['frontend_show'] == 1) {
106
+ return true;
107
+ }
108
+
109
+ // Prior to 1.2.4.4
110
+ if (get_option(WPACU_PLUGIN_NAME.'_frontend_show') == 1) {
111
+ // Put it in the main settings option
112
+ $settings = $this->getAll();
113
+ $settings['frontend_show'] = 1;
114
+ $this->update($settings);
115
+
116
+ delete_option(WPACU_PLUGIN_NAME.'_frontend_show');
117
+ return true;
118
+ }
119
+
120
+ return false;
121
+ }
122
+
123
+ /**
124
+ * @return array
125
+ */
126
+ public function getAll()
127
+ {
128
+ if (! empty($this->currentSettings)) {
129
+ return $this->currentSettings;
130
+ }
131
+
132
+ $settingsOption = get_option(WPACU_PLUGIN_NAME.'_settings');
133
+
134
+ if ($settingsOption != '' && is_string($settingsOption)) {
135
+ $settings = (array)json_decode($settingsOption);
136
+
137
+ if (json_last_error() == JSON_ERROR_NONE) {
138
+ // Make sure all the keys are there even if no value is attached to them
139
+ // To avoid writing extra checks in other parts of the code and prevent PHP notice errors
140
+ foreach ($this->settingsKeys as $settingsKey) {
141
+ if (! array_key_exists($settingsKey, $settings)) {
142
+ $settings[$settingsKey] = '';
143
+ }
144
+ }
145
+
146
+ $this->currentSettings = $settings;
147
+
148
+ return $this->currentSettings;
149
+ }
150
+ }
151
+
152
+ // Keep the keys with empty values
153
+ $list = array();
154
+
155
+ foreach ($this->settingsKeys as $settingsKey) {
156
+ $list[$settingsKey] = '';
157
+ }
158
+
159
+ return $list;
160
+ }
161
+
162
+ /**
163
+ * @param $settings
164
+ */
165
+ public function update($settings)
166
+ {
167
+ update_option(WPACU_PLUGIN_NAME . '_settings', json_encode($settings), 'no');
168
+ $this->status['updated'] = true;
169
+ }
170
+ }
classes/Update.php CHANGED
@@ -22,19 +22,20 @@ class Update
22
  public function init()
23
  {
24
  if (Main::instance()->frontendShow) {
25
- add_action('wp', array($this, 'frontendUpdate'), 1);
26
  }
27
 
28
  // After post/page is saved - update your styles/scripts lists
 
29
  add_action('save_post', array($this, 'savePost'));
30
  }
31
 
32
  /**
33
- *
34
  */
35
  public function frontendUpdate()
36
  {
37
- global $post;
38
 
39
  // Check nonce
40
  $nonceName = self::NONCE_FIELD_NAME;
@@ -64,7 +65,7 @@ class Update
64
  );
65
  }
66
 
67
- if (Misc::isHomePage()) {
68
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
69
  ? $_POST[WPACU_PLUGIN_NAME] : array();
70
 
@@ -75,7 +76,10 @@ class Update
75
  }
76
 
77
  /**
78
- * Save post metadata when a post is saved.
 
 
 
79
  *
80
  * @param $postId
81
  * @param array $post
@@ -167,7 +171,7 @@ class Update
167
  /**
168
  * @param string $type
169
  * @param string $postId
170
- * @return bool|void
171
  */
172
  public function saveLoadExceptions($type = 'post', $postId = '')
173
  {
22
  public function init()
23
  {
24
  if (Main::instance()->frontendShow) {
25
+ add_action('wp', array($this, 'frontendUpdate'), 9);
26
  }
27
 
28
  // After post/page is saved - update your styles/scripts lists
29
+ // This triggers ONLY in the Dashboard after "Update" button is clicked (on Edit mode)
30
  add_action('save_post', array($this, 'savePost'));
31
  }
32
 
33
  /**
34
+ * Priority: 9 (AFTER current post ID is correctly retrieved and BEFORE the data from the database is fetched)
35
  */
36
  public function frontendUpdate()
37
  {
38
+ $post = get_post(Main::instance()->currentPostId);
39
 
40
  // Check nonce
41
  $nonceName = self::NONCE_FIELD_NAME;
65
  );
66
  }
67
 
68
+ if (Misc::isHomePage() && ! (isset($post->ID) && $post->ID > 0)) {
69
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
70
  ? $_POST[WPACU_PLUGIN_NAME] : array();
71
 
76
  }
77
 
78
  /**
79
+ * Save post metadata when a post is saved
80
+ *
81
+ * Admin: triggered via hook
82
+ * Front-end view: triggered by direct call
83
  *
84
  * @param $postId
85
  * @param array $post
171
  /**
172
  * @param string $type
173
  * @param string $postId
174
+ * @return bool
175
  */
176
  public function saveLoadExceptions($type = 'post', $postId = '')
177
  {
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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
 
@@ -46,9 +46,25 @@ NOTE: People that have tested the plugin are so far happy with it and I want to
46
 
47
  5.3+
48
 
49
- = I've noticed scripts and styles that are loaded on the page, but they do not show in the "WP Asset CleanUp" list when editing the page. Why is that? =
50
 
51
- If that's the case, then those assets weren't loaded properly into WordPress by the theme/plugin author as they were likely hardcoded and not enqueued the WordPress way. Here's a tutorial that will help you understand better the enqueuing process: http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  = jQuery and jQuery Migrate are often loading on pages/post. Are they always needed? =
54
 
@@ -68,19 +84,13 @@ The plugin makes AJAX calls to retrieve the data from the front-end page with 10
68
 
69
  - There could be a conflict between plugins or your theme and something is interfering with the script that is retrieving the assets
70
 
71
- - You are loading the WordPress Dashboard through HTTPS, but you are forcing the front-end to load via HTTP.
72
 
73
  In this case, it's advisable to enable "Manage in the Front-end?" in "Settings" of "WP Asset CleanUp", thus making the list to show at the bottom of the posts, pages and front-page only for the logged in users with admin privileges.
74
 
75
  Although I've written the code to ensure maximum compatibility, there are factors which are not up to the quality of the plugin that could interfere with it.
76
  In case the assets are not loading for you, please write me on the forum and I will be happy to assist you!
77
 
78
- = In some pages, I do not see styles and scripts in the "WP Asset CleanUp" List =
79
-
80
- If that's the case, you might have other functions or plugins (e.g. Plugin Organizer) that are loading prior to WP Asset CleanUp.
81
-
82
- Note that Plugin Organizer has a file that is in "mu-plugins" which will load prior to any plugin you have in "plugins", thus, if you have disabled specific plugins through "Plugin Organizer" in some pages, their assets will obviously not show in the assets list as they are not loaded at all in the first place.
83
-
84
  = I do not know or I'm not sure which assets to unload on my pages. What should I do? =
85
 
86
  If that's the case, then it's advisable to consult with a developer (ideally the person who helped you with your website) to give you assistance in unloading the unused assets.
@@ -92,6 +102,12 @@ 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.3 =
96
  * Bug Fix: PHP versions < 5.4 triggered errors
97
 
@@ -134,7 +150,7 @@ If that's the case, then it's advisable to consult with a developer (ideally the
134
  * Improved code to not show any PHP errors in case WP_DEBUG constant is set to 'true'
135
 
136
  = 1.1.4.2 =
137
- * Prevent JavaScript errors from showing in the background and interfere with the functionality of other plugins in case script.js is loaded in pages where the plugin is not needed
138
 
139
  = 1.1.4.1 =
140
  * Prevent any calls to be made for non-published posts/pages as the list of assets is relevant only after the post is published and all assets (from plugins and the themes) are properly loaded on that post/page
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.5
7
+ Stable tag: 1.2.4.4
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
46
 
47
  5.3+
48
 
49
+ = Is this plugin a caching one?
50
 
51
+ No, WP Asset CleanUp does not do any caching. It just unloads .css and .js when needed. This combined with an existing caching plugin will make your website pages load faster and get a better score in speed checking tools such as GTMetrix.
52
+
53
+ = Has this plugin been tested with other caching / speed booster plugins?
54
+
55
+ Yes, this plugin was tested with W3 Total Cache, WP Rocket and Autoptimize and should work with any caching plugin as any page should be cached only after the page (HTML Source) was rendered and all the enqueueing / dequeueing was already completed (from either the plugins or the theme).
56
+
57
+ = I've noticed scripts and styles that are loaded on the page, but they do not show in the "WP Asset CleanUp" list when editing the page or no assets are showing at all. Why is that? =
58
+
59
+ There are a few known reasons why you might see different or no assets loading for management:
60
+
61
+ - Those assets weren't loaded properly into WordPress by the theme/plugin author as they were likely hardcoded and not enqueued the WordPress way. Here's a tutorial that will help you understand better the enqueuing process: http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/
62
+
63
+ - You're using a cache plugin that is caching pages even when you're logged in which is something I don't recommend as you might have conflicts with other plugins as well (e.g. in W3 Total Cache, you can enable/disable this) or that plugin is caching pages even when a POST request is made to them (which is not a good practice as there are many situations in which a page should not be cached). That could happen if you're using "WP Remote POST" method (from version 1.2.4.4) of retrieving the assets in the Dashboard.
64
+
65
+ - You might have other functions or plugins (e.g. Plugin Organizer) that are loading prior to WP Asset CleanUp. Note that Plugin Organizer has a file that is in “mu-plugins” which will load prior to any plugin you have in “plugins”, thus, if you have disabled specific plugins through “Plugin Organizer” in some pages, their assets will obviously not show in the assets list as they are not loaded at all in the first place.
66
+
67
+ If none of these apply to you and you just don't see assets that should definitely show there, please open a support ticket.
68
 
69
  = jQuery and jQuery Migrate are often loading on pages/post. Are they always needed? =
70
 
84
 
85
  - There could be a conflict between plugins or your theme and something is interfering with the script that is retrieving the assets
86
 
87
+ - You are loading the WordPress Dashboard through HTTPS, but you are forcing the front-end to load via HTTP. Although WP Asset CleanUp auto-corrects the retrieval URL (e.g. if you're logged in the Dashboard securely via HTTPS, it will attempt to fetch the assets through HTTPS too), there could be cases where another plugin or .htaccess forces a HTTP connection only for the public view. Due to Same Origin Policy (read more here: https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript), you can't make plain HTTP AJAX calls from HTTPS connections. If that's the case, try to enable "WP Remote POST" as a retrieval method in the plugin's settings if you want to manage the assets in the Dashboard.
88
 
89
  In this case, it's advisable to enable "Manage in the Front-end?" in "Settings" of "WP Asset CleanUp", thus making the list to show at the bottom of the posts, pages and front-page only for the logged in users with admin privileges.
90
 
91
  Although I've written the code to ensure maximum compatibility, there are factors which are not up to the quality of the plugin that could interfere with it.
92
  In case the assets are not loading for you, please write me on the forum and I will be happy to assist you!
93
 
 
 
 
 
 
 
94
  = I do not know or I'm not sure which assets to unload on my pages. What should I do? =
95
 
96
  If that's the case, then it's advisable to consult with a developer (ideally the person who helped you with your website) to give you assistance in unloading the unused assets.
102
  4. Scripts (.JS) are selected for site-wide unload
103
 
104
  == Changelog ==
105
+ = 1.2.4.4 =
106
+ * Updated AJAX calls to work fine within the Dashboard even if mod_security Apache module is enabled as there were some problems on specific servers
107
+ * Added "Unload on this page" text next to the first checkbox to explain its purpose better
108
+ * Added "WP Remote Post" method to retrieve assets (in case the default "Direct" method doesn't work)
109
+ * Enable/disable asset list loading within the Dashboard (in case one prefers to only have it within the front-end)
110
+
111
  = 1.2.4.3 =
112
  * Bug Fix: PHP versions < 5.4 triggered errors
113
 
150
  * Improved code to not show any PHP errors in case WP_DEBUG constant is set to 'true'
151
 
152
  = 1.1.4.2 =
153
+ * Prevent JavaScript errors from showing in the background and interfere with the functionality of other plugins in case script.min.js is loaded in pages where the plugin is not needed
154
 
155
  = 1.1.4.1 =
156
  * Prevent any calls to be made for non-published posts/pages as the list of assets is relevant only after the post is published and all assets (from plugins and the themes) are properly loaded on that post/page
templates/meta-box-loaded.php CHANGED
@@ -17,7 +17,17 @@ if (! isset($data)) {
17
  * --------------------
18
  */
19
  ?>
 
20
  <h3><?php _e('Styles (.css files)', WPACU_PLUGIN_NAME); ?></h3>
 
 
 
 
 
 
 
 
 
21
  <?php
22
  if (! empty($data['all']['styles'])) {
23
  ?>
@@ -29,7 +39,7 @@ if (! empty($data['all']['styles'])) {
29
  <div class="wpacu_note wpacu_warning"><em><?php
30
  echo sprintf(
31
  __('Assets that are marked with %s are part of WordPress core files. Be careful if you decide to unload them!', WPACU_PLUGIN_NAME),
32
- '<img src="'.WPACU_PLUGIN_URL.'/assets/img/icon-warning.png" width="20" height="20" alt="" align="top" />'
33
  );
34
  ?>
35
  </em></div><br />
@@ -65,25 +75,29 @@ if (! empty($data['all']['styles'])) {
65
  $class .= ' wpacu_not_load';
66
  }
67
  }
 
 
68
  ?>
69
  <tr class="wpacu_asset_row <?php echo $class; ?>">
70
- <td scope="row" class="wpacu_check check-column" valign="top"><input id="style_<?php echo $obj->handle; ?>" <?php if ($globalUnloaded) { echo 'disabled="disabled"'; } echo $checked; ?> name="<?php echo WPACU_PLUGIN_NAME; ?>[styles][]" class="icheckbox_square-red" type="checkbox" value="<?php echo $obj->handle; ?>" /></td>
71
  <td valign="top" style="width: 100%;">
72
- <p style="margin-top: 0px;">
73
  <label for="style_<?php echo $obj->handle; ?>"><?php _e('Handle:', WPACU_PLUGIN_NAME); ?> <strong><span style="color: green;"><?php echo $obj->handle; ?></span></strong></label>
74
  <?php
75
  if (isset($obj->wp) && $obj->wp) {
76
  ?>
77
- <img src="<?php echo WPACU_PLUGIN_URL; ?>/assets/img/icon-warning.png"
78
- width="20"
79
- height="20"
80
- alt=""
81
- align="top" />
82
  <?php
83
  }
84
  ?>
85
  </p>
86
 
 
 
 
 
 
 
 
87
  <div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
88
  <?php
89
  // Unloaded Everywhere
@@ -205,7 +219,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 ' * works only IF any of two rules above are selected'; } ?>)</label>
209
  </li>
210
  </ul>
211
  <?php
@@ -252,6 +266,15 @@ if (! empty($data['all']['styles'])) {
252
  */
253
  ?>
254
  <h3><?php _e('Scripts (.js files)', WPACU_PLUGIN_NAME); ?></h3>
 
 
 
 
 
 
 
 
 
255
  <?php
256
  if (! empty($data['all']['scripts'])) {
257
  ?>
@@ -263,7 +286,7 @@ if (! empty($data['all']['scripts'])) {
263
  <div class="wpacu_note wpacu_warning"><em><?php
264
  echo sprintf(
265
  __('Assets that are marked with %s are part of WordPress core files. Be careful if you decide to unload them!', WPACU_PLUGIN_NAME),
266
- '<img src="'.WPACU_PLUGIN_URL.'/assets/img/icon-warning.png" width="20" height="20" alt="" align="top" />'
267
  );
268
  ?>
269
  </em></div><br />
@@ -299,20 +322,17 @@ if (! empty($data['all']['scripts'])) {
299
  $class .= ' wpacu_not_load';
300
  }
301
  }
 
 
302
  ?>
303
  <tr class="wpacu_asset_row <?php echo $class; ?>">
304
- <td scope="row" class="wpacu_check check-column" valign="top"><input id="script_<?php echo $obj->handle; ?>" <?php if ($globalUnloaded) { echo 'disabled="disabled"'; } echo $checked; ?> name="<?php echo WPACU_PLUGIN_NAME; ?>[scripts][]" class="icheckbox_square-red" type="checkbox" value="<?php echo $obj->handle; ?>" /></td>
305
  <td valign="top" style="width: 100%;">
306
- <p style="margin-top: 0px;">
307
  <label for="script_<?php echo $obj->handle; ?>"> <?php _e('Handle:', WPACU_PLUGIN_NAME); ?> <strong><span style="color: green;"><?php echo $obj->handle; ?></span></strong></label>
308
  <?php
309
  if (isset($obj->wp) && $obj->wp) {
310
  ?>
311
- <img src="<?php echo WPACU_PLUGIN_URL; ?>/assets/img/icon-warning.png"
312
- width="20"
313
- height="20"
314
- alt=""
315
- align="top" />
316
  <?php
317
  }
318
  ?>
@@ -328,8 +348,15 @@ if (! empty($data['all']['scripts'])) {
328
  ?>
329
 
330
  <div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
331
- <ul class="wpacu_asset_options">
 
 
 
 
 
332
 
 
 
333
  <?php
334
  // [START] UNLOAD EVERYWHERE
335
  if ($globalUnloaded) {
@@ -441,7 +468,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 ' * works only IF any of two rules above are selected'; } ?>)</label>
445
  </li>
446
  </ul>
447
  <?php
17
  * --------------------
18
  */
19
  ?>
20
+
21
  <h3><?php _e('Styles (.css files)', WPACU_PLUGIN_NAME); ?></h3>
22
+
23
+ <?php
24
+ if ($data['total_styles']) {
25
+ ?>
26
+ <h4>&#10141; Total enqueued files: <strong><?php echo $data['total_styles']; ?></strong></h4>
27
+ <?php
28
+ }
29
+ ?>
30
+
31
  <?php
32
  if (! empty($data['all']['styles'])) {
33
  ?>
39
  <div class="wpacu_note wpacu_warning"><em><?php
40
  echo sprintf(
41
  __('Assets that are marked with %s are part of WordPress core files. Be careful if you decide to unload them!', WPACU_PLUGIN_NAME),
42
+ '<span class="dashicons dashicons-warning"></span>'
43
  );
44
  ?>
45
  </em></div><br />
75
  $class .= ' wpacu_not_load';
76
  }
77
  }
78
+
79
+ $class .= ' style_'.$obj->handle;
80
  ?>
81
  <tr class="wpacu_asset_row <?php echo $class; ?>">
 
82
  <td valign="top" style="width: 100%;">
83
+ <p style="margin-top: 0;">
84
  <label for="style_<?php echo $obj->handle; ?>"><?php _e('Handle:', WPACU_PLUGIN_NAME); ?> <strong><span style="color: green;"><?php echo $obj->handle; ?></span></strong></label>
85
  <?php
86
  if (isset($obj->wp) && $obj->wp) {
87
  ?>
88
+ <span class="dashicons dashicons-warning"></span>
 
 
 
 
89
  <?php
90
  }
91
  ?>
92
  </p>
93
 
94
+ <div>
95
+ <ul class="wpacu_asset_options">
96
+ <li>
97
+ <label><input id="style_<?php echo $obj->handle; ?>" <?php if ($globalUnloaded) { echo 'disabled="disabled"'; } echo $checked; ?> name="<?php echo WPACU_PLUGIN_NAME; ?>[styles][]" class="icheckbox_square-red" type="checkbox" value="<?php echo $obj->handle; ?>" /> &nbsp;Unload on this page</label>
98
+ </li>
99
+ </div>
100
+
101
  <div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
102
  <?php
103
  // Unloaded Everywhere
219
  <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
220
  name="wpacu_styles_load_it[]"
221
  value="<?php echo $obj->handle; ?>"/>
222
+ Load it on this page (make exception<?php if (! $isGlobalRule) { echo ' * works only IF any of rules above is selected'; } ?>)</label>
223
  </li>
224
  </ul>
225
  <?php
266
  */
267
  ?>
268
  <h3><?php _e('Scripts (.js files)', WPACU_PLUGIN_NAME); ?></h3>
269
+
270
+ <?php
271
+ if ($data['total_scripts']) {
272
+ ?>
273
+ <h4>&#10141; Total enqueued files: <strong><?php echo $data['total_scripts']; ?></strong></h4>
274
+ <?php
275
+ }
276
+ ?>
277
+
278
  <?php
279
  if (! empty($data['all']['scripts'])) {
280
  ?>
286
  <div class="wpacu_note wpacu_warning"><em><?php
287
  echo sprintf(
288
  __('Assets that are marked with %s are part of WordPress core files. Be careful if you decide to unload them!', WPACU_PLUGIN_NAME),
289
+ '<span class="dashicons dashicons-warning"></span>'
290
  );
291
  ?>
292
  </em></div><br />
322
  $class .= ' wpacu_not_load';
323
  }
324
  }
325
+
326
+ $class .= ' script_'.$obj->handle;
327
  ?>
328
  <tr class="wpacu_asset_row <?php echo $class; ?>">
 
329
  <td valign="top" style="width: 100%;">
330
+ <p style="margin-top: 0;">
331
  <label for="script_<?php echo $obj->handle; ?>"> <?php _e('Handle:', WPACU_PLUGIN_NAME); ?> <strong><span style="color: green;"><?php echo $obj->handle; ?></span></strong></label>
332
  <?php
333
  if (isset($obj->wp) && $obj->wp) {
334
  ?>
335
+ <span class="dashicons dashicons-warning"></span>
 
 
 
 
336
  <?php
337
  }
338
  ?>
348
  ?>
349
 
350
  <div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
351
+ <ul class="wpacu_asset_options">
352
+ <li>
353
+ <label><input id="script_<?php echo $obj->handle; ?>" <?php if ($globalUnloaded) { echo 'disabled="disabled"'; } echo $checked; ?> name="<?php echo WPACU_PLUGIN_NAME; ?>[scripts][]" class="icheckbox_square-red" type="checkbox" value="<?php echo $obj->handle; ?>" /> &nbsp;Unload on this page</label>
354
+ </li>
355
+ </ul>
356
+ </div>
357
 
358
+ <div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
359
+ <ul class="wpacu_asset_options">
360
  <?php
361
  // [START] UNLOAD EVERYWHERE
362
  if ($globalUnloaded) {
468
  name="wpacu_scripts_load_it[]"
469
  <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
470
  value="<?php echo $obj->handle; ?>" />
471
+ Load it on this page (make exception<?php if (! $isGlobalRule) { echo ' * works only IF any of rules above is selected'; } ?>)</label>
472
  </li>
473
  </ul>
474
  <?php
templates/settings-frontend.php CHANGED
@@ -10,10 +10,34 @@ if (! isset($data)) {
10
  <form action="#wpacu_wrap_assets" method="post">
11
  <div id="wpacu_wrap_assets">
12
  <h1>WP Asset CleanUp</h1>
13
- <p><small>* this area is shown only for the admin users and if "Manage in the Front-end?" was selected in the plugin's settings</small></p>
14
- <p><small>* 'admin-bar', 'wpassetcleanup-icheck-square-red' and 'wpassetcleanup-style' are not included as they are irrelevant since they are used by the plugin for this area</small></p>
15
  <?php
16
- require_once 'meta-box-loaded.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ?>
18
  <div style="margin: 10px 0;">
19
  <input class="wpacu_update_btn"
@@ -23,7 +47,13 @@ if (! isset($data)) {
23
  </div>
24
 
25
  <p align="right"><small>Powered by WP Asset CleanUp</small></p>
 
26
  </div>
 
 
 
 
27
  <?php wp_nonce_field($data['nonce_action'], $data['nonce_name']); ?>
28
  <input type="hidden" name="wpacu_update_asset_frontend" value="1" />
 
29
  </form>
10
  <form action="#wpacu_wrap_assets" method="post">
11
  <div id="wpacu_wrap_assets">
12
  <h1>WP Asset CleanUp</h1>
 
 
13
  <?php
14
+ if ($data['is_updateable']) {
15
+ ?>
16
+ <p><small>* this area is shown only for the admin users and if "Manage in the Front-end?" was selected in the plugin's settings</small></p>
17
+ <p><small>* 'admin-bar', 'wpassetcleanup-icheck-square-red' and 'wpassetcleanup-style' are not included as they are irrelevant since they are used by the plugin for this area</small></p>
18
+ <?php
19
+ if ($data['is_woocommerce_shop_page']) {
20
+ ?>
21
+ <p><strong>This is the "Shop" page from WooCommerce plugin. Unloading assets will also take effect for the pagination/sorting pages (e.g. /2, /3, /?orderby=popularity etc.).</strong></p>
22
+ <?php
23
+ }
24
+
25
+ if (isset($data['vars']['woo_url_not_match'])) {
26
+ ?>
27
+ <div class="wpacu_note wpacu_warning">
28
+ <p>Although this page is detected as the home page, its URL is not the same as the one from "General Settings" -&gt; "Site Address (URL)" and the WooCommerce plugin is not active anymore. This could be the "Shop" page that is no longer active.</p>
29
+ </div>
30
+ <?php
31
+ }
32
+ require_once 'meta-box-loaded.php';
33
+ } else {
34
+ ?>
35
+ <p>This page format is not supported at this time (e.g. it is likely an archive having multiple posts, category or 404 page) and unloading assets for this type of page is not supported at the moment.</p>
36
+ <p>If there are assets unloaded everywhere, then the rule will apply and they will not be loaded on this page.</p>
37
+ <?php
38
+ }
39
+
40
+ if ($data['is_updateable']) {
41
  ?>
42
  <div style="margin: 10px 0;">
43
  <input class="wpacu_update_btn"
47
  </div>
48
 
49
  <p align="right"><small>Powered by WP Asset CleanUp</small></p>
50
+ <?php } ?>
51
  </div>
52
+
53
+ <?php
54
+ if ($data['is_updateable']) {
55
+ ?>
56
  <?php wp_nonce_field($data['nonce_action'], $data['nonce_name']); ?>
57
  <input type="hidden" name="wpacu_update_asset_frontend" value="1" />
58
+ <?php } ?>
59
  </form>
templates/settings-globals.php CHANGED
@@ -24,7 +24,7 @@ if ($data['for'] === 'post_types') {
24
  <input type="hidden" name="page" value="wpassetcleanup_globals" />
25
  <input type="hidden" name="wpacu_for" value="post_types" />
26
 
27
- <div style="margin: 0 0 10px 0;">Select the post type for which you want to see the unloaded scripts &amp; styles:</div>
28
  <select id="wpacu_post_type_select" name="wpacu_post_type">
29
  <?php foreach ($data['post_types_list'] as $postType) { ?>
30
  <option <?php if ($data['post_type'] === $postType) { echo 'selected="selected"'; } ?> value="<?php echo $postType; ?>"><?php echo $postType; ?></option>
@@ -45,7 +45,12 @@ if ($data['for'] === 'everywhere') {
45
  <div class="alert">
46
  <p>This is the list of the assets that are <strong>globally unloaded</strong> on all pages (including home page).</p>
47
  <p>If you want to remove this rule and have them loading, use the "Remove rule" checkbox.</p>
48
- <p style="margin: 0; background: white; padding: 10px; border: 1px solid #ccc; width: auto; display: inline-block;">This list fills once you select "<em>Unload everywhere</em>" when you edit posts/pages for the assets that you want to prevent from loading on every page.</p>
 
 
 
 
 
49
  </div>
50
 
51
  <div class="clear"></div>
@@ -79,7 +84,7 @@ if ($data['for'] === 'everywhere') {
79
  <?php
80
  } else {
81
  ?>
82
- <p>There are no unloaded styles for your selection.</p>
83
  <?php
84
  }
85
  ?>
@@ -124,8 +129,13 @@ if ($data['for'] === 'everywhere') {
124
 
125
  <div class="alert">
126
  <p>This is the list of the assets that are <strong>unloaded</strong> on all pages belonging to the <strong><u><?php echo $data['post_type']; ?></u></strong> post type.</p>
127
- <p>If you want to remove this rule, use the "Remove rule" checkbox.</p>
128
- <p style="margin: 0; background: white; padding: 10px; border: 1px solid #ccc; width: auto; display: inline-block;">This list fills once you select "<em>Unload on All Pages of <strong><?php echo $data['post_type']; ?></strong> post type</em>" when you edit posts/pages for the assets that you want to prevent from loading.</p>
 
 
 
 
 
129
  </div>
130
 
131
  <div class="clear"></div>
@@ -208,7 +218,7 @@ $noAssetsToRemove = (empty($data['values']['styles']) && empty($data['values']['
208
  <input type="hidden" name="wpacu_update" value="1" />
209
 
210
  <?php
211
- if ($data['post_type']) {
212
  ?>
213
  <input type="hidden" name="wpacu_post_type" value="<?php echo $data['post_type']; ?>" />
214
  <?php
24
  <input type="hidden" name="page" value="wpassetcleanup_globals" />
25
  <input type="hidden" name="wpacu_for" value="post_types" />
26
 
27
+ <div style="margin: 0 0 10px 0;">Select the page or post type (including custom ones) for which you want to see the unloaded scripts &amp; styles:</div>
28
  <select id="wpacu_post_type_select" name="wpacu_post_type">
29
  <?php foreach ($data['post_types_list'] as $postType) { ?>
30
  <option <?php if ($data['post_type'] === $postType) { echo 'selected="selected"'; } ?> value="<?php echo $postType; ?>"><?php echo $postType; ?></option>
45
  <div class="alert">
46
  <p>This is the list of the assets that are <strong>globally unloaded</strong> on all pages (including home page).</p>
47
  <p>If you want to remove this rule and have them loading, use the "Remove rule" checkbox.</p>
48
+ <div style="margin: 0; background: white; padding: 10px; border: 1px solid #ccc; width: auto; display: inline-block;">
49
+ <ul>
50
+ <li>This list fills once you select "<em>Unload everywhere</em>" when you edit posts/pages for the assets that you want to prevent from loading on every page.</li>
51
+ <li>On this page you can only remove the global rules that were added while editing the pages/posts.</li>
52
+ </ul>
53
+ </div>
54
  </div>
55
 
56
  <div class="clear"></div>
84
  <?php
85
  } else {
86
  ?>
87
+ <p>There are no global unloaded styles for your selection.</p>
88
  <?php
89
  }
90
  ?>
129
 
130
  <div class="alert">
131
  <p>This is the list of the assets that are <strong>unloaded</strong> on all pages belonging to the <strong><u><?php echo $data['post_type']; ?></u></strong> post type.</p>
132
+ <p>If you want to make an asset load again, use the "Remove rule" checkbox.</p>
133
+ <div style="margin: 0; background: white; padding: 10px; border: 1px solid #ccc; width: auto; display: inline-block;">
134
+ <ul>
135
+ <li>This list fills once you select "<em>Unload on All Pages of <strong><?php echo $data['post_type']; ?></strong> post type</em>" when you edit posts/pages for the assets that you want to prevent from loading.</li>
136
+ <li>On this page you can only remove the global rules that were added while editing <strong><?php echo $data['post_type']; ?></strong> post types.</li>
137
+ </ul>
138
+ </div>
139
  </div>
140
 
141
  <div class="clear"></div>
218
  <input type="hidden" name="wpacu_update" value="1" />
219
 
220
  <?php
221
+ if ($data['for'] === 'post_types' && isset($data['post_type'])) {
222
  ?>
223
  <input type="hidden" name="wpacu_post_type" value="<?php echo $data['post_type']; ?>" />
224
  <?php
templates/settings-home-page.php CHANGED
@@ -10,9 +10,16 @@ if (! isset($data)) {
10
  <h2><?php _e('Home Page Scripts &amp; Styles Management', WPACU_PLUGIN_NAME); ?></h2>
11
 
12
  <?php
 
 
 
 
 
 
 
13
  if ($data['show_on_front'] === 'page') {
14
  ?>
15
- <p><?php _e('In "Settings" -> "Reading" you have selected a static page for "Front page displays" setting. To manage the assets (.CSS &amp; .JS) that will NOT LOAD, use the link(s) below:', WPACU_PLUGIN_NAME); ?></p>
16
  <div>
17
  <ul>
18
  <?php
@@ -62,4 +69,10 @@ if ($data['show_on_front'] === 'page') {
62
  <p class="submit"><input type="submit" name="submit" id="submit" class="hidden button button-primary" value="<?php esc_attr_e('Update', WPACU_PLUGIN_NAME); ?>"></p>
63
  </form>
64
  <?php
 
 
 
 
 
 
65
  }
10
  <h2><?php _e('Home Page Scripts &amp; Styles Management', WPACU_PLUGIN_NAME); ?></h2>
11
 
12
  <?php
13
+ if ($data['wpacu_settings']['dashboard_show'] != 1) {
14
+ ?>
15
+ <div class="error" style="padding: 10px;"><?php echo sprintf(__('As "Manage in the Dashboard?" is not enabled in "%sSettings%s", you can not manage the assets from the Dashboard.', WPACU_PLUGIN_NAME), '<a href="admin.php?page=wpassetcleanup_settings">', '</a>'); ?></div>
16
+ <?php
17
+ return;
18
+ }
19
+
20
  if ($data['show_on_front'] === 'page') {
21
  ?>
22
+ <p><?php _e('In "Settings" -&gt; "Reading" you have selected a static page for "Front page displays" setting. To manage the assets (.CSS &amp; .JS) that will NOT LOAD, use the link(s) below:', WPACU_PLUGIN_NAME); ?></p>
23
  <div>
24
  <ul>
25
  <?php
69
  <p class="submit"><input type="submit" name="submit" id="submit" class="hidden button button-primary" value="<?php esc_attr_e('Update', WPACU_PLUGIN_NAME); ?>"></p>
70
  </form>
71
  <?php
72
+ } else {
73
+ ?>
74
+ <p>It looks like in "Settings" -&gt; "Reading" (/wp-admin/options-reading.php), you have neither of the following options checked: "Your latest posts" and "A static page (select below)".</p>
75
+ <p>Your theme or a plugin could interfere with it. Consider enabling "Manage in the Front-end?" in plugin's settings (WP Asset CleanUp -&gt; Settings). This should show the list of all assets at the bottom of your home page on front-end view (only if you're logged in).</p>
76
+ <p>If you already tried the suggested option and still can't make it work, <a href="https://wordpress.org/support/plugin/wp-asset-clean-up">please open a ticket</a> on the plugin's support page.</p>
77
+ <?php
78
  }
templates/settings-plugin.php CHANGED
@@ -10,18 +10,43 @@ if (! isset($data)) {
10
  <h1><?php _e('WP Asset CleanUp', WPACU_PLUGIN_NAME); ?></h1>
11
  <h2><?php _e('Plugin Settings', WPACU_PLUGIN_NAME); ?></h2>
12
 
13
- <form method="post" action="options.php">
14
- <?php settings_fields('wpacu-plugin-settings-group'); ?>
15
- <?php do_settings_sections('wpacu-plugin-settings-group'); ?>
16
  <table class="form-table">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  <tr valign="top">
18
  <th scope="row">
19
  <label for="wpacu_frontend">Manage in the Front-end?</label>
20
  </th>
21
  <td><input id="wpacu_frontend" type="checkbox"
22
  <?php echo (($data['frontend_show'] == 1) ? 'checked="checked"' : ''); ?>
23
- name="<?php echo WPACU_PLUGIN_NAME.'_frontend_show'; ?>"
24
- value="1" /> &nbsp; <small>If you are logged in, this will make the list of assets show below the page that you view (either home page, a post or a page).</small>
25
  <p><small>The area will be shown through the <code>wp_footer</code> action so in case you do not see the asset list at the bottom of the page, make sure the theme is using <a href="https://codex.wordpress.org/Function_Reference/wp_footer"><code>wp_footer()</code></a> function before the <code>&lt;/body&gt;</code> tag. Any theme that follows the standards should have it. If not, you will have to add it to make sure other plugins and code from functions.php will work fine.</small></p>
26
  </td>
27
  </tr>
10
  <h1><?php _e('WP Asset CleanUp', WPACU_PLUGIN_NAME); ?></h1>
11
  <h2><?php _e('Plugin Settings', WPACU_PLUGIN_NAME); ?></h2>
12
 
13
+ <form method="post" action="">
14
+ <input type="hidden" name="wpacu_settings_page" value="1" />
 
15
  <table class="form-table">
16
+ <tr valign="top">
17
+ <th scope="row">
18
+ <label for="wpacu_dashboard">Manage in the Dashboard?</label>
19
+ </th>
20
+ <td><input id="wpacu_dashboard" type="checkbox"
21
+ <?php echo (($data['dashboard_show'] == 1) ? 'checked="checked"' : ''); ?>
22
+ name="<?php echo WPACU_PLUGIN_NAME.'_settings'; ?>[dashboard_show]"
23
+ value="1" />&nbsp;<label for="wpacu_dashboard"><small>This will show the list of assets in a meta box on edit the post (any type) / page within the Dashboard</small></label>
24
+ <p><small>The assets would be retrieved via AJAX call(s) that will fetch the post/page URL and extract all the styles &amp; scripts that are enqueued.</small></p>
25
+ <p><small>Note that sometimes the assets list is not loading within the Dashboard. That could be because "mod_security" Apache module is enabled or some securiy plugins are blocking the AJAX request. If this option doesn't work, consider managing the list in the front-end view.</small></p>
26
+ </td>
27
+ </tr>
28
+ <tr valign="top">
29
+ <th scope="row">
30
+ <label for="wpacu_dom_get_type">Assets Retrieval Mode (if managed in the Dashboard)</label>
31
+ </th>
32
+ <td><select id="wpacu_dom_get_type" name="<?php echo WPACU_PLUGIN_NAME.'_settings'; ?>[dom_get_type]">
33
+ <option <?php if ($data['dom_get_type'] === 'direct') { ?>selected="selected"<?php } ?> value="direct">Direct</option>
34
+ <option <?php if ($data['dom_get_type'] === 'wp_remote_post') { ?>selected="selected"<?php } ?> value="wp_remote_post">WP Remote Post</option>
35
+ </select>
36
+ <ul>
37
+ <li style="margin-bottom: 20px;"><strong>Direct</strong> - <small>This one makes an AJAX call directly on the URL for which the assets are retrieved, then an extra WordPress AJAX call to process the list. Sometimes, due to some external factors (e.g. mod_security module from Apache, security plugin or the fact that non-http is forced for the front-end view and the AJAX request will be blocked), this might not work and another choice method might work better. This used to be the only option available, prior to version 1.2.4.4 and is set as default.</small></li>
38
+ <li><strong>WP Remote Post</strong> - <small>It makes a WordPress AJAX call and gets the HTML source code through wp_remote_post(). This one is less likely to be blocked as it is made on the same protocol (no HTTP request from HTTPS). However, in some cases (e.g. a different load balancer configuration), this might not work when the call to fetch a domain's URL (your website) is actually made from the same domain.</small></li>
39
+ </ul>
40
+ </td>
41
+ </tr>
42
  <tr valign="top">
43
  <th scope="row">
44
  <label for="wpacu_frontend">Manage in the Front-end?</label>
45
  </th>
46
  <td><input id="wpacu_frontend" type="checkbox"
47
  <?php echo (($data['frontend_show'] == 1) ? 'checked="checked"' : ''); ?>
48
+ name="<?php echo WPACU_PLUGIN_NAME.'_settings'; ?>[frontend_show]"
49
+ value="1" />&nbsp;<label for="wpacu_frontend"><small>If you are logged in, this will make the list of assets show below the page that you view (either home page, a post or a page).</small></label>
50
  <p><small>The area will be shown through the <code>wp_footer</code> action so in case you do not see the asset list at the bottom of the page, make sure the theme is using <a href="https://codex.wordpress.org/Function_Reference/wp_footer"><code>wp_footer()</code></a> function before the <code>&lt;/body&gt;</code> tag. Any theme that follows the standards should have it. If not, you will have to add it to make sure other plugins and code from functions.php will work fine.</small></p>
51
  </td>
52
  </tr>
wpacu-load.php CHANGED
@@ -1,14 +1,9 @@
1
  <?php
2
  // Exit if accessed directly
3
- if (! defined('ABSPATH')) {
4
  exit;
5
  }
6
 
7
- define('WPACU_PLUGIN_NAME', 'wpassetcleanup');
8
- define('WPACU_PLUGIN_CLASSES_PATH', dirname(__FILE__).'/classes/');
9
- define('WPACU_PLUGIN_FILE', $pluginFile);
10
- define('WPACU_PLUGIN_URL', plugins_url('', WPACU_PLUGIN_FILE));
11
-
12
  // Autoload Classes
13
  function includeWpAssetCleanUpClassesAutoload($class)
14
  {
@@ -44,7 +39,8 @@ $wpacuUpdate = new WpAssetCleanUp\Update;
44
  $wpacuUpdate->init();
45
 
46
  // Settings
47
- new WpAssetCleanUp\Settings;
 
48
 
49
  // HomePage
50
  new WpAssetCleanUp\HomePage;
@@ -54,3 +50,6 @@ new WpAssetCleanUp\Misc;
54
 
55
  // Menu
56
  new \WpAssetCleanUp\Menu;
 
 
 
1
  <?php
2
  // Exit if accessed directly
3
+ if (! defined('WPACU_PLUGIN_CLASSES_PATH')) {
4
  exit;
5
  }
6
 
 
 
 
 
 
7
  // Autoload Classes
8
  function includeWpAssetCleanUpClassesAutoload($class)
9
  {
39
  $wpacuUpdate->init();
40
 
41
  // Settings
42
+ $wpacuSettings = new WpAssetCleanUp\Settings;
43
+ $wpacuSettings->init();
44
 
45
  // HomePage
46
  new WpAssetCleanUp\HomePage;
50
 
51
  // Menu
52
  new \WpAssetCleanUp\Menu;
53
+
54
+ // Plugin (Various Hooks)
55
+ new \WpAssetCleanUp\Plugin;
wpacu.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
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/
@@ -13,19 +13,27 @@ if (! defined('ABSPATH')) {
13
  exit;
14
  }
15
 
 
 
 
 
 
 
 
 
 
 
16
  // Do not load the plugin if the PHP version is below 5.3
17
  $wpacuWrongPhp = version_compare(PHP_VERSION, '5.3.0', '<');
18
 
19
  if (is_admin() && $wpacuWrongPhp) { // Dashboard
20
  wp_die(
21
- __('This plugin requires <span style="color: green;"><strong>5.3+</strong> PHP version</span> installed. You have <strong>'.PHP_VERSION.'</strong>. If your website is working in 5.3+ (check with your developers if you are not sure), then an upgrade is highly recommended.', AFP_TEXT_DOMAIN),
22
- __('Plugin Activation Error', AFP_TEXT_DOMAIN),
23
  array('response' => 200, 'back_link' => true)
24
  );
25
  } elseif ($wpacuWrongPhp) { // Front
26
  return;
27
  }
28
 
29
- $pluginFile = __FILE__;
30
-
31
  require_once dirname(__FILE__).'/wpacu-load.php';
1
  <?php
2
  /*
3
  * Plugin Name: WP Asset CleanUp
4
+ * Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
5
+ * Version: 1.2.4.4
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/
13
  exit;
14
  }
15
 
16
+ // Could be already set by the premium extension
17
+ // Keep the text domain the same
18
+ if (! defined('WPACU_PLUGIN_NAME')) {
19
+ define('WPACU_PLUGIN_NAME', 'wpassetcleanup');
20
+ }
21
+
22
+ define('WPACU_PLUGIN_CLASSES_PATH', dirname(__FILE__).'/classes/');
23
+ define('WPACU_PLUGIN_FILE', __FILE__);
24
+ define('WPACU_PLUGIN_URL', plugins_url('', __FILE__));
25
+
26
  // Do not load the plugin if the PHP version is below 5.3
27
  $wpacuWrongPhp = version_compare(PHP_VERSION, '5.3.0', '<');
28
 
29
  if (is_admin() && $wpacuWrongPhp) { // Dashboard
30
  wp_die(
31
+ __('This plugin requires <span style="color: green;"><strong>5.3+</strong> PHP version</span> installed. You have <strong>'.PHP_VERSION.'</strong>. If your website is working in 5.3+ (check with your developers if you are not sure), then an upgrade is highly recommended.', WPACU_PLUGIN_NAME),
32
+ __('Plugin Activation Error', WPACU_PLUGIN_NAME),
33
  array('response' => 200, 'back_link' => true)
34
  );
35
  } elseif ($wpacuWrongPhp) { // Front
36
  return;
37
  }
38
 
 
 
39
  require_once dirname(__FILE__).'/wpacu-load.php';