Asset CleanUp: Page Speed Booster - Version 1.2

Version Description

  • Disable assets site-wide
  • Add exceptions on pages where assets should load (if they are disabled everywhere)
  • Bug Fix: Sometimes, due to website caching services/plugins, the HTML comments are removed needed from getting the assets
Download this release

Release Info

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

Code changes from version 1.1.4.6 to 1.2

assets/script.js CHANGED
@@ -1,7 +1,118 @@
1
  /**
2
- * WP Asset Clean Up - Dashboard
3
  */
4
  jQuery(document).ready(function($) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  if (typeof wpacu_object === 'undefined' || $('#wpacu_meta_box_content').length < 1) {
6
  return false; // stop if we are not on the right page (with asset list)
7
  }
@@ -15,7 +126,7 @@ jQuery(document).ready(function($) {
15
  'contents': contents,
16
  'post_id': wpacu_object.post_id,
17
  'post_url': wpacu_object.post_url
18
- }
19
 
20
  jQuery.post(wpacu_object.ajax_url, data, function (response) {
21
  if (response == '') {
@@ -28,20 +139,8 @@ jQuery(document).ready(function($) {
28
  $('#submit').show();
29
  }
30
 
31
- var cbSelector = '.icheckbox_square-red';
32
-
33
- $(cbSelector).iCheck({
34
- checkboxClass: 'icheckbox_square-red',
35
- increaseArea: '20%' // optional
36
- });
37
-
38
- $(cbSelector).on('ifChecked', function (event) {
39
- $(event.target).closest('tr').addClass('wpacu_not_load');
40
- });
41
-
42
- $(cbSelector).on('ifUnchecked', function (event) {
43
- $(event.target).closest('tr').removeClass('wpacu_not_load');
44
- });
45
  });
46
  });
47
- });
 
1
  /**
2
+ * WP Asset Clean Up
3
  */
4
  jQuery(document).ready(function($) {
5
+ //
6
+ // Common Code For Both Dashboard and Front-end View
7
+ //
8
+ var WpAssetCleanUp = {
9
+ load: function() {
10
+ var cbSelector = '.icheckbox_square-red';
11
+
12
+ $(cbSelector).iCheck({
13
+ checkboxClass: 'icheckbox_square-red',
14
+ increaseArea: '20%' // optional
15
+ });
16
+
17
+ $(cbSelector).on('ifChecked', function (event) {
18
+ $(event.target).closest('tr').addClass('wpacu_not_load');
19
+ });
20
+
21
+ $(cbSelector).on('ifUnchecked', function (event) {
22
+ $(event.target).closest('tr').removeClass('wpacu_not_load');
23
+ });
24
+
25
+ var handle;
26
+
27
+ // Unload Everywhere
28
+ $('.wpacu_global_unload').click(function() {
29
+ handle = $(this).attr('data-handle');
30
+
31
+ if ($(this).prop('checked')) {
32
+ $(this).parent('label').addClass('wpacu_global_checked');
33
+ $(this).closest('tr').addClass('wpacu_not_load');
34
+
35
+ if ($(this).hasClass('wpacu_global_style')) {
36
+ $('#style_' + handle).iCheck('check').iCheck('disable');
37
+ } else if($(this).hasClass('wpacu_global_script')) {
38
+ $('#script_' + handle).iCheck('check').iCheck('disable');
39
+ }
40
+ } else {
41
+ $(this).parent('label').removeClass('wpacu_global_checked');
42
+ $(this).closest('tr').removeClass('wpacu_not_load');
43
+
44
+ if ($(this).hasClass('wpacu_global_style')) {
45
+ $('#style_' + handle).iCheck('uncheck').iCheck('enable');
46
+ } else if($(this).hasClass('wpacu_global_script')) {
47
+ $('#script_' + handle).iCheck('uncheck').iCheck('enable');
48
+ }
49
+
50
+ // Un-check make exception as it is not relevant
51
+ // if unload everywhere is selected
52
+ $('#wpacu_style_load_it_' + handle)
53
+ .prop('checked', false)
54
+ .parent('label').removeClass('wpacu_global_unload_exception');
55
+ }
56
+ });
57
+
58
+ // Asset Global Options
59
+ $('.wpacu_global_option').click(function() {
60
+ var handle = $(this).attr('data-handle'), handleType;
61
+
62
+ if ($(this).hasClass('wpacu_style')) {
63
+ handleType = 'style';
64
+ } else if ($(this).hasClass('wpacu_script')) {
65
+ handleType = 'script';
66
+ }
67
+
68
+ if ($(this).val() == 'remove') {
69
+ $(this).closest('tr').removeClass('wpacu_not_load');
70
+
71
+ $('#wpacu_load_it_option_'+ handleType +'_'+ handle).hide();
72
+
73
+ } else if ($(this).val() == 'default'
74
+ && !$('#wpacu_'+ handleType +'_load_it_'+ handle).prop('checked')) {
75
+ $(this).closest('tr').addClass('wpacu_not_load');
76
+ }
77
+
78
+ if ($(this).val() == 'default') {
79
+ $('#wpacu_load_it_option_'+ handleType + '_' + handle).show();
80
+ }
81
+ });
82
+
83
+ // Load it checkbox
84
+ $('.wpacu_load_it_option').click(function() {
85
+ var handle = $(this).attr('data-handle'), wpacu_input_name;
86
+
87
+ if ($(this).hasClass('wpacu_style')) {
88
+ wpacu_input_name = 'wpacu_options_styles['+ handle +']';
89
+ } else if ($(this).hasClass('wpacu_script')) {
90
+ wpacu_input_name = 'wpacu_options_scripts['+ handle +']';
91
+ }
92
+
93
+ if ($(this).prop('checked')) {
94
+ $(this).parent('label').addClass('wpacu_global_unload_exception');
95
+ $(this).closest('tr').removeClass('wpacu_not_load');
96
+ } else if ($('input[name="'+ wpacu_input_name +'"]:checked').val() == 'default') {
97
+ $(this).parent('label').removeClass('wpacu_global_unload_exception');
98
+ $(this).closest('tr').addClass('wpacu_not_load');
99
+ } else {
100
+ $(this).parent('label').removeClass('wpacu_global_unload_exception');
101
+ }
102
+ });
103
+ }
104
+ };
105
+
106
+ //
107
+ // Asset Front-end Edit (if setting is enabled)
108
+ //
109
+ if ($('#wpacu_wrap_assets').length > 0) {
110
+ WpAssetCleanUp.load();
111
+ }
112
+
113
+ //
114
+ // The code below is for the pages loaded on the Dashboard
115
+ //
116
  if (typeof wpacu_object === 'undefined' || $('#wpacu_meta_box_content').length < 1) {
117
  return false; // stop if we are not on the right page (with asset list)
118
  }
126
  'contents': contents,
127
  'post_id': wpacu_object.post_id,
128
  'post_url': wpacu_object.post_url
129
+ };
130
 
131
  jQuery.post(wpacu_object.ajax_url, data, function (response) {
132
  if (response == '') {
139
  $('#submit').show();
140
  }
141
 
142
+ WpAssetCleanUp.load();
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  });
144
  });
145
+ });
146
+
assets/style.css CHANGED
@@ -1,37 +1,153 @@
1
- tr.wpacu_not_load th,
2
- tr.wpacu_not_load td {
3
- background: #FFE1E1;
4
- }
5
 
6
  .widefat .check-column.wpacu_check {
7
- padding: 10px;
8
- }
9
 
10
  #wpacu_meta_box_content {
11
- width: 99%;
12
- }
13
-
14
- #wpacu_meta_box_content h3 {
15
- margin-left: 0px;
16
- padding-left: 0px;
17
- }
18
-
19
- #wpacu_meta_box_content div.wpacu_note {
20
  padding: 10px;
21
- background-color: #f5f5f5;
22
- }
23
 
24
- #wpacu_meta_box_content div.wpacu_warning {
25
- border: 1px solid #cc0000;
26
- }
27
 
28
- #wpacu_meta_box_content div.wpacu_verified {
29
- padding: 10px;
30
- background-color: #f5f5f5;
31
- border-left: 1px solid #ddd;
32
- }
33
 
34
- #wpacu_meta_box_content div.wpacu_verified span {
 
 
 
 
35
  color: #0073aa;
36
- font-weight: bold;
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tr.wpacu_not_load th, tr.wpacu_not_load td {
2
+ background: #FFE1E1; }
 
 
3
 
4
  .widefat .check-column.wpacu_check {
5
+ padding: 10px; }
 
6
 
7
  #wpacu_meta_box_content {
8
+ width: 99%; }
9
+ #wpacu_meta_box_content h3 {
10
+ margin-left: 0;
11
+ padding-left: 0; }
12
+ #wpacu_meta_box_content div.wpacu_note {
 
 
 
 
13
  padding: 10px;
14
+ background-color: #f5f5f5; }
 
15
 
16
+ #wpacu_wrap_assets div.wpacu_note {
17
+ padding: 10px;
18
+ background-color: #f5f5f5; }
19
 
20
+ #wpacu_meta_box_content div.wpacu_warning, #wpacu_wrap_assets div.wpacu_warning {
21
+ border: 1px solid #cc0000; }
 
 
 
22
 
23
+ #wpacu_meta_box_content div.wpacu_verified {
24
+ padding: 10px;
25
+ background-color: #f5f5f5;
26
+ border-left: 1px solid #ddd; }
27
+ #wpacu_meta_box_content div.wpacu_verified span {
28
  color: #0073aa;
