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 +132 -49 3.2.22 → 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
@@ -44,8 +41,9 @@
44 41 add_action('wp_optimize_admin_page_wpo_minify_status', array($this, 'output_status'), 20);
45 42 add_action('wp_optimize_admin_page_wpo_minify_settings', array($this, 'output_settings'), 20);
46 43 add_action('wp_optimize_admin_page_wpo_minify_advanced', array($this, 'output_advanced'), 20);
47 44 add_action('wp_optimize_admin_page_wpo_minify_font', array($this, 'output_font_settings'), 20);
45 + add_action('wp_optimize_admin_page_wpo_minify_analytics', array($this, 'output_analytics_settings'), 20);
48 46 add_action('wp_optimize_admin_page_wpo_minify_css', array($this, 'output_css_settings'), 20);
49 47 add_action('wp_optimize_admin_page_wpo_minify_js', array($this, 'output_js_settings'), 20);
50 48 add_action('wp_optimize_admin_page_wpo_minify_preload', array($this, 'output_preload_settings'), 20);
51 49 }
@@ -50,8 +48,21 @@
50 48 add_action('wp_optimize_admin_page_wpo_minify_preload', array($this, 'output_preload_settings'), 20);
51 49 }
52 50
53 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 + /**
54 65 * Load scripts for controlling the admin pages
55 66 *
56 67 * @param string $hook
57 68 * @return void
@@ -59,41 +70,23 @@
59 70 public function admin_enqueue_scripts($hook) {
60 71 $enqueue_version = WP_Optimize()->get_enqueue_version();
61 72 $min_or_not_internal = WP_Optimize()->get_min_or_not_internal_string();
62 73 if (preg_match('/wp\-optimize/i', $hook)) {
63 - 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);
64 75 }
65 76 }
66 77
67 78 /**
68 - * Conditionally runs upon the WP action admin_notices to display errors
79 + * Conditionally runs upon the WP action admin_notices to display error
69 80 *
70 81 * @return void
71 82 */
72 - public function admin_notices_activation_errors() {
73 - global $wp_version;
74 - include ABSPATH . WPINC . '/version.php';
75 - $errors = array();
76 -
77 - if (!WPO_MINIFY_PHP_VERSION_MET) {
78 - $errors[] = __('WP-Optimize Minify requires PHP 5.4 or higher.', 'wp-optimize') . ' ' . sprintf(__("You're using version %s.", 'wp-optimize'), PHP_VERSION);
79 - }
80 -
83 + public function admin_notices_activation_error() {
81 84 if (!extension_loaded('mbstring')) {
82 - $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>';
83 88 }
84 -
85 - if (version_compare($wp_version, $this->wp_version_required, '<')) {
86 - $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);
87 - }
88 -
89 - foreach ($errors as $error) {
90 - ?>
91 - <div class="notice notice-error wpo-warning">
92 - <p><?php echo $error; ?></p>
93 - </div>
94 - <?php
95 - }
96 89 }
97 90
98 91 /**
99 92 * Display an admin notice if the user has inadequate filesystem permissions
@@ -103,27 +96,34 @@
103 96 public function check_permissions_admin_notices() {
104 97 // get cache path
105 98 $cache_path = WP_Optimize_Minify_Cache_Functions::cache_path();
106 99 $cache_dir = $cache_path['cachedir'];
107 - if (is_dir($cache_dir) && !is_writable($cache_dir)) {
100 + if (is_dir($cache_dir) && !wp_is_writable($cache_dir)) {
108 101 $chmod = substr(sprintf('%o', fileperms($cache_dir)), -4);
109 102 ?>
110 103 <div class="notice notice-error wpo-warning">
111 104 <p>
112 - <?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 + ?>
113 109 </p>
114 110 </div>
115 111 <div class="notice notice-error wpo-warning">
116 112 <p>
117 - <?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 + ?>
118 117 </p>
119 118 </div>
120 119 <div class="notice notice-error wpo-warning">
121 120 <p>
122 121 <?php
123 - 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>'));
124 124 echo " ";
125 - _e('Please contact your hosting provider.', 'wp-optimize');
125 + esc_html_e('Please contact your hosting provider.', 'wp-optimize');
126 126 ?>
127 127 </p>
128 128 </div>
129 129 <?php
@@ -158,30 +158,115 @@
158 158 * @return void
159 159 */
160 160 public function output_font_settings() {
161 161 $wpo_minify_options = wp_optimize_minify_config()->get();
162 +
162 163 WP_Optimize()->include_template(
163 164 'minify/font-settings-tab.php',
164 165 false,
165 166 array(
166 - '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() : '',
167 169 )
168 170 );
169 171 }
172 +
173 + /**
174 + * Minify - Outputs the analytics settings tab
175 + *
176 + * @return void
177 + */
178 + public function output_analytics_settings() {
179 + $config = wp_optimize_minify_config()->get();
180 + $id = $config['tracking_id'] ?? '';
181 + $method = $config['analytics_method'] ?? '';
182 + $is_enabled = $config['enable_analytics'] ?? false;
183 +
184 + WP_Optimize()->include_template(
185 + 'minify/analytics-settings-tab.php',
186 + false,
187 + array(
188 + 'id' => $id,
189 + 'method'=> $method,
190 + 'is_enabled'=> $is_enabled
191 + )
192 + );
193 + }
170 194
171 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 + /**
172 255 * Minify - Outputs the CSS settings tab
173 256 *
174 257 * @return void
175 258 */
176 259 public function output_css_settings() {
177 - $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 +
178 265 WP_Optimize()->include_template(
179 266 'minify/css-settings-tab.php',
180 267 false,
181 - array(
182 - 'wpo_minify_options' => $wpo_minify_options
183 - )
268 + $template_args
184 269 );
185 270 }
186 271
187 272 /**
@@ -189,15 +274,13 @@
189 274 *
190 275 * @return void
191 276 */
192 277 public function output_js_settings() {
193 - $wpo_minify_options = wp_optimize_minify_config()->get();
278 + $template_args = $this->get_output_setting('js');
194 279 WP_Optimize()->include_template(
195 280 'minify/js-settings-tab.php',
196 281 false,
197 - array(
198 - 'wpo_minify_options' => $wpo_minify_options
199 - )
282 + $template_args
200 283 );
201 284 }
202 285
203 286 /**
@@ -206,9 +289,9 @@
206 289 * @return void
207 290 */
208 291 public function output_settings() {
209 292 $wpo_minify_options = wp_optimize_minify_config()->get();
210 - $url = parse_url(get_home_url());
293 + $url = wp_parse_url(get_home_url());
211 294 WP_Optimize()->include_template(
212 295 'minify/settings-tab.php',
213 296 false,
214 297 array(
@@ -248,9 +331,9 @@
248 331 false,
249 332 array(
250 333 'is_cache_enabled' => $cache_config->get_option('enable_page_caching'),
251 334 'is_running' => $is_running,
252 - 'status_message' => isset($status['message']) ? $status['message'] : '',
335 + 'status_message' => $status['message'] ?? '',
253 336 )
254 337 );
255 338 }
256 339
@@ -261,9 +344,9 @@
261 344 */
262 345 public function output_advanced() {
263 346 $wpo_minify_options = wp_optimize_minify_config()->get();
264 347 $files = false;
265 - 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)) {
266 349 $files = WP_Optimize_Minify_Cache_Functions::get_cached_files();
267 350 }
268 351
269 352 // WP_Optimize_Minify_Functions is only loaded when Minify is active