Asset CleanUp: Page Speed Booster - Version 1.2.4

Version Description

  • Bug Fix: Remove "Unload everywhere" rule had to be updated to work no matter what key is assigned to the handle in the array resulting from the JSON
Download this release

Release Info

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

Code changes from version 1.2.1 to 1.2.4

assets/icheck/icheck.min.js CHANGED
File without changes
assets/icheck/skins/square/red.css CHANGED
File without changes
assets/icheck/skins/square/red.png CHANGED
File without changes
assets/icheck/skins/square/red@2x.png CHANGED
File without changes
assets/script.js CHANGED
@@ -7,7 +7,7 @@ jQuery(document).ready(function($) {
7
//
8
var WpAssetCleanUp = {
9
load: function() {
10
- var cbSelector = '.icheckbox_square-red';
11
12
$(cbSelector).iCheck({
13
checkboxClass: 'icheckbox_square-red',
@@ -22,39 +22,44 @@ jQuery(document).ready(function($) {
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;
@@ -67,10 +72,10 @@ jQuery(document).ready(function($) {
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
}
@@ -79,9 +84,19 @@ jQuery(document).ready(function($) {
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')) {
@@ -89,13 +104,14 @@ jQuery(document).ready(function($) {
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
}
@@ -103,6 +119,22 @@ jQuery(document).ready(function($) {
103
}
104
};
105
106
//
107
// Asset Front-end Edit (if setting is enabled)
108
//
7
//
8
var WpAssetCleanUp = {
9
load: function() {
10
+ var cbSelector = '.icheckbox_square-red', handle;
11
12
$(cbSelector).iCheck({
13
checkboxClass: 'icheckbox_square-red',
22
$(event.target).closest('tr').removeClass('wpacu_not_load');
23
});
24
25
// Unload Everywhere
26
$('.wpacu_global_unload').click(function() {
27
handle = $(this).attr('data-handle');
28
29
if ($(this).prop('checked')) {
30
$(this).parent('label').addClass('wpacu_global_checked');
31
+ //$(this).closest('tr').addClass('wpacu_not_load');
32
33
+ /*
34
if ($(this).hasClass('wpacu_global_style')) {
35
$('#style_' + handle).iCheck('check').iCheck('disable');
36
} else if($(this).hasClass('wpacu_global_script')) {
37
$('#script_' + handle).iCheck('check').iCheck('disable');
38
}
39
+ */
40
} else {
41
$(this).parent('label').removeClass('wpacu_global_checked');
42
+ //$(this).closest('tr').removeClass('wpacu_not_load');
43
44
+ /*
45
if ($(this).hasClass('wpacu_global_style')) {
46
$('#style_' + handle).iCheck('uncheck').iCheck('enable');
47
} else if($(this).hasClass('wpacu_global_script')) {
48
$('#script_' + handle).iCheck('uncheck').iCheck('enable');
49
}
50
+ */
51
52
+ /*
53
// Un-check make exception as it is not relevant
54
// if unload everywhere is selected
55
$('#wpacu_style_load_it_' + handle)
56
.prop('checked', false)
57
.parent('label').removeClass('wpacu_global_unload_exception');
58
+ */
59
}
60
});
61
62
+ /*
63
// Asset Global Options
64
$('.wpacu_global_option').click(function() {
65
var handle = $(this).attr('data-handle'), handleType;
72
73
if ($(this).val() == 'remove') {
74
$(this).closest('tr').removeClass('wpacu_not_load');
75
$('#wpacu_load_it_option_'+ handleType +'_'+ handle).hide();
76
+ }
77
78
+ if ($(this).val() == 'default'
79
&& !$('#wpacu_'+ handleType +'_load_it_'+ handle).prop('checked')) {
80
$(this).closest('tr').addClass('wpacu_not_load');
81
}
84
$('#wpacu_load_it_option_'+ handleType + '_' + handle).show();
85
}
86
});
87
+ */
88
+
89
+ $('.wpacu_post_type_unload').click(function() {
90
+ if ($(this).prop('checked')) {
91
+ $(this).parent('label').addClass('wpacu_post_type_unload_active');
92
+ } else {
93
+ $(this).parent('label').removeClass('wpacu_post_type_unload_active');
94
+ }
95
+ });
96
97
// Load it checkbox
98
$('.wpacu_load_it_option').click(function() {
99
+ /*
100
var handle = $(this).attr('data-handle'), wpacu_input_name;
101
102
if ($(this).hasClass('wpacu_style')) {
104
} else if ($(this).hasClass('wpacu_script')) {
105
wpacu_input_name = 'wpacu_options_scripts['+ handle +']';
106
}
107
+ */
108
109
if ($(this).prop('checked')) {
110
$(this).parent('label').addClass('wpacu_global_unload_exception');
111
+ //$(this).closest('tr').removeClass('wpacu_not_load');
112
+ ///} else if ($('input[name="'+ wpacu_input_name +'"]:checked').val() == 'default') {
113
+ // $(this).parent('label').removeClass('wpacu_global_unload_exception');
114
+ //$(this).closest('tr').addClass('wpacu_not_load');
115
} else {
116
$(this).parent('label').removeClass('wpacu_global_unload_exception');
117
}
119
}
120
};
121
122
+ $('#wpacu_post_type_select').change(function() {
123
+ $('#wpacu_post_type_form').submit();
124
+ });
125
+
126
+ // Items are marked for removal from the unload list
127
+ // from either "Everywhere" or "Post Type"
128
+ $('.wpacu_remove_rule').click(function() {
129
+ var $wpacuGlobalRuleRow = $(this).parents('.wpacu_global_rule_row');
130
+
131
+ if ($(this).prop('checked')) {
132
+ $wpacuGlobalRuleRow.addClass('selected');
133
+ } else {
134
+ $wpacuGlobalRuleRow.removeClass('selected');
135
+ }
136
+ });
137
+
138
//
139
// Asset Front-end Edit (if setting is enabled)
140
//
assets/script.min.js ADDED
@@ -0,0 +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())})})});
assets/style.css CHANGED
@@ -1,156 +1,63 @@
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
- .wp-asset-clean-up.widefat {
112
- width: 99%; }
113
-
114
- .wpacu_widefat {
115
- border: 1px solid #e5e5e5 !important; }
116
- .wpacu_widefat td {
117
- border: 1px solid #e5e5e5 !important; }
118
-
119
- .wpacu_striped > tbody > :nth-child(odd), ul.wpacu_striped > :nth-child(odd) {
120
- background-color: #f9f9f9 !important; }
121
-
122
- .wpacu_update_btn {
123
- -moz-box-shadow: inset 0 1px 0 0 #54a3f7 !important;
124
- -webkit-box-shadow: inset 0 1px 0 0 #54a3f7 !important;
125
- box-shadow: inset 0 1px 0 0 #54a3f7 !important;
126
- background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7)) !important;
127
- background: -moz-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
128
- background: -webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
129
- background: -o-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
130
- background: -ms-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
131
- background: linear-gradient(to bottom, #007dc1 5%, #0061a7 100%) !important;
132
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0) !important;
133
- background-color: #007dc1 !important;
134
- -moz-border-radius: 3px !important;
135
- -webkit-border-radius: 3px !important;
136
- border-radius: 3px !important;
137
- border: 1px solid #124d77 !important;
138
- display: inline-block !important;
139
- cursor: pointer !important;
140
- color: #ffffff !important;
141
- font-size: 15px !important;
142
- padding: 10px 24px !important;
143
- text-decoration: none !important;
144
- text-shadow: 0 1px 0 #154682 !important; }
145
- .wpacu_update_btn:hover {
146
- background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1)) !important;
147
- background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
148
- background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
149
- background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
150
- background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
151
- background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%) !important;
152
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0) !important;
153
- background-color: #0061a7 !important; }
154
- .wpacu_update_btn:active {
155
- position: relative !important;
156
- top: 1px !important; }
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 ADDED
@@ -0,0 +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}
assets/style.scss ADDED
@@ -0,0 +1,218 @@
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 !important;
131
+ }
132
+
133
+ &.wpacu_post_type_unload_active {
134
+ color: #d54e21;
135
+ }
136
+ }
137
+
138
+ tr.wpacu_global_rule_row {
139
+ &.selected {
140
+ background: #e7e7e7;
141
+ }
142
+ }
143
+
144
+ .nav-tab-wrapper {
145
+ border-bottom: 1px solid #ccc;
146
+ width: 95%;
147
+ }
148
+
149
+ ul.wpacu_asset_options {
150
+ margin: 0;
151
+ padding: 0;
152
+ li {
153
+ list-style: none;
154
+ display: inline-block;
155
+ }
156
+ label {
157
+ margin-right: 20px;
158
+ font-weight: normal;
159
+ input {
160
+ margin-right: 4px;
161
+ }
162
+ }
163
+ }
164
+
165
+ /* Assets Table */
166
+ .wp-asset-clean-up.widefat {
167
+ width: 99%;
168
+ }
169
+
170
+ .wpacu_widefat {
171
+ border: 1px solid #e5e5e5 !important;
172
+ td {
173
+ border: 1px solid #e5e5e5 !important;
174
+ }
175
+ }
176
+
177
+ .wpacu_striped > tbody > :nth-child(odd), ul.wpacu_striped > :nth-child(odd) {
178
+ background-color: #f9f9f9 !important;
179
+ }
180
+
181
+ .wpacu_update_btn {
182
+ -moz-box-shadow: inset 0 1px 0 0 #54a3f7 !important;
183
+ -webkit-box-shadow: inset 0 1px 0 0 #54a3f7 !important;
184
+ box-shadow: inset 0 1px 0 0 #54a3f7 !important;
185
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7)) !important;
186
+ background: -moz-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
187
+ background: -webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
188
+ background: -o-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
189
+ background: -ms-linear-gradient(top, #007dc1 5%, #0061a7 100%) !important;
190
+ background: linear-gradient(to bottom, #007dc1 5%, #0061a7 100%) !important;
191
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0) !important;
192
+ background-color: #007dc1 !important;
193
+ -moz-border-radius: 3px !important;
194
+ -webkit-border-radius: 3px !important;
195
+ border-radius: 3px !important;
196
+ border: 1px solid #124d77 !important;
197
+ display: inline-block !important;
198
+ cursor: pointer !important;
199
+ color: #ffffff !important;
200
+ font-size: 15px !important;
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;
207
+ background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
208
+ background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
209
+ background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%) !important;
210
+ background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%) !important;
211
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0) !important;
212
+ background-color: #0061a7 !important;
213
+ }
214
+ &:active {
215
+ position: relative !important;
216
+ top: 1px !important;
217
+ }
218
+ }
classes/GlobalRules.php ADDED
@@ -0,0 +1,129 @@
1
+ <?php
2
+ namespace WpAssetCleanUp;
3
+
4
+ /**
5
+ * Class GlobalRules
6
+ * @package WpAssetCleanUp
7
+ */
8
+ class GlobalRules
9
+ {
10
+ /**
11
+ * @var string
12
+ */
13
+ public $wpacuFor = 'everywhere';
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ public $wpacuPostType = 'post';
19
+
20
+ /**
21
+ * @var array
22
+ */
23
+ public $data = array();
24
+
25
+ /**
26
+ * GlobalRules constructor.
27
+ */
28
+ public function __construct()
29
+ {
30
+ $this->wpacuFor = isset($_REQUEST['wpacu_for'])
31
+ ? $_REQUEST['wpacu_for']
32
+ : $this->wpacuFor;
33
+
34
+ $this->wpacuPostType = isset($_REQUEST['wpacu_post_type'])
35
+ ? $_REQUEST['wpacu_post_type']
36
+ : $this->wpacuPostType;
37
+
38
+ if (isset($_REQUEST['wpacu_update']) && $_REQUEST['wpacu_update'] == 1) {
39
+ $this->update();
40
+ }
41
+ }
42
+
43
+ /**
44
+ * @return array
45
+ */
46
+ public function getCount()
47
+ {
48
+ $values = array();
49
+
50
+ if ($this->wpacuFor === 'everywhere') {
51
+ $values = Main::instance()->getGlobalUnload();
52
+ } elseif ($this->wpacuFor === 'post_types') {
53
+ $values = Main::instance()->getPostTypeUnload($this->wpacuPostType);
54
+ }
55
+
56
+ return $values;
57
+ }
58
+
59
+ /**
60
+ *
61
+ */
62
+ public function page()
63
+ {
64
+ $this->data['for'] = $this->wpacuFor;
65
+
66
+ if ($this->wpacuFor === 'post_types') {
67
+ $this->data['post_type'] = $this->wpacuPostType;
68
+
69
+ // Get All Post Types
70
+ $postTypes = get_post_types(array('public' => true));
71
+ $this->data['post_types_list'] = $postTypes;
72
+ }
73
+
74
+ $this->data['values'] = $this->getCount();
75
+
76
+ $this->data['nonce_name'] = Update::NONCE_FIELD_NAME;
77
+ $this->data['nonce_action'] = Update::NONCE_ACTION_NAME;
78
+
79
+ Main::instance()->parseTemplate('settings-globals', $this->data, true);
80
+ }
81
+
82
+ /**
83
+ *
84
+ */
85
+ public function update()
86
+ {
87
+ if ($this->wpacuFor === 'everywhere') {
88
+ $removed = (new Update)->removeEverywhereUnloads();
89
+
90
+ if ($removed) {
91
+ add_action('admin_notices', array($this, 'noticeGlobalsRemoved'));
92
+ }
93
+ }
94
+
95
+ if ($this->wpacuFor === 'post_types') {
96
+ $removed = (new Update)->removeBulkUnloads($this->wpacuPostType);
97
+
98
+ if ($removed) {
99
+ add_action('admin_notices', array($this, 'noticePostTypesRemoved'));
100
+ }
101
+ }
102
+ }
103
+
104
+ /**
105
+ *
106
+ */
107
+ public function noticeGlobalsRemoved()
108
+ {
109
+ ?>
110
+ <div class="updated notice is-dismissible">
111
+ <p>The selected styles/scripts were removed from the global unload list and they will now load in the pages/posts,
112
+ unless you have other rules that would prevent them from loading.</p>
113
+ </div>
114
+ <?php
115
+ }
116
+
117
+ /**
118
+ *
119
+ */
120
+ public function noticePostTypesRemoved()
121
+ {
122
+ ?>
123
+ <div class="updated notice is-dismissible">
124
+ <p>The selected styles/scripts were removed from the unload list for <strong><u><?php echo $this->wpacuPostType; ?></u></strong>
125
+ post type and they will now load in the pages/posts, unless you have other rules that would prevent them from loading.</p>
126
+ </div>
127
+ <?php
128
+ }
129
+ }
classes/HomePage.php CHANGED
@@ -20,59 +20,36 @@ class HomePage
20
$this->data['nonce_name'] = WPACU_PLUGIN_NAME.'_settings';
21
$this->data['show_on_front'] = get_option('show_on_front');
22
23
- if (isset($_GET['page']) && $_GET['page'] == WPACU_PLUGIN_NAME.'_home_page') {
24
25
- if ($this->data['show_on_front'] === 'page') {
26
- // Front page displays: A Static Page
27
- $this->data['page_on_front'] = get_option('page_on_front');
28
-
29
- if ($this->data['page_on_front']) {
30
- $this->data['page_on_front_title'] = get_the_title($this->data['page_on_front']);
31
- }
32
33
- $this->data['page_for_posts'] = get_option('page_for_posts');
34
35
- if ($this->data['page_for_posts']) {
36
- $this->data['page_for_posts_title'] = get_the_title($this->data['page_for_posts']);
37
- }
38
- } elseif ($this->data['show_on_front'] === 'posts') {
39
- // Your latest posts
40
- $postUrl = get_option('siteurl');
41
42
- if (substr($postUrl, -1) != '/') {
43
- $postUrl .= '/';
44
- }
45
46
- $this->data['site_url'] = $postUrl;
47
-
48
- add_action('admin_enqueue_scripts', array(Main::instance(), 'stylesAndScriptsForAdmin'));
49
}
50
- }
51
- }
52
-
53
- /**
54
- * @param $wpacuNoLoadAssets
55
- */
56
- public static function updateFrontPage($wpacuNoLoadAssets)
57
- {
58
- if (! is_array($wpacuNoLoadAssets)) {
59
- return; // only arrays (empty or not) should be used
60
- }
61
62
- $jsonNoAssetsLoadList = json_encode($wpacuNoLoadAssets);
63
64
- if (! update_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList)) {
65
- add_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList);
66
}
67
-
68
- // If globally disabled, make exception to load for submitted assets
69
- Main::instance()->saveLoadExceptions('front_page');
70
-
71
- // Any global unloads?
72
- Main::instance()->saveToGlobalUnload();
73
-
74
- // Any global unloads removed?
75
- Main::instance()->removeGlobalUnloads();
76
}
77
78
/**
@@ -87,7 +64,7 @@ class HomePage
87
? $_POST[$this->data['nonce_name']] : '';
88
89
if (is_array($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
90
- $this->updateFrontPage($wpacuNoLoadAssets);
91
}
92
93
$this->data['nonce_value'] = wp_create_nonce($this->data['nonce_name']);
20
$this->data['nonce_name'] = WPACU_PLUGIN_NAME.'_settings';
21
$this->data['show_on_front'] = get_option('show_on_front');
22
23
+ $isHomePageEdit = (isset($_GET['page']) && $_GET['page'] == WPACU_PLUGIN_NAME.'_home_page');
24
25
+ // Only continue if we are on the plugin's homepage edit mode
26
+ if (! $isHomePageEdit) {
27
+ return '';
28
+ }
29
30
+ if ($this->data['show_on_front'] === 'page') {
31
+ // Front page displays: A Static Page
32
+ $this->data['page_on_front'] = get_option('page_on_front');
33
34
+ if ($this->data['page_on_front']) {
35
+ $this->data['page_on_front_title'] = get_the_title($this->data['page_on_front']);
36
+ }
37
38
+ $this->data['page_for_posts'] = get_option('page_for_posts');
39
40
+ if ($this->data['page_for_posts']) {
41
+ $this->data['page_for_posts_title'] = get_the_title($this->data['page_for_posts']);
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 .= '/';
49
+ }
50
51
+ $this->data['site_url'] = $postUrl;
52
}
53
}
54
55
/**
64
? $_POST[$this->data['nonce_name']] : '';
65
66
if (is_array($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
67
+ (new Update)->updateFrontPage($wpacuNoLoadAssets);
68
}
69
70
$this->data['nonce_value'] = wp_create_nonce($this->data['nonce_name']);
classes/Main.php CHANGED
@@ -11,30 +11,17 @@ class Main
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
*/
@@ -64,11 +51,17 @@ class Main
64
* @var array
65
*/
66
public $wpScripts = array();
67
/**
68
* @var array
69
*/
70
public $wpStyles = array();
71
72
/**
73
* @var Main|null
74
*/
@@ -94,19 +87,8 @@ class Main
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
-
110
// Fetch the page in the background to see what scripts/styles are already loading
111
if (isset($_POST[WPACU_PLUGIN_NAME.'_load']) || $this->frontendShow) {
112
if (isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
@@ -157,6 +139,10 @@ class Main
157
158
$type = (is_front_page()) ? 'front_page' : 'post';
159
160
$this->loadExceptions = $this->getLoadExceptions($type, $postId);
161
}
162
}
@@ -208,7 +194,7 @@ class Main
208
209
$data['get_assets'] = $getAssets;
210
211
- $data['fetch_url'] = $this->fetchUrl;
212
213
$this->parseTemplate('meta-box', $data, true);
214
}
@@ -259,6 +245,20 @@ class Main
259
}
260
}
261
262
$list = array_unique($list);
263
}
264
@@ -345,6 +345,20 @@ class Main
345
}
346
}
347
348
$list = array_unique($list);
349
}
350
@@ -385,99 +399,6 @@ class Main
385
}
386
}
387
388
- /**
389
- * Save post metadata when a post is saved.
390
- *
391
- * @param $postId
392
- */
393
- public function savePost($postId, $post = array())
394
- {
395
- if (empty($post)) {
396
- global $post;
397
- }
398
-
399
- if (! isset($post->ID)) {
400
- return;
401
- }
402
-
403
- // Has to be a public post type
404
- $obj = get_post_type_object($post->post_type);
405
-
406
- if ($obj->public < 1) {
407
- return;
408
- }
409
-
410
- // only for admins
411
- if (! current_user_can('manage_options')) {
412
- return;
413
- }
414
-
415
- $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
416
- ? $_POST[WPACU_PLUGIN_NAME] : array();
417
-
418
- if (is_array($wpacuNoLoadAssets)) {
419
- $jsonNoAssetsLoadList = json_encode($wpacuNoLoadAssets);
420
-
421
- if (! add_post_meta($postId, '_'.WPACU_PLUGIN_NAME.'_no_load', $jsonNoAssetsLoadList, true)) {
422
- update_post_meta($postId, '_'.WPACU_PLUGIN_NAME.'_no_load', $jsonNoAssetsLoadList);
423
- }
424
- }
425
-
426
- // If globally disabled, make exception to load for submitted assets
427
- Main::instance()->saveLoadExceptions('post', $postId);
428
-
429
- // Any global unloads?
430
- Main::instance()->saveToGlobalUnload();
431
-
432
- // Any global unloads removed?
433
- Main::instance()->removeGlobalUnloads();
434
- }
435
-
436
- /**
437
- *
438
- */
439
- public function frontendUpdate()
440
- {
441
- global $post;
442
-
443
- // Check nonce
444
- $nonceName = self::FRONT_NONCE_FIELD_NAME;
445
- $nonceAction = self::FRONT_NONCE_ACTION_NAME;
446
-
447
- $updateAction = isset($_POST['wpacu_update_asset_frontend']) ?
448
- $_POST['wpacu_update_asset_frontend'] : '';
449
-
450
- if (! isset($_POST[$nonceName]) || $updateAction != 1 || ! $this->frontendShow) {
451
- return;
452
- }
453
-
454
- // only for admins
455
- if (! current_user_can('manage_options')) {
456
- return;
457
- }
458
-
459
- if (! wp_verify_nonce($_POST[$nonceName], $nonceAction)) {
460
- $postUrlAnchor = get_permalink($post->ID).'#wpacu_wrap_assets';
461
- wp_die(
462
- sprintf(
463
- __('The nonce expired or is not correct, thus the request was not processed. %sPlease retry%s.', WPACU_PLUGIN_NAME),
464
- '<a href="'.$postUrlAnchor.'">',
465
- '</a>'
466
- ),
467
- __('Nonce Expired', WPACU_PLUGIN_NAME)
468
- );
469
- }
470
-
471
- if (is_front_page()) {
472
- $wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
473
- ? $_POST[WPACU_PLUGIN_NAME] : array();
474
-
475
- HomePage::updateFrontPage($wpacuNoLoadAssets);
476
- } else {
477
- $this->savePost($post->ID, $post);
478
- }
479
- }
480
-
481
/**
482
* @param string $type
483
* @param string $postId
@@ -527,150 +448,6 @@ class Main
527
return $exceptionsList;
528
}
529
530
- /**
531
- * @param string $type
532
- * @param string $postId
533
- * @return bool
534
- */
535
- public function saveLoadExceptions($type = 'post', $postId = '')
536
- {
537
- if ($type == 'post' && !$postId) {
538
- // $postId needs to have a value if $type is a 'post' type
539
- return false;
540
- }
541
-
542
- if (! in_array($type, array('post', 'front_page'))) {
543
- // Invalid request
544
- return false;
545
- }
546
-
547
- // Any global upload options
548
- $isPostOptionStyles = (isset($_POST['wpacu_styles_load_it']) && ! empty($_POST['wpacu_styles_load_it']));
549
- $isPostOptionScripts = (isset($_POST['wpacu_scripts_load_it']) && ! empty($_POST['wpacu_scripts_load_it']));
550
-
551
- $loadExceptionsStyles = $loadExceptionsScripts = array();
552
-
553
- // Clear existing list first
554
- if ($type == 'post') {
555
- delete_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions');
556
- } elseif ($type == 'front_page') {
557
- delete_option(WPACU_PLUGIN_NAME . '_front_page_load_exceptions');
558
- }
559
-
560
- if (!$isPostOptionStyles && !$isPostOptionScripts) {
561
- return false;
562
- }
563
-
564
- // Load Exception
565
- if (isset($_POST['wpacu_styles_load_it']) && ! empty($_POST['wpacu_styles_load_it'])) {
566
- foreach ($_POST['wpacu_styles_load_it'] as $wpacuHandle) {
567
- // Do not append it if the global unload is removed
568
- if (isset($_POST['wpacu_options_styles'][$wpacuHandle])
569
- && $_POST['wpacu_options_styles'][$wpacuHandle] == 'remove') {
570
- continue;
571
- }
572
- $loadExceptionsStyles[] = $wpacuHandle;
573
- }
574
- }
575
-
576
- if (! empty($_POST['wpacu_scripts_load_it'])) {
577
- foreach ($_POST['wpacu_scripts_load_it'] as $wpacuHandle) {
578
- // Do not append it if the global unload is removed
579
- if (isset($_POST['wpacu_options_scripts'][$wpacuHandle])
580
- && $_POST['wpacu_options_scripts'][$wpacuHandle] == 'remove') {
581
- continue;
582
- }
583
- $loadExceptionsScripts[] = $wpacuHandle;
584
- }
585
- }
586
-
587
- if (! empty($loadExceptionsStyles) || ! empty($loadExceptionsScripts)) {
588
- // Default
589
- $list = array('styles' => array(), 'scripts' => array());
590
-
591
- // Build list
592
- if (! empty($loadExceptionsStyles)) {
593
- foreach ($loadExceptionsStyles as $postHandle) {
594
- $list['styles'][] = $postHandle;
595
- }
596
- }
597
-
598
- if (! empty($loadExceptionsScripts)) {
599
- foreach ($loadExceptionsScripts as $postHandle) {
600
- $list['scripts'][] = $postHandle;
601
- }
602
- }
603
-
604
- if (is_array($list['styles'])) {
605
- $list['styles'] = array_unique($list['styles']);
606
- }
607
-
608
- if (is_array($list['scripts'])) {
609
- $list['scripts'] = array_unique($list['scripts']);
610
- }
611
-
612
- $jsonLoadExceptions = json_encode($list);
613
-
614
- if ($type == 'post') {
615
- if (! add_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions', $jsonLoadExceptions, true)) {
616
- update_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions', $jsonLoadExceptions);
617
- }
618
- } elseif ($type == 'front_page') {
619
- update_option(WPACU_PLUGIN_NAME . '_front_page_load_exceptions', $jsonLoadExceptions);
620
- }
621
- }
622
- }
623
-
624
- /**
625
- *
626
- */
627
- public function saveToGlobalUnload()
628
- {
629
- $postStyles = (isset($_POST['wpacu_global_unload_styles']) && is_array($_POST['wpacu_global_unload_styles']))
630
- ? $_POST['wpacu_global_unload_styles'] : array();
631
-
632
- $postScripts = (isset($_POST['wpacu_global_unload_scripts']) && is_array($_POST['wpacu_global_unload_scripts']))
633
- ? $_POST['wpacu_global_unload_scripts'] : array();
634
-
635
- // Is there any entry already in JSON format?
636
- $existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
637
-
638
- // Default list as array
639
- $existingListEmpty = array('styles' => array(), 'scripts' => array());
640
-
641
- if (! $existingListJson) {
642
- $existingList = $existingListEmpty;
643
- } else {
644
- $existingList = json_decode($existingListJson, true);
645
-
646
- if (json_last_error() != JSON_ERROR_NONE) {
647
- $existingList = $existingListEmpty;
648
- }
649
- }
650
-
651
- // Append to the list anything from the POST (if any)
652
- if (! empty($postStyles)) {
653
- foreach ($postStyles as $postStyleHandle) {
654
- $existingList['styles'][] = $postStyleHandle;
655
- }
656
- }
657
-
658
- if (! empty($postScripts)) {
659
- foreach ($postScripts as $postScriptHandle) {
660
- $existingList['scripts'][] = $postScriptHandle;
661
- }
662
- }
663
-
664
- // Make sure all entries are unique (no handle duplicates)
665
- $existingList['styles'] = array_unique($existingList['styles']);
666
- $existingList['scripts'] = array_unique($existingList['scripts']);
667
-
668
- update_option(
669
- WPACU_PLUGIN_NAME.'_global_unload',
670
- json_encode($existingList)
671
- );
672
- }
673
-
674
/**
675
* @return array
676
*/
@@ -694,61 +471,38 @@ class Main
694
}
695
696
/**
697
- *
698
*/
699
- public function removeGlobalUnloads()
700
{
701
- $stylesList = isset($_POST['wpacu_options_styles']) ? $_POST['wpacu_options_styles'] : array();
702
- $scriptsList = isset($_POST['wpacu_options_scripts']) ? $_POST['wpacu_options_scripts'] : array();
703
704
- $removeStylesList = $removeScriptsList = array();
705
706
- if (! empty($stylesList)) {
707
- foreach ($stylesList as $handle => $value) {
708
- if ($value == 'remove') {
709
- $removeStylesList[] = $handle;
710
- }
711
- }
712
- }
713
-
714
- if (! empty($scriptsList)) {
715
- foreach ($scriptsList as $handle => $value) {
716
- if ($value == 'remove') {
717
- $removeScriptsList[] = $handle;
718
- }
719
- }
720
}
721
722
- $existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
723
724
- if (! $existingListJson) {
725
- return;
726
}
727
728
- $existingList = json_decode($existingListJson, true);
729
730
- if (json_last_error() == JSON_ERROR_NONE) {
731
- if (! empty($removeStylesList)) {
732
- foreach ($existingList['styles'] as $handleKey => $handle) {
733
- if (in_array($handle, $removeStylesList)) {
734
- unset($existingList['styles'][$handleKey]);
735
- }
736
- }
737
- }
738
-
739
- if (! empty($removeScriptsList)) {
740
- foreach ($existingList['scripts'] as $handleKey => $handle) {
741
- if (in_array($handle, $removeScriptsList)) {
742
- unset($existingList['scripts'][$handleKey]);
743
- }
744
- }
745
- }
746
747
- update_option(
748
- WPACU_PLUGIN_NAME.'_global_unload',
749
- json_encode($existingList)
750
- );
751
}
752
}
753
754
/**
@@ -815,10 +569,27 @@ class Main
815
}
816
}
817
818
/*
819
* Style List
820
*/
821
if (! empty($wp_styles)) {
822
$skipStyles = array(
823
'admin-bar',
824
WPACU_PLUGIN_NAME . '-icheck-square-red',
@@ -841,7 +612,7 @@ class Main
841
}
842
}
843
844
- // Apppend unloaded ones (if any)
845
if (! empty($currentUnloadedAll['styles']) && !empty($stylesBeforeUnload)) {
846
foreach ($currentUnloadedAll['styles'] as $sbuHandle) {
847
if (!in_array($sbuHandle, $wp_styles->done)) {
@@ -866,6 +637,8 @@ class Main
866
* Scripts List
867
*/
868
if (! empty($wp_scripts)) {
869
$skipScripts = array(
870
'admin-bar',
871
WPACU_PLUGIN_NAME . '-icheck',
@@ -888,7 +661,7 @@ class Main
888
}
889
}
890
891
- // Apppend unloaded ones (if any)
892
if (! empty($currentUnloadedAll['scripts']) && !empty($scriptsBeforeUnload)) {
893
foreach ($currentUnloadedAll['scripts'] as $sbuHandle) {
894
if (!in_array($sbuHandle, $wp_scripts->done)) {
@@ -918,13 +691,12 @@ class Main
918
$data['all']['scripts'] = $list['scripts'];
919
$data['all']['styles'] = $list['styles'];
920
921
- $this->fetchUrl = (is_front_page())
922
- ? get_option('siteurl') : $this->getPostUrl($post->ID);
923
924
$data['fetch_url'] = $this->fetchUrl;
925
926
- $data['nonce_name'] = self::FRONT_NONCE_FIELD_NAME;
927
- $data['nonce_action'] = self::FRONT_NONCE_ACTION_NAME;
928
929
$data = $this->alterAssetObj($data);
930
@@ -935,6 +707,15 @@ class Main
935
936
$data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
937
938
$this->parseTemplate('settings-frontend', $data, true);
939
} elseif ($isDashboardView) {
940
// AJAX call from the WordPress Dashboard
@@ -972,169 +753,6 @@ class Main
972
return $result;
973
}
974
975
- /**
976
- *
977
- */
978
- public function stylesAndScriptsForAdmin()
979
- {
980
- global $post;
981
-
982
- $page = (isset($_GET['page'])) ? $_GET['page'] : '';
983
- $getPostId = (isset($_GET['post'])) ? (int)$_GET['post'] : '';
984
-
985
- $homepageClass = new HomePage;
986
-
987
- if (isset($post->ID)) {
988
- $this->loadPluginAssets = true;
989
- }
990
-
991
- if ($getPostId > 0) {
992
- $this->loadPluginAssets = true;
993
- }
994
-
995
- if ($page == WPACU_PLUGIN_NAME.'_home_page'
996
- && $homepageClass->data['show_on_front'] === 'posts'
997
- ) {
998
- $this->loadPluginAssets = true;
999
- }
1000
-
1001
- if (! $this->loadPluginAssets) {
1002
- return;
1003
- }
1004
-
1005
- $this->enqueueAdminStyles();
1006
- $this->enqueueAdminScripts();
1007
- }
1008
-
1009
- /**
1010
- *
1011
- */
1012
- public function stylesAndScriptsForPublic()
1013
- {
1014
- $this->enqueuePublicStyles();
1015
- $this->enqueuePublicScripts();
1016
- }
1017
-
1018
- /**
1019
- *
1020
- */
1021
- private function enqueueAdminStyles()
1022
- {
1023
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-style', plugins_url('/assets/style.css', WPACU_PLUGIN_FILE));
1024
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-icheck-square-red', plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE));
1025
- }
1026
-
1027
- /**
1028
- *
1029
- */
1030
- private function enqueueAdminScripts()
1031
- {
1032
- global $post, $pagenow;
1033
-
1034
- $page = (isset($_GET['page'])) ? $_GET['page'] : '';
1035
-
1036
- $getPostId = (isset($_GET['post'])
1037
- && isset($_GET['action'])
1038
- && $_GET['action'] === 'edit'
1039
- && $pagenow == 'post.php')
1040
- ? (int)$_GET['post'] : '';
1041
-
1042
- $postId = (isset($post->ID)) ? $post->ID : 0;
1043
-
1044
- if ($getPostId > 0 && $getPostId != $postId) {
1045
- $postId = $getPostId;
1046
- }
1047
-
1048
- if ($page == WPACU_PLUGIN_NAME.'_home_page' || $postId < 1) {
1049
- $postId = 0; // for home page
1050
- }
1051
-
1052
- // Not home page (posts list)? See if the individual post is published to continue
1053
- if ($postId > 0) {
1054
- $postStatus = get_post_status($postId);
1055
-
1056
- if (! $postStatus) {
1057
- return;
1058
- }
1059
-
1060
- // Only for Published Posts
1061
- if ($postStatus != 'publish') {
1062
- return;
1063
- }
1064
- }
1065
-
1066
- wp_register_script(WPACU_PLUGIN_NAME . '-script', plugins_url('/assets/script.js', WPACU_PLUGIN_FILE), array('jquery'), '1.1');
1067
-
1068
- // It can also be the front page URL
1069
- $postUrl = $this->getPostUrl($postId);
1070
-
1071
- $this->fetchUrl = $postUrl;
1072
-
1073
- wp_localize_script(
1074
- WPACU_PLUGIN_NAME . '-script',
1075
- 'wpacu_object',
1076
- array(
1077
- 'plugin_name' => WPACU_PLUGIN_NAME,
1078
- 'ajax_url' => admin_url('admin-ajax.php'),
1079
- 'post_id' => $postId,
1080
- 'post_url' => $postUrl
1081
- )
1082
- );
1083
-
1084
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
1085
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-script');
1086
- }
1087
-
1088
- /**
1089
- *
1090
- */
1091
- private function enqueuePublicStyles()
1092
- {
1093
- if ($this->frontendShow && current_user_can('manage_options') && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
1094
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-style', plugins_url('/assets/style.css', WPACU_PLUGIN_FILE));
1095
- wp_enqueue_style(WPACU_PLUGIN_NAME . '-icheck-square-red', plugins_url('/assets/icheck/skins/square/red.css', WPACU_PLUGIN_FILE));
1096
- }
1097
- }
1098
-
1099
- /**
1100
- *
1101
- */
1102
- public function enqueuePublicScripts()
1103
- {
1104
- if ($this->frontendShow && current_user_can('manage_options') && !isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
1105
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
1106
- wp_enqueue_script(WPACU_PLUGIN_NAME . '-script', plugins_url('/assets/script.js', WPACU_PLUGIN_FILE), array('jquery'), '1.1');
1107
- }
1108
- }
1109
-
1110
- /**
1111
- * @param $postId
1112
- * @return false|mixed|string|void
1113
- */
1114
- public function getPostUrl($postId)
1115
- {
1116
- if ($postId > 0) {
1117
- $postUrl = get_permalink($postId);
1118
- } else {
1119
- $postUrl = get_option('siteurl');
1120
-
1121
- if (substr($postUrl, -1) != '/') {
1122
- $postUrl .= '/';
1123
- }
1124
- }
1125
-
1126
- // If we are in the Dashboard on a HTTPS connection,
1127
- // then we will make the AJAX call over HTTPS as well for the front-end
1128
- // to avoid blocking
1129
- $https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off');
1130
-
1131
- if ($https && strpos($postUrl, 'http://') === 0) {
1132
- $postUrl = str_ireplace('http://', 'https://', $postUrl);
1133
- }
1134
-
1135
- return $postUrl;
1136
- }
1137
-
1138
/**
1139
*
1140
*/
@@ -1145,7 +763,7 @@ class Main
1145
$postUrl = isset($_POST['post_url']) ? $_POST['post_url'] : '';
1146
1147
$json = base64_decode(
1148
- $this->extractBetween(
1149
$contents,
1150
self::STARTDEL,
1151
self::ENDDEL
@@ -1174,6 +792,18 @@ class Main
1174
$data['fetch_url'] = $postUrl;
1175
$data['global_unload'] = $this->getGlobalUnload();
1176
1177
$type = ($postId == 0) ? 'front_page' : 'post';
1178
1179
$data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
@@ -1237,8 +867,8 @@ class Main
1237
$data['core_scripts_loaded'] = false;
1238
1239
if (isset($data['contents'])) {
1240
- $headPart = $this->extractBetween($data['contents'], '<head', '</head>');
1241
- $bodyPart = $this->extractBetween($data['contents'], '<body', '</body>');
1242
}
1243
1244
foreach ($data['all']['scripts'] as $key => $obj) {
@@ -1311,8 +941,8 @@ class Main
1311
}
1312
1313
/**
1314
- * @param string $postId
1315
- * @return array|mixed|void
1316
*/
1317
public function getAssetsUnloaded($postId = 0)
1318
{
@@ -1336,27 +966,4 @@ class Main
1336
1337
return $this->assetsRemoved;
1338
}
1339
-
1340
- /**
1341
- * @param $string
1342
- * @param $start
1343
- * @param $end
1344
- * @return string
1345
- */
1346
- public function extractBetween($string, $start, $end)
1347
- {
1348
- $pos = stripos($string, $start);
1349
-
1350
- $str = substr($string, $pos);
1351
-
1352
- $strTwo = substr($str, strlen($start));
1353
-
1354
- $secondPos = stripos($strTwo, $end);
1355
-
1356
- $strThree = substr($strTwo, 0, $secondPos);
1357
-
1358
- $unit = trim($strThree); // remove whitespaces
1359
-
1360
- return $unit;
1361
- }
1362
}
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
22
*/
23
public $assetsRemoved = array();
24
25
/**
26
* @var array
27
*/
51
* @var array
52
*/
53
public $wpScripts = array();
54
+
55
/**
56
* @var array
57
*/
58
public $wpStyles = array();
59
60
+ /**
61
+ * @var array
62
+ */
63
+ public $postTypesUnloaded = array();
64
+
65
/**
66
* @var Main|null
67
*/
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) {
94
if (isset($_POST[WPACU_PLUGIN_NAME.'_load'])) {
139
140
$type = (is_front_page()) ? 'front_page' : 'post';
141
142
+ if (is_singular()) {
143
+ $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
144
+ }
145
+
146
$this->loadExceptions = $this->getLoadExceptions($type, $postId);
147
}
148
}
194
195
$data['get_assets'] = $getAssets;
196
197
+ $data['fetch_url'] = Misc::getPostUrl($postId);
198
199
$this->parseTemplate('meta-box', $data, true);
200
}
245
}
246
}
247
248
+ if (is_singular()) {
249
+ // Any bulk unloaded styles (e.g. for all pages belonging to a post type)? Append them
250
+ if (empty($this->postTypesUnloaded)) {
251
+ global $post;
252
+ $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
253
+ }
254
+
255
+ if (!empty($this->postTypesUnloaded['scripts'])) {
256
+ foreach ($this->postTypesUnloaded['scripts'] as $handleStyle) {
257
+ $list[] = $handleStyle;
258
+ }
259
+ }
260
+ }
261
+
262
$list = array_unique($list);
263
}
264
345
}
346
}
347
348
+ if (is_singular()) {
349
+ // Any bulk unloaded styles (e.g. for all pages belonging to a post type)? Append them
350
+ if (empty($this->postTypesUnloaded)) {
351
+ global $post;
352
+ $this->postTypesUnloaded = $this->getPostTypeUnload($post->post_type);
353
+ }
354
+
355
+ if (!empty($this->postTypesUnloaded['styles'])) {
356
+ foreach ($this->postTypesUnloaded['styles'] as $handleStyle) {
357
+ $list[] = $handleStyle;
358
+ }
359
+ }
360
+ }
361
+
362
$list = array_unique($list);
363
}
364
399
}
400
}
401
402
/**
403
* @param string $type
404
* @param string $postId
448
return $exceptionsList;
449
}
450
451
/**
452
* @return array
453
*/
471
}
472
473
/**
474
+ * @param $postType
475
+ * @return array
476
*/
477
+ public function getPostTypeUnload($postType)
478
{
479
+ $existingListEmpty = array();
480
481
+ $existingListAllJson = get_option(WPACU_PLUGIN_NAME.'_bulk_unload');
482
483
+ if (! $existingListAllJson) {
484
+ return $existingListEmpty;
485
}
486
487
+ $existingListAll = json_decode($existingListAllJson, true);
488
489
+ if (json_last_error() != JSON_ERROR_NONE) {
490
+ return $existingListEmpty;
491
}
492
493
+ $existingList = array();
494
495
+ if (isset($existingListAll['styles']['post_type'][$postType])
496
+ && is_array($existingListAll['styles']['post_type'][$postType])) {
497
+ $existingList['styles'] = $existingListAll['styles']['post_type'][$postType];
498
+ }
499
500
+ if (isset($existingListAll['scripts']['post_type'][$postType])
501
+ && is_array($existingListAll['scripts']['post_type'][$postType])) {
502
+ $existingList['scripts'] = $existingListAll['scripts']['post_type'][$postType];
503
}
504
+
505
+ return $existingList;
506
}
507
508
/**
569
}
570
}
571
572
+ // Append bulk unloaded assets to current (one by one) unloaded ones
573
+ if (is_singular()) {
574
+ if (! empty($this->postTypesUnloaded['styles'])) {
575
+ foreach ($this->postTypesUnloaded['styles'] as $postTypeStyle) {
576
+ $currentUnloadedAll['styles'][] = $postTypeStyle;
577
+ }
578
+ }
579
+
580
+ if (! empty($this->postTypesUnloaded['scripts'])) {
581
+ foreach ($this->postTypesUnloaded['scripts'] as $postTypeScript) {
582
+ $currentUnloadedAll['scripts'][] = $postTypeScript;
583
+ }
584
+ }
585
+ }
586
+
587
/*
588
* Style List
589
*/
590
if (! empty($wp_styles)) {
591
+ /* These styles below are used by this plugin (except admin-bar) and they should not show in the list
592
+ as they are loaded only when you (or other admin) manage the assets, never for your website visitors */
593
$skipStyles = array(
594
'admin-bar',
595
WPACU_PLUGIN_NAME . '-icheck-square-red',
612
}
613
}
614
615
+ // Append unloaded ones (if any)
616
if (! empty($currentUnloadedAll['styles']) && !empty($stylesBeforeUnload)) {
617
foreach ($currentUnloadedAll['styles'] as $sbuHandle) {
618
if (!in_array($sbuHandle, $wp_styles->done)) {
637
* Scripts List
638
*/
639
if (! empty($wp_scripts)) {
640
+ /* These scripts below are used by this plugin (except admin-bar) and they should not show in the list
641
+ as they are loaded only when you (or other admin) manage the assets, never for your website visitors */
642
$skipScripts = array(
643
'admin-bar',
644
WPACU_PLUGIN_NAME . '-icheck',
661
}
662
}
663
664
+ // Append unloaded ones (if any)
665
if (! empty($currentUnloadedAll['scripts']) && !empty($scriptsBeforeUnload)) {
666
foreach ($currentUnloadedAll['scripts'] as $sbuHandle) {
667
if (!in_array($sbuHandle, $wp_scripts->done)) {
691
$data['all']['scripts'] = $list['scripts'];
692
$data['all']['styles'] = $list['styles'];
693
694
+ $this->fetchUrl = Misc::getPostUrl($post->ID);
695
696
$data['fetch_url'] = $this->fetchUrl;
697
698
+ $data['nonce_name'] = Update::NONCE_FIELD_NAME;
699
+ $data['nonce_action'] = Update::NONCE_ACTION_NAME;
700
701
$data = $this->alterAssetObj($data);
702
707
708
$data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
709
710
+ if (is_singular()) {
711
+ // Current Post Type
712
+ $data['post_type'] = $post->post_type;
713
+
714
+ // Are there any assets unloaded for this specific post type?
715
+ // (e.g. page, post, product (from WooCommerce) or other custom post type)
716
+ $data['post_type_unloaded'] = $this->getPostTypeUnload($data['post_type']);
717
+ }
718
+
719
$this->parseTemplate('settings-frontend', $data, true);
720
} elseif ($isDashboardView) {
721
// AJAX call from the WordPress Dashboard
753
return $result;
754
}
755
756
/**
757
*
758
*/
763
$postUrl = isset($_POST['post_url']) ? $_POST['post_url'] : '';
764
765
$json = base64_decode(
766
+ Misc::extractBetween(
767
$contents,
768
self::STARTDEL,
769
self::ENDDEL
792
$data['fetch_url'] = $postUrl;
793
$data['global_unload'] = $this->getGlobalUnload();
794
795
+ // Post Information
796
+ $postData = get_post($postId);
797
+
798
+ // Current Post Type
799
+ $data['post_type'] = $postData->post_type;
800
+
801
+ // Are there any assets unloaded for this specific post type?
802
+ // (e.g. page, post, product (from WooCommerce) or other custom post type)
803
+ $data['post_type_unloaded'] = $this->getPostTypeUnload($data['post_type']);
804
+
805
+ //echo '<pre>'; print_r($data['post_type_unloaded']);
806
+
807
$type = ($postId == 0) ? 'front_page' : 'post';
808
809
$data['load_exceptions'] = $this->getLoadExceptions($type, $postId);
867
$data['core_scripts_loaded'] = false;
868
869
if (isset($data['contents'])) {
870
+ $headPart = Misc::extractBetween($data['contents'], '<head', '</head>');
871
+ $bodyPart = Misc::extractBetween($data['contents'], '<body', '</body>');
872
}
873
874
foreach ($data['all']['scripts'] as $key => $obj) {
941
}
942
943
/**
944
+ * @param int $postId
945
+ * @return array|mixed|string|void
946
*/
947
public function getAssetsUnloaded($postId = 0)
948
{
966
967
return $this->assetsRemoved;
968
}
969
}
classes/Menu.php CHANGED
@@ -41,6 +41,16 @@ class Menu
41
array(new HomePage, 'page')
42
);
43
44
$GLOBALS['submenu'][$menuSlug][0][0] = esc_attr__('Settings', WPACU_PLUGIN_NAME);
45
}
46
}
41
array(new HomePage, 'page')
42
);
43
44
+ add_submenu_page(
45
+ $menuSlug,
46
+ __('Global Rules', WPACU_PLUGIN_NAME),
47
+ __('Global Rules', WPACU_PLUGIN_NAME),
48
+ $capability,
49
+ WPACU_PLUGIN_NAME.'_globals',
50
+ array(new GlobalRules, 'page')
51
+ );
52
+
53
+ // Rename first item from the menu which has the same title as the menu page
54
$GLOBALS['submenu'][$menuSlug][0][0] = esc_attr__('Settings', WPACU_PLUGIN_NAME);
55
}
56
}
classes/Misc.php ADDED
@@ -0,0 +1,83 @@
1
+ <?php
2
+ namespace WpAssetCleanUp;
3
+
4
+ /**
5
+ * Class Misc
6
+ * contains various common functions that are used by the plugin
7
+ * @package WpAssetCleanUp
8
+ */
9
+ class Misc
10
+ {
11
+ /**
12
+ * @param $string
13
+ * @param $start
14
+ * @param $end
15
+ * @return string
16
+ */
17
+ public static function extractBetween($string, $start, $end)
18
+ {
19
+ $pos = stripos($string, $start);
20
+
21
+ $str = substr($string, $pos);
22
+
23
+ $strTwo = substr($str, strlen($start));
24
+
25
+ $secondPos = stripos($strTwo, $end);
26
+
27
+ $strThree = substr($strTwo, 0, $secondPos);
28
+
29
+ $unit = trim($strThree); // remove whitespaces
30
+
31
+ return $unit;
32
+ }
33
+
34
+ /**
35
+ * @return string
36
+ */
37
+ public static function isHttpsSecure()
38
+ {
39
+ $isSecure = false;
40
+
41
+ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
42
+ $isSecure = true;
43
+ } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'
44
+ || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
45
+ // Is it behind a load balancer?
46
+ $isSecure = true;
47
+ }
48
+
49
+ return $isSecure;
50
+ }
51
+
52
+ /**
53
+ * @param $postId
54
+ * @return false|mixed|string|void
55
+ */
56
+ public static function getPostUrl($postId)
57
+ {
58
+ if (is_front_page()) {
59
+ return get_option('siteurl');
60
+ }
61
+
62
+ if ($postId > 0) {
63
+ $postUrl = get_permalink($postId);
64
+ } else {
65
+ $postUrl = get_option('siteurl');
66
+
67
+ if (substr($postUrl, -1) != '/') {
68
+ $postUrl .= '/';
69
+ }
70
+ }
71
+
72
+ // If we are in the Dashboard on a HTTPS connection,
73
+ // then we will make the AJAX call over HTTPS as well for the front-end
74
+ // to avoid blocking
75
+ $https = Misc::isHttpsSecure();
76
+
77
+ if ($https && strpos($postUrl, 'http://') === 0) {
78
+ $postUrl = str_ireplace('http://', 'https://', $postUrl);
79
+ }
80
+
81
+ return $postUrl;
82
+ }
83
+ }
classes/OwnAssets.php ADDED
@@ -0,0 +1,160 @@
1
+ <?php
2
+ namespace WpAssetCleanUp;
3
+
4
+ /**
5
+ * Class OwnAssets
6
+ *
7
+ * These are plugin's own assets and they are used only when you're logged and do not show in the list for unload
8
+ *
9
+ * @package WpAssetCleanUp
10
+ */
11
+ class OwnAssets
12
+ {
13
+ /**
14
+ * @var bool
15
+ */
16
+ public $loadPluginAssets = false; // default
17
+
18
+ /**
19
+ * OwnAssets constructor.
20
+ */
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
+ /**
28
+ *
29
+ */
30
+ public function stylesAndScriptsForAdmin()
31
+ {
32
+ global $post;
33
+
34
+ $page = (isset($_GET['page'])) ? $_GET['page'] : '';
35
+ $getPostId = (isset($_GET['post'])) ? (int)$_GET['post'] : '';
36
+
37
+ // Only load the plugin's assets when they are needed
38
+ // This an example of assets that are correctly loaded in WordPress
39
+ if (isset($post->ID)) {
40
+ $this->loadPluginAssets = true;
41
+ }
42
+
43
+ if ($getPostId > 0) {
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
+
51
+ if (! $this->loadPluginAssets) {
52
+ return;
53
+ }
54
+
55
+ $this->enqueueAdminStyles();
56
+ $this->enqueueAdminScripts();
57
+ }
58
+
59
+
60
+ /**
61
+ *
62
+ */
63
+ public function stylesAndScriptsForPublic()
64
+ {
65
+ $this->enqueuePublicStyles();
66
+ $this->enqueuePublicScripts();
67
+ }
68
+
69
+ /**
70
+ *
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
+
78
+ /**
79
+ *
80
+ */
81
+ private function enqueueAdminScripts()
82
+ {
83
+ global $post, $pagenow;
84
+
85
+ $page = (isset($_GET['page'])) ? $_GET['page'] : '';
86
+
87
+ $getPostId = (isset($_GET['post'])
88
+ && isset($_GET['action'])
89
+ && $_GET['action'] === 'edit'
90
+ && $pagenow == 'post.php')
91
+ ? (int)$_GET['post'] : '';
92
+
93
+ $postId = (isset($post->ID)) ? $post->ID : 0;
94
+
95
+ if ($getPostId > 0 && $getPostId != $postId) {
96
+ $postId = $getPostId;
97
+ }
98
+
99
+ if ($page == WPACU_PLUGIN_NAME.'_home_page' || $postId < 1) {
100
+ $postId = 0; // for home page
101
+ }
102
+
103
+ // Not home page (posts list)? See if the individual post is published to continue
104
+ if ($postId > 0) {
105
+ $postStatus = get_post_status($postId);
106
+
107
+ if (! $postStatus) {
108
+ return;
109
+ }
110
+
111
+ // Only for Published Posts
112
+ if ($postStatus != 'publish') {
113
+ return;
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
+
135
+ wp_enqueue_script(WPACU_PLUGIN_NAME . '-icheck', plugins_url('/assets/icheck/icheck.min.js', WPACU_PLUGIN_FILE), array('jquery'));
136
+ wp_enqueue_script(WPACU_PLUGIN_NAME . '-script');
137
+ }
138
+
139
+ /**
140
+ *
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
+ /**
151
+ *
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
+ }
classes/Update.php ADDED
@@ -0,0 +1,523 @@