29
+ font-weight: bold; }
30
+ #wpacu_meta_box_content ul.wpacu_asset_options {
31
+ margin: 0;
32
+ padding: 0; }
33
+ #wpacu_meta_box_content ul.wpacu_asset_options li {
34
+ list-style: none;
35
+ display: inline-block; }
36
+ #wpacu_meta_box_content ul.wpacu_asset_options label {
37
+ margin-right: 20px;
38
+ font-weight: normal; }
39
+
40
+ /*
41
+ * Asset List Styling: Front-end and Back-end
42
+ */
43
+ #wpacu_wrap_assets {
44
+ color: #000000 !important;
45
+ text-align: left;
46
+ clear: both;
47
+ width: 90%;
48
+ padding: 20px;
49
+ margin: 30px 0 0 15px;
50
+ border: 1px solid #cdcdcd;
51
+ z-index: 10000 !important;
52
+ position: relative;
53
+ background-color: white; }
54
+ #wpacu_wrap_assets img {
55
+ display: inline-block !important; }
56
+ #wpacu_wrap_assets p {
57
+ margin: 10px 0;
58
+ line-height: 22px;
59
+ text-align: left; }
60
+ #wpacu_wrap_assets h1 {
61
+ margin: 0 0 20px;
62
+ font-size: 160%;
63
+ text-align: left; }
64
+ #wpacu_wrap_assets h3 {
65
+ margin: 20px 0;
66
+ font-size: 130%; }
67
+
68
+ .wpacu_verified {
69
+ margin: 0 0 10px 0; }
70
+
71
+ .wpacu_asset_row td {
72
+ padding: 10px; }
73
+ .wpacu_asset_row td p {
74
+ margin-bottom: 10px;
75
+ word-wrap: break-word; }
76
+ .wpacu_asset_row td label {
77
+ cursor: pointer !important;
78
+ display: inline-block !important;
79
+ font-size: 100%;
80
+ font-weight: normal; }
81
+ .wpacu_asset_row td label span {
82
+ font-size: 100% !important; }
83
+ .wpacu_asset_row td.wpacu_check {
84
+ width: 50px; }
85
+
86
+ /* Dashboard adjust */
87
+ body.wp-admin .wpacu_asset_row td.wpacu_check {
88
+ width: 25px; }
89
+
90
+ label.wpacu_add_global {
91
+ cursor: pointer; }
92
+ label.wpacu_global_checked {
93
+ font-weight: bold;
94
+ color: #d54e21; }
95
+ label.wpacu_global_unload_exception {
96
+ font-weight: bold; }
97
+
98
+ ul.wpacu_asset_options {
99
+ margin: 0;
100
+ padding: 0; }
101
+ ul.wpacu_asset_options li {
102
+ list-style: none;
103
+ display: inline-block; }
104
+ ul.wpacu_asset_options label {
105
+ margin-right: 20px;
106
+ font-weight: normal; }
107
+ ul.wpacu_asset_options label input {
108
+ margin-right: 4px; }
109
+
110
+ /* Assets Table */
111
+ .wpacu_widefat {
112
+ border: 1px solid #e5e5e5 !important; }
113
+ .wpacu_widefat td {
114
+ border: 1px solid #e5e5e5 !important; }
115
+
116
+ .wpacu_striped > tbody > :nth-child(odd), ul.wpacu_striped > :nth-child(odd) {
117
+ background-color: #f9f9f9 !important; }
118
+
119
+ .wpacu_update_btn {
120
+ -moz-box-shadow: inset 0px 1px 0px 0px #54a3f7 !important;
121
+ -webkit-box-shadow: inset 0px 1px 0px 0px #54a3f7 !important;
122
+ box-shadow: inset 0px 1px 0px 0px #54a3f7 !important;
123
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7)) !important;
124
+ background: -moz-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
125
+ background: -webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
126
+ background: -o-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
127
+ background: -ms-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
128
+ background: linear-gradient(to bottom, #007dc1 5%, #0061a7 100%) !important;
129
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0) !important;
130
+ background-color: #007dc1 !important;
131
+ -moz-border-radius: 3px !important;
132
+ -webkit-border-radius: 3px !important;
133
+ border-radius: 3px !important;
134
+ border: 1px solid #124d77 !important;
135
+ display: inline-block !important;
136
+ cursor: pointer !important;
137
+ color: #ffffff !important;
138
+ font-size: 15px !important;
139
+ padding: 10px 24px !important;
140
+ text-decoration: none !important;
141
+ text-shadow: 0px 1px 0px #154682 !important; }
142
+ .wpacu_update_btn:hover {
143
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important;
144
+ background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
145
+ background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
146
+ background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
147
+ background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
148
+ background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%) !important;
149
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0) !important;
150
+ background-color: #0061a7 !important; }
151
+ .wpacu_update_btn:active {
152
+ position: relative !important;
153
+ top: 1px !important; }
assets/style.scss ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tr.wpacu_not_load {
2
+ th, td {
3
+ background: #FFE1E1;
4
+ }
5
+ }
6
+
7
+ .widefat .check-column.wpacu_check {
8
+ padding: 10px;
9
+ }
10
+
11
+ #wpacu_meta_box_content {
12
+ width: 99%;
13
+
14
+ h3 {
15
+ margin-left: 0;
16
+ padding-left: 0;
17
+ }
18
+ div.wpacu_note {
19
+ padding: 10px;
20
+ background-color: #f5f5f5;
21
+ }
22
+ }
23
+
24
+ #wpacu_wrap_assets div.wpacu_note {
25
+ padding: 10px;
26
+ background-color: #f5f5f5;
27
+ }
28
+
29
+ #wpacu_meta_box_content div.wpacu_warning, #wpacu_wrap_assets div.wpacu_warning {
30
+ border: 1px solid #cc0000;
31
+ }
32
+
33
+ #wpacu_meta_box_content {
34
+ div.wpacu_verified {
35
+ padding: 10px;
36
+ background-color: #f5f5f5;
37
+ border-left: 1px solid #ddd;
38
+ span {
39
+ color: #0073aa;
40
+ font-weight: bold;
41
+ }
42
+ }
43
+ ul.wpacu_asset_options {
44
+ margin: 0;
45
+ padding: 0;
46
+ li {
47
+ list-style: none;
48
+ display: inline-block;
49
+ }
50
+ label {
51
+ margin-right: 20px;
52
+ font-weight: normal;
53
+ }
54
+ }
55
+ }
56
+
57
+ /*
58
+ * Asset List Styling: Front-end and Back-end
59
+ */
60
+
61
+ #wpacu_wrap_assets {
62
+ color: #000000 !important;
63
+ text-align: left;
64
+ clear: both;
65
+ width: 90%;
66
+ padding: 20px;
67
+ margin: 30px 0 0 15px;
68
+ border: 1px solid #cdcdcd;
69
+ z-index: 10000 !important;
70
+ position: relative;
71
+ background-color: white;
72
+ img {
73
+ display: inline-block !important;
74
+ }
75
+ p {
76
+ margin: 10px 0;
77
+ line-height: 22px;
78
+ text-align: left;
79
+ }
80
+ h1 {
81
+ margin: 0 0 20px;
82
+ font-size: 160%;
83
+ text-align: left;
84
+ }
85
+ h3 {
86
+ margin: 20px 0;
87
+ font-size: 130%;
88
+ }
89
+ }
90
+
91
+ .wpacu_verified {
92
+ margin: 0 0 10px 0;
93
+ }
94
+
95
+ .wpacu_asset_row td {
96
+ padding: 10px;
97
+ p {
98
+ margin-bottom: 10px;
99
+ word-wrap: break-word;
100
+ }
101
+ label {
102
+ cursor: pointer !important;
103
+ display: inline-block !important;
104
+ font-size: 100%;
105
+ font-weight: normal;
106
+ span {
107
+ font-size: 100% !important;
108
+ }
109
+ }
110
+ &.wpacu_check {
111
+ width: 50px;
112
+ }
113
+ }
114
+
115
+ /* Dashboard adjust */
116
+
117
+ body.wp-admin .wpacu_asset_row td.wpacu_check {
118
+ width: 25px;
119
+ }
120
+
121
+ label {
122
+ &.wpacu_add_global {
123
+ cursor: pointer;
124
+ }
125
+ &.wpacu_global_checked {
126
+ font-weight: bold;
127
+ color: #d54e21;
128
+ }
129
+ &.wpacu_global_unload_exception {
130
+ font-weight: bold;
131
+ }
132
+ }
133
+
134
+ ul.wpacu_asset_options {
135
+ margin: 0;
136
+ padding: 0;
137
+ li {
138
+ list-style: none;
139
+ display: inline-block;
140
+ }
141
+ label {
142
+ margin-right: 20px;
143
+ font-weight: normal;
144
+ input {
145
+ margin-right: 4px;
146
+ }
147
+ }
148
+ }
149
+
150
+ /* Assets Table */
151
+
152
+ .wpacu_widefat {
153
+ border: 1px solid #e5e5e5 !important;
154
+ td {
155
+ border: 1px solid #e5e5e5 !important;
156
+ }
157
+ }
158
+
159
+ .wpacu_striped > tbody > :nth-child(odd), ul.wpacu_striped > :nth-child(odd) {
160
+ background-color: #f9f9f9 !important;
161
+ }
162
+
163
+ .wpacu_update_btn {
164
+ -moz-box-shadow: inset 0px 1px 0px 0px #54a3f7 !important;
165
+ -webkit-box-shadow: inset 0px 1px 0px 0px #54a3f7 !important;
166
+ box-shadow: inset 0px 1px 0px 0px #54a3f7 !important;
167
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7)) !important;
168
+ background: -moz-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
169
+ background: -webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
170
+ background: -o-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
171
+ background: -ms-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
172
+ background: linear-gradient(to bottom, #007dc1 5%, #0061a7 100%) !important;
173
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0) !important;
174
+ background-color: #007dc1 !important;
175
+ -moz-border-radius: 3px !important;
176
+ -webkit-border-radius: 3px !important;
177
+ border-radius: 3px !important;
178
+ border: 1px solid #124d77 !important;
179
+ display: inline-block !important;
180
+ cursor: pointer !important;
181
+ color: #ffffff !important;
182
+ font-size: 15px !important;
183
+ padding: 10px 24px !important;
184
+ text-decoration: none !important;
185
+ text-shadow: 0px 1px 0px #154682 !important;
186
+ &:hover {
187
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important;
188
+ background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
189
+ background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
190
+ background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
191
+ background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
192
+ background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%) !important;
193
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0) !important;
194
+ background-color: #0061a7 !important;
195
+ }
196
+ &:active {
197
+ position: relative !important;
198
+ top: 1px !important;
199
+ }
200
+ }
classes/HomePage.php CHANGED
@@ -1,15 +1,22 @@
1
  <?php
2
  namespace WpAssetCleanUp;
3
 
 
 
 
 
4
  class HomePage
5
  {
 
 
 
 
 
6
  /**
7
  * @var HomePage|null
8
  */
9
  private static $singleton = null;
10
 
11
- public $data = array();
12
-
13
  /**
14
  * @return null|HomePage
15
  */
@@ -62,10 +69,16 @@ class HomePage
62
  }
63
  }
64
 
 
 
 
65
  public function init()
66
  {
67
  }
68
 
 
 
 
69
  public function inlineAdminHead()
70
  {
71
  ?>
@@ -77,6 +90,9 @@ class HomePage
77
  <?php
78
  }
79
 
 
 
 
80
  public function introPage()
81
  {
82
 
@@ -85,7 +101,7 @@ class HomePage
85
  /**
86
  * @param $wpacuNoLoadAssets
87
  */
88
- public function updateFrontPage($wpacuNoLoadAssets)
89
  {
90
  if (! is_array($wpacuNoLoadAssets)) {
91
  return; // only arrays (empty or not) should be used
@@ -96,6 +112,15 @@ class HomePage
96
  if (! update_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList)) {
97
  add_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList);
98
  }
 
 
 
 
 
 
 
 
 
99
  }
100
 
101
  /**
@@ -106,9 +131,10 @@ class HomePage
106
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
107
  ? $_POST[WPACU_PLUGIN_NAME] : array();
108
 
109
- $noncePost = isset($_POST[$this->data['nonce_name']]) ? $_POST[$this->data['nonce_name']] : '';
 
110
 
111
- if (is_array($wpacuNoLoadAssets) && !empty($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
112
  $this->updateFrontPage($wpacuNoLoadAssets);
113
  }
114
 
1
  <?php
2
  namespace WpAssetCleanUp;
3
 
4
+ /**
5
+ * Class HomePage
6
+ * @package WpAssetCleanUp
7
+ */
8
  class HomePage
