PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | minify/class-wp-optimize-minify-admin.php +112 -52 3.7.0 → 4.7.0 View file →
@@ -2,10 +2,8 @@
2 2 if (!defined('ABSPATH')) die('No direct access allowed');
3 3
4 4 class WP_Optimize_Minify_Admin {
5 5
6 - private $wp_version_required = '4.5';
7 -
8 6 /**
9 7 * Initialize, add actions and filters
10 8 *
11 9 * @return void
@@ -10,14 +8,12 @@
10 8 *
11 9 * @return void
12 10 */
13 11 public function __construct() {
14 - if (WPO_MINIFY_PHP_VERSION_MET) {
15 - // exclude processing for editors and administrators (fix editors)
16 - add_action('wp_optimize_admin_page_wpo_minify_status', array($this, 'check_permissions_admin_notices'));
17 - }
12 + // exclude processing for editors and administrators (fix editors)
13 + add_action('wp_optimize_admin_page_wpo_minify_status', array($this, 'check_permissions_admin_notices'));
18 14
19 - add_action('wp_optimize_admin_page_wpo_minify_status', array($this, 'admin_notices_activation_errors'));
15 + add_action('wp_optimize_admin_page_wpo_minify_status', array($this, 'admin_notices_activation_error'));
20 16
21 17 add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
22 18
23 19 // This function runs when WordPress updates or installs/remove something. Forces new cache
@@ -29,11 +25,12 @@
29 25 add_action('updraftcentral_version_updated', array('WP_Optimize_Minify_Cache_Functions', 'reset'));
30 26 add_action('elementor/editor/after_save', array('WP_Optimize_Minify_Cache_Functions', 'reset'));
31 27 add_action('fusion_cache_reset_after', array('WP_Optimize_Minify_Cache_Functions', 'reset'));
32 28 // Output asset preload placeholder, replaced by premium
33 - add_action('wpo_minify_settings_tabs', array($this, 'output_assets_preload_placeholder'), 10, 1);
29 + add_action('wpo_minify_settings_tabs', array($this, 'output_assets_preload_placeholder'));
34 30
35 31 add_action('wp_optimize_register_admin_content', array($this, 'register_content'));
32 + add_action('wpo_after_minify_javascript_options', array($this, 'output_capo_js_settings'));
36 33 }
37 34
38 35 /**
39 36 * Register the content
@@ -51,8 +48,21 @@
51 48 add_action('wp_optimize_admin_page_wpo_minify_preload', array($this, 'output_preload_settings'), 20);
52 49 }
53 50
54 51 /**
52 + * Output Capo JS settings
53 + *
54 + * @return void
55 + */
56 + public function output_capo_js_settings() {
57 + $wpo_minify_options = wp_optimize_minify_config()->get();
58 + $extract = array(
59 + 'enable_capo_js' => $wpo_minify_options['enable_capo_js'] ?? false,
60 + );
61 + WP_Optimize()->include_template('minify/capo-js.php', false, $extract);
62 + }
63 +
64 + /**
55 65 * Load scripts for controlling the admin pages
56 66 *
57 67 * @param string $hook
58 68 * @return void
@@ -60,41 +70,23 @@
60 70 public function admin_enqueue_scripts($hook) {
61 71 $enqueue_version = WP_Optimize()->get_enqueue_version();
62 72 $min_or_not_internal = WP_Optimize()->get_min_or_not_internal_string();
63 73 if (preg_match('/wp\-optimize/i', $hook)) {
64 - wp_enqueue_script('wp-optimize-min-js', WPO_PLUGIN_URL.'js/minify' . $min_or_not_internal . '.js', array('jquery', 'wp-optimize-admin-js'), $enqueue_version);
74 + wp_enqueue_script('wp-optimize-min-js', WPO_PLUGIN_URL.'js/minify' . $min_or_not_internal . '.js', array('jquery', 'wp-optimize-admin-js'), $enqueue_version, true);
65 75 }
66 76 }
67 77
68 78 /**
69 - * Conditionally runs upon the WP action admin_notices to display errors
79 + * Conditionally runs upon the WP action admin_notices to display error
70 80 *
71 81 * @return void
72 82 */
73 - public function admin_notices_activation_errors() {
74 - global $wp_version;
75 - include ABSPATH . WPINC . '/version.php';
76 - $errors = array();
77 -
78 - if (!WPO_MINIFY_PHP_VERSION_MET) {
79 - $errors[] = __('WP-Optimize Minify requires PHP 5.4 or higher.', 'wp-optimize') . ' ' . sprintf(__("You're using version %s.", 'wp-optimize'), PHP_VERSION);
80 - }
81 -
83 + public function admin_notices_activation_error() {
82 84 if (!extension_loaded('mbstring')) {
83 - $errors[] = __('WP-Optimize Minify requires the PHP mbstring module to be installed on the server; please ask your web hosting company for advice on how to enable it on your server.', 'wp-optimize');
85 + echo '<div class="notice notice-error wpo-warning">';
86 + echo '<p>' . esc_html__('WP-Optimize Minify requires the PHP mbstring module to be installed on the server; please ask your web hosting company for advice on how to enable it on your server.', 'wp-optimize') . '</p>';
87 + echo '</div>';
84 88 }
85 -
86 - if (version_compare($wp_version, $this->wp_version_required, '<')) {
87 - $errors[] = sprintf(__('WP-Optimize Minify requires WordPress version %s or higher.', 'wp-optimize'), $this->wp_version_required) . ' ' . sprintf(__("You're using version %s.", 'wp-optimize'), $wp_version);
88 - }
89 -
90 - foreach ($errors as $error) {
91 - ?>
92 - <div class="notice notice-error wpo-warning">
93 - <p><?php echo $error; ?></p>
94 - </div>
95 - <?php
96 - }
97 89 }
98 90
99 91 /**
100 92 * Display an admin notice if the user has inadequate filesystem permissions
@@ -104,27 +96,34 @@
104 96 public function check_permissions_admin_notices() {
105 97 // get cache path
106 98 $cache_path = WP_Optimize_Minify_Cache_Functions::cache_path();
107 99 $cache_dir = $cache_path['cachedir'];
108 - if (is_dir($cache_dir) && !is_writable($cache_dir)) {
100 + if (is_dir($cache_dir) && !wp_is_writable($cache_dir)) {
109 101 $chmod = substr(sprintf('%o', fileperms($cache_dir)), -4);
110 102 ?>
111 103 <div class="notice notice-error wpo-warning">
112 104 <p>
113 - <?php printf(__('WP-Optimize Minify needs write permissions on the folder %s.', 'wp-optimize'), "<strong>".htmlspecialchars($cache_dir)."</strpmg>"); ?>
105 + <?php
106 + // translators: %s is a directory
107 + echo wp_kses_post(sprintf(__('WP-Optimize Minify needs write permissions on the folder %s.', 'wp-optimize'), "<strong>". esc_html($cache_dir)."</strong>"));
108 + ?>
114 109 </p>
115 110 </div>
116 111 <div class="notice notice-error wpo-warning">
117 112 <p>
118 - <?php printf(__('The current permissions for WP-Optimize Minify are chmod %s.', 'wp-optimize'), "<strong>$chmod</strong>"); ?>
113 + <?php
114 + // translators: %s is a file permissions code
115 + echo wp_kses_post(sprintf(__('The current permissions for WP-Optimize Minify are chmod %s.', 'wp-optimize'), "<strong>" . esc_html($chmod) . "</strong>"));
116 + ?>
119 117 </p>
120 118 </div>
121 119 <div class="notice notice-error wpo-warning">
122 120 <p>
123 121 <?php
124 - printf(__('If you need something more than %s for it to work, then your server is probably misconfigured.', 'wp-optimize'), '<strong>775</strong>');
122 + // translators: %s is a file permissions code
123 + echo wp_kses_post(sprintf(__('If you need something more than %s for it to work, then your server is probably misconfigured.', 'wp-optimize'), '<strong>775</strong>'));
125 124 echo " ";
126 - _e('Please contact your hosting provider.', 'wp-optimize');
125 + esc_html_e('Please contact your hosting provider.', 'wp-optimize');
127 126 ?>
128 127 </p>
129 128 </div>
130 129 <?php
@@ -159,13 +158,15 @@
159 158 * @return void
160 159 */
161 160 public function output_font_settings() {
162 161 $wpo_minify_options = wp_optimize_minify_config()->get();
162 +
163 163 WP_Optimize()->include_template(
164 164 'minify/font-settings-tab.php',
165 165 false,
166 166 array(
167 - 'wpo_minify_options' => $wpo_minify_options
167 + 'wpo_minify_options' => $wpo_minify_options,
168 + 'fonts_cache_size' => WP_Optimize()::is_premium() ? WP_Optimize_Host_Google_Fonts::instance()->get_cache_stats() : '',
168 169 )
169 170 );
170 171 }
171 172
@@ -175,11 +176,11 @@
175 176 * @return void
176 177 */
177 178 public function output_analytics_settings() {
178 179 $config = wp_optimize_minify_config()->get();
179 - $id = isset($config['tracking_id']) ? $config['tracking_id'] : '';
180 - $method = isset($config['analytics_method']) ? $config['analytics_method'] : '';
181 - $is_enabled = isset($config['enable_analytics']) ? $config['enable_analytics'] : false;
180 + $id = $config['tracking_id'] ?? '';
181 + $method = $config['analytics_method'] ?? '';
182 + $is_enabled = $config['enable_analytics'] ?? false;
182 183
183 184 WP_Optimize()->include_template(
184 185 'minify/analytics-settings-tab.php',
185 186 false,
@@ -191,20 +192,81 @@
191 192 );
192 193 }
193 194
194 195 /**
196 + * Minify - Get the output settings for the CSS or JS settings tabs
197 + *
198 + * @param string $type - css or js
199 + *
200 + * @return array
201 + */
202 + private function get_output_setting($type) {
203 + $wpo_minify_options = wp_optimize_minify_config()->get();
204 + $is_http1 = WP_Optimize_Utils::is_request_protocol_http1();
205 + $protocol = $is_http1 ? 'HTTP/1.x' : 'HTTP/2/3';
206 +
207 + $merge_enabled = !empty($wpo_minify_options['enable_merging_of_'.$type]);
208 +
209 + // Determine if the notice should be shown
210 + $should_show_notice = (($is_http1 && !$merge_enabled) || (!$is_http1 && $merge_enabled));
211 + $user_dismissed = get_user_meta(get_current_user_id(), 'wpo_hide_'.$type.'_merging_notice', true);
212 +
213 + // Only show if a user hasn't dismissed yet
214 + $show_section_notice = $should_show_notice && !$user_dismissed;
215 + $is_enabled_minification = $wpo_minify_options['enable_'.$type.'_minification'];
216 +
217 + $label = 'js' === $type ? 'JavaScript' : 'CSS';
218 +
219 + // Notice text
220 + $notice_text = sprintf(
221 + /* translators: 1: File type (CSS/JS), 2: HTTP protocol */
222 + __('Merging %1$s files may improve performance on HTTP/1.1, but could reduce speed on HTTP/2/3.<br><b>Note:</b> Your site is currently using %2$s.', 'wp-optimize'),
223 + $label,
224 + $protocol
225 + );
226 +
227 + // Tooltip parts
228 + $tooltip_parts = array(
229 + sprintf(
230 + /* translators: %s: File type (CSS/JS) */
231 + __('Combines multiple %s files into one to reduce HTTP requests.', 'wp-optimize'),
232 + $label
233 + ),
234 + __('May improve performance on HTTP/1.1, but could reduce speed on HTTP/2/3.', 'wp-optimize'),
235 + __('Disable this option if your site experiences issues.', 'wp-optimize'),
236 + sprintf(
237 + /* translators: %s: HTTP protocol */
238 + __('Note: Your site is currently using %s.', 'wp-optimize'),
239 + $protocol
240 + ),
241 + );
242 + $tooltip = implode(' ', $tooltip_parts);
243 +
244 + return array(
245 + 'protocol' => $protocol,
246 + 'show_section_notice' => $show_section_notice,
247 + 'wpo_minify_options' => $wpo_minify_options,
248 + 'is_enabled_minification' => $is_enabled_minification,
249 + 'notice_text' => $notice_text,
250 + 'tooltip' => $tooltip,
251 + );
252 + }
253 +
254 + /**
195 255 * Minify - Outputs the CSS settings tab
196 256 *
197 257 * @return void
198 258 */
199 259 public function output_css_settings() {
200 - $wpo_minify_options = wp_optimize_minify_config()->get();
260 + $template_args = $this->get_output_setting('css');
261 + $template_args['show_unused_css'] = !WP_Optimize::is_premium() || (WP_Optimize::is_premium() && $template_args['is_enabled_minification']);
262 + $template_args['show_unused_css_advertise'] = !WP_Optimize::is_premium();
263 + $template_args['is_page_cache_enabled'] = WPO_Cache_Config::instance()->get_option('enable_page_caching');
264 +
201 265 WP_Optimize()->include_template(
202 266 'minify/css-settings-tab.php',
203 267 false,
204 - array(
205 - 'wpo_minify_options' => $wpo_minify_options
206 - )
268 + $template_args
207 269 );
208 270 }
209 271
210 272 /**
@@ -212,15 +274,13 @@
212 274 *
213 275 * @return void
214 276 */
215 277 public function output_js_settings() {
216 - $wpo_minify_options = wp_optimize_minify_config()->get();
278 + $template_args = $this->get_output_setting('js');
217 279 WP_Optimize()->include_template(
218 280 'minify/js-settings-tab.php',
219 281 false,
220 - array(
221 - 'wpo_minify_options' => $wpo_minify_options
222 - )
282 + $template_args
223 283 );
224 284 }
225 285
226 286 /**
@@ -229,9 +289,9 @@
229 289 * @return void
230 290 */
231 291 public function output_settings() {
232 292 $wpo_minify_options = wp_optimize_minify_config()->get();
233 - $url = parse_url(get_home_url());
293 + $url = wp_parse_url(get_home_url());
234 294 WP_Optimize()->include_template(
235 295 'minify/settings-tab.php',
236 296 false,
237 297 array(
@@ -271,9 +331,9 @@
271 331 false,
272 332 array(
273 333 'is_cache_enabled' => $cache_config->get_option('enable_page_caching'),
274 334 'is_running' => $is_running,
275 - 'status_message' => isset($status['message']) ? $status['message'] : '',
335 + 'status_message' => $status['message'] ?? '',
276 336 )
277 337 );
278 338 }
279 339
@@ -284,9 +344,9 @@
284 344 */
285 345 public function output_advanced() {
286 346 $wpo_minify_options = wp_optimize_minify_config()->get();
287 347 $files = false;
288 - if (apply_filters('wpo_minify_status_show_files_on_load', true) && WPO_MINIFY_PHP_VERSION_MET) {
348 + if (apply_filters('wpo_minify_status_show_files_on_load', true)) {
289 349 $files = WP_Optimize_Minify_Cache_Functions::get_cached_files();
290 350 }
291 351
292 352 // WP_Optimize_Minify_Functions is only loaded when Minify is active