Version Description
- Bug Fix: Sometimes scripts in the footer were not detected for unloading
Download this release
Release Info
Developer | gabelivan |
Plugin | Asset CleanUp: Page Speed Booster |
Version | 1.2.2 |
Comparing to | |
See all releases |
Code changes from version 1.2.3 to 1.2.2
- assets/icheck/icheck.min.js +0 -0
- assets/icheck/skins/square/red.css +0 -0
- assets/icheck/skins/square/red.png +0 -0
- assets/icheck/skins/square/red@2x.png +0 -0
- assets/script.js +11 -43
- assets/script.min.js +0 -1
- assets/style.css +148 -55
- assets/style.min.css +0 -1
- assets/style.scss +5 -23
- classes/GlobalRules.php +0 -129
- classes/HomePage.php +45 -22
- classes/Main.php +503 -110
- classes/Menu.php +0 -10
- classes/Misc.php +0 -83
- classes/OwnAssets.php +0 -160
- classes/Update.php +0 -523
- readme.txt +1 -5
- templates/meta-box-loaded.php +26 -201
- templates/settings-globals.php +0 -237
- wpacu-load.php +10 -16
- wpacu.php +1 -1
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,44 +22,39 @@ jQuery(document).ready(function($) {
|
|
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 |
-
|
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 |
-
|
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,10 +67,10 @@ jQuery(document).ready(function($) {
|
|
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,19 +79,9 @@ jQuery(document).ready(function($) {
|
|
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,14 +89,13 @@ jQuery(document).ready(function($) {
|
|
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
} else {
|
116 |
$(this).parent('label').removeClass('wpacu_global_unload_exception');
|
117 |
}
|
@@ -119,22 +103,6 @@ jQuery(document).ready(function($) {
|
|
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 |
//
|
7 |
//
|
8 |
var WpAssetCleanUp = {
|
9 |
load: function() {
|
10 |
+
var cbSelector = '.icheckbox_square-red';
|
11 |
|
12 |
$(cbSelector).iCheck({
|
13 |
checkboxClass: 'icheckbox_square-red',
|
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 |
|
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 |
$('#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 |
} 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 |
}
|
104 |
};
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
//
|
107 |
// Asset Front-end Edit (if setting is enabled)
|
108 |
//
|
assets/script.min.js
DELETED
@@ -1 +0,0 @@
|
|
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,63 +1,156 @@
|
|
1 |
-
tr.wpacu_not_load th, tr.wpacu_not_load td {
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
#wpacu_meta_box_content
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
#
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
/*
|
20 |
* Asset List Styling: Front-end and Back-end
|
21 |
*/
|
22 |
-
#wpacu_wrap_assets {
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
/* Dashboard adjust */
|
37 |
-
body.wp-admin .wpacu_asset_row td.wpacu_check {
|
38 |
-
|
39 |
-
|
40 |
-
label.
|
41 |
-
|
42 |
-
label.
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
ul.wpacu_asset_options {
|
49 |
-
|
50 |
-
|
51 |
-
ul.wpacu_asset_options
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
/* Assets Table */
|
54 |
-
.wp-asset-clean-up.widefat {
|
55 |
-
|
56 |
-
|
57 |
-
.wpacu_widefat
|
58 |
-
|
59 |
-
.
|
60 |
-
|
61 |
-
|
62 |
-
.
|
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; }
|
assets/style.min.css
DELETED
@@ -1 +0,0 @@
|
|
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
CHANGED
@@ -127,25 +127,10 @@ label {
|
|
127 |
color: #d54e21;
|
128 |
}
|
129 |
&.wpacu_global_unload_exception {
|
130 |
-
font-weight: bold
|
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;
|
@@ -163,9 +148,6 @@ ul.wpacu_asset_options {
|
|
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;
|
@@ -179,9 +161,9 @@ ul.wpacu_asset_options {
|
|
179 |
}
|
180 |
|
181 |
.wpacu_update_btn {
|
182 |
-
-moz-box-shadow: inset
|
183 |
-
-webkit-box-shadow: inset
|
184 |
-
box-shadow: inset
|
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;
|
@@ -200,7 +182,7 @@ ul.wpacu_asset_options {
|
|
200 |
font-size: 15px !important;
|
201 |
padding: 10px 24px !important;
|
202 |
text-decoration: none !important;
|
203 |
-
text-shadow:
|
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;
|
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;
|
148 |
}
|
149 |
|
150 |
/* Assets Table */
|
|
|
|
|
|
|
151 |
|
152 |
.wpacu_widefat {
|
153 |
border: 1px solid #e5e5e5 !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;
|
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;
|
classes/GlobalRules.php
DELETED
@@ -1,129 +0,0 @@
|
|
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,36 +20,59 @@ class HomePage
|
|
20 |
$this->data['nonce_name'] = WPACU_PLUGIN_NAME.'_settings';
|
21 |
$this->data['show_on_front'] = get_option('show_on_front');
|
22 |
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
}
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
$this->data['page_on_front_title'] = get_the_title($this->data['page_on_front']);
|
36 |
-
}
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
} elseif ($this->data['show_on_front'] === 'posts') {
|
44 |
-
// Your latest posts
|
45 |
-
$postUrl = get_option('siteurl');
|
46 |
|
47 |
-
|
48 |
-
|
|
|
49 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
|
|
52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
|
55 |
/**
|
@@ -64,7 +87,7 @@ class HomePage
|
|
64 |
? $_POST[$this->data['nonce_name']] : '';
|
65 |
|
66 |
if (is_array($wpacuNoLoadAssets) && wp_verify_nonce($noncePost, $this->data['nonce_name'])) {
|
67 |
-
|
68 |
}
|
69 |
|
70 |
$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 |
+
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 |
? $_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']);
|
classes/Main.php
CHANGED
@@ -11,17 +11,30 @@ class Main
|
|
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,17 +64,11 @@ class Main
|
|
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,8 +94,19 @@ class Main
|
|
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,10 +157,6 @@ class Main
|
|
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,7 +208,7 @@ class Main
|
|
194 |
|
195 |
$data['get_assets'] = $getAssets;
|
196 |
|
197 |
-
$data['fetch_url'] =
|
198 |
|
199 |
$this->parseTemplate('meta-box', $data, true);
|
200 |
}
|
@@ -245,20 +259,6 @@ class Main
|
|
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,20 +345,6 @@ class Main
|
|
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,6 +385,99 @@ class Main
|
|
399 |
}
|
400 |
}
|
401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
/**
|
403 |
* @param string $type
|
404 |
* @param string $postId
|
@@ -448,6 +527,150 @@ class Main
|
|
448 |
return $exceptionsList;
|
449 |
}
|
450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
/**
|
452 |
* @return array
|
453 |
*/
|
@@ -471,38 +694,61 @@ class Main
|
|
471 |
}
|
472 |
|
473 |
/**
|
474 |
-
*
|
475 |
-
* @return array
|
476 |
*/
|
477 |
-
public function
|
478 |
{
|
479 |
-
$
|
|
|
480 |
|
481 |
-
$
|
482 |
|
483 |
-
if (! $
|
484 |
-
|
|
|
|
|
|
|
|
|
485 |
}
|
486 |
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
|
|
|
|
491 |
}
|
492 |
|
493 |
-
$
|
494 |
|
495 |
-
if (
|
496 |
-
|
497 |
-
$existingList['styles'] = $existingListAll['styles']['post_type'][$postType];
|
498 |
}
|
499 |
|
500 |
-
|
501 |
-
&& is_array($existingListAll['scripts']['post_type'][$postType])) {
|
502 |
-
$existingList['scripts'] = $existingListAll['scripts']['post_type'][$postType];
|
503 |
-
}
|
504 |
|
505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
}
|
507 |
|
508 |
/**
|
@@ -569,27 +815,10 @@ class Main
|
|
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,7 +841,7 @@ class Main
|
|
612 |
}
|
613 |
}
|
614 |
|
615 |
-
//
|
616 |
if (! empty($currentUnloadedAll['styles']) && !empty($stylesBeforeUnload)) {
|
617 |
foreach ($currentUnloadedAll['styles'] as $sbuHandle) {
|
618 |
if (!in_array($sbuHandle, $wp_styles->done)) {
|
@@ -637,8 +866,6 @@ class Main
|
|
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,7 +888,7 @@ class Main
|
|
661 |
}
|
662 |
}
|
663 |
|
664 |
-
//
|
665 |
if (! empty($currentUnloadedAll['scripts']) && !empty($scriptsBeforeUnload)) {
|
666 |
foreach ($currentUnloadedAll['scripts'] as $sbuHandle) {
|
667 |
if (!in_array($sbuHandle, $wp_scripts->done)) {
|
@@ -691,12 +918,13 @@ class Main
|
|
691 |
$data['all']['scripts'] = $list['scripts'];
|
692 |
$data['all']['styles'] = $list['styles'];
|
693 |
|
694 |
-
$this->fetchUrl =
|
|
|
695 |
|
696 |
$data['fetch_url'] = $this->fetchUrl;
|
697 |
|
698 |
-
$data['nonce_name'] =
|
699 |
-
$data['nonce_action'] =
|
700 |
|
701 |
$data = $this->alterAssetObj($data);
|
702 |
|
@@ -707,15 +935,6 @@ class Main
|
|
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,6 +972,169 @@ class Main
|
|
753 |
return $result;
|
754 |
}
|
755 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
756 |
/**
|
757 |
*
|
758 |
*/
|
@@ -763,7 +1145,7 @@ class Main
|
|
763 |
$postUrl = isset($_POST['post_url']) ? $_POST['post_url'] : '';
|
764 |
|
765 |
$json = base64_decode(
|
766 |
-
|
767 |
$contents,
|
768 |
self::STARTDEL,
|
769 |
self::ENDDEL
|
@@ -792,18 +1174,6 @@ class Main
|
|
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,8 +1237,8 @@ class Main
|
|
867 |
$data['core_scripts_loaded'] = false;
|
868 |
|
869 |
if (isset($data['contents'])) {
|
870 |
-
$headPart =
|
871 |
-
$bodyPart =
|
872 |
}
|
873 |
|
874 |
foreach ($data['all']['scripts'] as $key => $obj) {
|
@@ -941,8 +1311,8 @@ class Main
|
|
941 |
}
|
942 |
|
943 |
/**
|
944 |
-
* @param
|
945 |
-
* @return array|mixed|
|
946 |
*/
|
947 |
public function getAssetsUnloaded($postId = 0)
|
948 |
{
|
@@ -966,4 +1336,27 @@ class Main
|
|
966 |
|
967 |
return $this->assetsRemoved;
|
968 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
969 |
}
|
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 |
* @var array
|
65 |
*/
|
66 |
public $wpScripts = array();
|
|
|
67 |
/**
|
68 |
* @var array
|
69 |
*/
|
70 |
public $wpStyles = array();
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
/**
|
73 |
* @var Main|null
|
74 |
*/
|
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 |
|
158 |
$type = (is_front_page()) ? 'front_page' : 'post';
|
159 |
|
|
|
|
|
|
|
|
|
160 |
$this->loadExceptions = $this->getLoadExceptions($type, $postId);
|
161 |
}
|
162 |
}
|
208 |
|
209 |
$data['get_assets'] = $getAssets;
|
210 |
|
211 |
+
$data['fetch_url'] = $this->fetchUrl;
|
212 |
|
213 |
$this->parseTemplate('meta-box', $data, true);
|
214 |
}
|
259 |
}
|
260 |
}
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
$list = array_unique($list);
|
263 |
}
|
264 |
|
345 |
}
|
346 |
}
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
$list = array_unique($list);
|
349 |
}
|
350 |
|
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 |
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 |
}
|
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 |
}
|
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 |
}
|
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 |
* Scripts List
|
867 |
*/
|
868 |
if (! empty($wp_scripts)) {
|
|
|
|
|
869 |
$skipScripts = array(
|
870 |
'admin-bar',
|
871 |
WPACU_PLUGIN_NAME . '-icheck',
|
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 |
$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 |
|
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 |
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 |
$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 |
$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 |
$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 |
}
|
1312 |
|
1313 |
/**
|
1314 |
+
* @param string $postId
|
1315 |
+
* @return array|mixed|void
|
1316 |
*/
|
1317 |
public function getAssetsUnloaded($postId = 0)
|
1318 |
{
|
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 |
}
|
classes/Menu.php
CHANGED
@@ -41,16 +41,6 @@ class Menu
|
|
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 |
}
|
41 |
array(new HomePage, 'page')
|
42 |
);
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
$GLOBALS['submenu'][$menuSlug][0][0] = esc_attr__('Settings', WPACU_PLUGIN_NAME);
|
45 |
}
|
46 |
}
|
classes/Misc.php
DELETED
@@ -1,83 +0,0 @@
|
|
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
DELETED
@@ -1,160 +0,0 @@
|
|
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
DELETED
@@ -1,523 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace WpAssetCleanUp;
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Class Update
|
6 |
-
* @package WpAssetCleanUp
|
7 |
-
*/
|
8 |
-
class Update
|
9 |
-
{
|
10 |
-
/**
|
11 |
-
*
|
12 |
-
*/
|
13 |
-
const NONCE_ACTION_NAME = 'wpacu_data_update';
|
14 |
-
/**
|
15 |
-
*
|
16 |
-
*/
|
17 |
-
const NONCE_FIELD_NAME = 'wpacu_data_nonce';
|
18 |
-
|
19 |
-
/**
|
20 |
-
*
|
21 |
-
*/
|
22 |
-
public function init()
|
23 |
-
{
|
24 |
-
if (Main::instance()->frontendShow) {
|
25 |
-
add_action('wp', array($this, 'frontendUpdate'), 1);
|
26 |
-
}
|
27 |
-
|
28 |
-
// After post/page is saved - update your styles/scripts lists
|
29 |
-
add_action('save_post', array($this, 'savePost'));
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
*
|
34 |
-
*/
|
35 |
-
public function frontendUpdate()
|
36 |
-
{
|
37 |
-
global $post;
|
38 |
-
|
39 |
-
// Check nonce
|
40 |
-
$nonceName = self::NONCE_FIELD_NAME;
|
41 |
-
$nonceAction = self::NONCE_ACTION_NAME;
|
42 |
-
|
43 |
-
$updateAction = isset($_POST['wpacu_update_asset_frontend']) ?
|
44 |
-
$_POST['wpacu_update_asset_frontend'] : '';
|
45 |
-
|
46 |
-
if (! isset($_POST[$nonceName]) || $updateAction != 1 || ! Main::instance()->frontendShow) {
|
47 |
-
return;
|
48 |
-
}
|
49 |
-
|
50 |
-
// only for admins
|
51 |
-
if (! current_user_can('manage_options')) {
|
52 |
-
return;
|
53 |
-
}
|
54 |
-
|
55 |
-
if (! wp_verify_nonce($_POST[$nonceName], $nonceAction)) {
|
56 |
-
$postUrlAnchor = get_permalink($post->ID).'#wpacu_wrap_assets';
|
57 |
-
wp_die(
|
58 |
-
sprintf(
|
59 |
-
__('The nonce expired or is not correct, thus the request was not processed. %sPlease retry%s.', WPACU_PLUGIN_NAME),
|
60 |
-
'<a href="'.$postUrlAnchor.'">',
|
61 |
-
'</a>'
|
62 |
-
),
|
63 |
-
__('Nonce Expired', WPACU_PLUGIN_NAME)
|
64 |
-
);
|
65 |
-
}
|
66 |
-
|
67 |
-
if (is_front_page()) {
|
68 |
-
$wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
|
69 |
-
? $_POST[WPACU_PLUGIN_NAME] : array();
|
70 |
-
|
71 |
-
$this->updateFrontPage($wpacuNoLoadAssets);
|
72 |
-
} else {
|
73 |
-
$this->savePost($post->ID, $post);
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Save post metadata when a post is saved.
|
79 |
-
*
|
80 |
-
* @param $postId
|
81 |
-
* @param array $post
|
82 |
-
*/
|
83 |
-
public function savePost($postId, $post = array())
|
84 |
-
{
|
85 |
-
if (empty($post)) {
|
86 |
-
global $post;
|
87 |
-
}
|
88 |
-
|
89 |
-
if (! isset($post->ID)) {
|
90 |
-
return;
|
91 |
-
}
|
92 |
-
|
93 |
-
// Has to be a public post type
|
94 |
-
$obj = get_post_type_object($post->post_type);
|
95 |
-
|
96 |
-
if ($obj->public < 1) {
|
97 |
-
return;
|
98 |
-
}
|
99 |
-
|
100 |
-
// only for admins
|
101 |
-
if (! current_user_can('manage_options')) {
|
102 |
-
return;
|
103 |
-
}
|
104 |
-
|
105 |
-
$wpacuNoLoadAssets = isset($_POST[WPACU_PLUGIN_NAME])
|
106 |
-
? $_POST[WPACU_PLUGIN_NAME] : array();
|
107 |
-
|
108 |
-
if (is_array($wpacuNoLoadAssets)) {
|
109 |
-
global $wpdb;
|
110 |
-
|
111 |
-
$noUpdate = false;
|
112 |
-
|
113 |
-
// Is the list empty?
|
114 |
-
if (empty($wpacuNoLoadAssets)) {
|
115 |
-
// Remove any row with no results
|
116 |
-
$wpdb->delete(
|
117 |
-
$wpdb->postmeta,
|
118 |
-
array('post_id' => $postId, 'meta_key' => '_' . WPACU_PLUGIN_NAME . '_no_load')
|
119 |
-
);
|
120 |
-
$noUpdate = true;
|
121 |
-
}
|
122 |
-
|
123 |
-
if (! $noUpdate) {
|
124 |
-
$jsonNoAssetsLoadList = json_encode($wpacuNoLoadAssets);
|
125 |
-
|
126 |
-
if (! add_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_no_load', $jsonNoAssetsLoadList, true)) {
|
127 |
-
update_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_no_load', $jsonNoAssetsLoadList);
|
128 |
-
}
|
129 |
-
}
|
130 |
-
}
|
131 |
-
|
132 |
-
// If globally disabled, make exception to load for submitted assets
|
133 |
-
$this->saveLoadExceptions('post', $postId);
|
134 |
-
|
135 |
-
// Any global (all pages / everywhere) unloads or removed?
|
136 |
-
$this->saveToEverywhereUnloads();
|
137 |
-
$this->removeEverywhereUnloads();
|
138 |
-
|
139 |
-
// Any bulk unloads or removed? (e.g. all pages of a certain post type)
|
140 |
-
$this->saveToBulkUnloads();
|
141 |
-
$this->removeBulkUnloads();
|
142 |
-
}
|
143 |
-
|
144 |
-
/**
|
145 |
-
* @param $wpacuNoLoadAssets
|
146 |
-
*/
|
147 |
-
public function updateFrontPage($wpacuNoLoadAssets)
|
148 |
-
{
|
149 |
-
if (! is_array($wpacuNoLoadAssets)) {
|
150 |
-
return; // only arrays (empty or not) should be used
|
151 |
-
}
|
152 |
-
|
153 |
-
$jsonNoAssetsLoadList = json_encode($wpacuNoLoadAssets);
|
154 |
-
|
155 |
-
if (! update_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList)) {
|
156 |
-
add_option(WPACU_PLUGIN_NAME . '_front_page_no_load', $jsonNoAssetsLoadList);
|
157 |
-
}
|
158 |
-
|
159 |
-
// If globally disabled, make exception to load for submitted assets
|
160 |
-
$this->saveLoadExceptions('front_page');
|
161 |
-
|
162 |
-
// Any global unloads or removed?
|
163 |
-
$this->saveToEverywhereUnloads();
|
164 |
-
$this->removeEverywhereUnloads();
|
165 |
-
}
|
166 |
-
|
167 |
-
/**
|
168 |
-
* @param string $type
|
169 |
-
* @param string $postId
|
170 |
-
* @return bool|void
|
171 |
-
*/
|
172 |
-
public function saveLoadExceptions($type = 'post', $postId = '')
|
173 |
-
{
|
174 |
-
if ($type == 'post' && !$postId) {
|
175 |
-
// $postId needs to have a value if $type is a 'post' type
|
176 |
-
return false;
|
177 |
-
}
|
178 |
-
|
179 |
-
if (! in_array($type, array('post', 'front_page'))) {
|
180 |
-
// Invalid request
|
181 |
-
return false;
|
182 |
-
}
|
183 |
-
|
184 |
-
// Any global upload options
|
185 |
-
$isPostOptionStyles = (isset($_POST['wpacu_styles_load_it']) && ! empty($_POST['wpacu_styles_load_it']));
|
186 |
-
$isPostOptionScripts = (isset($_POST['wpacu_scripts_load_it']) && ! empty($_POST['wpacu_scripts_load_it']));
|
187 |
-
|
188 |
-
$loadExceptionsStyles = $loadExceptionsScripts = array();
|
189 |
-
|
190 |
-
// Clear existing list first
|
191 |
-
if ($type == 'post') {
|
192 |
-
delete_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions');
|
193 |
-
} elseif ($type == 'front_page') {
|
194 |
-
delete_option(WPACU_PLUGIN_NAME . '_front_page_load_exceptions');
|
195 |
-
}
|
196 |
-
|
197 |
-
if (! $isPostOptionStyles && ! $isPostOptionScripts) {
|
198 |
-
return false;
|
199 |
-
}
|
200 |
-
|
201 |
-
// Load Exception
|
202 |
-
if (isset($_POST['wpacu_styles_load_it']) && ! empty($_POST['wpacu_styles_load_it'])) {
|
203 |
-
foreach ($_POST['wpacu_styles_load_it'] as $wpacuHandle) {
|
204 |
-
// Do not append it if the global unload is removed
|
205 |
-
if (isset($_POST['wpacu_options_styles'][$wpacuHandle])
|
206 |
-
&& $_POST['wpacu_options_styles'][$wpacuHandle] == 'remove') {
|
207 |
-
continue;
|
208 |
-
}
|
209 |
-
$loadExceptionsStyles[] = $wpacuHandle;
|
210 |
-
}
|
211 |
-
}
|
212 |
-
|
213 |
-
if (! empty($_POST['wpacu_scripts_load_it'])) {
|
214 |
-
foreach ($_POST['wpacu_scripts_load_it'] as $wpacuHandle) {
|
215 |
-
// Do not append it if the global unload is removed
|
216 |
-
if (isset($_POST['wpacu_options_scripts'][$wpacuHandle])
|
217 |
-
&& $_POST['wpacu_options_scripts'][$wpacuHandle] == 'remove') {
|
218 |
-
continue;
|
219 |
-
}
|
220 |
-
$loadExceptionsScripts[] = $wpacuHandle;
|
221 |
-
}
|
222 |
-
}
|
223 |
-
|
224 |
-
if (! empty($loadExceptionsStyles) || ! empty($loadExceptionsScripts)) {
|
225 |
-
// Default
|
226 |
-
$list = array('styles' => array(), 'scripts' => array());
|
227 |
-
|
228 |
-
// Build list
|
229 |
-
if (! empty($loadExceptionsStyles)) {
|
230 |
-
foreach ($loadExceptionsStyles as $postHandle) {
|
231 |
-
$list['styles'][] = $postHandle;
|
232 |
-
}
|
233 |
-
}
|
234 |
-
|
235 |
-
if (! empty($loadExceptionsScripts)) {
|
236 |
-
foreach ($loadExceptionsScripts as $postHandle) {
|
237 |
-
$list['scripts'][] = $postHandle;
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
if (is_array($list['styles'])) {
|
242 |
-
$list['styles'] = array_unique($list['styles']);
|
243 |
-
}
|
244 |
-
|
245 |
-
if (is_array($list['scripts'])) {
|
246 |
-
$list['scripts'] = array_unique($list['scripts']);
|
247 |
-
}
|
248 |
-
|
249 |
-
$jsonLoadExceptions = json_encode($list);
|
250 |
-
|
251 |
-
if ($type == 'post') {
|
252 |
-
if (! add_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions', $jsonLoadExceptions, true)) {
|
253 |
-
update_post_meta($postId, '_' . WPACU_PLUGIN_NAME . '_load_exceptions', $jsonLoadExceptions);
|
254 |
-
}
|
255 |
-
} elseif ($type == 'front_page') {
|
256 |
-
update_option(WPACU_PLUGIN_NAME . '_front_page_load_exceptions', $jsonLoadExceptions);
|
257 |
-
}
|
258 |
-
}
|
259 |
-
}
|
260 |
-
|
261 |
-
/**
|
262 |
-
*
|
263 |
-
*/
|
264 |
-
public function saveToEverywhereUnloads()
|
265 |
-
{
|
266 |
-
$postStyles = (isset($_POST['wpacu_global_unload_styles']) && is_array($_POST['wpacu_global_unload_styles']))
|
267 |
-
? $_POST['wpacu_global_unload_styles'] : array();
|
268 |
-
|
269 |
-
$postScripts = (isset($_POST['wpacu_global_unload_scripts']) && is_array($_POST['wpacu_global_unload_scripts']))
|
270 |
-
? $_POST['wpacu_global_unload_scripts'] : array();
|
271 |
-
|
272 |
-
// Is there any entry already in JSON format?
|
273 |
-
$existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
|
274 |
-
|
275 |
-
// Default list as array
|
276 |
-
$existingListEmpty = array('styles' => array(), 'scripts' => array());
|
277 |
-
|
278 |
-
if (! $existingListJson) {
|
279 |
-
$existingList = $existingListEmpty;
|
280 |
-
} else {
|
281 |
-
$existingList = json_decode($existingListJson, true);
|
282 |
-
|
283 |
-
if (json_last_error() != JSON_ERROR_NONE) {
|
284 |
-
$existingList = $existingListEmpty;
|
285 |
-
}
|
286 |
-
}
|
287 |
-
|
288 |
-
// Append to the list anything from the POST (if any)
|
289 |
-
if (! empty($postStyles)) {
|
290 |
-
foreach ($postStyles as $postStyleHandle) {
|
291 |
-
$existingList['styles'][] = $postStyleHandle;
|
292 |
-
}
|
293 |
-
}
|
294 |
-
|
295 |
-
if (! empty($postScripts)) {
|
296 |
-
foreach ($postScripts as $postScriptHandle) {
|
297 |
-
$existingList['scripts'][] = $postScriptHandle;
|
298 |
-
}
|
299 |
-
}
|
300 |
-
|
301 |
-
// Make sure all entries are unique (no handle duplicates)
|
302 |
-
$existingList['styles'] = array_unique($existingList['styles']);
|
303 |
-
$existingList['scripts'] = array_unique($existingList['scripts']);
|
304 |
-
|
305 |
-
update_option(
|
306 |
-
WPACU_PLUGIN_NAME.'_global_unload',
|
307 |
-
json_encode($existingList)
|
308 |
-
);
|
309 |
-
}
|
310 |
-
|
311 |
-
/**
|
312 |
-
* @return bool
|
313 |
-
*/
|
314 |
-
public function removeEverywhereUnloads()
|
315 |
-
{
|
316 |
-
$stylesList = isset($_POST['wpacu_options_styles']) ? $_POST['wpacu_options_styles'] : array();
|
317 |
-
$scriptsList = isset($_POST['wpacu_options_scripts']) ? $_POST['wpacu_options_scripts'] : array();
|
318 |
-
|
319 |
-
$removeStylesList = $removeScriptsList = array();
|
320 |
-
|
321 |
-
$isUpdated = false;
|
322 |
-
|
323 |
-
if (! empty($stylesList)) {
|
324 |
-
foreach ($stylesList as $handle => $value) {
|
325 |
-
if ($value == 'remove') {
|
326 |
-
$removeStylesList[] = $handle;
|
327 |
-
}
|
328 |
-
}
|
329 |
-
}
|
330 |
-
|
331 |
-
if (! empty($scriptsList)) {
|
332 |
-
foreach ($scriptsList as $handle => $value) {
|
333 |
-
if ($value == 'remove') {
|
334 |
-
$removeScriptsList[] = $handle;
|
335 |
-
}
|
336 |
-
}
|
337 |
-
}
|
338 |
-
|
339 |
-
$existingListJson = get_option(WPACU_PLUGIN_NAME.'_global_unload');
|
340 |
-
|
341 |
-
if (! $existingListJson) {
|
342 |
-
return false;
|
343 |
-
}
|
344 |
-
|
345 |
-
$existingList = json_decode($existingListJson, true);
|
346 |
-
|
347 |
-
if (json_last_error() == JSON_ERROR_NONE) {
|
348 |
-
foreach (array('styles', 'scripts') as $assetType) {
|
349 |
-
if ($assetType === 'styles') {
|
350 |
-
$list = $removeStylesList;
|
351 |
-
} elseif ($assetType === 'scripts') {
|
352 |
-
$list = $removeScriptsList;
|
353 |
-
}
|
354 |
-
|
355 |
-
if (empty($list)) {
|
356 |
-
continue;
|
357 |
-
}
|
358 |
-
|
359 |
-
foreach ($list as $handle) {
|
360 |
-
if ($handleKey = array_search($handle, $existingList[$assetType])) {
|
361 |
-
unset($existingList[$assetType][$handleKey]);
|
362 |
-
$isUpdated = true;
|
363 |
-
}
|
364 |
-
}
|
365 |
-
}
|
366 |
-
|
367 |
-
if ($isUpdated) {
|
368 |
-
update_option(
|
369 |
-
WPACU_PLUGIN_NAME . '_global_unload',
|
370 |
-
json_encode($existingList)
|
371 |
-
);
|
372 |
-
}
|
373 |
-
}
|
374 |
-
|
375 |
-
return $isUpdated;
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
*
|
380 |
-
*/
|
381 |
-
public function saveToBulkUnloads()
|
382 |
-
{
|
383 |
-
global $post;
|
384 |
-
|
385 |
-
$postType = $post->post_type;
|
386 |
-
|
387 |
-
$postStyles = (isset($_POST['wpacu_bulk_unload_styles']) && is_array($_POST['wpacu_bulk_unload_styles']))
|
388 |
-
? $_POST['wpacu_bulk_unload_styles'] : array();
|
389 |
-
|
390 |
-
$postScripts = (isset($_POST['wpacu_bulk_unload_scripts']) && is_array($_POST['wpacu_bulk_unload_scripts']))
|
391 |
-
? $_POST['wpacu_bulk_unload_scripts'] : array();
|
392 |
-
|
393 |
-
// Is there any entry already in JSON format?
|
394 |
-
$existingListJson = get_option(WPACU_PLUGIN_NAME.'_bulk_unload');
|
395 |
-
|
396 |
-
// Default list as array
|
397 |
-
$existingListEmpty = array(
|
398 |
-
'styles' => array('post_type' => array($postType => array())),
|
399 |
-
'scripts' => array('post_type' => array($postType => array()))
|
400 |
-
);
|
401 |
-
|
402 |
-
if (! $existingListJson) {
|
403 |
-
$existingList = $existingListEmpty;
|
404 |
-
} else {
|
405 |
-
$existingList = json_decode($existingListJson, true);
|
406 |
-
|
407 |
-
if (json_last_error() != JSON_ERROR_NONE) {
|
408 |
-
$existingList = $existingListEmpty;
|
409 |
-
}
|
410 |
-
}
|
411 |
-
|
412 |
-
// Append to the list anything from the POST (if any)
|
413 |
-
// Make sure all entries are unique (no handle duplicates)
|
414 |
-
$list = array();
|
415 |
-
|
416 |
-
foreach (array('styles', 'scripts') as $assetType) {
|
417 |
-
if ($assetType === 'styles') {
|
418 |
-
$list = $postStyles;
|
419 |
-
} elseif ($assetType === 'scripts') {
|
420 |
-
$list = $postScripts;
|
421 |
-
}
|
422 |
-
|
423 |
-
if (empty($list)) {
|
424 |
-
continue;
|
425 |
-
}
|
426 |
-
|
427 |
-
foreach ($list as $bulkType => $values) {
|
428 |
-
if (empty($values)) {
|
429 |
-
continue;
|
430 |
-
}
|
431 |
-
|
432 |
-
if ($bulkType === 'post_type') {
|
433 |
-
foreach ($values as $postType => $handles) {
|
434 |
-
$existingList[$assetType]['post_type'][$postType] = array_unique($handles);
|
435 |
-
}
|
436 |
-
}
|
437 |
-
}
|
438 |
-
}
|
439 |
-
|
440 |
-
update_option(
|
441 |
-
WPACU_PLUGIN_NAME.'_bulk_unload',
|
442 |
-
json_encode($existingList)
|
443 |
-
);
|
444 |
-
}
|
445 |
-
|
446 |
-
/**
|
447 |
-
* @param string $postType
|
448 |
-
* @return bool
|
449 |
-
*/
|
450 |
-
public function removeBulkUnloads($postType = '')
|
451 |
-
{
|
452 |
-
if (! $postType) {
|
453 |
-
global $post;
|
454 |
-
|
455 |
-
// At this time (12 Nov 2016) post type unload is the only option in bulk unloads
|
456 |
-
$postType = $post->post_type;
|
457 |
-
}
|
458 |
-
|
459 |
-
$stylesList = isset($_POST['wpacu_options_post_type_styles'])
|
460 |
-
? $_POST['wpacu_options_post_type_styles'] : array();
|
461 |
-
|
462 |
-
$scriptsList = isset($_POST['wpacu_options_post_type_scripts'])
|
463 |
-
? $_POST['wpacu_options_post_type_scripts'] : array();
|
464 |
-
|
465 |
-
$removeStylesList = $removeScriptsList = array();
|
466 |
-
|
467 |
-
$isUpdated = false;
|
468 |
-
|
469 |
-
if (! empty($stylesList)) {
|
470 |
-
foreach ($stylesList as $handle => $value) {
|
471 |
-
if ($value == 'remove') {
|
472 |
-
$removeStylesList[] = $handle;
|
473 |
-
}
|
474 |
-
}
|
475 |
-
}
|
476 |
-
|
477 |
-
if (! empty($scriptsList)) {
|
478 |
-
foreach ($scriptsList as $handle => $value) {
|
479 |
-
if ($value == 'remove') {
|
480 |
-
$removeScriptsList[] = $handle;
|
481 |
-
}
|
482 |
-
}
|
483 |
-
}
|
484 |
-
|
485 |
-
$existingListJson = get_option(WPACU_PLUGIN_NAME.'_bulk_unload');
|
486 |
-
|
487 |
-
if (! $existingListJson) {
|
488 |
-
return false;
|
489 |
-
}
|
490 |
-
|
491 |
-
$existingList = json_decode($existingListJson, true);
|
492 |
-
|
493 |
-
if (json_last_error() == JSON_ERROR_NONE) {
|
494 |
-
$list = array();
|
495 |
-
|
496 |
-
foreach (array('styles', 'scripts') as $assetType) {
|
497 |
-
if ($assetType === 'styles') {
|
498 |
-
$list = $removeStylesList;
|
499 |
-
} elseif ($assetType === 'scripts') {
|
500 |
-
$list = $removeScriptsList;
|
501 |
-
}
|
502 |
-
|
503 |
-
if (empty($list)) {
|
504 |
-
continue;
|
505 |
-
}
|
506 |
-
|
507 |
-
foreach ($existingList[$assetType]['post_type'][$postType] as $handleKey => $handle) {
|
508 |
-
if (in_array($handle, $list)) {
|
509 |
-
unset($existingList[$assetType]['post_type'][$postType][$handleKey]);
|
510 |
-
$isUpdated = true;
|
511 |
-
}
|
512 |
-
}
|
513 |
-
}
|
514 |
-
|
515 |
-
update_option(
|
516 |
-
WPACU_PLUGIN_NAME.'_bulk_unload',
|
517 |
-
json_encode($existingList)
|
518 |
-
);
|
519 |
-
}
|
520 |
-
|
521 |
-
return $isUpdated;
|
522 |
-
}
|
523 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: speed, pagespeed, dequeue style, dequeue script, unload style, unload scri
|
|
4 |
Donate link: http://www.gabelivan.com/donate/
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 4.6.1
|
7 |
-
Stable tag: 1.2.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
@@ -92,10 +92,6 @@ If that's the case, then it's advisable to consult with a developer (ideally the
|
|
92 |
4. Scripts (.JS) are selected for site-wide unload
|
93 |
|
94 |
== Changelog ==
|
95 |
-
= 1.2.3 =
|
96 |
-
* Assets can now be disabled for all the pages belonging to a specific post type
|
97 |
-
* The list of assets disabled globally (everywhere, for a specific post type etc.) can be managed in a single page too
|
98 |
-
|
99 |
= 1.2.2 =
|
100 |
* Bug Fix: Sometimes scripts in the footer were not detected for unloading
|
101 |
|
4 |
Donate link: http://www.gabelivan.com/donate/
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 4.6.1
|
7 |
+
Stable tag: 1.2.2
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
92 |
4. Scripts (.JS) are selected for site-wide unload
|
93 |
|
94 |
== Changelog ==
|
|
|
|
|
|
|
|
|
95 |
= 1.2.2 =
|
96 |
* Bug Fix: Sometimes scripts in the footer were not detected for unloading
|
97 |
|
templates/meta-box-loaded.php
CHANGED
@@ -10,19 +10,13 @@ if (! isset($data)) {
|
|
10 |
<div class="wpacu_verified">
|
11 |
<strong>Verified Page:</strong> <a target="_blank" href="<?php echo $data['fetch_url']; ?>"><span><?php echo $data['fetch_url']; ?></span></a>
|
12 |
</div>
|
13 |
-
|
14 |
-
/*
|
15 |
-
* --------------------
|
16 |
-
* [START] STYLES LIST
|
17 |
-
* --------------------
|
18 |
-
*/
|
19 |
-
?>
|
20 |
<h3><?php _e('Styles (.css files)', WPACU_PLUGIN_NAME); ?></h3>
|
21 |
<?php
|
22 |
if (! empty($data['all']['styles'])) {
|
23 |
?>
|
24 |
<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>
|
25 |
-
<p><?php echo __('"Load in on this page (make exception)" will take effect when
|
26 |
<?php
|
27 |
if ($data['core_styles_loaded']) {
|
28 |
?>
|
@@ -46,19 +40,13 @@ if (! empty($data['all']['styles'])) {
|
|
46 |
$class = ($active) ? 'wpacu_not_load' : '';
|
47 |
$checked = ($active) ? 'checked="checked"' : '';
|
48 |
|
49 |
-
$globalUnloaded = $
|
50 |
-
|
51 |
-
// Mark it as unloaded - Everywhere
|
52 |
-
if (in_array($obj->handle, $data['global_unload']['styles'])) {
|
53 |
-
$globalUnloaded = $isGlobalRule = true;
|
54 |
-
}
|
55 |
|
56 |
-
//
|
57 |
-
if (
|
58 |
-
$
|
59 |
-
|
60 |
|
61 |
-
if ($isGlobalRule) {
|
62 |
if (in_array($obj->handle, $data['load_exceptions']['styles'])) {
|
63 |
$isLoadException = true;
|
64 |
} else {
|
@@ -84,20 +72,16 @@ if (! empty($data['all']['styles'])) {
|
|
84 |
?>
|
85 |
</p>
|
86 |
|
87 |
-
<div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
|
88 |
<?php
|
89 |
-
// Unloaded Everywhere
|
90 |
if ($globalUnloaded) {
|
91 |
-
|
92 |
<p><strong style="color: #d54e21;">This asset is unloaded everywhere</strong></p>
|
93 |
-
<div class="clear"></div>
|
94 |
<?php
|
95 |
}
|
96 |
?>
|
97 |
|
98 |
<ul class="wpacu_asset_options">
|
99 |
<?php
|
100 |
-
// [START] UNLOAD EVERYWHERE
|
101 |
if ($globalUnloaded) {
|
102 |
?>
|
103 |
<li>
|
@@ -126,77 +110,11 @@ if (! empty($data['all']['styles'])) {
|
|
126 |
class="wpacu_global_unload wpacu_global_style"
|
127 |
id="wpacu_global_unload_style_<?php echo $obj->handle; ?>" type="checkbox"
|
128 |
name="wpacu_global_unload_styles[]" value="<?php echo $obj->handle; ?>"/>
|
129 |
-
Unload Everywhere</label>
|
130 |
</li>
|
131 |
<?php
|
132 |
}
|
133 |
-
// [END] UNLOAD EVERYWHERE
|
134 |
-
?>
|
135 |
-
</ul>
|
136 |
-
</div>
|
137 |
-
|
138 |
-
<?php if ($globalUnloaded || $data['post_type']) { ?>
|
139 |
-
<div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
|
140 |
-
<?php } ?>
|
141 |
-
|
142 |
-
<?php
|
143 |
-
// Unloaded On All Pages Belonging to the page's Post Type
|
144 |
-
if ($postTypeUnloaded) {
|
145 |
-
?>
|
146 |
-
<p><strong style="color: #d54e21;">This asset is unloaded on all <u><?php echo $data['post_type']; ?></u> post types.</strong></p>
|
147 |
-
<div class="clear"></div>
|
148 |
-
<?php
|
149 |
-
}
|
150 |
-
?>
|
151 |
-
|
152 |
-
<ul class="wpacu_asset_options">
|
153 |
-
<?php
|
154 |
-
if ($data['post_type']) {
|
155 |
-
// [START] ALL PAGES HAVING THE SAME POST TYPE
|
156 |
-
if ($postTypeUnloaded) {
|
157 |
-
?>
|
158 |
-
<li>
|
159 |
-
<label><input data-handle="<?php echo $obj->handle; ?>"
|
160 |
-
class="wpacu_bulk_option wpacu_style"
|
161 |
-
type="radio"
|
162 |
-
name="wpacu_options_post_type_styles[<?php echo $obj->handle; ?>]"
|
163 |
-
checked="checked"
|
164 |
-
value="default"/>
|
165 |
-
Keep rule</label>
|
166 |
-
</li>
|
167 |
-
|
168 |
-
<li>
|
169 |
-
<label><input data-handle="<?php echo $obj->handle; ?>"
|
170 |
-
class="wpacu_bulk_option wpacu_style"
|
171 |
-
type="radio"
|
172 |
-
name="wpacu_options_post_type_styles[<?php echo $obj->handle; ?>]"
|
173 |
-
value="remove"/>
|
174 |
-
Remove rule</label>
|
175 |
-
</li>
|
176 |
-
<?php
|
177 |
-
} else {
|
178 |
-
?>
|
179 |
-
<li>
|
180 |
-
<label><input data-handle="<?php echo $obj->handle; ?>"
|
181 |
-
class="wpacu_post_type_unload wpacu_post_type_style"
|
182 |
-
id="wpacu_bulk_unload_post_type_style_<?php echo $obj->handle; ?>"
|
183 |
-
type="checkbox"
|
184 |
-
name="wpacu_bulk_unload_styles[post_type][<?php echo $data['post_type']; ?>][]"
|
185 |
-
value="<?php echo $obj->handle; ?>"/>
|
186 |
-
Unload on All Pages of <strong><?php echo $data['post_type']; ?></strong> post type</label>
|
187 |
-
</li>
|
188 |
-
<?php
|
189 |
-
}
|
190 |
-
}
|
191 |
-
// [END] ALL PAGES HAVING THE SAME POST TYPE
|
192 |
?>
|
193 |
-
</ul>
|
194 |
-
|
195 |
-
<?php if ($globalUnloaded || $data['post_type']) { ?>
|
196 |
-
</div>
|
197 |
-
<?php } ?>
|
198 |
-
|
199 |
-
<ul class="wpacu_asset_options">
|
200 |
<li id="wpacu_load_it_option_style_<?php echo $obj->handle; ?>">
|
201 |
<label><input data-handle="<?php echo $obj->handle; ?>"
|
202 |
id="wpacu_style_load_it_<?php echo $obj->handle; ?>"
|
@@ -205,7 +123,7 @@ if (! empty($data['all']['styles'])) {
|
|
205 |
<?php if ($isLoadException) { ?> checked="checked" <?php } ?>
|
206 |
name="wpacu_styles_load_it[]"
|
207 |
value="<?php echo $obj->handle; ?>"/>
|
208 |
-
Load it on this page (make exception<?php if (! $
|
209 |
</li>
|
210 |
</ul>
|
211 |
<?php
|
@@ -240,23 +158,13 @@ if (! empty($data['all']['styles'])) {
|
|
240 |
} else {
|
241 |
echo __('It looks like there are no public .css files loaded or the ones visible do not follow <a href="https://codex.wordpress.org/Function_Reference/wp_enqueue_style">the WordPress way of enqueuing styles</a>.', WPACU_PLUGIN_NAME);
|
242 |
}
|
243 |
-
/* -------------------
|
244 |
-
* [END] STYLES LIST
|
245 |
-
* -------------------
|
246 |
-
*/
|
247 |
-
|
248 |
-
/*
|
249 |
-
* ---------------------
|
250 |
-
* [START] SCRIPTS LIST
|
251 |
-
* ---------------------
|
252 |
-
*/
|
253 |
?>
|
254 |
<h3><?php _e('Scripts (.js files)', WPACU_PLUGIN_NAME); ?></h3>
|
255 |
<?php
|
256 |
if (! empty($data['all']['scripts'])) {
|
257 |
?>
|
258 |
<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>
|
259 |
-
<p><?php echo __('"Load in on this page (make exception)" will take effect when
|
260 |
<?php
|
261 |
if ($data['core_scripts_loaded']) {
|
262 |
?>
|
@@ -280,19 +188,13 @@ if (! empty($data['all']['scripts'])) {
|
|
280 |
$class = ($active) ? 'wpacu_not_load' : '';
|
281 |
$checked = ($active) ? 'checked="checked"' : '';
|
282 |
|
283 |
-
$globalUnloaded = $
|
284 |
|
285 |
-
//
|
286 |
if (in_array($obj->handle, $data['global_unload']['scripts']) && !$class) {
|
287 |
-
$globalUnloaded =
|
288 |
-
|
289 |
|
290 |
-
// Mark it as unloaded - for the Current Post Type
|
291 |
-
if (isset($data['post_type_unloaded']['scripts']) && in_array($obj->handle, $data['post_type_unloaded']['scripts']) && !$class) {
|
292 |
-
$postTypeUnloaded = $isGlobalRule = true;
|
293 |
-
}
|
294 |
-
|
295 |
-
if ($isGlobalRule) {
|
296 |
if (in_array($obj->handle, $data['load_exceptions']['scripts'])) {
|
297 |
$isLoadException = true;
|
298 |
} else {
|
@@ -317,26 +219,20 @@ if (! empty($data['all']['scripts'])) {
|
|
317 |
}
|
318 |
?>
|
319 |
</p>
|
|
|
|
|
|
|
|
|
|
|
320 |
|
321 |
-
<?php
|
322 |
-
// Unloaded Everywhere
|
323 |
-
if ($globalUnloaded) {
|
324 |
-
?>
|
325 |
-
<p><strong style="color: #d54e21;">This asset is unloaded everywhere</strong></p>
|
326 |
-
<?php
|
327 |
-
}
|
328 |
-
?>
|
329 |
-
|
330 |
-
<div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
|
331 |
<ul class="wpacu_asset_options">
|
332 |
|
333 |
<?php
|
334 |
-
// [START] UNLOAD EVERYWHERE
|
335 |
if ($globalUnloaded) {
|
336 |
-
|
337 |
<li>
|
338 |
<label><input data-handle="<?php echo $obj->handle; ?>"
|
339 |
-
class="
|
340 |
type="radio"
|
341 |
name="wpacu_options_scripts[<?php echo $obj->handle; ?>]"
|
342 |
checked="checked"
|
@@ -346,7 +242,7 @@ if (! empty($data['all']['scripts'])) {
|
|
346 |
|
347 |
<li>
|
348 |
<label><input data-handle="<?php echo $obj->handle; ?>"
|
349 |
-
class="
|
350 |
type="radio"
|
351 |
name="wpacu_options_scripts[<?php echo $obj->handle; ?>]"
|
352 |
value="remove" />
|
@@ -362,77 +258,11 @@ if (! empty($data['all']['scripts'])) {
|
|
362 |
type="checkbox"
|
363 |
name="wpacu_global_unload_scripts[]"
|
364 |
value="<?php echo $obj->handle; ?>"/>
|
365 |
-
Unload Everywhere</label>
|
366 |
</li>
|
367 |
-
<?php
|
368 |
-
}
|
369 |
-
// [END] UNLOAD EVERYWHERE
|
370 |
-
?>
|
371 |
-
|
372 |
-
</ul>
|
373 |
-
</div>
|
374 |
-
|
375 |
-
<?php if ($globalUnloaded || $data['post_type']) { ?>
|
376 |
-
<div style="padding: 5px 10px; margin: 15px 0; background: white; border: 1px solid #eee; border-radius: 5px;">
|
377 |
-
<?php } ?>
|
378 |
-
|
379 |
<?php
|
380 |
-
// Unloaded On All Pages Belonging to the page's Post Type
|
381 |
-
if ($postTypeUnloaded) {
|
382 |
-
?>
|
383 |
-
<p><strong style="color: #d54e21;">This asset is unloaded on all <u><?php echo $data['post_type']; ?></u> post types.</strong></p>
|
384 |
-
<div class="clear"></div>
|
385 |
-
<?php
|
386 |
-
}
|
387 |
-
?>
|
388 |
-
|
389 |
-
<ul class="wpacu_asset_options">
|
390 |
-
<?php
|
391 |
-
if ($data['post_type']) {
|
392 |
-
// [START] ALL PAGES HAVING THE SAME POST TYPE
|
393 |
-
if ($postTypeUnloaded) {
|
394 |
-
?>
|
395 |
-
<li>
|
396 |
-
<label><input data-handle="<?php echo $obj->handle; ?>"
|
397 |
-
class="wpacu_post_type_option wpacu_post_type_script"
|
398 |
-
type="radio"
|
399 |
-
name="wpacu_options_post_type_scripts[<?php echo $obj->handle; ?>]"
|
400 |
-
checked="checked"
|
401 |
-
value="default"/>
|
402 |
-
Keep rule</label>
|
403 |
-
</li>
|
404 |
-
|
405 |
-
<li>
|
406 |
-
<label><input data-handle="<?php echo $obj->handle; ?>"
|
407 |
-
class="wpacu_post_type_option wpacu_post_type_script"
|
408 |
-
type="radio"
|
409 |
-
name="wpacu_options_post_type_scripts[<?php echo $obj->handle; ?>]"
|
410 |
-
value="remove"/>
|
411 |
-
Remove rule</label>
|
412 |
-
</li>
|
413 |
-
<?php
|
414 |
-
} else {
|
415 |
-
?>
|
416 |
-
<li>
|
417 |
-
<label><input data-handle="<?php echo $obj->handle; ?>"
|
418 |
-
class="wpacu_post_type_unload wpacu_post_type_script"
|
419 |
-
id="wpacu_global_unload_post_type_script_<?php echo $obj->handle; ?>"
|
420 |
-
type="checkbox"
|
421 |
-
name="wpacu_bulk_unload_scripts[post_type][<?php echo $data['post_type']; ?>][]"
|
422 |
-
value="<?php echo $obj->handle; ?>"/>
|
423 |
-
Unload on All Pages of <strong><?php echo $data['post_type']; ?></strong> post type</label>
|
424 |
-
</li>
|
425 |
-
<?php
|
426 |
-
}
|
427 |
}
|
428 |
-
// [END] ALL PAGES HAVING THE SAME POST TYPE
|
429 |
?>
|
430 |
-
</ul>
|
431 |
-
<?php if ($globalUnloaded || $data['post_type']) { ?>
|
432 |
-
</div>
|
433 |
-
<?php } ?>
|
434 |
-
|
435 |
-
<ul class="wpacu_asset_options">
|
436 |
<li id="wpacu_load_it_option_script_<?php echo $obj->handle; ?>">
|
437 |
<label><input data-handle="<?php echo $obj->handle; ?>"
|
438 |
id="wpacu_script_load_it_<?php echo $obj->handle; ?>"
|
@@ -441,7 +271,7 @@ if (! empty($data['all']['scripts'])) {
|
|
441 |
name="wpacu_scripts_load_it[]"
|
442 |
<?php if ($isLoadException) { ?> checked="checked" <?php } ?>
|
443 |
value="<?php echo $obj->handle; ?>" />
|
444 |
-
Load it on this page (make exception<?php if (! $
|
445 |
</li>
|
446 |
</ul>
|
447 |
<?php
|
@@ -464,7 +294,7 @@ if (! empty($data['all']['scripts'])) {
|
|
464 |
}
|
465 |
|
466 |
if (isset($obj->extra->data) && ! empty($obj->extra->data)) { ?>
|
467 |
-
<p><?php _e('Inline:', WPACU_PLUGIN_NAME); ?> <em><?php echo
|
468 |
<?php
|
469 |
}
|
470 |
|
@@ -485,8 +315,3 @@ if (! empty($data['all']['scripts'])) {
|
|
485 |
} else {
|
486 |
echo __('It looks like there are no public .js files loaded or the ones visible do not follow <a href="https://codex.wordpress.org/Function_Reference/wp_enqueue_script">the WordPress way of enqueuing scripts</a>.', WPACU_PLUGIN_NAME);
|
487 |
}
|
488 |
-
/*
|
489 |
-
* -------------------
|
490 |
-
* [END] SCRIPTS LIST
|
491 |
-
* -------------------
|
492 |
-
*/
|
10 |
<div class="wpacu_verified">
|
11 |
<strong>Verified Page:</strong> <a target="_blank" href="<?php echo $data['fetch_url']; ?>"><span><?php echo $data['fetch_url']; ?></span></a>
|
12 |
</div>
|
13 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
<h3><?php _e('Styles (.css files)', WPACU_PLUGIN_NAME); ?></h3>
|
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 |
?>
|
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 {
|
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>
|
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 |
+
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; ?>"
|
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
|
158 |
} else {
|
159 |
echo __('It looks like there are no public .css files loaded or the ones visible do not follow <a href="https://codex.wordpress.org/Function_Reference/wp_enqueue_style">the WordPress way of enqueuing styles</a>.', WPACU_PLUGIN_NAME);
|
160 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
?>
|
162 |
<h3><?php _e('Scripts (.js files)', WPACU_PLUGIN_NAME); ?></h3>
|
163 |
<?php
|
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 |
?>
|
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 {
|
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"
|
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" />
|
258 |
type="checkbox"
|
259 |
name="wpacu_global_unload_scripts[]"
|
260 |
value="<?php echo $obj->handle; ?>"/>
|
261 |
+
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; ?>"
|
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
|
294 |
}
|
295 |
|
296 |
if (isset($obj->extra->data) && ! empty($obj->extra->data)) { ?>
|
297 |
+
<p><?php _e('Inline:', WPACU_PLUGIN_NAME); ?> <em><?php echo $obj->extra->data; ?></em></p>
|
298 |
<?php
|
299 |
}
|
300 |
|
315 |
} else {
|
316 |
echo __('It looks like there are no public .js files loaded or the ones visible do not follow <a href="https://codex.wordpress.org/Function_Reference/wp_enqueue_script">the WordPress way of enqueuing scripts</a>.', WPACU_PLUGIN_NAME);
|
317 |
}
|
|
|
|
|
|
|
|
|
|
templates/settings-globals.php
DELETED
@@ -1,237 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
* No direct access to this file
|
4 |
-
*/
|
5 |
-
if (! isset($data)) {
|
6 |
-
exit;
|
7 |
-
}
|
8 |
-
?>
|
9 |
-
<h1><?php _e('WP Asset Clean Up', WPACU_PLUGIN_NAME); ?></h1>
|
10 |
-
<h2><?php _e('Global Rules', WPACU_PLUGIN_NAME); ?></h2>
|
11 |
-
|
12 |
-
<nav class="nav-tab-wrapper">
|
13 |
-
<a href="admin.php?page=wpassetcleanup_globals" class="nav-tab <?php if ($data['for'] === 'everywhere') { ?>nav-tab-active<?php } ?>">Everywhere</a>
|
14 |
-
<a href="admin.php?page=wpassetcleanup_globals&wpacu_for=post_types" class="nav-tab <?php if ($data['for'] === 'post_types') { ?>nav-tab-active<?php } ?>">Post Types</a>
|
15 |
-
</nav>
|
16 |
-
|
17 |
-
<div class="clear"></div>
|
18 |
-
|
19 |
-
<?php
|
20 |
-
if ($data['for'] === 'post_types') {
|
21 |
-
?>
|
22 |
-
<div style="margin: 15px 0;">
|
23 |
-
<form id="wpacu_post_type_form" method="get" action="admin.php">
|
24 |
-
<input type="hidden" name="page" value="wpassetcleanup_globals" />
|
25 |
-
<input type="hidden" name="wpacu_for" value="post_types" />
|
26 |
-
|
27 |
-
<div style="margin: 0 0 10px 0;">Select the post type for which you want to see the unloaded scripts & styles:</div>
|
28 |
-
<select id="wpacu_post_type_select" name="wpacu_post_type">
|
29 |
-
<?php foreach ($data['post_types_list'] as $postType) { ?>
|
30 |
-
<option <?php if ($data['post_type'] === $postType) { echo 'selected="selected"'; } ?> value="<?php echo $postType; ?>"><?php echo $postType; ?></option>
|
31 |
-
<?php } ?>
|
32 |
-
</select>
|
33 |
-
</form>
|
34 |
-
</div>
|
35 |
-
<?php
|
36 |
-
}
|
37 |
-
?>
|
38 |
-
|
39 |
-
<form action="" method="post">
|
40 |
-
<?php
|
41 |
-
if ($data['for'] === 'everywhere') {
|
42 |
-
?>
|
43 |
-
<div class="clear"></div>
|
44 |
-
|
45 |
-
<div class="alert">
|
46 |
-
<p>This is the list of the assets that are <strong>globally unloaded</strong> on all pages (including home page).</p>
|
47 |
-
<p>If you want to remove this rule and have them loading, use the "Remove rule" checkbox.</p>
|
48 |
-
<p style="margin: 0; background: white; padding: 10px; border: 1px solid #ccc; width: auto; display: inline-block;">This list fills once you select "<em>Unload everywhere</em>" when you edit posts/pages for the assets that you want to prevent from loading on every page.</p>
|
49 |
-
</div>
|
50 |
-
|
51 |
-
<div class="clear"></div>
|
52 |
-
|
53 |
-
<div style="padding: 0 10px 0 0;">
|
54 |
-
<h3>Styles</h3>
|
55 |
-
<?php
|
56 |
-
if (! empty($data['values']['styles'])) {
|
57 |
-
?>
|
58 |
-
<table class="wp-list-table widefat fixed striped">
|
59 |
-
<tr>
|
60 |
-
<td><strong>Handle</strong></td>
|
61 |
-
<td><strong>Actions</strong></td>
|
62 |
-
</tr>
|
63 |
-
<?php
|
64 |
-
foreach ($data['values']['styles'] as $handle) {
|
65 |
-
?>
|
66 |
-
<tr class="wpacu_global_rule_row">
|
67 |
-
<td><strong><span style="color: green;"><?php echo $handle; ?></span></strong></td>
|
68 |
-
<td>
|
69 |
-
<label><input type="checkbox"
|
70 |
-
class="wpacu_remove_rule"
|
71 |
-
name="wpacu_options_styles[<?php echo $handle; ?>]"
|
72 |
-
value="remove" /> Remove rule</label>
|
73 |
-
</td>
|
74 |
-
</tr>
|
75 |
-
<?php
|
76 |
-
}
|
77 |
-
?>
|
78 |
-
</table>
|
79 |
-
<?php
|
80 |
-
} else {
|
81 |
-
?>
|
82 |
-
<p>There are no unloaded styles for your selection.</p>
|
83 |
-
<?php
|
84 |
-
}
|
85 |
-
?>
|
86 |
-
|
87 |
-
<h3>Scripts</h3>
|
88 |
-
<?php
|
89 |
-
if (! empty($data['values']['scripts'])) {
|
90 |
-
?>
|
91 |
-
<table class="wp-list-table widefat fixed striped">
|
92 |
-
<tr>
|
93 |
-
<td><strong>Handle</strong></td>
|
94 |
-
<td><strong>Actions</strong></td>
|
95 |
-
</tr>
|
96 |
-
<?php
|
97 |
-
foreach ($data['values']['scripts'] as $handle) {
|
98 |
-
?>
|
99 |
-
<tr class="wpacu_global_rule_row">
|
100 |
-
<td><strong><span style="color: green;"><?php echo $handle; ?></span></strong></td>
|
101 |
-
<td>
|
102 |
-
<label><input type="checkbox"
|
103 |
-
class="wpacu_remove_rule"
|
104 |
-
name="wpacu_options_scripts[<?php echo $handle; ?>]"
|
105 |
-
value="remove" /> Remove rule</label>
|
106 |
-
</td>
|
107 |
-
</tr>
|
108 |
-
<?php
|
109 |
-
}
|
110 |
-
?>
|
111 |
-
</table>
|
112 |
-
<?php
|
113 |
-
} else {
|
114 |
-
?>
|
115 |
-
<p>There are no unloaded scripts for your selection.</p>
|
116 |
-
<?php
|
117 |
-
}
|
118 |
-
?>
|
119 |
-
</div>
|
120 |
-
<?php
|
121 |
-
} elseif ($data['for'] === 'post_types') {
|
122 |
-
?>
|
123 |
-
<div class="clear"></div>
|
124 |
-
|
125 |
-
<div class="alert">
|
126 |
-
<p>This is the list of the assets that are <strong>unloaded</strong> on all pages belonging to the <strong><u><?php echo $data['post_type']; ?></u></strong> post type.</p>
|
127 |
-
<p>If you want to remove this rule, use the "Remove rule" checkbox.</p>
|
128 |
-
<p style="margin: 0; background: white; padding: 10px; border: 1px solid #ccc; width: auto; display: inline-block;">This list fills once you select "<em>Unload on All Pages of <strong><?php echo $data['post_type']; ?></strong> post type</em>" when you edit posts/pages for the assets that you want to prevent from loading.</p>
|
129 |
-
</div>
|
130 |
-
|
131 |
-
<div class="clear"></div>
|
132 |
-
|
133 |
-
<div style="padding: 0 10px 0 0;">
|
134 |
-
<h3>Styles</h3>
|
135 |
-
<?php
|
136 |
-
if (! empty($data['values']['styles'])) {
|
137 |
-
?>
|
138 |
-
<table class="wp-list-table widefat fixed striped">
|
139 |
-
<tr>
|
140 |
-
<td><strong>Handle</strong></td>
|
141 |
-
<td><strong>Actions</strong></td>
|
142 |
-
</tr>
|
143 |
-
<?php
|
144 |
-
foreach ($data['values']['styles'] as $handle) {
|
145 |
-
?>
|
146 |
-
<tr class="wpacu_global_rule_row">
|
147 |
-
<td><strong><span style="color: green;"><?php echo $handle; ?></span></strong></td>
|
148 |
-
<td>
|
149 |
-
<label><input type="checkbox"
|
150 |
-
class="wpacu_remove_rule"
|
151 |
-
name="wpacu_options_post_type_styles[<?php echo $handle; ?>]"
|
152 |
-
value="remove" /> Remove rule</label>
|
153 |
-
</td>
|
154 |
-
</tr>
|
155 |
-
<?php
|
156 |
-
}
|
157 |
-
?>
|
158 |
-
</table>
|
159 |
-
<?php
|
160 |
-
} else {
|
161 |
-
?>
|
162 |
-
<p>There are no unloaded styles for your selection.</p>
|
163 |
-
<?php
|
164 |
-
}
|
165 |
-
?>
|
166 |
-
|
167 |
-
<h3>Scripts</h3>
|
168 |
-
<?php
|
169 |
-
if (! empty($data['values']['scripts'])) {
|
170 |
-
?>
|
171 |
-
<table class="wp-list-table widefat fixed striped">
|
172 |
-
<tr>
|
173 |
-
<td><strong>Handle</strong></td>
|
174 |
-
<td><strong>Actions</strong></td>
|
175 |
-
</tr>
|
176 |
-
<?php
|
177 |
-
foreach ($data['values']['scripts'] as $handle) {
|
178 |
-
?>
|
179 |
-
<tr class="wpacu_global_rule_row">
|
180 |
-
<td><strong><span style="color: green;"><?php echo $handle; ?></span></strong></td>
|
181 |
-
<td>
|
182 |
-
<label><input type="checkbox"
|
183 |
-
class="wpacu_remove_rule"
|
184 |
-
name="wpacu_options_post_type_scripts[<?php echo $handle; ?>]"
|
185 |
-
value="remove" /> Remove rule</label>
|
186 |
-
</td>
|
187 |
-
</tr>
|
188 |
-
<?php
|
189 |
-
}
|
190 |
-
?>
|
191 |
-
</table>
|
192 |
-
<?php
|
193 |
-
} else {
|
194 |
-
?>
|
195 |
-
<p>There are no unloaded scripts for your selection.</p>
|
196 |
-
<?php
|
197 |
-
}
|
198 |
-
?>
|
199 |
-
</div>
|
200 |
-
<?php
|
201 |
-
}
|
202 |
-
|
203 |
-
$noAssetsToRemove = (empty($data['values']['styles']) && empty($data['values']['scripts']));
|
204 |
-
?>
|
205 |
-
<?php wp_nonce_field($data['nonce_action'], $data['nonce_name']); ?>
|
206 |
-
|
207 |
-
<input type="hidden" name="wpacu_for" value="<?php echo $data['for']; ?>" />
|
208 |
-
<input type="hidden" name="wpacu_update" value="1" />
|
209 |
-
|
210 |
-
<?php
|
211 |
-
if ($data['post_type']) {
|
212 |
-
?>
|
213 |
-
<input type="hidden" name="wpacu_post_type" value="<?php echo $data['post_type']; ?>" />
|
214 |
-
<?php
|
215 |
-
}
|
216 |
-
?>
|
217 |
-
|
218 |
-
<div class="clear"></div>
|
219 |
-
|
220 |
-
<p class="submit">
|
221 |
-
<input type="submit"
|
222 |
-
name="submit"
|
223 |
-
id="submit"
|
224 |
-
<?php if ($noAssetsToRemove) { ?>
|
225 |
-
disabled="disabled"
|
226 |
-
<?php } ?>
|
227 |
-
class="button button-primary"
|
228 |
-
value="<?php esc_attr_e('Update', WPACU_PLUGIN_NAME); ?>" />
|
229 |
-
<?php
|
230 |
-
if ($noAssetsToRemove) {
|
231 |
-
?>
|
232 |
-
<small>Note: There are no unloaded assets (scripts & styles) to be managed</small>
|
233 |
-
<?php
|
234 |
-
}
|
235 |
-
?>
|
236 |
-
</p>
|
237 |
-
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wpacu-load.php
CHANGED
@@ -12,19 +12,19 @@ define('WPACU_PLUGIN_URL', plugins_url('', WPACU_PLUGIN_FILE));
|
|
12 |
// Autoload Classes
|
13 |
function includeWpAssetCleanUpClassesAutoload($class)
|
14 |
{
|
15 |
-
$
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
return;
|
20 |
}
|
21 |
|
22 |
-
$
|
23 |
-
|
24 |
-
// Can be directories such as "Helpers"
|
25 |
-
$classFilter = str_replace('\\', '/', $classFilter);
|
26 |
-
|
27 |
-
$pathToClass = WPACU_PLUGIN_CLASSES_PATH.$classFilter.'.php';
|
28 |
|
29 |
if (file_exists($pathToClass)) {
|
30 |
include_once $pathToClass;
|
@@ -36,12 +36,6 @@ spl_autoload_register('includeWpAssetCleanUpClassesAutoload');
|
|
36 |
// Main Class
|
37 |
WpAssetCleanUp\Main::instance();
|
38 |
|
39 |
-
// Plugin's Assets (used only when you're logged in)
|
40 |
-
new \WpAssetCleanUp\OwnAssets;
|
41 |
-
|
42 |
-
// Add / Update / Remove Settings
|
43 |
-
(new WpAssetCleanUp\Update)->init();
|
44 |
-
|
45 |
// Settings
|
46 |
new WpAssetCleanUp\Settings;
|
47 |
|
12 |
// Autoload Classes
|
13 |
function includeWpAssetCleanUpClassesAutoload($class)
|
14 |
{
|
15 |
+
$classes = array(
|
16 |
+
'WpAssetCleanUp\ClassLoader' => 'ClassLoader',
|
17 |
+
'WpAssetCleanUp\HomePage' => 'HomePage',
|
18 |
+
'WpAssetCleanUp\Main' => 'Main',
|
19 |
+
'WpAssetCleanUp\Menu' => 'Menu',
|
20 |
+
'WpAssetCleanUp\Settings' => 'Settings'
|
21 |
+
);
|
22 |
+
|
23 |
+
if (! isset($classes[$class])) {
|
24 |
return;
|
25 |
}
|
26 |
|
27 |
+
$pathToClass = WPACU_PLUGIN_CLASSES_PATH.$classes[$class].'.php';
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if (file_exists($pathToClass)) {
|
30 |
include_once $pathToClass;
|
36 |
// Main Class
|
37 |
WpAssetCleanUp\Main::instance();
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
// Settings
|
40 |
new WpAssetCleanUp\Settings;
|
41 |
|
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.2.
|
6 |
* Description: Prevent Chosen Scripts & Styles from loading in Posts/Pages that you don't need
|
7 |
* Author: Gabriel Livan
|
8 |
* Author URI: http://www.gabelivan.com/
|
2 |
/*
|
3 |
* Plugin Name: WP Asset Clean Up
|
4 |
* Plugin URI: http://www.bitrepository.com/remove-unused-scripts-styles-wordpress-pages.html
|
5 |
+
* Version: 1.2.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/
|