9
  {
10
+ /**
11
+ * @var array
12
+ */
13
+ public $data = array();
14
+
15
  /**
16
  * @var HomePage|null
17
  */
18
  private static $singleton = null;
19
 
 
 
20
  /**
21
  * @return null|HomePage
22
  */
69
  }
70
  }
71
 
72
+ /**
73
+ *
74
+ */
75
  public function init()
76
  {
77
  }
78
 
79
+ /**
80
+ *
81
+ */
82
  public function inlineAdminHead()
83
  {
84
  ?>
90
  <?php
91
  }
92
 
93
+ /**
94
+ *
95
+ */
96
  public function introPage()
97
  {
98
 
101
  /**
102
  * @param $wpacuNoLoadAssets
103
  */
104
+ public static function updateFrontPage($wpacuNoLoadAssets)
105
  {
106
  if (! is_array($wpacuNoLoadAssets)) {
107
  return; // only arrays (empty or not) should be used
112
  if (! update_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList)) {
113
  add_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList);
114
  }
115
+
116
+ // If globally disabled, make exception to load for submitted assets
117
+ Main::instance()->saveLoadExceptions('front_page');
118
+
119
+ // Any global unloads?
120
+ Main::instance()->saveToGlobalUnload();
121
+
122
+ // Any global unloads removed?
123
+ Main::instance()->removeGlobalUnloads();
124
  }
125
 
126
  /**
131
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
132
  ? $_POST[WPACU_PLUGIN_NAME] : array();
133
 
134
+ $noncePost = isset($_POST[$this->data['nonce_name']])
135
+ ? $_POST[$this->data['nonce_name']] : '';
136
 
137
+ if (is_array($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
138
  $this->updateFrontPage($wpacuNoLoadAssets);
139
  }
140
 
classes/Main.php CHANGED
@@ -7,33 +7,73 @@ namespace WpAssetCleanUp;
7
  */
8
  class Main
