1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
<?php namespace WpAssetCleanUp;
/** * * Class BulkChanges * @package WpAssetCleanUp */ class BulkChanges { /** * @var string */ public $wpacuFor = 'everywhere';
/** * @var string */ public $wpacuPostType = 'post';
/** * @var array */ public $data = array();
/** * BulkChanges constructor. */ public function __construct() { $this->wpacuFor = sanitize_text_field(Misc::getVar('request', 'wpacu_for', $this->wpacuFor)); $this->wpacuPostType = sanitize_text_field(Misc::getVar('request', 'wpacu_post_type', $this->wpacuPostType));
if (Misc::getVar('request', 'wpacu_update') == 1) { $this->update(); } }
/** * @return array */ public function getCount() { $values = array();
if ($this->wpacuFor === 'everywhere') { $values = Main::instance()->getGlobalUnload(); } elseif ($this->wpacuFor === 'post_types') { $values = Main::instance()->getBulkUnload('post_type', $this->wpacuPostType); }
if (isset($values['styles']) && ! empty($values['styles'])) { sort($values['styles']); }
if (isset($values['scripts']) && ! empty($values['scripts'])) { sort($values['scripts']); }
return $values; }
/** * */ public function pageBulkUnloads() { $this->data['assets_info'] = Main::getHandlesInfo(); $this->data['for'] = $this->wpacuFor;
if ($this->wpacuFor === 'post_types') { $this->data['post_type'] = $this->wpacuPostType;
// Get All Post Types $postTypes = get_post_types(array('public' => true)); $this->data['post_types_list'] = $this->filterPostTypesList($postTypes); }
$this->data['values'] = $this->getCount();
$this->data['nonce_name'] = Update::NONCE_FIELD_NAME; $this->data['nonce_action'] = Update::NONCE_ACTION_NAME;
$this->data['plugin_settings'] = Main::instance()->settings;
Main::instance()->parseTemplate('admin-page-settings-bulk-changes', $this->data, true); }
/** * @param $postTypes * * @return mixed */ public function filterPostTypesList($postTypes) { foreach ($postTypes as $postTypeKey => $postTypeValue) { // Exclude irrelevant custom post types if (in_array($postTypeKey, MetaBoxes::$noMetaBoxesForPostTypes)) { unset($postTypes[$postTypeKey]); }
// Polish existing values if ($postTypeKey === 'product' && Misc::isPluginActive('woocommerce/woocommerce.php')) { $postTypes[$postTypeKey] = 'product ⟶ WooCommerce'; } }
return $postTypes; }
/** * */ public function update() { if ( ! Misc::getVar('post', 'wpacu_bulk_unloads_update_nonce') ) { return; }
check_admin_referer('wpacu_bulk_unloads_update', 'wpacu_bulk_unloads_update_nonce');
$wpacuUpdate = new Update;
if ($this->wpacuFor === 'everywhere') { $removed = $wpacuUpdate->removeEverywhereUnloads(array(), array(), 'post');
if ($removed) { add_action('wpacu_admin_notices', array($this, 'noticeGlobalsRemoved')); } }
if ($this->wpacuFor === 'post_types') { $removed = $wpacuUpdate->removeBulkUnloads($this->wpacuPostType);
if ($removed) { add_action('wpacu_admin_notices', array($this, 'noticePostTypesRemoved')); } } }
/** * */ public function noticeGlobalsRemoved() { ?> <div class="updated notice wpacu-notice is-dismissible"> <p><span class="dashicons dashicons-yes"></span> <?php _e('The selected styles/scripts were removed from the global unload list and they will now load in the pages/posts, unless you have other rules that would prevent them from loading.', 'wp-asset-clean-up'); ?> </p> </div> <?php }
/** * */ public function noticePostTypesRemoved() { ?> <div class="updated notice wpacu-notice is-dismissible"> <p><span class="dashicons dashicons-yes"></span> <?php echo sprintf( __('The selected styles/scripts were removed from the unload list for <strong><u>%s</u></strong> post type and they will now load in the pages/posts, unless you have other rules that would prevent them from loading.', 'wp-asset-clean-up'), $this->wpacuPostType ); ?> </p> </div> <?php } }
|