9
  {
10
- const STARTDEL = '<!-- BEGIN WPACU PLUGIN JSON -->';
11
- const ENDDEL = '<!-- END WPACU PLUGIN JSON -->';
 
 
 
 
 
 
12
 
 
 
 
13
  const FRONT_NONCE_ACTION_NAME = 'wpacu_front_update';
14
- const FRONT_NONCE_FIELD_NAME = 'wpacu_front_nonce';
15
-
16
  /**
17
- * @var Main|null
18
  */
19
- private static $singleton = null;
20
 
21
  /**
22
  * @var array
23
  */
24
  public $assetsRemoved = array();
25
 
 
 
 
26
  public $loadPluginAssets = false; // default
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  public $fetchUrl;
29
 
 
 
 
30
  public $frontendShow = false;
31
 
 
 
 
32
  public $assetsInFooter = array();
33
 
 
 
 
34
  public $wpScripts = array();
 
 
 
35
  public $wpStyles = array();
36
 
 
 
 
 
 
37
  /**
38
  * @return null|Main
39
  */
@@ -53,17 +93,17 @@ class Main
53
  {
54
  $this->frontendShow = (get_option(WPACU_PLUGIN_NAME.'_frontend_show'));
55
 
 
 
 
 
56
  add_action('admin_enqueue_scripts', array($this, 'stylesAndScriptsForAdmin'));
57
  add_action('wp_enqueue_scripts', array($this, 'stylesAndScriptsForPublic'));
58
 
59
  if ($this->frontendShow) {
60
- add_action('wp_head', array($this, 'frontendHead'));
61
- add_action('wp', array($this, 'frontendUpdate'));
62
  }
63
 
64
- // Used as a fallback in case something goes wrong
65
- add_action('admin_footer', array($this, 'footerArea'));
66
-
67
  // After post/page is saved - update your styles/scripts lists
68
  add_action('save_post', array($this, 'savePost'));
69
 
@@ -96,6 +136,28 @@ class Main
96
  add_action('add_meta_boxes', array($this, 'addMetaBox'));
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  /**
100
  * @param $postType
101
  */
@@ -154,27 +216,56 @@ class Main
154
  */
155
  public function filterScripts()
156
  {
157
- if (is_admin() || (!is_singular() && !is_front_page())) {
158
  return;
159
  }
160
 
161
- $toRemove = $this->getAssetsUnloaded();
162
 
163
- if (! $toRemove) {
164
- return;
165
- }
166
 
167
- $jsonList = json_decode($toRemove);
 
 
 
 
168
 
169
- if (json_last_error()) {
170
- return;
171
- }
172
 
173
- if (! isset($jsonList->scripts)) {
174
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  }
176
 
177
- $list = (array)$jsonList->scripts;
 
 
 
 
 
 
 
178
 
179
  if (empty($list)) {
180
  return;
@@ -186,11 +277,13 @@ class Main
186
  if (empty($this->wpScripts)) {
187
  $this->wpScripts = (array)$wp_scripts;
188
 
189
- $i = 1;
 
190
 
191
- foreach ($this->wpScripts['registered'] as $handle => $value) {
192
- $this->wpScripts['registered'][$handle]->wpacu_pos = $i;
193
- $i++;
 
194
  }
195
  }
196
 
@@ -208,27 +301,56 @@ class Main
208
  */
209
  public function filterStyles()
210
  {
211
- if (is_admin() || (!is_singular() && !is_front_page())) {
212
  return;
213
  }
214
 
215
- $toRemove = $this->getAssetsUnloaded();
216
 
217
- if (! $toRemove) {
218
- return;
219
- }
220
 
221
- $jsonList = json_decode($toRemove);
 
 
 
 
222
 
223
- if (json_last_error()) {
224
- return;
225
- }
226
 
227
- if (! isset($jsonList->styles)) {
228
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  }
230
 
231
- $list = (array)$jsonList->styles;
 
 
 
 
 
 
 
232
 
233
  if (empty($list)) {
234
  return;
@@ -240,11 +362,13 @@ class Main
240
  if (empty($this->wpStyles)) {
241
  $this->wpStyles = (array)$wp_styles;
242
 
243
- $i = 1;
 
244
 
245
- foreach ($this->wpStyles['registered'] as $handle => $value) {
246
- $this->wpStyles['registered'][$handle]->wpacu_pos = $i;
247
- $i++;
 
248
  }
249
  }
250
 
@@ -293,8 +417,20 @@ class Main
293
  update_post_meta($postId, '_'.WPACU_PLUGIN_NAME.'_no_load', $jsonNoAssetsLoadList);
294
  }
295
  }
 
 
 
 
 
 
 
 
 
296
  }
297
 
 
 
 
298
  public function frontendUpdate()
299
  {
300
  global $post;
@@ -310,6 +446,11 @@ class Main
310
  return;
311
  }
312
 
 
 
 
 
 
313
  if (! wp_verify_nonce($_POST[$nonceName], $nonceAction)) {
314
  $postUrlAnchor = get_permalink($post->ID).'#wpacu_wrap_assets';
315
  wp_die(
@@ -326,12 +467,281 @@ class Main
326
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
327
  ? $_POST[WPACU_PLUGIN_NAME] : array();
328
 
329
- HomePage::instance()->updateFrontPage($wpacuNoLoadAssets);
330
  } else {
331
  $this->savePost($post->ID, $post);
332
  }
333
  }
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  public function saveFooterAssets()
336
  {
337
  global $wp_scripts;
@@ -376,15 +786,32 @@ class Main
376
 
377
  $list = array();
378
 
379
- $currentUnloaded = (array)json_decode(
380
  $this->getAssetsUnloaded($post->ID)
381
  );
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  /*
384
  * Style List
385
  */
386
  if (! empty($wp_styles)) {
387
- $skipStyles = array('admin-bar', WPACU_PLUGIN_NAME . '-icheck-square-red', WPACU_PLUGIN_NAME . '-style');
 
 
 
 
388
 
389
  foreach ($wp_styles->done as $handle) {
390
  if ($isFrontEndView && in_array($handle, $skipStyles)) {
@@ -403,9 +830,15 @@ class Main
403
  }
404
 
405
  // Apppend unloaded ones (if any)
406
- if (! empty($currentUnloaded['styles']) && !empty($stylesBeforeUnload)) {
407
- foreach ($currentUnloaded['styles'] as $sbuHandle) {
408
  if (!in_array($sbuHandle, $wp_styles->done)) {
 
 
 
 
 
 
409
  $sbuValue = $stylesBeforeUnload['registered'][$sbuHandle];
410
  $wpacuPos = $sbuValue->wpacu_pos;
411
 
@@ -421,7 +854,11 @@ class Main
421
  * Scripts List
422
  */
423
  if (! empty($wp_scripts)) {
424
- $skipScripts = array('admin-bar', WPACU_PLUGIN_NAME . '-icheck');
 
 
 
 
425
 
426
  foreach ($wp_scripts->done as $handle) {
427
  if ($isFrontEndView && in_array($handle, $skipScripts)) {
@@ -440,9 +877,15 @@ class Main
440
  }
441
 
442
  // Apppend unloaded ones (if any)
443
- if (! empty($currentUnloaded['scripts']) && !empty($scriptsBeforeUnload)) {
444
- foreach ($currentUnloaded['scripts'] as $sbuHandle) {
445
  if (!in_array($sbuHandle, $wp_scripts->done)) {
 
 
 
 
 
 
446
  $sbuValue = $scriptsBeforeUnload['registered'][$sbuHandle];
447
  $wpacuPos = $sbuValue->wpacu_pos;
448
 
@@ -454,7 +897,6 @@ class Main
454
  ksort($list['scripts']);
455
  }
456
 
457
-
458
  // Front-end View while admin is logged in
459
  if ($isFrontEndView) {
460
  $data = array();
@@ -474,6 +916,13 @@ class Main
474
 
475
  $data = $this->alterAssetObj($data);
476
 
 
 
 
 
 
 
 
477
  $this->parseTemplate('settings-frontend', $data, true);
478
  } elseif ($isDashboardView) {
479
  // AJAX call from the WordPress Dashboard
@@ -618,8 +1067,8 @@ class Main
618
  )
619
  );
620
 
621
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-script');
622
  wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
 
623
  }
624
 
625
  /**
@@ -640,6 +1089,7 @@ class Main
640
  {
641
  if ($this->frontendShow && current_user_can('manage_options') && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
642
  wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
 
643
  }
644
  }
645
 
@@ -676,9 +1126,9 @@ class Main
676
  */
677
  public function ajaxGetJsonListCallback()
678
  {
679
- $contents = $_POST['contents'];
680
- $postId = (int)$_POST['post_id'];
681
- $postUrl = $_POST['post_url'];
682
 
683
  $json = base64_decode(
684
  $this->extractBetween(
@@ -699,21 +1149,30 @@ class Main
699
  $data['current'] = (array)json_decode($this->getAssetsUnloaded($postId));
700
 
701
  // Set to empty if not set to avoid any errors
702
- if (! isset($data['current']['styles'])) {
703
  $data['current']['styles'] = array();
704
  }
705
 
706
- if (! isset($data['current']['scripts'])) {
707
  $data['current']['scripts'] = array();
708
  }
709
 
710
  $data['fetch_url'] = $postUrl;
 
 
 
 
 
711
 
712
  $this->parseTemplate('meta-box-loaded', $data, true);
713
 
714
  exit;
715
  }
716
 
 
 
 
 
717
  public function alterAssetObj($data)
718
  {
719
  $siteUrl = get_option('siteurl');
@@ -723,6 +1182,7 @@ class Main
723
 
724
  foreach ($data['all']['styles'] as $key => $obj) {
725
  if (! isset($obj->handle)) {
 
726
  continue;
727
  }
728
 
@@ -769,6 +1229,7 @@ class Main
769
 
770
  foreach ($data['all']['scripts'] as $key => $obj) {
771
  if (! isset($obj->handle)) {
 
772
  continue;
773
  }
774
 
@@ -853,162 +1314,13 @@ class Main
853
  } elseif ($postId > 0) {
854
  $this->assetsRemoved = get_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_no_load', true);
855
  }
856
- }
857
 
858
- return $this->assetsRemoved;
859
- }
860
-
861
- public function frontendHead()
862
- {
863
- // Only visible for the logged in admin
864
- if (! current_user_can('manage_options')) {
865
- return;
866
- }
867
- ?>
868
- <style type="text/css">
869
- #wpacu_wrap_assets {
870
- 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;
871
- }
872
-
873
- #wpacu_wrap_assets img {
874
- display: inline-block !important;
875
- }
876
-
877
- #wpacu_wrap_assets p {
878
- margin: 10px 0;
879
- text-align: left;
880
- }
881
-
882
- #wpacu_wrap_assets h1 {
883
- margin: 0 0 20px;
884
- font-size: 160%;
885
- text-align: left;
886
- }
887
-
888
- #wpacu_wrap_assets h3 {
889
- margin: 20px 0;
890
- font-size: 130%;
891
- }
892
-
893
- .wpacu_verified {
894
- margin: 0 0 10px 0;
895
- }
896
-
897
- .wpacu_asset_row td {
898
- padding: 10px;
899
- }
900
-
901
- .wpacu_asset_row td p {
902
- margin-bottom: 10px;
903
- word-wrap: break-word;
904
- }
905
-
906
- .wpacu_asset_row td label {
907
- cursor: pointer !important;
908
- display: inline-block !important;
909
- font-size: 100%;
910
- }
911
-
912
- .wpacu_asset_row td.wpacu_check {
913
- width: 50px;
914
- }
915
-
916
- /* Assets Table */
917
- .wpacu_widefat, .wpacu_widefat td {
918
- border: 1px solid #e5e5e5 !important;
919
- }
920
-
921
- .wpacu_striped>tbody>:nth-child(odd), ul.wpacu_striped>:nth-child(odd) {
922
- background-color: #f9f9f9 !important;
923
  }
924
-
925
- .wpacu_update_btn {
926
- -moz-box-shadow:inset 0px 1px 0px 0px #54a3f7 !important;
927
- -webkit-box-shadow:inset 0px 1px 0px 0px #54a3f7 !important;
928
- box-shadow:inset 0px 1px 0px 0px #54a3f7 !important;
929
- background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7)) !important;
930
- background:-moz-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
931
- background:-webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
932
- background:-o-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
933
- background:-ms-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
934
- background:linear-gradient(to bottom, #007dc1 5%, #0061a7 100%) !important;
935
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0) !important;
936
- background-color:#007dc1 !important;
937
- -moz-border-radius:3px !important;
938
- -webkit-border-radius:3px !important;
939
- border-radius:3px !important;
940
- border:1px solid #124d77 !important;
941
- display:inline-block !important;
942
- cursor:pointer !important;
943
- color:#ffffff !important;
944
- font-size:15px !important;
945
- padding:10px 24px !important;
946
- text-decoration:none !important;
947
- text-shadow:0px 1px 0px #154682 !important;
948
- }
949
-
950
- .wpacu_update_btn:hover {
951
- background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important;
952
- background:-moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
953
- background:-webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
954
- background:-o-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
955
- background:-ms-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
956
- background:linear-gradient(to bottom, #0061a7 5%, #007dc1 100%) !important;
957
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0) !important;
958
- background-color:#0061a7 !important;
959
- }
960
-
961
- .wpacu_update_btn:active {
962
- position:relative !important;
963
- top:1px !important;
964
- }
965
- </style>
966
-
967
- <script type="text/javascript">
968
- jQuery(document).ready(function($) {
969
- var cbSelector = '.icheckbox_square-red';
970
-
971
- $(cbSelector).iCheck({
972
- checkboxClass: 'icheckbox_square-red',
973
- increaseArea: '20%' // optional
974
- });
975
-
976
- $(cbSelector).on('ifChecked', function (event) {
977
- $(event.target).closest('tr').addClass('wpacu_not_load');
978
- });
979
-
980
- $(cbSelector).on('ifUnchecked', function (event) {
981
- $(event.target).closest('tr').removeClass('wpacu_not_load');
982
- });
983
- });
984
- </script>
985
- <?php
986
- }
987
-
988
- /**
989
- *
990
- */
991
- public function footerArea()
992
- {
993
- // Hmm, for some reason the WPACU script was not loaded
994
- // based on the conditions set and we have to hard code it here
995
- // Not the ideal way in terms of coding and loading
996
- // but a fallback to make the plugin work 100%
997
- if (! defined('WPACU_TPL_LOADED')) {
998
- ?>
999
- <link rel='stylesheet' id='wpassetcleanup-style-css'
1000
- href='<?php echo plugins_url('/assets/style.css', WPACU_PLUGIN_FILE); ?>?ver=4.4.1'
1001
- type='text/css' media='all'/>
1002
- <link rel='stylesheet' id='wpassetcleanup-icheck-square-red-css'
1003
- href='<?php echo plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE); ?>?ver=4.4.1'
1004
- type='text/css' media='all'/>
1005
-
1006
- <script type='text/javascript'
1007
- src='<?php echo plugins_url('/assets/script.js', WPACU_PLUGIN_FILE); ?>?ver=1.1'></script>
1008
- <script type='text/javascript'
1009
- src='<?php echo plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE); ?>?ver=4.4'></script>
1010
- <?php
1011
  }
 
 
1012
  }
1013
 
1014
  /**
7
  */
8
  class Main
9
  {
10
+ /**
11
+ *
12
+ */
13
+ const STARTDEL = '@ BEGIN WPACU PLUGIN JSON @';
14
+ /**
15
+ *
16
+ */
17
+ const ENDDEL = '@ END WPACU PLUGIN JSON @';
18
 
19
+ /**
20
+ *
21
+ */
22
  const FRONT_NONCE_ACTION_NAME = 'wpacu_front_update';
 
 
23
  /**
24
+ *
25
  */
26
+ const FRONT_NONCE_FIELD_NAME = 'wpacu_front_nonce';
27
 
28
  /**
29
  * @var array
30
  */
31
  public $assetsRemoved = array();
32
 
33
+ /**
34
+ * @var bool
35
+ */
36
  public $loadPluginAssets = false; // default
37
 
38
+ /**
39
+ * @var array
40
+ */
41
+ public $globalUnloaded = array();
42
+
43
+ /**
44
+ * @var array
45
+ */
46
+ public $loadExceptions = array();
47
+
48
+ /**
49
+ * @var
50
+ */
51
  public $fetchUrl;
52
 
53
+ /**
54
+ * @var bool|mixed|void
55
+ */
56
  public $frontendShow = false;
57
 
58
+ /**
59
+ * @var array
60
+ */
61
  public $assetsInFooter = array();
62
 
63
+ /**
64
+ * @var array
65
+ */
66
  public $wpScripts = array();
67
+ /**
68
+ * @var array
69
+ */
70
  public $wpStyles = array();
71
 
72
+ /**
73
+ * @var Main|null
74
+ */
75
+ private static $singleton = null;
76
+
77
  /**
78
  * @return null|Main
79
  */
93
  {
94
  $this->frontendShow = (get_option(WPACU_PLUGIN_NAME.'_frontend_show'));
95
 
96
+ // Early Triggers
97
+ // run right after the other 'wp_loaded' action
98
+ add_action('wp', array($this, 'setVars'), 2);
99
+
100
  add_action('admin_enqueue_scripts', array($this, 'stylesAndScriptsForAdmin'));
101
  add_action('wp_enqueue_scripts', array($this, 'stylesAndScriptsForPublic'));
102
 
103
  if ($this->frontendShow) {
104
+ add_action('wp', array($this, 'frontendUpdate'), 1);
 
105
  }
106
 
 
 
 
107
  // After post/page is saved - update your styles/scripts lists
108
  add_action('save_post', array($this, 'savePost'));
109
 
136
  add_action('add_meta_boxes', array($this, 'addMetaBox'));
137
  }
138
 
139
+ /**
140
+ *
141
+ */
142
+ public function setVars()
143
+ {
144
+ if (! isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
145
+ $this->globalUnloaded = $this->getGlobalUnload();
146
+
147
+ if (!is_singular() && !is_front_page()) {
148
+ return;
149
+ }
150
+
151
+ global $post;
152
+
153
+ $postId = isset($post->ID) ? $post->ID : '';
154
+
155
+ $type = (is_front_page()) ? 'front_page' : 'post';
156
+
157
+ $this->loadExceptions = $this->getLoadExceptions($type, $postId);
158
+ }
159
+ }
160
+
161
  /**
162
  * @param $postType
163
  */
216
  */
217
  public function filterScripts()
218
  {
219
+ if (is_admin()) {
220
  return;
221
  }
222
 
223
+ $nonAssetConfigPage = (!is_singular() && !is_front_page());
224
 
225
+ // It looks like the page loaded is neither a post, page or the front-page
226
+ // We'll see if there are assets unloaded globally and unload them
227
+ $globalUnload = $this->globalUnloaded;
228
 
229
+ if (! empty($globalUnload['scripts']) && $nonAssetConfigPage) {
230
+ $list = $globalUnload['scripts'];
231
+ } else {
232
+ // Post, Page or Front-page?
233
+ $toRemove = $this->getAssetsUnloaded();
234
 
235
+ if (!$toRemove) {
236
+ return;
237
+ }
238
 
239
+ $jsonList = @json_decode($toRemove);
240
+
241
+ if (json_last_error()) {
242
+ return;
243
+ }
244
+
245
+ $list = array();
246
+
247
+ if (isset($jsonList->scripts)) {
248
+ $list = (array)$jsonList->scripts;
249
+ }
250
+
251
+ // Any global unloaded styles? Append them
252
+ if (! empty($globalUnload['scripts'])) {
253
+ foreach ($globalUnload['scripts'] as $handleScript) {
254
+ $list[] = $handleScript;
255
+ }
256
+ }
257
+
258
+ $list = array_unique($list);
259
  }
260
 
261
+ // Let's see if there are load exceptions for this page
262
+ if (! empty($list) && ! empty($this->loadExceptions['scripts'])) {
263
+ foreach ($list as $handleKey => $handle) {
264
+ if (in_array($handle, $this->loadExceptions['scripts'])) {
265
+ unset($list[$handleKey]);
266
+ }
267
+ }
268
+ }
269
 
270
  if (empty($list)) {
271
  return;
277
  if (empty($this->wpScripts)) {
278
  $this->wpScripts = (array)$wp_scripts;
279
 
280
+ if (! empty($this->wpScripts) && isset($this->wpScripts['registered'])) {
281
+ $i = 1;
282
 
283
+ foreach ($this->wpScripts['registered'] as $handle => $value) {
284
+ $this->wpScripts['registered'][$handle]->wpacu_pos = $i;
285
+ $i++;
286
+ }
287
  }
288
  }
289
 
301
  */
302
  public function filterStyles()
303
  {
304
+ if (is_admin()) {
305
  return;
306
  }
307
 
308
+ $nonAssetConfigPage = (!is_singular() && !is_front_page());
309
 
310
+ // It looks like the page loaded is neither a post, page or the front-page
311
+ // We'll see if there are assets unloaded globally and unload them
312
+ $globalUnload = $this->globalUnloaded;
313
 
314
+ if (! empty($globalUnload['styles']) && $nonAssetConfigPage) {
315
+ $list = $globalUnload['styles'];
316
+ } else {
317
+ // Post, Page or Front-page
318
+ $toRemove = $this->getAssetsUnloaded();
319
 
320
+ if (!$toRemove) {
321
+ return;
322
+ }
323
 
324
+ $jsonList = @json_decode($toRemove);
325
+
326
+ if (json_last_error()) {
327
+ return;
328
+ }
329
+
330
+ $list = array();
331
+
332
+ if (isset($jsonList->styles)) {
333
+ $list = (array)$jsonList->styles;
334
+ }
335
+
336
+ // Any global unloaded styles? Append them
337
+ if (! empty($globalUnload['styles'])) {
338
+ foreach ($globalUnload['styles'] as $handleStyle) {
339
+ $list[] = $handleStyle;
340
+ }
341
+ }
342
+
343
+ $list = array_unique($list);
344
  }
345
 
346
+ // Let's see if there are load exceptions for this page
347
+ if (! empty($list) && ! empty($this->loadExceptions['styles'])) {
348
+ foreach ($list as $handleKey => $handle) {
349
+ if (in_array($handle, $this->loadExceptions['styles'])) {
350
+ unset($list[$handleKey]);
351
+ }
352
+ }
353
+ }
354
 
355
  if (empty($list)) {
356
  return;
362
  if (empty($this->wpStyles)) {
363
  $this->wpStyles = (array)$wp_styles;
364
 
365
+ if (! empty($this->wpStyles) && isset($this->wpStyles['registered'])) {
366
+ $i = 1;
367
 
368
+ foreach ($this->wpStyles['registered'] as $handle => $value) {
369
+ $this->wpStyles['registered'][$handle]->wpacu_pos = $i;
370
+ $i++;
371
+ }
372
  }
373
  }
374
 
417
  update_post_meta($postId, '_'.WPACU_PLUGIN_NAME.'_no_load', $jsonNoAssetsLoadList);
418
  }
419
  }
420
+
421
+ // If globally disabled, make exception to load for submitted assets
422
+ Main::instance()->saveLoadExceptions('post', $postId);
423
+
424
+ // Any global unloads?
425
+ Main::instance()->saveToGlobalUnload();
426
+
427
+ // Any global unloads removed?
428
+ Main::instance()->removeGlobalUnloads();
429
  }
430
 
431
+ /**
432
+ *
433
+ */
434
  public function frontendUpdate()
435
  {
436
  global $post;
446
  return;
447
  }
448
 
449
+ // only for admins
450
+ if (! current_user_can('manage_options')) {
451
+ return;
452
+ }
453
+
454
  if (! wp_verify_nonce($_POST[$nonceName], $nonceAction)) {
455
  $postUrlAnchor = get_permalink($post->ID).'#wpacu_wrap_assets';
456
  wp_die(
467
  $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
468
  ? $_POST[WPACU_PLUGIN_NAME] : array();
469
 
470
+ HomePage::updateFrontPage($wpacuNoLoadAssets);
471
  } else {
472
  $this->savePost($post->ID, $post);
473
  }
474
  }
475
 
476
+ /**
477
+ * @param string $type
478
+ * @param string $postId
479
+ * @return array|mixed|object|void
480
+ */
481
+ public function getLoadExceptions($type = 'post', $postId = '')
482
+ {
483
+ if ($type == 'post' && !$postId) {
484
+ // $postId needs to have a value if $type is a 'post' type
485
+ return false;
486
+ }
487
+
488
+ if (! in_array($type, array('post', 'front_page'))) {
489
+ // Invalid request
490
+ return false;
491
+ }
492
+
493
+ // Default
494
+ $exceptionsListJson = '';
495
+ $exceptionsListEmpty = $exceptionsList = array('styles' => array(), 'scripts' => array());
496
+
497
+ if ($type == 'post') {
498
+ $exceptionsListJson = get_post_meta(
499
+ $postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions',
500
+ true
501
+ );
502
+ } elseif ($type == 'front_page') {
503
+ $exceptionsListJson = get_option(
504
+ WPACU_PLUGIN_NAME . '_front_page_load_exceptions'
505
+ );
506
+ }
507
+
508
+ if ($exceptionsListJson) {
509
+ $exceptionsList = json_decode($exceptionsListJson, true);
510
+
511
+ if (json_last_error() != JSON_ERROR_NONE) {
512
+ $exceptionsList = $exceptionsListEmpty;
513
+ }
514
+ }
515
+
516
+ return $exceptionsList;
517
+ }
518
+
519
+ /**
520
+ * @param string $type
521
+ * @param string $postId
522
+ */
523
+ public function saveLoadExceptions($type = 'post', $postId = '')
524
+ {
525
+ if ($type == 'post' && !$postId) {
526
+ // $postId needs to have a value if $type is a 'post' type
527
+ return false;
528
+ }
529
+
530
+ if (! in_array($type, array('post', 'front_page'))) {
531
+ // Invalid request
532
+ return false;
533
+ }
534
+
535
+ // Any global upload options
536
+ $isPostOptionStyles = (isset($_POST['wpacu_styles_load_it']) && ! empty($_POST['wpacu_styles_load_it']));
537
+ $isPostOptionScripts = (isset($_POST['wpacu_scripts_load_it']) && ! empty($_POST['wpacu_scripts_load_it']));
538
+
539
+ $loadExceptionsStyles = $loadExceptionsScripts = array();
540
+
541
+ // Clear existing list first
542
+ if ($type == 'post') {
543
+ delete_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions');
544
+ } elseif ($type == 'front_page') {
545
+ delete_option(WPACU_PLUGIN_NAME . '_front_page_load_exceptions');
546
+ }
547
+
548
+ if (!$isPostOptionStyles && !$isPostOptionScripts) {
549
+ return false;
550
+ }
551
+
552
+ // Load Exception
553
+ if (! empty($_POST['wpacu_styles_load_it'])) {
554
+ foreach ($_POST['wpacu_styles_load_it'] as $wpacuHandle) {
555
+ // Do not append it if the global unload is removed
556
+ if (isset($_POST['wpacu_options_styles'][$wpacuHandle])
557
+ && $_POST['wpacu_options_styles'][$wpacuHandle] == 'remove') {
558
+ continue;
559
+ }
560
+ $loadExceptionsStyles[] = $wpacuHandle;
561
+ }
562
+ }
563
+
564
+ if (! empty($_POST['wpacu_scripts_load_it'])) {
565
+ foreach ($_POST['wpacu_scripts_load_it'] as $wpacuHandle) {
566
+ // Do not append it if the global unload is removed
567
+ if (isset($_POST['wpacu_options_scripts'][$wpacuHandle])
568
+ && $_POST['wpacu_options_scripts'][$wpacuHandle] == 'remove') {
569
+ continue;
570
+ }
571
+ $loadExceptionsScripts[] = $wpacuHandle;
572
+ }
573
+ }
574
+
575
+ if (! empty($loadExceptionsStyles) || ! empty($loadExceptionsScripts)) {
576
+ // Default
577
+ $list = array('styles' => array(), 'scripts' => array());
578
+
579
+ // Build list
580
+ if (! empty($loadExceptionsStyles)) {
581
+ foreach ($loadExceptionsStyles as $postHandle) {
582
+ $list['styles'][] = $postHandle;
583
+ }
584
+ }
585
+
586
+ if (! empty($loadExceptionsScripts)) {
587
+ foreach ($loadExceptionsScripts as $postHandle) {
588
+ $list['scripts'][] = $postHandle;
589
+ }
590
+ }
591
+
592
+ if (is_array($list['styles'])) {
593
+ $list['styles'] = array_unique($list['styles']);
594
+ }
595
+
596
+ if (is_array($list['scripts'])) {
597
+ $list['scripts'] = array_unique($list['scripts']);
598
+ }
599
+
600
+ $jsonLoadExceptions = json_encode($list);
601
+
602
+ if ($type == 'post') {
603
+ if (! add_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions', $jsonLoadExceptions, true)) {
604
+ update_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions', $jsonLoadExceptions);
605
+ }
606
+ } elseif ($type == 'front_page') {
607
+ update_option(WPACU_PLUGIN_NAME . '_front_page_load_exceptions', $jsonLoadExceptions);
608
+ }
609
+ }
610
+ }
611
+
612
+ /**
613
+ *
614
+ */
615
+ public function saveToGlobalUnload()
616
+ {
617
+ $postStyles = (isset($_POST['wpacu_global_unload_styles']) && is_array($_POST['wpacu_global_unload_styles']))
618
+ ? $_POST['wpacu_global_unload_styles'] : array();
619
+
620
+ $postScripts = (isset($_POST['wpacu_global_unload_scripts']) && is_array($_POST['wpacu_global_unload_scripts']))
621
+ ? $_POST['wpacu_global_unload_scripts'] : array();
622
+
623
+ // Is there any entry already in JSON format?
624
+ $existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
625
+
626
+ // Default list as array
627
+ $existingListEmpty = array('styles' => array(), 'scripts' => array());
628
+
629
+ if (! $existingListJson) {
630
+ $existingList = $existingListEmpty;
631
+ } else {
632
+ $existingList = json_decode($existingListJson, true);
633
+
634
+ if (json_last_error() != JSON_ERROR_NONE) {
635
+ $existingList = $existingListEmpty;
636
+ }
637
+ }
638
+
639
+ // Append to the list anything from the POST (if any)
640
+ if (! empty($postStyles)) {
641
+ foreach ($postStyles as $postStyleHandle) {
642
+ $existingList['styles'][] = $postStyleHandle;
643
+ }
644
+ }
645
+
646
+ if (! empty($postScripts)) {
647
+ foreach ($postScripts as $postScriptHandle) {
648
+ $existingList['scripts'][] = $postScriptHandle;
649
+ }
650
+ }
651
+
652
+ // Make sure all entries are unique (no handle duplicates)
653
+ $existingList['styles'] = array_unique($existingList['styles']);
654
+ $existingList['scripts'] = array_unique($existingList['scripts']);
655
+
656
+ update_option(
657
+ WPACU_PLUGIN_NAME.'_global_unload',
658
+ json_encode($existingList)
659
+ );
660
+ }
661
+
662
+ /**
663
+ * @return array
664
+ */
665
+ public function getGlobalUnload()
666
+ {
667
+ $existingListEmpty = array('styles' => array(), 'scripts' => array());
668
+
669
+ $existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
670
+
671
+ if (! $existingListJson) {
672
+ return $existingListEmpty;
673
+ }
674
+
675
+ $existingList = json_decode($existingListJson, true);
676
+
677
+ if (json_last_error() != JSON_ERROR_NONE) {
678
+ $existingList = $existingListEmpty;
679
+ }
680
+
681
+ return $existingList;
682
+ }
683
+
684
+ /**
685
+ *
686
+ */
687
+ public function removeGlobalUnloads()
688
+ {
689
+ $stylesList = isset($_POST['wpacu_options_styles']) ? $_POST['wpacu_options_styles'] : array();
690
+ $scriptsList = isset($_POST['wpacu_options_scripts']) ? $_POST['wpacu_options_scripts'] : array();
691
+
692
+ $removeStylesList = $removeScriptsList = array();
693
+
694
+ if (! empty($stylesList)) {
695
+ foreach ($stylesList as $handle => $value) {
696
+ if ($value == 'remove') {
697
+ $removeStylesList[] = $handle;
698
+ }
699
+ }
700
+ }
701
+
702
+ if (! empty($scriptsList)) {
703
+ foreach ($scriptsList as $handle => $value) {
704
+ if ($value == 'remove') {
705
+ $removeScriptsList[] = $handle;
706
+ }
707
+ }
708
+ }
709
+
710
+ $existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
711
+
712
+ if (! $existingListJson) {
713
+ return;
714
+ }
715
+
716
+ $existingList = json_decode($existingListJson, true);
717
+
718
+ if (json_last_error() == JSON_ERROR_NONE) {
719
+ if (! empty($removeStylesList)) {
720
+ foreach ($existingList['styles'] as $handleKey => $handle) {
721
+ if (in_array($handle, $removeStylesList)) {
722
+ unset($existingList['styles'][$handleKey]);
723
+ }
724
+ }
725
+ }
726
+
727
+ if (! empty($removeScriptsList)) {
728
+ foreach ($existingList['scripts'] as $handleKey => $handle) {
729
+ if (in_array($handle, $removeScriptsList)) {
730
+ unset($existingList['scripts'][$handleKey]);
731
+ }
732
+ }
733
+ }
734
+
735
+ update_option(
736
+ WPACU_PLUGIN_NAME.'_global_unload',
737
+ json_encode($existingList)
738
+ );
739
+ }
740
+ }
741
+
742
+ /**
743
+ *
744
+ */
745
  public function saveFooterAssets()
746
  {
747
  global $wp_scripts;
786
 
787
  $list = array();
788
 
789
+ $currentUnloadedAll = $currentUnloaded = (array)json_decode(
790
  $this->getAssetsUnloaded($post->ID)
791
  );
792
 
793
+ // Append global unloaded assets to current (one by one) unloaded ones
794
+ if (! empty($this->globalUnloaded['styles'])) {
795
+ foreach ($this->globalUnloaded['styles'] as $globalStyle) {
796
+ $currentUnloadedAll['styles'][] = $globalStyle;
797
+ }
798
+ }
799
+
800
+ if (! empty($this->globalUnloaded['scripts'])) {
801
+ foreach ($this->globalUnloaded['scripts'] as $globalScript) {
802
+ $currentUnloadedAll['scripts'][] = $globalScript;
803
+ }
804
+ }
805
+
806
  /*
807
  * Style List
808
  */
809
  if (! empty($wp_styles)) {
810
+ $skipStyles = array(
811
+ 'admin-bar',
812
+ WPACU_PLUGIN_NAME . '-icheck-square-red',
813
+ WPACU_PLUGIN_NAME . '-style'
814
+ );
815
 
816
  foreach ($wp_styles->done as $handle) {
817
  if ($isFrontEndView && in_array($handle, $skipStyles)) {
830
  }
831
 
832
  // Apppend unloaded ones (if any)
833
+ if (! empty($currentUnloadedAll['styles']) && !empty($stylesBeforeUnload)) {
834
+ foreach ($currentUnloadedAll['styles'] as $sbuHandle) {
835
  if (!in_array($sbuHandle, $wp_styles->done)) {
836
+ // Could be an old style that is not loaded anymore
837
+ // We have to check that
838
+ if (! isset($stylesBeforeUnload['registered'][$sbuHandle])) {
839
+ continue;
840
+ }
841
+
842
  $sbuValue = $stylesBeforeUnload['registered'][$sbuHandle];
843
  $wpacuPos = $sbuValue->wpacu_pos;
844
 
854
  * Scripts List
855
  */
856
  if (! empty($wp_scripts)) {
857
+ $skipScripts = array(
858
+ 'admin-bar',
859
+ WPACU_PLUGIN_NAME . '-icheck',
860
+ WPACU_PLUGIN_NAME.'-script'
861
+ );
862
 
863
  foreach ($wp_scripts->done as $handle) {
864
  if ($isFrontEndView && in_array($handle, $skipScripts)) {
877
  }
878
 
879
  // Apppend unloaded ones (if any)
880
+ if (! empty($currentUnloadedAll['scripts']) && !empty($scriptsBeforeUnload)) {
881
+ foreach ($currentUnloadedAll['scripts'] as $sbuHandle) {
882
  if (!in_array($sbuHandle, $wp_scripts->done)) {
883
+ // Could be an old script that is not loaded anymore
884
+ // We have to check that
885
+ if (! isset($scriptsBeforeUnload['registered'][$sbuHandle])) {
886
+ continue;
887
+ }
888
+
889
  $sbuValue = $scriptsBeforeUnload['registered'][$sbuHandle];
890
  $wpacuPos = $sbuValue->wpacu_pos;
891
 
897
  ksort($list['scripts']);
898
  }
899
 
 
900
  // Front-end View while admin is logged in
901
  if ($isFrontEndView) {
902
  $data = array();
916
 
917
  $data = $this->alterAssetObj($data);
918
 
919
+ $data['global_unload'] = $this->globalUnloaded;
920
+
921
+ $type = (is_front_page()) ? 'front_page' : 'post';
922
+ $postId = $post->ID;
923
+
924
+ $data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
925
+
926
  $this->parseTemplate('settings-frontend', $data, true);
927
  } elseif ($isDashboardView) {
928
  // AJAX call from the WordPress Dashboard
1067
  )
1068
  );
1069
 
 
1070
  wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
1071
+ wp_enqueue_script(WPACU_PLUGIN_NAME . '-script');
1072
  }
1073
 
1074
  /**
1089
  {
1090
  if ($this->frontendShow && current_user_can('manage_options') && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
1091
  wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
1092
+ wp_enqueue_script(WPACU_PLUGIN_NAME . '-script', plugins_url('/assets/script.js', WPACU_PLUGIN_FILE), array('jquery'), '1.1');
1093
  }
1094
  }
1095
 
1126
  */
1127
  public function ajaxGetJsonListCallback()
1128
  {
1129
+ $contents = isset($_POST['contents']) ? $_POST['contents'] : '';
1130
+ $postId = isset($_POST['post_id']) ? (int)$_POST['post_id'] : '';
1131
+ $postUrl = isset($_POST['post_url']) ? $_POST['post_url'] : '';
1132
 
1133
  $json = base64_decode(
1134
  $this->extractBetween(
1149
  $data['current'] = (array)json_decode($this->getAssetsUnloaded($postId));
1150
 
1151
  // Set to empty if not set to avoid any errors
1152
+ if (! isset($data['current']['styles']) || !is_array($data['current']['styles'])) {
1153
  $data['current']['styles'] = array();
1154
  }
1155
 
1156
+ if (! isset($data['current']['scripts']) || !is_array($data['current']['scripts'])) {
1157
  $data['current']['scripts'] = array();
1158
  }
1159
 
1160
  $data['fetch_url'] = $postUrl;
1161
+ $data['global_unload'] = $this->getGlobalUnload();
1162
+
1163
+ $type = ($postId == 0) ? 'front_page' : 'post';
1164
+
1165
+ $data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
1166
 
1167
  $this->parseTemplate('meta-box-loaded', $data, true);
1168
 
1169
  exit;
1170
  }
1171
 
1172
+ /**
1173
+ * @param $data
1174
+ * @return mixed
1175
+ */
1176
  public function alterAssetObj($data)
1177
  {
1178
  $siteUrl = get_option('siteurl');
1182
 
1183
  foreach ($data['all']['styles'] as $key => $obj) {
1184
  if (! isset($obj->handle)) {
1185
+ unset($data['all']['styles']['']);
1186
  continue;
1187
  }
1188
 
1229
 
1230
  foreach ($data['all']['scripts'] as $key => $obj) {
1231
  if (! isset($obj->handle)) {
1232
+ unset($data['all']['scripts']['']);
1233
  continue;
1234
  }
1235
 
1314
  } elseif ($postId > 0) {
1315
  $this->assetsRemoved = get_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_no_load', true);
1316
  }
 
1317
 
1318
+ if ($this->assetsRemoved == '') {
1319
+ $this->assetsRemoved = array('styles' => array(), 'scripts' => array());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1320
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1321
  }
1322
+
1323
+ return $this->assetsRemoved;
1324
  }
1325
 
1326
  /**
classes/Menu.php CHANGED
@@ -28,7 +28,7 @@ class Menu
28
  __('WP Asset Clean Up', WPACU_PLUGIN_NAME),
29
  $capability,
30
  $menuSlug,
31
- array(Settings::instance(), 'page'),
32
  plugin_dir_url(WPACU_PLUGIN_FILE).'/assets/img/icon-clean-up.png'
33
  );
34
 
28
  __('WP Asset Clean Up', 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
 
classes/PluginManager.php DELETED
@@ -1,10 +0,0 @@
1
- <?php
2
- namespace WpAssetCleanUp;
3
-
4
- class PluginManager
5
- {
6
- public static function init()
7
- {
8
-
9
- }
10
- }
 
 
 
 
 
 
 
 
 
 
classes/Settings.php CHANGED
@@ -1,41 +1,40 @@
1
  <?php
2
  namespace WpAssetCleanUp;
3
 
 
 
 
 
4
  class Settings
5
  {
6
  /**
7
- * @var Settings|null
8
  */
9
- private static $singleton = null;
10
-
11
- /**
12
- * @return null|Settings
13
- */
14
- public static function instance()
15
- {
16
- if (is_null(self::$singleton)) {
17
- self::$singleton = new self();
18
- }
19
-
20
- return self::$singleton;
21
- }
22
-
23
  public function __construct()
24
  {
25
  add_action('admin_init', array($this, 'registerSettings'));
26
  }
27
 
 
 
 
28
  public function registerSettings()
29
  {
30
  // Register settings
31
  register_setting('wpacu-plugin-settings-group', WPACU_PLUGIN_NAME.'_frontend_show');
 
 
 
32
  }
33
 
34
- public function page()
 
 
 
35
  {
36
  $data = array();
37
 
38
- $data['frontend_show'] = esc_attr(get_option(WPACU_PLUGIN_NAME.'_frontend_show'));
39
 
40
  Main::instance()->parseTemplate('settings-plugin', $data, true);
41
  }
1
  <?php
2
  namespace WpAssetCleanUp;
3
 
4
+ /**
5
+ * Class Settings
6
+ * @package 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
 
37
+ $data['frontend_show'] = get_option(WPACU_PLUGIN_NAME.'_frontend_show');
38
 
39
  Main::instance()->parseTemplate('settings-plugin', $data, true);
40
  }
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: http://www.gabelivan.com/donate/
5
  Requires at least: 4.0
6
- Tested up to: 4.4
7
- Stable tag: trunk
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
@@ -68,17 +68,38 @@ 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
  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.
72
  In case the assets are not loading for you, please write me on the forum and I will be happy to assist you!
73
 
 
 
 
 
 
 
 
 
 
 
74
  == Screenshots ==
75
  1. When editing a post/page (custom post type as well) a meta box will load with the asset list
76
  2. Styles (.CSS) loaded for the home page when accessing the "WP Asset Clean Up" Dashboard's menu
77
  3. Scripts (.JS) loaded for the home page having an alert message when accessing the "WP Asset Clean Up" Dashboard's menu
 
78
 
79
  == Changelog ==
 
 
 
 
 
80
  = 1.1.4.6 =
81
  * Now the asset list can be updated on the front-end (below the loaded page, post, front page) if feature is enabled in the "Settings"
 
82
 
83
  = 1.1.4.5 =
84
  * Some assets containing specific ASCII characters in the URL were not shown. This is solved now and they will show fine in the list.
3
  Tags: speed, pagespeed, dequeue style, dequeue script, unload style, unload script, fast
4
  Donate link: http://www.gabelivan.com/donate/
5
  Requires at least: 4.0
6
+ Tested up to: 4.5
7
+ Stable tag: 1.2
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
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 Clean Up", 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 Clean Up" 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 Clean Up.
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.
87
+
88
  == Screenshots ==
89
  1. When editing a post/page (custom post type as well) a meta box will load with the asset list
90
  2. Styles (.CSS) loaded for the home page when accessing the "WP Asset Clean Up" Dashboard's menu
91
  3. Scripts (.JS) loaded for the home page having an alert message when accessing the "WP Asset Clean Up" Dashboard's menu
92
+ 4. Scripts (.JS) are selected for site-wide unload
93
 
94
  == Changelog ==
95
+ = 1.2 =
96
+ * Disable assets site-wide
97
+ * Add exceptions on pages where assets should load (if they are disabled everywhere)
98
+ * Bug Fix: Sometimes, due to website caching services/plugins, the HTML comments are removed needed from getting the assets
99
+
100
  = 1.1.4.6 =
101
  * Now the asset list can be updated on the front-end (below the loaded page, post, front page) if feature is enabled in the "Settings"
102
+ * The assets URL is now clickable and loads the CSS/JS file in a new tab
103
 
104
  = 1.1.4.5 =
105
  * Some assets containing specific ASCII characters in the URL were not shown. This is solved now and they will show fine in the list.
templates/meta-box-loaded.php CHANGED
@@ -15,8 +15,8 @@ if (! isset($data)) {
15
  <?php
16
  if (! empty($data['all']['styles'])) {
17
  ?>
18
- <p><?php echo sprintf(__('The following styles are loading on this page. Please select the ones that are %sNOT NEEDED%s. If you are not sure which ones to unload, it is better to leave them enabled and consult with a developer about unloading the assets.', WPACU_PLUGIN_NAME), '<span style="color: #CC0000;"><strong>', '</strong></span>'); ?></p>
19
-
20
  <?php
21
  if ($data['core_styles_loaded']) {
22
  ?>
@@ -39,9 +39,23 @@ if (! empty($data['all']['styles'])) {
39
 
40
  $class = ($active) ? 'wpacu_not_load' : '';
41
  $checked = ($active) ? 'checked="checked"' : '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ?>
43
  <tr class="wpacu_asset_row <?php echo $class; ?>">
44
- <td scope="row" class="wpacu_check check-column" valign="top"><input id="style_<?php echo $obj->handle; ?>" <?php echo $checked; ?> name="<?php echo WPACU_PLUGIN_NAME; ?>[styles][]" class="icheckbox_square-red" type="checkbox" value="<?php echo $obj->handle; ?>" /></td>
45
  <td valign="top" style="width: 100%;">
46
  <p style="margin-top: 0px;">
47
  <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>
@@ -58,6 +72,60 @@ if (! empty($data['all']['styles'])) {
58
  ?>
59
  </p>
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  <?php
62
  if (isset($obj->src) && $obj->src != '') {
63
  ?>
@@ -96,7 +164,7 @@ if (! empty($data['all']['styles'])) {
96
  if (! empty($data['all']['scripts'])) {
97
  ?>
98
  <p><?php echo sprintf(__('The following scripts are loading on this page. Please select the ones that are %sNOT NEEDED%s. If you are not sure which ones to unload, it is better to leave them enabled and consult with a developer about unloading the assets.', WPACU_PLUGIN_NAME), '<span style="color: #CC0000;"><strong>', '</strong></span>'); ?></p>
99
-
100
  <?php
101
  if ($data['core_scripts_loaded']) {
102
  ?>
@@ -119,12 +187,26 @@ if (! empty($data['all']['scripts'])) {
119
 
120
  $class = ($active) ? 'wpacu_not_load' : '';
121
  $checked = ($active) ? 'checked="checked"' : '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  ?>
123
  <tr class="wpacu_asset_row <?php echo $class; ?>">
124
- <td scope="row" class="wpacu_check check-column" valign="top"><input id="script_<?php echo $obj->handle; ?>" <?php echo $checked; ?> name="<?php echo WPACU_PLUGIN_NAME; ?>[scripts][]" class="icheckbox_square-red" type="checkbox" value="<?php echo $obj->handle; ?>" /></td>
125
  <td valign="top" style="width: 100%;">
126
  <p style="margin-top: 0px;">
127
- <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>
128
  <?php
129
  if (isset($obj->wp) && $obj->wp) {
130
  ?>
@@ -137,6 +219,61 @@ if (! empty($data['all']['scripts'])) {
137
  }
138
  ?>
139
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  <?php
141
  if (isset($obj->src) && $obj->src != '') {
142
  ?>
15
  <?php
16
  if (! empty($data['all']['styles'])) {
17
  ?>
18
+ <p><?php echo sprintf(__('The following styles are loading on this page. Please select the ones that are %sNOT NEEDED%s. If you are not sure which ones to unload, it is better to leave them enabled (unchecked) and consult with a developer about unloading the assets.', WPACU_PLUGIN_NAME), '<span style="color: #CC0000;"><strong>', '</strong></span>'); ?></p>
19
+ <p><?php echo __('"Load in on this page (make exception)" will take effect when "Unload everywhere" is used. Otherwise, the asset will load anyway unless you select it for unload.', WPACU_PLUGIN_NAME); ?></p>
20
  <?php
21
  if ($data['core_styles_loaded']) {
22
  ?>
39
 
40
  $class = ($active) ? 'wpacu_not_load' : '';
41
  $checked = ($active) ? 'checked="checked"' : '';
42
+
43
+ $globalUnloaded = $isLoadException = false;
44
+
45
+ // mark it as unloaded - global
46
+ if (in_array($obj->handle, $data['global_unload']['styles']) && !$class) {
47
+ $globalUnloaded = true;
48
+ $checked = 'checked="checked"';
49
+
50
+ if (in_array($obj->handle, $data['load_exceptions']['styles'])) {
51
+ $isLoadException = true;
52
+ } else {
53
+ $class .= ' wpacu_not_load';
54
+ }
55
+ }
56
  ?>
57
  <tr class="wpacu_asset_row <?php echo $class; ?>">
58
+ <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>
59
  <td valign="top" style="width: 100%;">
60
  <p style="margin-top: 0px;">
61
  <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>
72
  ?>
73
  </p>
74
 
75
+ <?php
76
+ if ($globalUnloaded) {
77
+ ?>
78
+ <p><strong style="color: #d54e21;">This asset is unloaded everywhere</strong></p>
79
+ <?php
80
+ }
81
+ ?>
82
+
83
+ <ul class="wpacu_asset_options">
84
+ <?php
85
+ if ($globalUnloaded) {
86
+ ?>
87
+ <li>
88
+ <label><input data-handle="<?php echo $obj->handle; ?>"
89
+ class="wpacu_global_option wpacu_style"
90
+ type="radio"
91
+ name="wpacu_options_styles[<?php echo $obj->handle; ?>]"
92
+ checked="checked"
93
+ value="default" />
94
+ Keep the unload global rule</label>
95
+ </li>
96
+
97
+ <li>
98
+ <label><input data-handle="<?php echo $obj->handle; ?>"
99
+ class="wpacu_global_option wpacu_style"
100
+ type="radio"
101
+ name="wpacu_options_styles[<?php echo $obj->handle; ?>]"
102
+ value="remove" />
103
+ Remove global unload rule</label>
104
+ </li>
105
+ <?php
106
+ } else {
107
+ ?>
108
+ <li>
109
+ <label><input data-handle="<?php echo $obj->handle; ?>"
110
+ class="wpacu_global_unload wpacu_global_style"
111
+ id="wpacu_global_unload_style_<?php echo $obj->handle; ?>" type="checkbox"
112
+ name="wpacu_global_unload_styles[]" value="<?php echo $obj->handle; ?>"/>
113
+ &nbsp;Unload Everywhere</label>
114
+ </li>
115
+ <?php
116
+ }
117
+ ?>
118
+ <li id="wpacu_load_it_option_style_<?php echo $obj->handle; ?>">
119
+ <label><input data-handle="<?php echo $obj->handle; ?>"
120
+ id="wpacu_style_load_it_<?php echo $obj->handle; ?>"
121
+ class="wpacu_load_it_option wpacu_style wpacu_load_exception"
122
+ type="checkbox"
123
+ <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
124
+ name="wpacu_styles_load_it[]"
125
+ value="<?php echo $obj->handle; ?>"/>
126
+ Load it on this page (make exception<?php if (! $globalUnloaded) { echo ' IF unloaded everywhere is chosen'; } ?>)</label>
127
+ </li>
128
+ </ul>
129
  <?php
130
  if (isset($obj->src) && $obj->src != '') {
131
  ?>
164
  if (! empty($data['all']['scripts'])) {
165
  ?>
166
  <p><?php echo sprintf(__('The following scripts are loading on this page. Please select the ones that are %sNOT NEEDED%s. If you are not sure which ones to unload, it is better to leave them enabled and consult with a developer about unloading the assets.', WPACU_PLUGIN_NAME), '<span style="color: #CC0000;"><strong>', '</strong></span>'); ?></p>
167
+ <p><?php echo __('"Load in on this page (make exception)" will take effect when "Unload everywhere" is used. Otherwise, the asset will load anyway unless you select it for unload.', WPACU_PLUGIN_NAME); ?></p>
168
  <?php
169
  if ($data['core_scripts_loaded']) {
170
  ?>
187
 
188
  $class = ($active) ? 'wpacu_not_load' : '';
189
  $checked = ($active) ? 'checked="checked"' : '';
190
+
191
+ $globalUnloaded = $isLoadException = false;
192
+
193
+ // mark it as unloaded - global
194
+ if (in_array($obj->handle, $data['global_unload']['scripts']) && !$class) {
195
+ $globalUnloaded = true;
196
+ $checked = 'checked="checked"';
197
+
198
+ if (in_array($obj->handle, $data['load_exceptions']['scripts'])) {
199
+ $isLoadException = true;
200
+ } else {
201
+ $class .= ' wpacu_not_load';
202
+ }
203
+ }
204
  ?>
205
  <tr class="wpacu_asset_row <?php echo $class; ?>">
206
+ <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>
207
  <td valign="top" style="width: 100%;">
208
  <p style="margin-top: 0px;">
209
+ <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>
210
  <?php
211
  if (isset($obj->wp) && $obj->wp) {
212
  ?>
219
  }
220
  ?>
221
  </p>
222
+ <?php
223
+ if ($globalUnloaded) {
224
+ ?>
225
+ <p><strong style="color: #d54e21;">This asset is unloaded everywhere</strong></p>
226
+ <?php } ?>
227
+
228
+ <ul class="wpacu_asset_options">
229
+
230
+ <?php
231
+ if ($globalUnloaded) {
232
+ ?>
233
+ <li>
234
+ <label><input data-handle="<?php echo $obj->handle; ?>"
235
+ class="wpacu_global_option wpacu_script"
236
+ type="radio"
237
+ name="wpacu_options_scripts[<?php echo $obj->handle; ?>]"
238
+ checked="checked"
239
+ value="default" />
240
+ Keep the unload global rule</label>
241
+ </li>
242
+
243
+ <li>
244
+ <label><input data-handle="<?php echo $obj->handle; ?>"
245
+ class="wpacu_global_option wpacu_script"
246
+ type="radio"
247
+ name="wpacu_options_scripts[<?php echo $obj->handle; ?>]"
248
+ value="remove" />
249
+ Remove global unload rule</label>
250
+ </li>
251
+ <?php
252
+ } else {
253
+ ?>
254
+ <li>
255
+ <label><input data-handle="<?php echo $obj->handle; ?>"
256
+ class="wpacu_global_unload wpacu_global_script"
257
+ id="wpacu_global_unload_script_<?php echo $obj->handle; ?>"
258
+ type="checkbox"
259
+ name="wpacu_global_unload_scripts[]"
260
+ value="<?php echo $obj->handle; ?>"/>
261
+ &nbsp;Unload Everywhere</label>
262
+ </li>
263
+ <?php
264
+ }
265
+ ?>
266
+ <li id="wpacu_load_it_option_script_<?php echo $obj->handle; ?>">
267
+ <label><input data-handle="<?php echo $obj->handle; ?>"
268
+ id="wpacu_script_load_it_<?php echo $obj->handle; ?>"
269
+ class="wpacu_load_it_option wpacu_script wpacu_load_exception"
270
+ type="checkbox"
271
+ name="wpacu_scripts_load_it[]"
272
+ <?php if ($isLoadException) { ?> checked="checked" <?php } ?>
273
+ value="<?php echo $obj->handle; ?>" />
274
+ Load it on this page (make exception<?php if (! $globalUnloaded) { echo ' IF unloaded everywhere is chosen'; } ?>)</label>
275
+ </li>
276
+ </ul>
277
  <?php
278
  if (isset($obj->src) && $obj->src != '') {
279
  ?>
templates/meta-box.php CHANGED
@@ -12,6 +12,11 @@ if (! isset($data)) {
12
  ?>
13
  <img src="<?php echo admin_url(); ?>/images/spinner.gif" align="top" width="20" height="20" alt="" />&nbsp;
14
  <?php echo sprintf(__('Fetching the loaded scripts and styles for <strong>%s</strong> <br /><br /> Please wait... <br /><br /> In case the list does not show consider checking your internet connection and the actual page that is being fetched to see if it loads completely.', WPACU_PLUGIN_NAME), $data['fetch_url']); ?>
 
 
 
 
 
15
  <?php
16
  } else {
17
  _e('The styles and scripts will be available for unload once this post/page is <strong>public</strong> and <strong>publish</strong>ed as the whole page needs to be scanned for all the loaded assets.', WPACU_PLUGIN_NAME);
12
  ?>
13
  <img src="<?php echo admin_url(); ?>/images/spinner.gif" align="top" width="20" height="20" alt="" />&nbsp;
14
  <?php echo sprintf(__('Fetching the loaded scripts and styles for <strong>%s</strong> <br /><br /> Please wait... <br /><br /> In case the list does not show consider checking your internet connection and the actual page that is being fetched to see if it loads completely.', WPACU_PLUGIN_NAME), $data['fetch_url']); ?>
15
+ <p><?php echo sprintf(
16
+ __('If you believe fetching the page takes too long and the assets should have loaded by now, I suggest you go to "Settings", make sure "Manage in front-end" is checked and then %smanage the assets in the front-end%s.', WPACU_PLUGIN_NAME),
17
+ '<a href="'.$data['fetch_url'].'#wpacu_wrap_assets">',
18
+ '</a>'
19
+ ); ?></p>
20
  <?php
21
  } else {
22
  _e('The styles and scripts will be available for unload once this post/page is <strong>public</strong> and <strong>publish</strong>ed as the whole page needs to be scanned for all the loaded assets.', WPACU_PLUGIN_NAME);
templates/settings-home-page.php CHANGED
@@ -51,6 +51,13 @@ if ($data['show_on_front'] === 'page') {
51
  <img src="<?php echo admin_url(); ?>/images/spinner.gif" align="top" width="20" height="20" alt="" />&nbsp;
52
  <?php _e('We\'re getting the loaded scripts and styles for the home page. Please wait...', WPACU_PLUGIN_NAME); ?>
53
  </div>
 
 
 
 
 
 
 
54
  <input type="hidden" name="<?php echo $data['nonce_name']; ?>" value="<?php echo $data['nonce_value']; ?>" />
55
  <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>
56
  </form>
51
  <img src="<?php echo admin_url(); ?>/images/spinner.gif" align="top" width="20" height="20" alt="" />&nbsp;
52
  <?php _e('We\'re getting the loaded scripts and styles for the home page. Please wait...', WPACU_PLUGIN_NAME); ?>
53
  </div>
54
+
55
+ <p><?php echo sprintf(
56
+ __('If you believe fetching the page takes too long and the assets should have loaded by now, I suggest you go to "Settings", make sure "Manage in front-end" is checked and then %smanage the assets in the front-end%s.', WPACU_PLUGIN_NAME),
57
+ '<a href="'.$data['site_url'].'#wpacu_wrap_assets">',
58
+ '</a>'
59
+ ); ?></p>
60
+
61
  <input type="hidden" name="<?php echo $data['nonce_name']; ?>" value="<?php echo $data['nonce_value']; ?>" />
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>
wpacu-load.php CHANGED
@@ -16,7 +16,6 @@ function includeWpAssetCleanUpClassesAutoload($class)
16
  'WpAssetCleanUp\ClassLoader' => 'ClassLoader',
17
  'WpAssetCleanUp\HomePage' => 'HomePage',
18
  'WpAssetCleanUp\Main' => 'Main',
19
- 'WpAssetCleanUp\PluginManager' => 'PluginManager',
20
  'WpAssetCleanUp\Menu' => 'Menu',
21
  'WpAssetCleanUp\Settings' => 'Settings'
22
  );
@@ -35,14 +34,11 @@ function includeWpAssetCleanUpClassesAutoload($class)
35
  spl_autoload_register('includeWpAssetCleanUpClassesAutoload');
36
 
37
  // Main Class
38
- new WpAssetCleanUp\Main;
39
 
40
  // Settings
41
  new WpAssetCleanUp\Settings;
42
 
43
- // Plugin Manager
44
- WpAssetCleanUp\PluginManager::init();
45
-
46
  // Menu
47
  $wpacuMenu = new \WpAssetCleanUp\Menu;
48
  $wpacuMenu->init();
16
  'WpAssetCleanUp\ClassLoader' => 'ClassLoader',
17
  'WpAssetCleanUp\HomePage' => 'HomePage',
18
  'WpAssetCleanUp\Main' => 'Main',
 
19
  'WpAssetCleanUp\Menu' => 'Menu',
20
  'WpAssetCleanUp\Settings' => 'Settings'
21
  );
34
  spl_autoload_register('includeWpAssetCleanUpClassesAutoload');
35
 
36
  // Main Class
37
+ WpAssetCleanUp\Main::instance();
38
 
39
  // Settings
40
  new WpAssetCleanUp\Settings;
41
 
 
 
 
42
  // Menu
43
  $wpacuMenu = new \WpAssetCleanUp\Menu;
44
  $wpacuMenu->init();
wpacu.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  * Plugin Name: WP Asset Clean Up
4
  * Plugin URI: http://www.bitrepository.com/remove-unused-scripts-styles-wordpress-pages.html
5
- * Version: 1.1.4.6
6
  * Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages that you don't need
7
  * Author: Gabriel Livan
8
  * Author URI: http://www.gabelivan.com/
2
  /*
3
  * Plugin Name: WP Asset Clean Up
4
  * Plugin URI: http://www.bitrepository.com/remove-unused-scripts-styles-wordpress-pages.html
5
+ * Version: 1.2
6
  * Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages that you don't need
7
  * Author: Gabriel Livan
8
  * Author URI: http://www.gabelivan.com/