@@ -378,6 +378,9 @@ discard block |
||
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | + /** |
|
382 | + * @return string |
|
383 | + */ |
|
381 | 384 | private function get_imgopt_base_url() |
382 | 385 | { |
383 | 386 | static $imgopt_base_url = null; |
@@ -750,6 +753,9 @@ discard block |
||
750 | 753 | return $out; |
751 | 754 | } |
752 | 755 | |
756 | + /** |
|
757 | + * @param string $tag |
|
758 | + */ |
|
753 | 759 | public function add_lazyload( $tag, $placeholder = '' ) { |
754 | 760 | // adds actual lazyload-attributes to an image node. |
755 | 761 | if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) { |
@@ -832,6 +838,9 @@ discard block |
||
832 | 838 | } |
833 | 839 | } |
834 | 840 | |
841 | + /** |
|
842 | + * @return string |
|
843 | + */ |
|
835 | 844 | public function get_cdn_url() { |
836 | 845 | // getting CDN url here to avoid having to make bigger changes to autoptimizeBase. |
837 | 846 | static $cdn_url = null; |
@@ -935,6 +944,9 @@ discard block |
||
935 | 944 | return $out; |
936 | 945 | } |
937 | 946 | |
947 | + /** |
|
948 | + * @return string |
|
949 | + */ |
|
938 | 950 | public function process_bgimage( $in ) { |
939 | 951 | if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) { |
940 | 952 | $out = preg_replace_callback( |
@@ -1279,7 +1291,7 @@ discard block |
||
1279 | 1291 | /** |
1280 | 1292 | * Determines and returns the service launch status. |
1281 | 1293 | * |
1282 | - * @return bool |
|
1294 | + * @return null|boolean |
|
1283 | 1295 | */ |
1284 | 1296 | public function launch_ok() |
1285 | 1297 | { |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles optimizing images. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -23,17 +23,17 @@ discard block |
||
23 | 23 | */ |
24 | 24 | protected static $instance = null; |
25 | 25 | |
26 | - public function __construct( array $options = array() ) |
|
26 | + public function __construct(array $options = array()) |
|
27 | 27 | { |
28 | 28 | // If options are not provided, fetch them. |
29 | - if ( empty( $options ) ) { |
|
29 | + if (empty($options)) { |
|
30 | 30 | $options = $this->fetch_options(); |
31 | 31 | } |
32 | 32 | |
33 | - $this->set_options( $options ); |
|
33 | + $this->set_options($options); |
|
34 | 34 | } |
35 | 35 | |
36 | - public function set_options( array $options ) |
|
36 | + public function set_options(array $options) |
|
37 | 37 | { |
38 | 38 | $this->options = $options; |
39 | 39 | |
@@ -42,17 +42,17 @@ discard block |
||
42 | 42 | |
43 | 43 | public static function fetch_options() |
44 | 44 | { |
45 | - $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' ); |
|
46 | - if ( empty( $value ) ) { |
|
45 | + $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings'); |
|
46 | + if (empty($value)) { |
|
47 | 47 | // Fallback to returning defaults when no stored option exists yet. |
48 | 48 | $value = autoptimizeConfig::get_ao_imgopt_default_options(); |
49 | 49 | } |
50 | 50 | |
51 | 51 | // get service availability and add it to the options-array. |
52 | - $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' ); |
|
52 | + $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity'); |
|
53 | 53 | |
54 | - if ( empty( $value['availabilities'] ) ) { |
|
55 | - $value['availabilities'] = autoptimizeUtils::check_service_availability( true ); |
|
54 | + if (empty($value['availabilities'])) { |
|
55 | + $value['availabilities'] = autoptimizeUtils::check_service_availability(true); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return $value; |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | // and does not use/ request the availablity data (which could slow things down). |
66 | 66 | static $imgopt_active = null; |
67 | 67 | |
68 | - if ( null === $imgopt_active ) { |
|
69 | - $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' ); |
|
70 | - if ( ! empty( $opts ) && is_array( $opts ) && array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $opts ) && ! empty( $opts['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $opts['autoptimize_imgopt_checkbox_field_1'] ) { |
|
68 | + if (null === $imgopt_active) { |
|
69 | + $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', ''); |
|
70 | + if (!empty($opts) && is_array($opts) && array_key_exists('autoptimize_imgopt_checkbox_field_1', $opts) && !empty($opts['autoptimize_imgopt_checkbox_field_1']) && '1' === $opts['autoptimize_imgopt_checkbox_field_1']) { |
|
71 | 71 | $imgopt_active = true; |
72 | 72 | } else { |
73 | 73 | $imgopt_active = false; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public static function instance() |
89 | 89 | { |
90 | - if ( null === self::$instance ) { |
|
90 | + if (null === self::$instance) { |
|
91 | 91 | self::$instance = new self(); |
92 | 92 | } |
93 | 93 | |
@@ -96,34 +96,34 @@ discard block |
||
96 | 96 | |
97 | 97 | public function run() |
98 | 98 | { |
99 | - if ( is_admin() ) { |
|
100 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
101 | - add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) ); |
|
99 | + if (is_admin()) { |
|
100 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
101 | + add_action('network_admin_menu', array($this, 'imgopt_admin_menu')); |
|
102 | 102 | } else { |
103 | - add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) ); |
|
103 | + add_action('admin_menu', array($this, 'imgopt_admin_menu')); |
|
104 | 104 | } |
105 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 ); |
|
105 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9); |
|
106 | 106 | } else { |
107 | - add_action( 'wp', array( $this, 'run_on_frontend' ) ); |
|
107 | + add_action('wp', array($this, 'run_on_frontend')); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | 111 | public function run_on_frontend() { |
112 | - if ( ! $this->should_run() ) { |
|
113 | - if ( $this->should_lazyload() ) { |
|
112 | + if (!$this->should_run()) { |
|
113 | + if ($this->should_lazyload()) { |
|
114 | 114 | add_filter( |
115 | 115 | 'wp_lazy_loading_enabled', |
116 | 116 | '__return_false' |
117 | 117 | ); |
118 | 118 | add_filter( |
119 | 119 | 'autoptimize_html_after_minify', |
120 | - array( $this, 'filter_lazyload_images' ), |
|
120 | + array($this, 'filter_lazyload_images'), |
|
121 | 121 | 10, |
122 | 122 | 1 |
123 | 123 | ); |
124 | 124 | add_action( |
125 | 125 | 'wp_footer', |
126 | - array( $this, 'add_lazyload_js_footer' ), |
|
126 | + array($this, 'add_lazyload_js_footer'), |
|
127 | 127 | 10, |
128 | 128 | 0 |
129 | 129 | ); |
@@ -133,43 +133,43 @@ discard block |
||
133 | 133 | |
134 | 134 | $active = false; |
135 | 135 | |
136 | - if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) { |
|
136 | + if (apply_filters('autoptimize_filter_imgopt_do', true)) { |
|
137 | 137 | add_filter( |
138 | 138 | 'autoptimize_html_after_minify', |
139 | - array( $this, 'filter_optimize_images' ), |
|
139 | + array($this, 'filter_optimize_images'), |
|
140 | 140 | 10, |
141 | 141 | 1 |
142 | 142 | ); |
143 | 143 | $active = true; |
144 | 144 | } |
145 | 145 | |
146 | - if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) { |
|
146 | + if (apply_filters('autoptimize_filter_imgopt_do_css', true)) { |
|
147 | 147 | add_filter( |
148 | 148 | 'autoptimize_filter_base_replace_cdn', |
149 | - array( $this, 'filter_optimize_css_images' ), |
|
149 | + array($this, 'filter_optimize_css_images'), |
|
150 | 150 | 10, |
151 | 151 | 1 |
152 | 152 | ); |
153 | 153 | $active = true; |
154 | 154 | } |
155 | 155 | |
156 | - if ( $active ) { |
|
156 | + if ($active) { |
|
157 | 157 | add_filter( |
158 | 158 | 'autoptimize_extra_filter_tobepreconn', |
159 | - array( $this, 'filter_preconnect_imgopt_url' ), |
|
159 | + array($this, 'filter_preconnect_imgopt_url'), |
|
160 | 160 | 10, |
161 | 161 | 1 |
162 | 162 | ); |
163 | 163 | } |
164 | 164 | |
165 | - if ( $this->should_lazyload() ) { |
|
165 | + if ($this->should_lazyload()) { |
|
166 | 166 | add_filter( |
167 | 167 | 'wp_lazy_loading_enabled', |
168 | 168 | '__return_false' |
169 | 169 | ); |
170 | 170 | add_action( |
171 | 171 | 'wp_footer', |
172 | - array( $this, 'add_lazyload_js_footer' ), |
|
172 | + array($this, 'add_lazyload_js_footer'), |
|
173 | 173 | 10, |
174 | 174 | 0 |
175 | 175 | ); |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | protected function should_run() |
185 | 185 | { |
186 | 186 | $opts = $this->options; |
187 | - $service_not_down = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] ); |
|
188 | - $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] ); |
|
187 | + $service_not_down = ('down' !== $opts['availabilities']['extra_imgopt']['status']); |
|
188 | + $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']); |
|
189 | 189 | |
190 | 190 | $do_cdn = true; |
191 | 191 | $_userstatus = $this->get_imgopt_provider_userstatus(); |
192 | - if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) { |
|
192 | + if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) { |
|
193 | 193 | // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable. |
194 | 194 | $do_cdn = false; |
195 | 195 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $this->imgopt_active() |
199 | 199 | && $do_cdn |
200 | 200 | && $service_not_down |
201 | - && ( $not_launch_status || $this->launch_ok() ) |
|
201 | + && ($not_launch_status || $this->launch_ok()) |
|
202 | 202 | ) { |
203 | 203 | return true; |
204 | 204 | } |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | { |
210 | 210 | static $imgopt_host = null; |
211 | 211 | |
212 | - if ( null === $imgopt_host ) { |
|
212 | + if (null === $imgopt_host) { |
|
213 | 213 | $imgopt_host = 'https://cdn.shortpixel.ai/'; |
214 | 214 | $avail_imgopt = $this->options['availabilities']['extra_imgopt']; |
215 | - if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) { |
|
216 | - $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) ); |
|
215 | + if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) { |
|
216 | + $imgopt_host = array_rand(array_flip($avail_imgopt['hosts'])); |
|
217 | 217 | } |
218 | - $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host ); |
|
218 | + $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | return $imgopt_host; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | public static function get_service_url_suffix() |
232 | 232 | { |
233 | - $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN; |
|
233 | + $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN; |
|
234 | 234 | |
235 | 235 | return $suffix; |
236 | 236 | } |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | { |
240 | 240 | static $quality = null; |
241 | 241 | |
242 | - if ( null === $quality ) { |
|
242 | + if (null === $quality) { |
|
243 | 243 | $q_array = $this->get_img_quality_array(); |
244 | 244 | $setting = $this->get_img_quality_setting(); |
245 | 245 | $quality = apply_filters( |
246 | 246 | 'autoptimize_filter_imgopt_quality', |
247 | - 'q_' . $q_array[ $setting ] |
|
247 | + 'q_'.$q_array[$setting] |
|
248 | 248 | ); |
249 | 249 | } |
250 | 250 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | { |
256 | 256 | static $map = null; |
257 | 257 | |
258 | - if ( null === $map ) { |
|
258 | + if (null === $map) { |
|
259 | 259 | $map = array( |
260 | 260 | '1' => 'lossy', |
261 | 261 | '2' => 'glossy', |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | { |
275 | 275 | static $q = null; |
276 | 276 | |
277 | - if ( null === $q ) { |
|
278 | - if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) { |
|
277 | + if (null === $q) { |
|
278 | + if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) { |
|
279 | 279 | $setting = $this->options['autoptimize_imgopt_select_field_2']; |
280 | 280 | } |
281 | 281 | |
282 | - if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) { |
|
282 | + if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) { |
|
283 | 283 | // default image opt. value is 2 ("glossy"). |
284 | 284 | $q = '2'; |
285 | 285 | } else { |
@@ -290,10 +290,10 @@ discard block |
||
290 | 290 | return $q; |
291 | 291 | } |
292 | 292 | |
293 | - public function filter_preconnect_imgopt_url( array $in ) |
|
293 | + public function filter_preconnect_imgopt_url(array $in) |
|
294 | 294 | { |
295 | - $url_parts = parse_url( $this->get_imgopt_base_url() ); |
|
296 | - $in[] = $url_parts['scheme'] . '://' . $url_parts['host']; |
|
295 | + $url_parts = parse_url($this->get_imgopt_base_url()); |
|
296 | + $in[] = $url_parts['scheme'].'://'.$url_parts['host']; |
|
297 | 297 | |
298 | 298 | return $in; |
299 | 299 | } |
@@ -306,20 +306,20 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - private function normalize_img_url( $in ) |
|
309 | + private function normalize_img_url($in) |
|
310 | 310 | { |
311 | 311 | // Only parse the site url once. |
312 | 312 | static $parsed_site_url = null; |
313 | - if ( null === $parsed_site_url ) { |
|
314 | - $parsed_site_url = parse_url( site_url() ); |
|
313 | + if (null === $parsed_site_url) { |
|
314 | + $parsed_site_url = parse_url(site_url()); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | // get CDN domain once. |
318 | 318 | static $cdn_domain = null; |
319 | - if ( is_null( $cdn_domain ) ) { |
|
319 | + if (is_null($cdn_domain)) { |
|
320 | 320 | $cdn_url = $this->get_cdn_url(); |
321 | - if ( ! empty( $cdn_url ) ) { |
|
322 | - $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST ); |
|
321 | + if (!empty($cdn_url)) { |
|
322 | + $cdn_domain = parse_url($cdn_url, PHP_URL_HOST); |
|
323 | 323 | } else { |
324 | 324 | $cdn_domain = ''; |
325 | 325 | } |
@@ -335,44 +335,44 @@ discard block |
||
335 | 335 | * identical string operations). |
336 | 336 | */ |
337 | 337 | static $cache = null; |
338 | - if ( null === $cache ) { |
|
338 | + if (null === $cache) { |
|
339 | 339 | $cache = array(); |
340 | 340 | } |
341 | 341 | |
342 | 342 | // Do the work on cache miss only. |
343 | - if ( ! isset( $cache[ $in ] ) ) { |
|
343 | + if (!isset($cache[$in])) { |
|
344 | 344 | // Default to (the trimmed version of) what was given to us. |
345 | - $result = trim( $in ); |
|
345 | + $result = trim($in); |
|
346 | 346 | |
347 | 347 | // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url. |
348 | - if ( strpos( $result, '"' ) !== false ) { |
|
349 | - $result = str_replace( '"', '', $result ); |
|
348 | + if (strpos($result, '"') !== false) { |
|
349 | + $result = str_replace('"', '', $result); |
|
350 | 350 | } |
351 | 351 | |
352 | - if ( autoptimizeUtils::is_protocol_relative( $result ) ) { |
|
353 | - $result = $parsed_site_url['scheme'] . ':' . $result; |
|
354 | - } elseif ( 0 === strpos( $result, '/' ) ) { |
|
352 | + if (autoptimizeUtils::is_protocol_relative($result)) { |
|
353 | + $result = $parsed_site_url['scheme'].':'.$result; |
|
354 | + } elseif (0 === strpos($result, '/')) { |
|
355 | 355 | // Root-relative... |
356 | - $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result; |
|
357 | - } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) { |
|
358 | - $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result ); |
|
356 | + $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result; |
|
357 | + } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) { |
|
358 | + $result = str_replace($cdn_domain, $parsed_site_url['host'], $result); |
|
359 | 359 | } |
360 | 360 | |
361 | - $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result ); |
|
361 | + $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result); |
|
362 | 362 | |
363 | 363 | // Store in cache. |
364 | - $cache[ $in ] = $result; |
|
364 | + $cache[$in] = $result; |
|
365 | 365 | } |
366 | 366 | |
367 | - return $cache[ $in ]; |
|
367 | + return $cache[$in]; |
|
368 | 368 | } |
369 | 369 | |
370 | - public function filter_optimize_css_images( $in ) |
|
370 | + public function filter_optimize_css_images($in) |
|
371 | 371 | { |
372 | - $in = $this->normalize_img_url( $in ); |
|
372 | + $in = $this->normalize_img_url($in); |
|
373 | 373 | |
374 | - if ( $this->can_optimize_image( $in ) ) { |
|
375 | - return $this->build_imgopt_url( $in, '', '' ); |
|
374 | + if ($this->can_optimize_image($in)) { |
|
375 | + return $this->build_imgopt_url($in, '', ''); |
|
376 | 376 | } else { |
377 | 377 | return $in; |
378 | 378 | } |
@@ -382,50 +382,50 @@ discard block |
||
382 | 382 | { |
383 | 383 | static $imgopt_base_url = null; |
384 | 384 | |
385 | - if ( null === $imgopt_base_url ) { |
|
385 | + if (null === $imgopt_base_url) { |
|
386 | 386 | $imgopt_host = $this->get_imgopt_host(); |
387 | 387 | $quality = $this->get_img_quality_string(); |
388 | - $ret_val = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank. |
|
389 | - $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val; |
|
390 | - $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url ); |
|
388 | + $ret_val = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank. |
|
389 | + $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val; |
|
390 | + $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | return $imgopt_base_url; |
394 | 394 | } |
395 | 395 | |
396 | - private function can_optimize_image( $url ) |
|
396 | + private function can_optimize_image($url) |
|
397 | 397 | { |
398 | 398 | static $cdn_url = null; |
399 | 399 | static $nopti_images = null; |
400 | 400 | |
401 | - if ( null === $cdn_url ) { |
|
401 | + if (null === $cdn_url) { |
|
402 | 402 | $cdn_url = apply_filters( |
403 | 403 | 'autoptimize_filter_base_cdnurl', |
404 | - autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ) |
|
404 | + autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '') |
|
405 | 405 | ); |
406 | 406 | } |
407 | 407 | |
408 | - if ( null === $nopti_images ) { |
|
409 | - $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' ); |
|
408 | + if (null === $nopti_images) { |
|
409 | + $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', ''); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $site_host = AUTOPTIMIZE_SITE_DOMAIN; |
413 | - $url = $this->normalize_img_url( $url ); |
|
414 | - $url_parsed = parse_url( $url ); |
|
413 | + $url = $this->normalize_img_url($url); |
|
414 | + $url_parsed = parse_url($url); |
|
415 | 415 | |
416 | - if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) { |
|
416 | + if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) { |
|
417 | 417 | return false; |
418 | - } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) { |
|
418 | + } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) { |
|
419 | 419 | return false; |
420 | - } elseif ( strpos( $url, '.php' ) !== false ) { |
|
420 | + } elseif (strpos($url, '.php') !== false) { |
|
421 | 421 | return false; |
422 | - } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) { |
|
422 | + } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp'), '', $url_parsed['path']) === $url_parsed['path']) { |
|
423 | 423 | // fixme: better check against end of string. |
424 | 424 | return false; |
425 | - } elseif ( ! empty( $nopti_images ) ) { |
|
426 | - $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) ); |
|
427 | - foreach ( $nopti_images_array as $nopti_image ) { |
|
428 | - if ( strpos( $url, $nopti_image ) !== false ) { |
|
425 | + } elseif (!empty($nopti_images)) { |
|
426 | + $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images))); |
|
427 | + foreach ($nopti_images_array as $nopti_image) { |
|
428 | + if (strpos($url, $nopti_image) !== false) { |
|
429 | 429 | return false; |
430 | 430 | } |
431 | 431 | } |
@@ -433,13 +433,13 @@ discard block |
||
433 | 433 | return true; |
434 | 434 | } |
435 | 435 | |
436 | - private function build_imgopt_url( $orig_url, $width = 0, $height = 0 ) |
|
436 | + private function build_imgopt_url($orig_url, $width = 0, $height = 0) |
|
437 | 437 | { |
438 | 438 | // sanitize width and height. |
439 | - if ( strpos( $width, '%' ) !== false ) { |
|
439 | + if (strpos($width, '%') !== false) { |
|
440 | 440 | $width = 0; |
441 | 441 | } |
442 | - if ( strpos( $height, '%' ) !== false ) { |
|
442 | + if (strpos($height, '%') !== false) { |
|
443 | 443 | $height = 0; |
444 | 444 | } |
445 | 445 | $width = (int) $width; |
@@ -453,56 +453,56 @@ discard block |
||
453 | 453 | ); |
454 | 454 | |
455 | 455 | // If filter modified the url, return that. |
456 | - if ( $filtered_url !== $orig_url ) { |
|
456 | + if ($filtered_url !== $orig_url) { |
|
457 | 457 | return $filtered_url; |
458 | 458 | } |
459 | 459 | |
460 | - $orig_url = $this->normalize_img_url( $orig_url ); |
|
460 | + $orig_url = $this->normalize_img_url($orig_url); |
|
461 | 461 | $imgopt_base_url = $this->get_imgopt_base_url(); |
462 | 462 | $imgopt_size = ''; |
463 | 463 | |
464 | - if ( $width && 0 !== $width ) { |
|
465 | - $imgopt_size = ',w_' . $width; |
|
464 | + if ($width && 0 !== $width) { |
|
465 | + $imgopt_size = ',w_'.$width; |
|
466 | 466 | } |
467 | 467 | |
468 | - if ( $height && 0 !== $height ) { |
|
469 | - $imgopt_size .= ',h_' . $height; |
|
468 | + if ($height && 0 !== $height) { |
|
469 | + $imgopt_size .= ',h_'.$height; |
|
470 | 470 | } |
471 | 471 | |
472 | - $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url; |
|
472 | + $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url; |
|
473 | 473 | |
474 | 474 | return $url; |
475 | 475 | } |
476 | 476 | |
477 | - public function replace_data_thumbs( $matches ) |
|
477 | + public function replace_data_thumbs($matches) |
|
478 | 478 | { |
479 | - return $this->replace_img_callback( $matches, 150, 150 ); |
|
479 | + return $this->replace_img_callback($matches, 150, 150); |
|
480 | 480 | } |
481 | 481 | |
482 | - public function replace_img_callback( $matches, $width = 0, $height = 0 ) |
|
482 | + public function replace_img_callback($matches, $width = 0, $height = 0) |
|
483 | 483 | { |
484 | - $_normalized_img_url = $this->normalize_img_url( $matches[1] ); |
|
485 | - if ( $this->can_optimize_image( $matches[1] ) ) { |
|
486 | - return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] ); |
|
484 | + $_normalized_img_url = $this->normalize_img_url($matches[1]); |
|
485 | + if ($this->can_optimize_image($matches[1])) { |
|
486 | + return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]); |
|
487 | 487 | } else { |
488 | 488 | return $matches[0]; |
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | - public function replace_icon_callback( $matches ) |
|
492 | + public function replace_icon_callback($matches) |
|
493 | 493 | { |
494 | - if ( array_key_exists( '2', $matches ) ) { |
|
495 | - $sizes = explode( 'x', $matches[2] ); |
|
494 | + if (array_key_exists('2', $matches)) { |
|
495 | + $sizes = explode('x', $matches[2]); |
|
496 | 496 | $width = $sizes[0]; |
497 | 497 | $height = $sizes[1]; |
498 | 498 | } else { |
499 | 499 | $width = 180; |
500 | 500 | $height = 180; |
501 | 501 | } |
502 | - return $this->replace_img_callback( $matches, $width, $height ); |
|
502 | + return $this->replace_img_callback($matches, $width, $height); |
|
503 | 503 | } |
504 | 504 | |
505 | - public function filter_optimize_images( $in ) |
|
505 | + public function filter_optimize_images($in) |
|
506 | 506 | { |
507 | 507 | /* |
508 | 508 | * potential future functional improvements: |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $to_replace = array(); |
513 | 513 | |
514 | 514 | // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript). |
515 | - if ( $this->should_lazyload() ) { |
|
515 | + if ($this->should_lazyload()) { |
|
516 | 516 | $in = autoptimizeBase::replace_contents_with_marker_if_exists( |
517 | 517 | 'SCRIPT', |
518 | 518 | '<script', |
@@ -522,25 +522,25 @@ discard block |
||
522 | 522 | } |
523 | 523 | |
524 | 524 | // extract img tags. |
525 | - if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) { |
|
526 | - foreach ( $matches[0] as $tag ) { |
|
525 | + if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) { |
|
526 | + foreach ($matches[0] as $tag) { |
|
527 | 527 | $orig_tag = $tag; |
528 | 528 | $imgopt_w = ''; |
529 | 529 | $imgopt_h = ''; |
530 | 530 | |
531 | 531 | // first do (data-)srcsets. |
532 | - if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) { |
|
533 | - foreach ( $allsrcsets as $srcset ) { |
|
532 | + if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) { |
|
533 | + foreach ($allsrcsets as $srcset) { |
|
534 | 534 | $srcset = $srcset[2]; |
535 | - $srcsets = explode( ',', $srcset ); |
|
536 | - foreach ( $srcsets as $indiv_srcset ) { |
|
537 | - $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) ); |
|
538 | - if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) { |
|
539 | - $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' ); |
|
535 | + $srcsets = explode(',', $srcset); |
|
536 | + foreach ($srcsets as $indiv_srcset) { |
|
537 | + $indiv_srcset_parts = explode(' ', trim($indiv_srcset)); |
|
538 | + if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) { |
|
539 | + $imgopt_w = rtrim($indiv_srcset_parts[1], 'w'); |
|
540 | 540 | } |
541 | - if ( $this->can_optimize_image( $indiv_srcset_parts[0] ) ) { |
|
542 | - $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' ); |
|
543 | - $tag = str_replace( $indiv_srcset_parts[0], $imgopt_url, $tag ); |
|
541 | + if ($this->can_optimize_image($indiv_srcset_parts[0])) { |
|
542 | + $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, ''); |
|
543 | + $tag = str_replace($indiv_srcset_parts[0], $imgopt_url, $tag); |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | } |
@@ -548,133 +548,133 @@ discard block |
||
548 | 548 | |
549 | 549 | // proceed with img src. |
550 | 550 | // get width and height and add to $imgopt_size. |
551 | - $_get_size = $this->get_size_from_tag( $tag ); |
|
551 | + $_get_size = $this->get_size_from_tag($tag); |
|
552 | 552 | $imgopt_w = $_get_size['width']; |
553 | 553 | $imgopt_h = $_get_size['height']; |
554 | 554 | |
555 | 555 | // then start replacing images src. |
556 | - if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) { |
|
557 | - foreach ( $urls as $url ) { |
|
556 | + if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) { |
|
557 | + foreach ($urls as $url) { |
|
558 | 558 | $full_src_orig = $url[0]; |
559 | 559 | $url = $url[1]; |
560 | - if ( $this->can_optimize_image( $url ) ) { |
|
561 | - $imgopt_url = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h ); |
|
562 | - $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig ); |
|
563 | - $tag = str_replace( $full_src_orig, $full_imgopt_src, $tag ); |
|
560 | + if ($this->can_optimize_image($url)) { |
|
561 | + $imgopt_url = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h); |
|
562 | + $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig); |
|
563 | + $tag = str_replace($full_src_orig, $full_imgopt_src, $tag); |
|
564 | 564 | } |
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
568 | 568 | // do lazyload stuff. |
569 | - if ( $this->should_lazyload( $in ) && ! empty( $url ) ) { |
|
569 | + if ($this->should_lazyload($in) && !empty($url)) { |
|
570 | 570 | // first do lpiq placeholder logic. |
571 | - if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) { |
|
571 | + if (strpos($url, $this->get_imgopt_host()) === 0) { |
|
572 | 572 | // if all img src have been replaced during srcset, we have to extract the |
573 | 573 | // origin url from the imgopt one to be able to set a lqip placeholder. |
574 | - $_url = substr( $url, strpos( $url, '/http' ) + 1 ); |
|
574 | + $_url = substr($url, strpos($url, '/http') + 1); |
|
575 | 575 | } else { |
576 | 576 | $_url = $url; |
577 | 577 | } |
578 | 578 | |
579 | - $_url = $this->normalize_img_url( $_url ); |
|
579 | + $_url = $this->normalize_img_url($_url); |
|
580 | 580 | |
581 | 581 | $placeholder = ''; |
582 | - if ( $this->can_optimize_image( $_url ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) { |
|
582 | + if ($this->can_optimize_image($_url) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) { |
|
583 | 583 | $lqip_w = ''; |
584 | 584 | $lqip_h = ''; |
585 | - if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) { |
|
586 | - $lqip_w = ',w_' . $imgopt_w; |
|
585 | + if (isset($imgopt_w) && !empty($imgopt_w)) { |
|
586 | + $lqip_w = ',w_'.$imgopt_w; |
|
587 | 587 | } |
588 | - if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) { |
|
589 | - $lqip_h = ',h_' . $imgopt_h; |
|
588 | + if (isset($imgopt_h) && !empty($imgopt_h)) { |
|
589 | + $lqip_h = ',h_'.$imgopt_h; |
|
590 | 590 | } |
591 | - $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url; |
|
591 | + $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url; |
|
592 | 592 | } |
593 | 593 | // then call add_lazyload-function with lpiq placeholder if set. |
594 | - $tag = $this->add_lazyload( $tag, $placeholder ); |
|
594 | + $tag = $this->add_lazyload($tag, $placeholder); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | // and add tag to array for later replacement. |
598 | - if ( $tag !== $orig_tag ) { |
|
599 | - $to_replace[ $orig_tag ] = $tag; |
|
598 | + if ($tag !== $orig_tag) { |
|
599 | + $to_replace[$orig_tag] = $tag; |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | } |
603 | 603 | |
604 | 604 | // and replace all. |
605 | - $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in ); |
|
605 | + $out = str_replace(array_keys($to_replace), array_values($to_replace), $in); |
|
606 | 606 | |
607 | 607 | // img thumbnails in e.g. woocommerce. |
608 | - if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) { |
|
608 | + if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) { |
|
609 | 609 | $out = preg_replace_callback( |
610 | 610 | '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s', |
611 | - array( $this, 'replace_data_thumbs' ), |
|
611 | + array($this, 'replace_data_thumbs'), |
|
612 | 612 | $out |
613 | 613 | ); |
614 | 614 | } |
615 | 615 | |
616 | 616 | // background-image in inline style. |
617 | - if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) { |
|
617 | + if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) { |
|
618 | 618 | $out = preg_replace_callback( |
619 | 619 | '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/', |
620 | - array( $this, 'replace_img_callback' ), |
|
620 | + array($this, 'replace_img_callback'), |
|
621 | 621 | $out |
622 | 622 | ); |
623 | 623 | } |
624 | 624 | |
625 | 625 | // act on icon links. |
626 | - if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) { |
|
626 | + if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) { |
|
627 | 627 | $out = preg_replace_callback( |
628 | 628 | '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um', |
629 | - array( $this, 'replace_icon_callback' ), |
|
629 | + array($this, 'replace_icon_callback'), |
|
630 | 630 | $out |
631 | 631 | ); |
632 | 632 | } |
633 | 633 | |
634 | 634 | // lazyload: restore noscript tags + lazyload picture source tags and bgimage. |
635 | - if ( $this->should_lazyload() ) { |
|
635 | + if ($this->should_lazyload()) { |
|
636 | 636 | $out = autoptimizeBase::restore_marked_content( |
637 | 637 | 'SCRIPT', |
638 | 638 | $out |
639 | 639 | ); |
640 | 640 | |
641 | - $out = $this->process_picture_tag( $out, true, true ); |
|
642 | - $out = $this->process_bgimage( $out ); |
|
641 | + $out = $this->process_picture_tag($out, true, true); |
|
642 | + $out = $this->process_bgimage($out); |
|
643 | 643 | } else { |
644 | - $out = $this->process_picture_tag( $out, true, false ); |
|
644 | + $out = $this->process_picture_tag($out, true, false); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | return $out; |
648 | 648 | } |
649 | 649 | |
650 | - public function get_size_from_tag( $tag ) { |
|
650 | + public function get_size_from_tag($tag) { |
|
651 | 651 | // reusable function to extract widht and height from an image tag |
652 | 652 | // enforcing a filterable maximum width and height (default 4999X4999). |
653 | 653 | $width = ''; |
654 | 654 | $height = ''; |
655 | 655 | |
656 | - if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) { |
|
657 | - if ( strpos( $_width[2], '%' ) === false ) { |
|
656 | + if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) { |
|
657 | + if (strpos($_width[2], '%') === false) { |
|
658 | 658 | $width = (int) $_width[2]; |
659 | 659 | } |
660 | 660 | } |
661 | - if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) { |
|
662 | - if ( strpos( $_height[2], '%' ) === false ) { |
|
661 | + if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) { |
|
662 | + if (strpos($_height[2], '%') === false) { |
|
663 | 663 | $height = (int) $_height[2]; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | 667 | // check for and enforce (filterable) max sizes. |
668 | - $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 ); |
|
669 | - if ( $width > $_max_width ) { |
|
668 | + $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999); |
|
669 | + if ($width > $_max_width) { |
|
670 | 670 | $_width = $_max_width; |
671 | - $height = $_width / $width * $height; |
|
671 | + $height = $_width/$width*$height; |
|
672 | 672 | $width = $_width; |
673 | 673 | } |
674 | - $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 ); |
|
675 | - if ( $height > $_max_height ) { |
|
674 | + $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999); |
|
675 | + if ($height > $_max_height) { |
|
676 | 676 | $_height = $_max_height; |
677 | - $width = $_height / $height * $width; |
|
677 | + $width = $_height/$height*$width; |
|
678 | 678 | $height = $_height; |
679 | 679 | } |
680 | 680 | |
@@ -693,26 +693,26 @@ discard block |
||
693 | 693 | return $self->should_lazyload(); |
694 | 694 | } |
695 | 695 | |
696 | - public function should_lazyload( $context = '' ) { |
|
697 | - if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) { |
|
696 | + public function should_lazyload($context = '') { |
|
697 | + if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) { |
|
698 | 698 | $lazyload_return = true; |
699 | 699 | } else { |
700 | 700 | $lazyload_return = false; |
701 | 701 | } |
702 | - $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context ); |
|
702 | + $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context); |
|
703 | 703 | |
704 | 704 | return $lazyload_return; |
705 | 705 | } |
706 | 706 | |
707 | 707 | public function check_nolazy() { |
708 | - if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) { |
|
708 | + if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) { |
|
709 | 709 | return true; |
710 | 710 | } else { |
711 | 711 | return false; |
712 | 712 | } |
713 | 713 | } |
714 | 714 | |
715 | - public function filter_lazyload_images( $in ) |
|
715 | + public function filter_lazyload_images($in) |
|
716 | 716 | { |
717 | 717 | // only used is image optimization is NOT active but lazyload is. |
718 | 718 | $to_replace = array(); |
@@ -726,20 +726,20 @@ discard block |
||
726 | 726 | ); |
727 | 727 | |
728 | 728 | // extract img tags and add lazyload attribs. |
729 | - if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) { |
|
730 | - foreach ( $matches[0] as $tag ) { |
|
731 | - if ( $this->should_lazyload( $out ) ) { |
|
732 | - $to_replace[ $tag ] = $this->add_lazyload( $tag ); |
|
729 | + if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) { |
|
730 | + foreach ($matches[0] as $tag) { |
|
731 | + if ($this->should_lazyload($out)) { |
|
732 | + $to_replace[$tag] = $this->add_lazyload($tag); |
|
733 | 733 | } |
734 | 734 | } |
735 | - $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out ); |
|
735 | + $out = str_replace(array_keys($to_replace), array_values($to_replace), $out); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | // and also lazyload picture tag. |
739 | - $out = $this->process_picture_tag( $out, false, true ); |
|
739 | + $out = $this->process_picture_tag($out, false, true); |
|
740 | 740 | |
741 | 741 | // and inline style blocks with background-image. |
742 | - $out = $this->process_bgimage( $out ); |
|
742 | + $out = $this->process_bgimage($out); |
|
743 | 743 | |
744 | 744 | // restore noscript tags. |
745 | 745 | $out = autoptimizeBase::restore_marked_content( |
@@ -750,85 +750,85 @@ discard block |
||
750 | 750 | return $out; |
751 | 751 | } |
752 | 752 | |
753 | - public function add_lazyload( $tag, $placeholder = '' ) { |
|
753 | + public function add_lazyload($tag, $placeholder = '') { |
|
754 | 754 | // adds actual lazyload-attributes to an image node. |
755 | - if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) { |
|
756 | - $tag = $this->maybe_fix_missing_quotes( $tag ); |
|
755 | + if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) { |
|
756 | + $tag = $this->maybe_fix_missing_quotes($tag); |
|
757 | 757 | |
758 | 758 | // store original tag for use in noscript version. |
759 | - $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>'; |
|
759 | + $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'; |
|
760 | 760 | |
761 | - $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' ); |
|
761 | + $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload'); |
|
762 | 762 | |
763 | 763 | // insert lazyload class. |
764 | - $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " ); |
|
764 | + $tag = $this->inject_classes_in_tag($tag, "$lazyload_class "); |
|
765 | 765 | |
766 | - if ( ! $placeholder || empty( $placeholder ) ) { |
|
766 | + if (!$placeholder || empty($placeholder)) { |
|
767 | 767 | // get image width & heigth for placeholder fun (and to prevent content reflow). |
768 | - $_get_size = $this->get_size_from_tag( $tag ); |
|
768 | + $_get_size = $this->get_size_from_tag($tag); |
|
769 | 769 | $width = $_get_size['width']; |
770 | 770 | $height = $_get_size['height']; |
771 | - if ( false === $width || empty( $width ) ) { |
|
771 | + if (false === $width || empty($width)) { |
|
772 | 772 | $width = 210; // default width for SVG placeholder. |
773 | 773 | } |
774 | - if ( false === $height || empty( $height ) ) { |
|
775 | - $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio. |
|
774 | + if (false === $height || empty($height)) { |
|
775 | + $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio. |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | // insert the actual lazyload stuff. |
779 | 779 | // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's. |
780 | - $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) ); |
|
780 | + $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height)); |
|
781 | 781 | } |
782 | 782 | |
783 | - $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag ); |
|
784 | - $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag ); |
|
783 | + $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag); |
|
784 | + $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag); |
|
785 | 785 | |
786 | 786 | // move sizes to data-sizes unless filter says no. |
787 | - if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) { |
|
788 | - $tag = str_replace( ' sizes=', ' data-sizes=', $tag ); |
|
787 | + if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) { |
|
788 | + $tag = str_replace(' sizes=', ' data-sizes=', $tag); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | // add the noscript-tag from earlier. |
792 | - $tag = $noscript_tag . $tag; |
|
793 | - $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag ); |
|
792 | + $tag = $noscript_tag.$tag; |
|
793 | + $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | return $tag; |
797 | 797 | } |
798 | 798 | |
799 | 799 | public function add_lazyload_js_footer() { |
800 | - if ( false === autoptimizeMain::should_buffer() ) { |
|
800 | + if (false === autoptimizeMain::should_buffer()) { |
|
801 | 801 | return; |
802 | 802 | } |
803 | 803 | |
804 | 804 | // The JS will by default be excluded form autoptimization but this can be changed with a filter. |
805 | 805 | $noptimize_flag = ''; |
806 | - if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) { |
|
806 | + if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) { |
|
807 | 807 | $noptimize_flag = ' data-noptimize="1"'; |
808 | 808 | } |
809 | 809 | |
810 | - $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ ); |
|
810 | + $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__); |
|
811 | 811 | $cdn_url = $this->get_cdn_url(); |
812 | - if ( ! empty( $cdn_url ) ) { |
|
813 | - $cdn_url = rtrim( $cdn_url, '/' ); |
|
814 | - $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js ); |
|
812 | + if (!empty($cdn_url)) { |
|
813 | + $cdn_url = rtrim($cdn_url, '/'); |
|
814 | + $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | $type_js = ''; |
818 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
818 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
819 | 819 | $type_js = ' type="text/javascript"'; |
820 | 820 | } |
821 | 821 | |
822 | 822 | // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async). |
823 | - echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' ); |
|
824 | - echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' ); |
|
825 | - echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' ); |
|
823 | + echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>'); |
|
824 | + echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>'); |
|
825 | + echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>'); |
|
826 | 826 | |
827 | 827 | // And add webp detection and loading JS. |
828 | - if ( $this->should_webp() ) { |
|
828 | + if ($this->should_webp()) { |
|
829 | 829 | $_webp_detect = "function c_webp(A){var n=new Image;n.onload=function(){var e=0<n.width&&0<n.height;A(e)},n.onerror=function(){A(!1)},n.src='data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA=='}function s_webp(e){window.supportsWebP=e}c_webp(s_webp);"; |
830 | 830 | $_webp_load = "document.addEventListener('lazybeforeunveil',function({target:b}){window.supportsWebP&&['data-src','data-srcset'].forEach(function(c){attr=b.getAttribute(c),null!==attr&&-1==attr.indexOf('/client/to_webp')&&b.setAttribute(c,attr.replace(/\/client\//,'/client/to_webp,'))})});"; |
831 | - echo apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_webp_detect . $_webp_load . '</script>' ); |
|
831 | + echo apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_webp_detect.$_webp_load.'</script>'); |
|
832 | 832 | } |
833 | 833 | } |
834 | 834 | |
@@ -836,10 +836,10 @@ discard block |
||
836 | 836 | // getting CDN url here to avoid having to make bigger changes to autoptimizeBase. |
837 | 837 | static $cdn_url = null; |
838 | 838 | |
839 | - if ( null === $cdn_url ) { |
|
840 | - $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ); |
|
841 | - $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url ); |
|
842 | - $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url ); |
|
839 | + if (null === $cdn_url) { |
|
840 | + $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''); |
|
841 | + $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url); |
|
842 | + $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | return $cdn_url; |
@@ -849,47 +849,47 @@ discard block |
||
849 | 849 | // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded. |
850 | 850 | static $exclude_lazyload_array = null; |
851 | 851 | |
852 | - if ( null === $exclude_lazyload_array ) { |
|
852 | + if (null === $exclude_lazyload_array) { |
|
853 | 853 | $options = $this->options; |
854 | 854 | |
855 | 855 | // set default exclusions. |
856 | - $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' ); |
|
856 | + $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"'); |
|
857 | 857 | |
858 | 858 | // add from setting. |
859 | - if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) { |
|
859 | + if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) { |
|
860 | 860 | $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5']; |
861 | - if ( ! empty( $exclude_lazyload_option ) ) { |
|
862 | - $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) ); |
|
861 | + if (!empty($exclude_lazyload_option)) { |
|
862 | + $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5'])))); |
|
863 | 863 | } |
864 | 864 | } |
865 | 865 | |
866 | 866 | // and filter for developer-initiated changes. |
867 | - $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array ); |
|
867 | + $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | return $exclude_lazyload_array; |
871 | 871 | } |
872 | 872 | |
873 | - public function inject_classes_in_tag( $tag, $target_class ) { |
|
874 | - if ( strpos( $tag, 'class=' ) !== false ) { |
|
875 | - $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag ); |
|
873 | + public function inject_classes_in_tag($tag, $target_class) { |
|
874 | + if (strpos($tag, 'class=') !== false) { |
|
875 | + $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag); |
|
876 | 876 | } else { |
877 | - $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag ); |
|
877 | + $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | return $tag; |
881 | 881 | } |
882 | 882 | |
883 | - public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) { |
|
884 | - return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20' . $imgopt_w . '%20' . $imgopt_h . '%22%3E%3C/svg%3E'; |
|
883 | + public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) { |
|
884 | + return 'data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20'.$imgopt_w.'%20'.$imgopt_h.'%22%3E%3C/svg%3E'; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | public function should_webp() { |
888 | 888 | static $webp_return = null; |
889 | 889 | |
890 | - if ( is_null( $webp_return ) ) { |
|
890 | + if (is_null($webp_return)) { |
|
891 | 891 | // webp only works if imgopt and lazyload are also active. |
892 | - if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) { |
|
892 | + if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) { |
|
893 | 893 | $webp_return = true; |
894 | 894 | } else { |
895 | 895 | $webp_return = false; |
@@ -899,9 +899,9 @@ discard block |
||
899 | 899 | return $webp_return; |
900 | 900 | } |
901 | 901 | |
902 | - public function process_picture_tag( $in, $imgopt = false, $lazy = false ) { |
|
902 | + public function process_picture_tag($in, $imgopt = false, $lazy = false) { |
|
903 | 903 | // check if "<picture" is present and if filter allows us to process <picture>. |
904 | - if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) { |
|
904 | + if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) { |
|
905 | 905 | return $in; |
906 | 906 | } |
907 | 907 | |
@@ -909,37 +909,37 @@ discard block |
||
909 | 909 | $to_replace_pict = array(); |
910 | 910 | |
911 | 911 | // extract and process each picture-node. |
912 | - preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER ); |
|
913 | - foreach ( $_pictures as $_picture ) { |
|
914 | - $_picture = $this->maybe_fix_missing_quotes( $_picture ); |
|
915 | - if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) { |
|
916 | - foreach ( $_sources as $_source ) { |
|
912 | + preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER); |
|
913 | + foreach ($_pictures as $_picture) { |
|
914 | + $_picture = $this->maybe_fix_missing_quotes($_picture); |
|
915 | + if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) { |
|
916 | + foreach ($_sources as $_source) { |
|
917 | 917 | $_picture_replacement = $_source[0]; |
918 | 918 | |
919 | 919 | // should we optimize the image? |
920 | - if ( $imgopt && $this->can_optimize_image( $_source[1] ) ) { |
|
921 | - $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement ); |
|
920 | + if ($imgopt && $this->can_optimize_image($_source[1])) { |
|
921 | + $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement); |
|
922 | 922 | } |
923 | 923 | // should we lazy-load? |
924 | - if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) { |
|
925 | - $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement ); |
|
924 | + if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) { |
|
925 | + $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement); |
|
926 | 926 | } |
927 | - $to_replace_pict[ $_source[0] ] = $_picture_replacement; |
|
927 | + $to_replace_pict[$_source[0]] = $_picture_replacement; |
|
928 | 928 | } |
929 | 929 | } |
930 | 930 | } |
931 | 931 | |
932 | 932 | // and return the fully procesed $in. |
933 | - $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in ); |
|
933 | + $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in); |
|
934 | 934 | |
935 | 935 | return $out; |
936 | 936 | } |
937 | 937 | |
938 | - public function process_bgimage( $in ) { |
|
939 | - if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) { |
|
938 | + public function process_bgimage($in) { |
|
939 | + if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) { |
|
940 | 940 | $out = preg_replace_callback( |
941 | 941 | '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/', |
942 | - array( $this, 'lazyload_bgimg_callback' ), |
|
942 | + array($this, 'lazyload_bgimg_callback'), |
|
943 | 943 | $in |
944 | 944 | ); |
945 | 945 | return $out; |
@@ -947,27 +947,27 @@ discard block |
||
947 | 947 | return $in; |
948 | 948 | } |
949 | 949 | |
950 | - public function lazyload_bgimg_callback( $matches ) { |
|
951 | - if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) { |
|
950 | + public function lazyload_bgimg_callback($matches) { |
|
951 | + if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) { |
|
952 | 952 | // get placeholder & lazyload class strings. |
953 | - $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) ); |
|
954 | - $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' ); |
|
953 | + $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300)); |
|
954 | + $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload'); |
|
955 | 955 | // replace background-image URL with SVG placeholder. |
956 | - $out = str_replace( $matches[2], $placeholder, $matches[0] ); |
|
956 | + $out = str_replace($matches[2], $placeholder, $matches[0]); |
|
957 | 957 | // add data-bg attribute with real background-image URL for lazyload to pick up. |
958 | - $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '"' ), '', $matches[2] ) ) . '"', $out ); |
|
958 | + $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '"'), '', $matches[2])).'"', $out); |
|
959 | 959 | // add lazyload class to tag. |
960 | - $out = $this->inject_classes_in_tag( $out, "$lazyload_class " ); |
|
960 | + $out = $this->inject_classes_in_tag($out, "$lazyload_class "); |
|
961 | 961 | return $out; |
962 | 962 | } |
963 | 963 | return $matches[0]; |
964 | 964 | } |
965 | 965 | |
966 | - public function maybe_fix_missing_quotes( $tag_in ) { |
|
966 | + public function maybe_fix_missing_quotes($tag_in) { |
|
967 | 967 | // W3TC's Minify_HTML class removes quotes around attribute value, this re-adds them for the class and width/height attributes so we can lazyload properly. |
968 | - if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) { |
|
969 | - $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in ); |
|
970 | - $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out ); |
|
968 | + if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) { |
|
969 | + $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in); |
|
970 | + $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out); |
|
971 | 971 | return $tag_out; |
972 | 972 | } else { |
973 | 973 | return $tag_in; |
@@ -980,23 +980,23 @@ discard block |
||
980 | 980 | public function imgopt_admin_menu() |
981 | 981 | { |
982 | 982 | // no acces if multisite and not network admin and no site config allowed. |
983 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
983 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
984 | 984 | add_submenu_page( |
985 | 985 | null, |
986 | 986 | 'autoptimize_imgopt', |
987 | 987 | 'autoptimize_imgopt', |
988 | 988 | 'manage_options', |
989 | 989 | 'autoptimize_imgopt', |
990 | - array( $this, 'imgopt_options_page' ) |
|
990 | + array($this, 'imgopt_options_page') |
|
991 | 991 | ); |
992 | 992 | } |
993 | - register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' ); |
|
993 | + register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings'); |
|
994 | 994 | } |
995 | 995 | |
996 | - public function add_imgopt_tab( $in ) |
|
996 | + public function add_imgopt_tab($in) |
|
997 | 997 | { |
998 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
999 | - $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) ); |
|
998 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
999 | + $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize'))); |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | return $in; |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | public function imgopt_options_page() |
1006 | 1006 | { |
1007 | 1007 | // Check querystring for "refreshCacheChecker" and call cachechecker if so. |
1008 | - if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) { |
|
1008 | + if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) { |
|
1009 | 1009 | $this->query_img_provider_stats(); |
1010 | 1010 | } |
1011 | 1011 | |
@@ -1017,47 +1017,47 @@ discard block |
||
1017 | 1017 | #ao_settings_form .form-table th {font-weight: normal;} |
1018 | 1018 | #autoptimize_imgopt_descr{font-size: 120%;} |
1019 | 1019 | </style> |
1020 | - <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script> |
|
1020 | + <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script> |
|
1021 | 1021 | <div class="wrap"> |
1022 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
1022 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
1023 | 1023 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
1024 | - <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?> |
|
1024 | + <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?> |
|
1025 | 1025 | <div class="notice-warning notice"><p> |
1026 | 1026 | <?php |
1027 | 1027 | // translators: "Autoptimize support forum" will appear in a "a href". |
1028 | - echo sprintf( __( 'The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize' ), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>' ); |
|
1028 | + echo sprintf(__('The image optimization service is currently down, image optimization will be skipped until further notice. Check the %1$sAutoptimize support forum%2$s for more info.', 'autoptimize'), '<a href="https://wordpress.org/support/plugin/autoptimize/" target="_blank">', '</a>'); |
|
1029 | 1029 | ?> |
1030 | 1030 | </p></div> |
1031 | 1031 | <?php } ?> |
1032 | 1032 | |
1033 | - <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?> |
|
1033 | + <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?> |
|
1034 | 1034 | <div class="notice-warning notice"><p> |
1035 | - <?php _e( 'The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize' ); ?> |
|
1035 | + <?php _e('The image optimization service is launching, but not yet available for this domain, it should become available in the next couple of days.', 'autoptimize'); ?> |
|
1036 | 1036 | </p></div> |
1037 | 1037 | <?php } ?> |
1038 | 1038 | |
1039 | - <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?> |
|
1039 | + <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?> |
|
1040 | 1040 | <div class="notice-warning notice"><p> |
1041 | 1041 | <?php |
1042 | 1042 | // translators: "disable Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page. |
1043 | - echo sprintf( __( 'Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize' ), '<a href="admin.php?page=jetpack#/settings">', '</a>' ); |
|
1043 | + echo sprintf(__('Please %1$sdisable Jetpack\'s site accelerator for images%2$s to be able to use Autoptomize\'s advanced image optimization features below.', 'autoptimize'), '<a href="admin.php?page=jetpack#/settings">', '</a>'); |
|
1044 | 1044 | ?> |
1045 | 1045 | </p></div> |
1046 | 1046 | <?php } ?> |
1047 | - <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'> |
|
1048 | - <?php settings_fields( 'autoptimize_imgopt_settings' ); ?> |
|
1049 | - <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2> |
|
1050 | - <span id='autoptimize_imgopt_descr'><?php _e( 'Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize' ); ?></span> |
|
1047 | + <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'> |
|
1048 | + <?php settings_fields('autoptimize_imgopt_settings'); ?> |
|
1049 | + <h2><?php _e('Image optimization', 'autoptimize'); ?></h2> |
|
1050 | + <span id='autoptimize_imgopt_descr'><?php _e('Make your site significantly faster by just ticking a couple of checkboxes to optimize and lazy load your images, WebP support included!', 'autoptimize'); ?></span> |
|
1051 | 1051 | <table class="form-table"> |
1052 | 1052 | <tr> |
1053 | - <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th> |
|
1053 | + <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th> |
|
1054 | 1054 | <td> |
1055 | - <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize' ); ?></label> |
|
1055 | + <label><input id='autoptimize_imgopt_checkbox' type='checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_1]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_1']) && '1' === $options['autoptimize_imgopt_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Optimize images on the fly and serve them from Shortpixel\'s global CDN.', 'autoptimize'); ?></label> |
|
1056 | 1056 | <?php |
1057 | 1057 | // show shortpixel status. |
1058 | 1058 | $_notice = autoptimizeImages::instance()->get_imgopt_status_notice(); |
1059 | - if ( $_notice ) { |
|
1060 | - switch ( $_notice['status'] ) { |
|
1059 | + if ($_notice) { |
|
1060 | + switch ($_notice['status']) { |
|
1061 | 1061 | case 2: |
1062 | 1062 | $_notice_color = 'green'; |
1063 | 1063 | break; |
@@ -1072,29 +1072,29 @@ discard block |
||
1072 | 1072 | default: |
1073 | 1073 | $_notice_color = 'green'; |
1074 | 1074 | } |
1075 | - echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' ); |
|
1075 | + echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>'); |
|
1076 | 1076 | } else { |
1077 | 1077 | // translators: link points to shortpixel. |
1078 | - $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' ); |
|
1079 | - if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) { |
|
1080 | - $upsell_msg_2 = __( 'For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize' ); |
|
1078 | + $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>'); |
|
1079 | + if ('launch' === $options['availabilities']['extra_imgopt']['status']) { |
|
1080 | + $upsell_msg_2 = __('For a limited time only, this service is offered free for all Autoptimize users, <b>don\'t miss the chance to test it</b> and see how much it could improve your site\'s speed.', 'autoptimize'); |
|
1081 | 1081 | } else { |
1082 | 1082 | // translators: link points to shortpixel. |
1083 | - $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive a 1 000 bonus + 50% more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' ); |
|
1083 | + $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive a 1 000 bonus + 50% more image optimization credits regardless of the traffic used. More image optimizations can be purchased starting with $4.99.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>'); |
|
1084 | 1084 | } |
1085 | - echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' ); |
|
1085 | + echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>'); |
|
1086 | 1086 | } |
1087 | 1087 | // translators: link points to shortpixel FAQ. |
1088 | - $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>' ); |
|
1089 | - $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' ); |
|
1088 | + $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://shortpixel.helpscoutdocs.com/category/60-shortpixel-ai-cdn" target="_blank">', '</strong></a>'); |
|
1089 | + $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize'); |
|
1090 | 1090 | // translators: links points to shortpixel TOS & Privacy Policy. |
1091 | - $toscopy = sprintf( __( 'Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize' ), '<a href="https://shortpixel.com/tos' . $sp_url_suffix . '" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp' . $sp_url_suffix . '" target="_blank">', '</a>' ); |
|
1092 | - echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' ); |
|
1091 | + $toscopy = sprintf(__('Usage of this feature is subject to Shortpixel\'s %1$sTerms of Use%2$s and %3$sPrivacy policy%4$s.', 'autoptimize'), '<a href="https://shortpixel.com/tos'.$sp_url_suffix.'" target="_blank">', '</a>', '<a href="https://shortpixel.com/pp'.$sp_url_suffix.'" target="_blank">', '</a>'); |
|
1092 | + echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>'); |
|
1093 | 1093 | ?> |
1094 | 1094 | </td> |
1095 | 1095 | </tr> |
1096 | - <tr id='autoptimize_imgopt_quality' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>> |
|
1097 | - <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th> |
|
1096 | + <tr id='autoptimize_imgopt_quality' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>> |
|
1097 | + <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th> |
|
1098 | 1098 | <td> |
1099 | 1099 | <label> |
1100 | 1100 | <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'> |
@@ -1102,12 +1102,12 @@ discard block |
||
1102 | 1102 | $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array(); |
1103 | 1103 | $_imgopt_val = autoptimizeImages::instance()->get_img_quality_setting(); |
1104 | 1104 | |
1105 | - foreach ( $_imgopt_array as $key => $value ) { |
|
1106 | - echo '<option value="' . $key . '"'; |
|
1107 | - if ( $_imgopt_val == $key ) { |
|
1105 | + foreach ($_imgopt_array as $key => $value) { |
|
1106 | + echo '<option value="'.$key.'"'; |
|
1107 | + if ($_imgopt_val == $key) { |
|
1108 | 1108 | echo ' selected'; |
1109 | 1109 | } |
1110 | - echo '>' . ucfirst( $value ) . '</option>'; |
|
1110 | + echo '>'.ucfirst($value).'</option>'; |
|
1111 | 1111 | } |
1112 | 1112 | echo "\n"; |
1113 | 1113 | ?> |
@@ -1116,31 +1116,31 @@ discard block |
||
1116 | 1116 | <p> |
1117 | 1117 | <?php |
1118 | 1118 | // translators: link points to shortpixel image test page. |
1119 | - echo apply_filters( 'autoptimize_imgopt_imgopt_quality_copy', sprintf( __( 'You can %1$stest compression levels here%2$s.', 'autoptimize' ), '<a href="https://shortpixel.com/oic' . $sp_url_suffix . '" target="_blank">', '</a>' ) ); |
|
1119 | + echo apply_filters('autoptimize_imgopt_imgopt_quality_copy', sprintf(__('You can %1$stest compression levels here%2$s.', 'autoptimize'), '<a href="https://shortpixel.com/oic'.$sp_url_suffix.'" target="_blank">', '</a>')); |
|
1120 | 1120 | ?> |
1121 | 1121 | </p> |
1122 | 1122 | </td> |
1123 | 1123 | </tr> |
1124 | - <tr id='autoptimize_imgopt_webp' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_1'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'] ) ) { echo 'class="hidden"'; } ?>> |
|
1125 | - <th scope="row"><?php _e( 'Load WebP in supported browsers?', 'autoptimize' ); ?></th> |
|
1124 | + <tr id='autoptimize_imgopt_webp' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_1', $options) || (isset($options['autoptimize_imgopt_checkbox_field_1']) && '1' !== $options['autoptimize_imgopt_checkbox_field_1'])) { echo 'class="hidden"'; } ?>> |
|
1125 | + <th scope="row"><?php _e('Load WebP in supported browsers?', 'autoptimize'); ?></th> |
|
1126 | 1126 | <td> |
1127 | - <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_4'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label> |
|
1127 | + <label><input type='checkbox' id='autoptimize_imgopt_webp_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_4]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_4']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Automatically serve "next-gen" WebP image format to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label> |
|
1128 | 1128 | </td> |
1129 | 1129 | </tr> |
1130 | 1130 | <tr> |
1131 | - <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th> |
|
1131 | + <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th> |
|
1132 | 1132 | <td> |
1133 | - <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if ( ! empty( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' === $options['autoptimize_imgopt_checkbox_field_3'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize' ); ?></label> |
|
1133 | + <label><input type='checkbox' id='autoptimize_imgopt_lazyload_checkbox' name='autoptimize_imgopt_settings[autoptimize_imgopt_checkbox_field_3]' <?php if (!empty($options['autoptimize_imgopt_checkbox_field_3']) && '1' === $options['autoptimize_imgopt_checkbox_field_3']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Image lazy-loading will delay the loading of non-visible images to allow the browser to optimally load all resources for the "above the fold"-page first.', 'autoptimize'); ?></label> |
|
1134 | 1134 | </td> |
1135 | 1135 | </tr> |
1136 | - <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="hidden"'; } ?>> |
|
1137 | - <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th> |
|
1136 | + <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="hidden"'; } ?>> |
|
1137 | + <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th> |
|
1138 | 1138 | <td> |
1139 | - <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label> |
|
1139 | + <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label> |
|
1140 | 1140 | </td> |
1141 | 1141 | </tr> |
1142 | 1142 | </table> |
1143 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
1143 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
1144 | 1144 | </form> |
1145 | 1145 | <script> |
1146 | 1146 | jQuery(document).ready(function() { |
@@ -1176,50 +1176,50 @@ discard block |
||
1176 | 1176 | * Ïmg opt status as used on dashboard. |
1177 | 1177 | */ |
1178 | 1178 | public function get_imgopt_status_notice() { |
1179 | - if ( $this->imgopt_active() ) { |
|
1179 | + if ($this->imgopt_active()) { |
|
1180 | 1180 | $_imgopt_notice = ''; |
1181 | - $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' ); |
|
1181 | + $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', ''); |
|
1182 | 1182 | $_site_host = AUTOPTIMIZE_SITE_DOMAIN; |
1183 | - $_imgopt_upsell = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host; |
|
1183 | + $_imgopt_upsell = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host; |
|
1184 | 1184 | $_imgopt_assoc = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account'; |
1185 | 1185 | $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai'; |
1186 | 1186 | |
1187 | - if ( is_array( $_stat ) ) { |
|
1188 | - if ( 1 == $_stat['Status'] ) { |
|
1187 | + if (is_array($_stat)) { |
|
1188 | + if (1 == $_stat['Status']) { |
|
1189 | 1189 | // translators: "add more credits" will appear in a "a href". |
1190 | - $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' ); |
|
1190 | + $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota is almost used, make sure you %1$sadd more credits%2$s to avoid slowing down your website.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>'); |
|
1191 | 1191 | } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) { |
1192 | 1192 | // translators: "add more credits" will appear in a "a href". |
1193 | - $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' ); |
|
1193 | + $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota was used, %1$sadd more credits%2$s to keep fast serving optimized images on your site', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>'); |
|
1194 | 1194 | // translators: "associate your domain" will appear in a "a href". |
1195 | - $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '<a rel="noopener noreferrer" href="' . $_imgopt_assoc . '" target="_blank">', '</a>' ); |
|
1195 | + $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you already have enough credits then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize'), '<a rel="noopener noreferrer" href="'.$_imgopt_assoc.'" target="_blank">', '</a>'); |
|
1196 | 1196 | } elseif ( -3 == $_stat['Status'] ) { |
1197 | 1197 | // translators: "check the documentation here" will appear in a "a href". |
1198 | - $_imgopt_notice = sprintf( __( 'It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize' ), '<a href="' . $_imgopt_unreach . '" target="_blank">', '</a>' ); |
|
1198 | + $_imgopt_notice = sprintf(__('It seems ShortPixel image optimization is not able to fetch images from your site, %1$scheck the documentation here%2$s for more information', 'autoptimize'), '<a href="'.$_imgopt_unreach.'" target="_blank">', '</a>'); |
|
1199 | 1199 | } else { |
1200 | 1200 | $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483'; |
1201 | 1201 | // translators: "log in to check your account" will appear in a "a href". |
1202 | - $_imgopt_notice = sprintf( __( 'Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize' ), '<a href="' . $_imgopt_upsell . '" target="_blank">', '</a>' ); |
|
1202 | + $_imgopt_notice = sprintf(__('Your ShortPixel image optimization and CDN quota are in good shape, %1$slog in to check your account%2$s.', 'autoptimize'), '<a href="'.$_imgopt_upsell.'" target="_blank">', '</a>'); |
|
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | // add info on freshness + refresh link if status is not 2 (good shape). |
1206 | - if ( 2 != $_stat['Status'] ) { |
|
1207 | - $_imgopt_stats_refresh_url = add_query_arg( array( |
|
1206 | + if (2 != $_stat['Status']) { |
|
1207 | + $_imgopt_stats_refresh_url = add_query_arg(array( |
|
1208 | 1208 | 'page' => 'autoptimize_imgopt', |
1209 | 1209 | 'refreshImgProvStats' => '1', |
1210 | - ), admin_url( 'options-general.php' ) ); |
|
1211 | - if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) { |
|
1212 | - $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] ); |
|
1210 | + ), admin_url('options-general.php')); |
|
1211 | + if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) { |
|
1212 | + $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']); |
|
1213 | 1213 | } else { |
1214 | - $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' ); |
|
1214 | + $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize'); |
|
1215 | 1215 | } |
1216 | - $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', '; |
|
1216 | + $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', '; |
|
1217 | 1217 | // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats. |
1218 | - $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' ); |
|
1218 | + $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).'); |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | // and make the full notice filterable. |
1222 | - $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice ); |
|
1222 | + $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice); |
|
1223 | 1223 | |
1224 | 1224 | return array( |
1225 | 1225 | 'status' => $_stat['Status'], |
@@ -1240,14 +1240,14 @@ discard block |
||
1240 | 1240 | * Get img provider stats (used to display notice). |
1241 | 1241 | */ |
1242 | 1242 | public function query_img_provider_stats() { |
1243 | - if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) { |
|
1243 | + if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) { |
|
1244 | 1244 | $url = ''; |
1245 | - $endpoint = $this->get_imgopt_host() . 'read-domain/'; |
|
1245 | + $endpoint = $this->get_imgopt_host().'read-domain/'; |
|
1246 | 1246 | $domain = AUTOPTIMIZE_SITE_DOMAIN; |
1247 | 1247 | |
1248 | 1248 | // make sure parse_url result makes sense, keeping $url empty if not. |
1249 | - if ( $domain && ! empty( $domain ) ) { |
|
1250 | - $url = $endpoint . $domain; |
|
1249 | + if ($domain && !empty($domain)) { |
|
1250 | + $url = $endpoint.$domain; |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | $url = apply_filters( |
@@ -1257,12 +1257,12 @@ discard block |
||
1257 | 1257 | |
1258 | 1258 | // only do the remote call if $url is not empty to make sure no parse_url |
1259 | 1259 | // weirdness results in useless calls. |
1260 | - if ( ! empty( $url ) ) { |
|
1261 | - $response = wp_remote_get( $url ); |
|
1262 | - if ( ! is_wp_error( $response ) ) { |
|
1263 | - if ( '200' == wp_remote_retrieve_response_code( $response ) ) { |
|
1264 | - $stats = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
1265 | - autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats ); |
|
1260 | + if (!empty($url)) { |
|
1261 | + $response = wp_remote_get($url); |
|
1262 | + if (!is_wp_error($response)) { |
|
1263 | + if ('200' == wp_remote_retrieve_response_code($response)) { |
|
1264 | + $stats = json_decode(wp_remote_retrieve_body($response), true); |
|
1265 | + autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats); |
|
1266 | 1266 | } |
1267 | 1267 | } |
1268 | 1268 | } |
@@ -1285,15 +1285,15 @@ discard block |
||
1285 | 1285 | { |
1286 | 1286 | static $launch_status = null; |
1287 | 1287 | |
1288 | - if ( null === $launch_status ) { |
|
1288 | + if (null === $launch_status) { |
|
1289 | 1289 | $avail_imgopt = $this->options['availabilities']['extra_imgopt']; |
1290 | - $magic_number = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 ); |
|
1291 | - $has_launched = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' ); |
|
1290 | + $magic_number = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16); |
|
1291 | + $has_launched = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', ''); |
|
1292 | 1292 | $launch_status = false; |
1293 | - if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) { |
|
1293 | + if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) { |
|
1294 | 1294 | $launch_status = true; |
1295 | - if ( ! $has_launched ) { |
|
1296 | - autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' ); |
|
1295 | + if (!$has_launched) { |
|
1296 | + autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on'); |
|
1297 | 1297 | } |
1298 | 1298 | } |
1299 | 1299 | } |
@@ -1310,16 +1310,16 @@ discard block |
||
1310 | 1310 | public function get_imgopt_provider_userstatus() { |
1311 | 1311 | static $_provider_userstatus = null; |
1312 | 1312 | |
1313 | - if ( is_null( $_provider_userstatus ) ) { |
|
1314 | - $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' ); |
|
1315 | - if ( is_array( $_stat ) ) { |
|
1316 | - if ( array_key_exists( 'Status', $_stat ) ) { |
|
1313 | + if (is_null($_provider_userstatus)) { |
|
1314 | + $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', ''); |
|
1315 | + if (is_array($_stat)) { |
|
1316 | + if (array_key_exists('Status', $_stat)) { |
|
1317 | 1317 | $_provider_userstatus['Status'] = $_stat['Status']; |
1318 | 1318 | } else { |
1319 | 1319 | // if no stats then we assume all is well. |
1320 | 1320 | $_provider_userstatus['Status'] = 2; |
1321 | 1321 | } |
1322 | - if ( array_key_exists( 'timestamp', $_stat ) ) { |
|
1322 | + if (array_key_exists('timestamp', $_stat)) { |
|
1323 | 1323 | $_provider_userstatus['timestamp'] = $_stat['timestamp']; |
1324 | 1324 | } else { |
1325 | 1325 | // if no timestamp then we return "". |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Class for CSS optimization. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -161,54 +161,54 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @param array $options all options. |
163 | 163 | */ |
164 | - public function read( $options ) |
|
164 | + public function read($options) |
|
165 | 165 | { |
166 | - $noptimize_css = apply_filters( 'autoptimize_filter_css_noptimize', false, $this->content ); |
|
167 | - if ( $noptimize_css ) { |
|
166 | + $noptimize_css = apply_filters('autoptimize_filter_css_noptimize', false, $this->content); |
|
167 | + if ($noptimize_css) { |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - $allowlist_css = apply_filters( 'autoptimize_filter_css_allowlist', '', $this->content ); |
|
172 | - $allowlist_css = apply_filters( 'autoptimize_filter_css_whitelist', $allowlist_css, $this->content ); // fixme: to be removed in next version. |
|
173 | - if ( ! empty( $allowlist_css ) ) { |
|
174 | - $this->allowlist = array_filter( array_map( 'trim', explode( ',', $allowlist_css ) ) ); |
|
171 | + $allowlist_css = apply_filters('autoptimize_filter_css_allowlist', '', $this->content); |
|
172 | + $allowlist_css = apply_filters('autoptimize_filter_css_whitelist', $allowlist_css, $this->content); // fixme: to be removed in next version. |
|
173 | + if (!empty($allowlist_css)) { |
|
174 | + $this->allowlist = array_filter(array_map('trim', explode(',', $allowlist_css))); |
|
175 | 175 | } |
176 | 176 | |
177 | - $removable_css = apply_filters( 'autoptimize_filter_css_removables', '' ); |
|
178 | - if ( ! empty( $removable_css ) ) { |
|
179 | - $this->cssremovables = array_filter( array_map( 'trim', explode( ',', $removable_css ) ) ); |
|
177 | + $removable_css = apply_filters('autoptimize_filter_css_removables', ''); |
|
178 | + if (!empty($removable_css)) { |
|
179 | + $this->cssremovables = array_filter(array_map('trim', explode(',', $removable_css))); |
|
180 | 180 | } |
181 | 181 | |
182 | - $this->cssinlinesize = apply_filters( 'autoptimize_filter_css_inlinesize', 256 ); |
|
182 | + $this->cssinlinesize = apply_filters('autoptimize_filter_css_inlinesize', 256); |
|
183 | 183 | |
184 | 184 | // filter to "late inject minified CSS", default to true for now (it is faster). |
185 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_css_inject_min_late', true ); |
|
185 | + $this->inject_min_late = apply_filters('autoptimize_filter_css_inject_min_late', true); |
|
186 | 186 | |
187 | 187 | // Remove everything that's not the header. |
188 | - if ( apply_filters( 'autoptimize_filter_css_justhead', $options['justhead'] ) ) { |
|
189 | - $content = explode( '</head>', $this->content, 2 ); |
|
190 | - $this->content = $content[0] . '</head>'; |
|
188 | + if (apply_filters('autoptimize_filter_css_justhead', $options['justhead'])) { |
|
189 | + $content = explode('</head>', $this->content, 2); |
|
190 | + $this->content = $content[0].'</head>'; |
|
191 | 191 | $this->restofcontent = $content[1]; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Determine whether we're doing CSS-files aggregation or not. |
195 | - if ( isset( $options['aggregate'] ) && ! $options['aggregate'] ) { |
|
195 | + if (isset($options['aggregate']) && !$options['aggregate']) { |
|
196 | 196 | $this->aggregate = false; |
197 | 197 | } |
198 | 198 | // Returning true for "dontaggregate" turns off aggregation. |
199 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_css_dontaggregate', false ) ) { |
|
199 | + if ($this->aggregate && apply_filters('autoptimize_filter_css_dontaggregate', false)) { |
|
200 | 200 | $this->aggregate = false; |
201 | 201 | } |
202 | 202 | |
203 | 203 | // include inline? |
204 | - if ( apply_filters( 'autoptimize_css_include_inline', $options['include_inline'] ) ) { |
|
204 | + if (apply_filters('autoptimize_css_include_inline', $options['include_inline'])) { |
|
205 | 205 | $this->include_inline = true; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // List of CSS strings which are excluded from autoptimization. |
209 | - $exclude_css = apply_filters( 'autoptimize_filter_css_exclude', $options['css_exclude'], $this->content ); |
|
210 | - if ( '' !== $exclude_css ) { |
|
211 | - $this->dontmove = array_filter( array_map( 'trim', explode( ',', $exclude_css ) ) ); |
|
209 | + $exclude_css = apply_filters('autoptimize_filter_css_exclude', $options['css_exclude'], $this->content); |
|
210 | + if ('' !== $exclude_css) { |
|
211 | + $this->dontmove = array_filter(array_map('trim', explode(',', $exclude_css))); |
|
212 | 212 | } else { |
213 | 213 | $this->dontmove = array(); |
214 | 214 | } |
@@ -219,16 +219,16 @@ discard block |
||
219 | 219 | // Should we defer css? |
220 | 220 | // value: true / false. |
221 | 221 | $this->defer = $options['defer']; |
222 | - $this->defer = apply_filters( 'autoptimize_filter_css_defer', $this->defer, $this->content ); |
|
222 | + $this->defer = apply_filters('autoptimize_filter_css_defer', $this->defer, $this->content); |
|
223 | 223 | |
224 | 224 | // Should we inline while deferring? |
225 | 225 | // value: inlined CSS. |
226 | - $this->defer_inline = apply_filters( 'autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content ); |
|
226 | + $this->defer_inline = apply_filters('autoptimize_filter_css_defer_inline', $options['defer_inline'], $this->content); |
|
227 | 227 | |
228 | 228 | // Should we inline? |
229 | 229 | // value: true / false. |
230 | 230 | $this->inline = $options['inline']; |
231 | - $this->inline = apply_filters( 'autoptimize_filter_css_inline', $this->inline, $this->content ); |
|
231 | + $this->inline = apply_filters('autoptimize_filter_css_inline', $this->inline, $this->content); |
|
232 | 232 | |
233 | 233 | // Store cdn url. |
234 | 234 | $this->cdn_url = $options['cdn_url']; |
@@ -237,16 +237,16 @@ discard block |
||
237 | 237 | $this->datauris = $options['datauris']; |
238 | 238 | |
239 | 239 | // Determine whether excluded files should be minified if not yet so. |
240 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
240 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
241 | 241 | $this->minify_excluded = false; |
242 | 242 | } |
243 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_css_minify_excluded', $this->minify_excluded, '' ); |
|
243 | + $this->minify_excluded = apply_filters('autoptimize_filter_css_minify_excluded', $this->minify_excluded, ''); |
|
244 | 244 | |
245 | 245 | // should we force all media-attributes to all? |
246 | - $this->media_force_all = apply_filters( 'autoptimize_filter_css_tagmedia_forceall', false ); |
|
246 | + $this->media_force_all = apply_filters('autoptimize_filter_css_tagmedia_forceall', false); |
|
247 | 247 | |
248 | 248 | // noptimize me. |
249 | - $this->content = $this->hide_noptimize( $this->content ); |
|
249 | + $this->content = $this->hide_noptimize($this->content); |
|
250 | 250 | |
251 | 251 | // Exclude (no)script, as those may contain CSS which should be left as is. |
252 | 252 | $this->content = $this->replace_contents_with_marker_if_exists( |
@@ -257,25 +257,25 @@ discard block |
||
257 | 257 | ); |
258 | 258 | |
259 | 259 | // Save IE hacks. |
260 | - $this->content = $this->hide_iehacks( $this->content ); |
|
260 | + $this->content = $this->hide_iehacks($this->content); |
|
261 | 261 | |
262 | 262 | // Hide HTML comments. |
263 | - $this->content = $this->hide_comments( $this->content ); |
|
263 | + $this->content = $this->hide_comments($this->content); |
|
264 | 264 | |
265 | 265 | // Get <style> and <link>. |
266 | - if ( preg_match_all( '#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches ) ) { |
|
266 | + if (preg_match_all('#(<style[^>]*>.*</style>)|(<link[^>]*stylesheet[^>]*>)#Usmi', $this->content, $matches)) { |
|
267 | 267 | |
268 | - foreach ( $matches[0] as $tag ) { |
|
269 | - if ( $this->isremovable( $tag, $this->cssremovables ) ) { |
|
270 | - $this->content = str_replace( $tag, '', $this->content ); |
|
271 | - } elseif ( $this->ismovable( $tag ) ) { |
|
268 | + foreach ($matches[0] as $tag) { |
|
269 | + if ($this->isremovable($tag, $this->cssremovables)) { |
|
270 | + $this->content = str_replace($tag, '', $this->content); |
|
271 | + } elseif ($this->ismovable($tag)) { |
|
272 | 272 | // Get the media. |
273 | - if ( false !== strpos( $tag, 'media=' ) ) { |
|
274 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias ); |
|
275 | - $medias = explode( ',', $medias[1] ); |
|
273 | + if (false !== strpos($tag, 'media=')) { |
|
274 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $medias); |
|
275 | + $medias = explode(',', $medias[1]); |
|
276 | 276 | $media = array(); |
277 | - foreach ( $medias as $elem ) { |
|
278 | - if ( empty( $elem ) ) { |
|
277 | + foreach ($medias as $elem) { |
|
278 | + if (empty($elem)) { |
|
279 | 279 | $elem = 'all'; |
280 | 280 | } |
281 | 281 | |
@@ -283,68 +283,68 @@ discard block |
||
283 | 283 | } |
284 | 284 | } else { |
285 | 285 | // No media specified - applies to all. |
286 | - $media = array( 'all' ); |
|
286 | + $media = array('all'); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // forcing media attribute to all to merge all in one file. |
290 | - if ( $this->media_force_all ) { |
|
291 | - $media = array( 'all' ); |
|
290 | + if ($this->media_force_all) { |
|
291 | + $media = array('all'); |
|
292 | 292 | } |
293 | 293 | |
294 | - $media = apply_filters( 'autoptimize_filter_css_tagmedia', $media, $tag ); |
|
294 | + $media = apply_filters('autoptimize_filter_css_tagmedia', $media, $tag); |
|
295 | 295 | |
296 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
296 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
297 | 297 | // <link>. |
298 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
299 | - $path = $this->getpath( $url ); |
|
298 | + $url = current(explode('?', $source[2], 2)); |
|
299 | + $path = $this->getpath($url); |
|
300 | 300 | |
301 | - if ( false !== $path && preg_match( '#\.css$#', $path ) ) { |
|
301 | + if (false !== $path && preg_match('#\.css$#', $path)) { |
|
302 | 302 | // Good link. |
303 | - $this->css[] = array( $media, $path ); |
|
303 | + $this->css[] = array($media, $path); |
|
304 | 304 | } else { |
305 | 305 | // Link is dynamic (.php etc). |
306 | - $new_tag = $this->optionally_defer_excluded( $tag, 'none' ); |
|
307 | - if ( '' !== $new_tag && $new_tag !== $tag ) { |
|
308 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
306 | + $new_tag = $this->optionally_defer_excluded($tag, 'none'); |
|
307 | + if ('' !== $new_tag && $new_tag !== $tag) { |
|
308 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
309 | 309 | } |
310 | 310 | $tag = ''; |
311 | 311 | } |
312 | 312 | } else { |
313 | 313 | // Inline css in style tags can be wrapped in comment tags, so restore comments. |
314 | - $tag = $this->restore_comments( $tag ); |
|
315 | - preg_match( '#<style.*>(.*)</style>#Usmi', $tag, $code ); |
|
314 | + $tag = $this->restore_comments($tag); |
|
315 | + preg_match('#<style.*>(.*)</style>#Usmi', $tag, $code); |
|
316 | 316 | |
317 | 317 | // And re-hide them to be able to to the removal based on tag. |
318 | - $tag = $this->hide_comments( $tag ); |
|
318 | + $tag = $this->hide_comments($tag); |
|
319 | 319 | |
320 | - if ( $this->include_inline ) { |
|
321 | - $code = preg_replace( '#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1] ); |
|
322 | - $this->css[] = array( $media, 'INLINE;' . $code ); |
|
320 | + if ($this->include_inline) { |
|
321 | + $code = preg_replace('#^.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*$#sm', '$1', $code[1]); |
|
322 | + $this->css[] = array($media, 'INLINE;'.$code); |
|
323 | 323 | } else { |
324 | 324 | $tag = ''; |
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | 328 | // Remove the original style tag. |
329 | - $this->content = str_replace( $tag, '', $this->content ); |
|
329 | + $this->content = str_replace($tag, '', $this->content); |
|
330 | 330 | } else { |
331 | - if ( preg_match( '#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source ) ) { |
|
332 | - $exploded_url = explode( '?', $source[2], 2 ); |
|
331 | + if (preg_match('#<link.*href=("|\')(.*)("|\')#Usmi', $tag, $source)) { |
|
332 | + $exploded_url = explode('?', $source[2], 2); |
|
333 | 333 | $url = $exploded_url[0]; |
334 | - $path = $this->getpath( $url ); |
|
334 | + $path = $this->getpath($url); |
|
335 | 335 | $new_tag = $tag; |
336 | 336 | |
337 | 337 | // Excluded CSS, minify that file: |
338 | 338 | // -> if aggregate is on and exclude minify is on |
339 | 339 | // -> if aggregate is off and the file is not in dontmove. |
340 | - if ( $path && $this->minify_excluded ) { |
|
341 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false ); |
|
342 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
343 | - $minified_url = $this->minify_single( $path ); |
|
344 | - if ( ! empty( $minified_url ) ) { |
|
340 | + if ($path && $this->minify_excluded) { |
|
341 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false); |
|
342 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
343 | + $minified_url = $this->minify_single($path); |
|
344 | + if (!empty($minified_url)) { |
|
345 | 345 | // Replace orig URL with cached minified URL. |
346 | - $new_tag = str_replace( $url, $minified_url, $tag ); |
|
347 | - } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) { |
|
346 | + $new_tag = str_replace($url, $minified_url, $tag); |
|
347 | + } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) { |
|
348 | 348 | // Remove the original style tag, because cache content is empty but only if |
349 | 349 | // filter is true-ed because $minified_url is also false if file is minified already. |
350 | 350 | $new_tag = ''; |
@@ -352,14 +352,14 @@ discard block |
||
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - if ( '' !== $new_tag ) { |
|
355 | + if ('' !== $new_tag) { |
|
356 | 356 | // Optionally defer (preload) non-aggregated CSS. |
357 | - $new_tag = $this->optionally_defer_excluded( $new_tag, $url ); |
|
357 | + $new_tag = $this->optionally_defer_excluded($new_tag, $url); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | // And replace! |
361 | - if ( ( '' !== $new_tag && $new_tag !== $tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_css_remove_empty_files', false ) ) ) { |
|
362 | - $this->content = str_replace( $tag, $new_tag, $this->content ); |
|
361 | + if (('' !== $new_tag && $new_tag !== $tag) || ('' === $new_tag && apply_filters('autoptimize_filter_css_remove_empty_files', false))) { |
|
362 | + $this->content = str_replace($tag, $new_tag, $this->content); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } |
@@ -380,30 +380,30 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return string $new_tag |
382 | 382 | */ |
383 | - private function optionally_defer_excluded( $tag, $url = '' ) |
|
383 | + private function optionally_defer_excluded($tag, $url = '') |
|
384 | 384 | { |
385 | 385 | // Defer single CSS if "inline & defer" is ON and there is inline CSS. |
386 | - if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) { |
|
386 | + if (!empty($tag) && false === strpos($tag, ' onload=') && $this->defer && !empty($this->defer_inline) && apply_filters('autoptimize_filter_css_defer_excluded', true, $tag)) { |
|
387 | 387 | // get media attribute and based on that create onload JS attribute value. |
388 | - if ( false === strpos( $tag, 'media=' ) ) { |
|
389 | - $tag = str_replace( '<link', "<link media='all'", $tag ); |
|
388 | + if (false === strpos($tag, 'media=')) { |
|
389 | + $tag = str_replace('<link', "<link media='all'", $tag); |
|
390 | 390 | } |
391 | 391 | |
392 | - preg_match( '#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias ); |
|
392 | + preg_match('#media=(?:"|\')([^>]*)(?:"|\')#Ui', $tag, $_medias); |
|
393 | 393 | $_media = $_medias[1]; |
394 | - $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $_media ); |
|
394 | + $_preload_onload = autoptimizeConfig::get_ao_css_preload_onload($_media); |
|
395 | 395 | |
396 | - if ( 'print' !== $_media ) { |
|
396 | + if ('print' !== $_media) { |
|
397 | 397 | // If not media=print, adapt original <link> element for CSS to be preloaded and add <noscript>-version for fallback. |
398 | - $new_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>' . str_replace( |
|
398 | + $new_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>'.str_replace( |
|
399 | 399 | $_medias[0], |
400 | - "media='print' onload=\"" . $_preload_onload . '"', |
|
400 | + "media='print' onload=\"".$_preload_onload.'"', |
|
401 | 401 | $tag |
402 | 402 | ); |
403 | 403 | |
404 | 404 | // Optionally (but default false) preload the (excluded) CSS-file. |
405 | - if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) && 'none' !== $url ) { |
|
406 | - $new_tag = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $new_tag; |
|
405 | + if (apply_filters('autoptimize_fitler_css_preload_and_print', false) && 'none' !== $url) { |
|
406 | + $new_tag = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$new_tag; |
|
407 | 407 | } |
408 | 408 | } else { |
409 | 409 | $new_tag = $tag; |
@@ -423,22 +423,22 @@ discard block |
||
423 | 423 | * @param string $path image path. |
424 | 424 | * @return boolean |
425 | 425 | */ |
426 | - private function is_datauri_candidate( $path ) |
|
426 | + private function is_datauri_candidate($path) |
|
427 | 427 | { |
428 | 428 | // Call only once since it's called from a loop. |
429 | 429 | static $max_size = null; |
430 | - if ( null === $max_size ) { |
|
430 | + if (null === $max_size) { |
|
431 | 431 | $max_size = $this->get_datauri_maxsize(); |
432 | 432 | } |
433 | 433 | |
434 | - if ( $path && preg_match( '#\.(jpe?g|png|gif|webp|bmp)$#i', $path ) && |
|
435 | - file_exists( $path ) && is_readable( $path ) && filesize( $path ) <= $max_size ) { |
|
434 | + if ($path && preg_match('#\.(jpe?g|png|gif|webp|bmp)$#i', $path) && |
|
435 | + file_exists($path) && is_readable($path) && filesize($path) <= $max_size) { |
|
436 | 436 | |
437 | 437 | // Seems we have a candidate. |
438 | 438 | $is_candidate = true; |
439 | 439 | } else { |
440 | 440 | // Filter allows overriding default decision (which checks for local file existence). |
441 | - $is_candidate = apply_filters( 'autoptimize_filter_css_is_datauri_candidate', false, $path ); |
|
441 | + $is_candidate = apply_filters('autoptimize_filter_css_is_datauri_candidate', false, $path); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | return $is_candidate; |
@@ -463,29 +463,29 @@ discard block |
||
463 | 463 | * of thing you're probably better of building assets completely |
464 | 464 | * outside of WordPress anyway. |
465 | 465 | */ |
466 | - if ( null === $max_size ) { |
|
467 | - $max_size = (int) apply_filters( 'autoptimize_filter_css_datauri_maxsize', 4096 ); |
|
466 | + if (null === $max_size) { |
|
467 | + $max_size = (int) apply_filters('autoptimize_filter_css_datauri_maxsize', 4096); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | return $max_size; |
471 | 471 | } |
472 | 472 | |
473 | - private function check_datauri_exclude_list( $url ) |
|
473 | + private function check_datauri_exclude_list($url) |
|
474 | 474 | { |
475 | 475 | static $exclude_list = null; |
476 | 476 | $no_datauris = array(); |
477 | 477 | |
478 | 478 | // Again, skip doing certain stuff repeatedly when loop-called. |
479 | - if ( null === $exclude_list ) { |
|
480 | - $exclude_list = apply_filters( 'autoptimize_filter_css_datauri_exclude', '' ); |
|
481 | - $no_datauris = array_filter( array_map( 'trim', explode( ',', $exclude_list ) ) ); |
|
479 | + if (null === $exclude_list) { |
|
480 | + $exclude_list = apply_filters('autoptimize_filter_css_datauri_exclude', ''); |
|
481 | + $no_datauris = array_filter(array_map('trim', explode(',', $exclude_list))); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | $matched = false; |
485 | 485 | |
486 | - if ( ! empty( $exclude_list ) ) { |
|
487 | - foreach ( $no_datauris as $no_datauri ) { |
|
488 | - if ( false !== strpos( $url, $no_datauri ) ) { |
|
486 | + if (!empty($exclude_list)) { |
|
487 | + foreach ($no_datauris as $no_datauri) { |
|
488 | + if (false !== strpos($url, $no_datauri)) { |
|
489 | 489 | $matched = true; |
490 | 490 | break; |
491 | 491 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | return $matched; |
496 | 496 | } |
497 | 497 | |
498 | - private function build_or_get_datauri_image( $path ) |
|
498 | + private function build_or_get_datauri_image($path) |
|
499 | 499 | { |
500 | 500 | /** |
501 | 501 | * TODO/FIXME: document the required return array format, or better yet, |
@@ -504,27 +504,27 @@ discard block |
||
504 | 504 | */ |
505 | 505 | |
506 | 506 | // Allows short-circuiting datauri generation for an image. |
507 | - $result = apply_filters( 'autoptimize_filter_css_datauri_image', array(), $path ); |
|
508 | - if ( ! empty( $result ) ) { |
|
509 | - if ( is_array( $result ) && isset( $result['full'] ) && isset( $result['base64data'] ) ) { |
|
507 | + $result = apply_filters('autoptimize_filter_css_datauri_image', array(), $path); |
|
508 | + if (!empty($result)) { |
|
509 | + if (is_array($result) && isset($result['full']) && isset($result['base64data'])) { |
|
510 | 510 | return $result; |
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | - $hash = md5( $path ); |
|
515 | - $check = new autoptimizeCache( $hash, 'img' ); |
|
516 | - if ( $check->check() ) { |
|
514 | + $hash = md5($path); |
|
515 | + $check = new autoptimizeCache($hash, 'img'); |
|
516 | + if ($check->check()) { |
|
517 | 517 | // we have the base64 image in cache. |
518 | 518 | $head_and_data = $check->retrieve(); |
519 | - $_base64data = explode( ';base64,', $head_and_data ); |
|
519 | + $_base64data = explode(';base64,', $head_and_data); |
|
520 | 520 | $base64data = $_base64data[1]; |
521 | - unset( $_base64data ); |
|
521 | + unset($_base64data); |
|
522 | 522 | } else { |
523 | 523 | // It's an image and we don't have it in cache, get the type by extension. |
524 | - $exploded_path = explode( '.', $path ); |
|
525 | - $type = end( $exploded_path ); |
|
524 | + $exploded_path = explode('.', $path); |
|
525 | + $type = end($exploded_path); |
|
526 | 526 | |
527 | - switch ( $type ) { |
|
527 | + switch ($type) { |
|
528 | 528 | case 'jpg': |
529 | 529 | case 'jpeg': |
530 | 530 | $dataurihead = 'data:image/jpeg;base64,'; |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | } |
547 | 547 | |
548 | 548 | // Encode the data. |
549 | - $base64data = base64_encode( file_get_contents( $path ) ); |
|
550 | - $head_and_data = $dataurihead . $base64data; |
|
549 | + $base64data = base64_encode(file_get_contents($path)); |
|
550 | + $head_and_data = $dataurihead.$base64data; |
|
551 | 551 | |
552 | 552 | // Save in cache. |
553 | - $check->cache( $head_and_data, 'text/plain' ); |
|
553 | + $check->cache($head_and_data, 'text/plain'); |
|
554 | 554 | } |
555 | - unset( $check ); |
|
555 | + unset($check); |
|
556 | 556 | |
557 | 557 | return array( |
558 | 558 | 'full' => $head_and_data, |
@@ -569,13 +569,13 @@ discard block |
||
569 | 569 | * |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - protected static function replace_longest_matches_first( $string, $replacements = array() ) |
|
572 | + protected static function replace_longest_matches_first($string, $replacements = array()) |
|
573 | 573 | { |
574 | - if ( ! empty( $replacements ) ) { |
|
574 | + if (!empty($replacements)) { |
|
575 | 575 | // Sort the replacements array by key length in desc order (so that the longest strings are replaced first). |
576 | - $keys = array_map( 'strlen', array_keys( $replacements ) ); |
|
577 | - array_multisort( $keys, SORT_DESC, $replacements ); |
|
578 | - $string = str_replace( array_keys( $replacements ), array_values( $replacements ), $string ); |
|
576 | + $keys = array_map('strlen', array_keys($replacements)); |
|
577 | + array_multisort($keys, SORT_DESC, $replacements); |
|
578 | + $string = str_replace(array_keys($replacements), array_values($replacements), $string); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $string; |
@@ -591,15 +591,15 @@ discard block |
||
591 | 591 | * |
592 | 592 | * @return string |
593 | 593 | */ |
594 | - public function replace_urls( $code = '' ) |
|
594 | + public function replace_urls($code = '') |
|
595 | 595 | { |
596 | 596 | $replacements = array(); |
597 | 597 | |
598 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
599 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
600 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
598 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
599 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
600 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
601 | 601 | // Removes quotes and other cruft. |
602 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
602 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
603 | 603 | |
604 | 604 | /** |
605 | 605 | * TODO/FIXME: Add a way for other code / callable to be called here |
@@ -617,17 +617,17 @@ discard block |
||
617 | 617 | */ |
618 | 618 | |
619 | 619 | // Do CDN replacement if needed. |
620 | - if ( ! empty( $this->cdn_url ) ) { |
|
621 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
620 | + if (!empty($this->cdn_url)) { |
|
621 | + $replacement_url = $this->url_replace_cdn($url); |
|
622 | 622 | // Prepare replacements array. |
623 | - $replacements[ $url_src_matches[1][ $count ] ] = str_replace( |
|
624 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
623 | + $replacements[$url_src_matches[1][$count]] = str_replace( |
|
624 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
625 | 625 | ); |
626 | 626 | } |
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | - $code = self::replace_longest_matches_first( $code, $replacements ); |
|
630 | + $code = self::replace_longest_matches_first($code, $replacements); |
|
631 | 631 | |
632 | 632 | return $code; |
633 | 633 | } |
@@ -640,26 +640,26 @@ discard block |
||
640 | 640 | * @param string $code HTML being processed to hide fonts. |
641 | 641 | * @return string |
642 | 642 | */ |
643 | - public function hide_fontface_and_maybe_cdn( $code ) |
|
643 | + public function hide_fontface_and_maybe_cdn($code) |
|
644 | 644 | { |
645 | 645 | // Proceed only if @font-face declarations exist within $code. |
646 | - preg_match_all( self::FONT_FACE_REGEX, $code, $fontfaces ); |
|
647 | - if ( isset( $fontfaces[0] ) ) { |
|
646 | + preg_match_all(self::FONT_FACE_REGEX, $code, $fontfaces); |
|
647 | + if (isset($fontfaces[0])) { |
|
648 | 648 | // Check if we need to cdn fonts or not. |
649 | - $do_font_cdn = apply_filters( 'autoptimize_filter_css_fonts_cdn', false ); |
|
649 | + $do_font_cdn = apply_filters('autoptimize_filter_css_fonts_cdn', false); |
|
650 | 650 | |
651 | - foreach ( $fontfaces[0] as $full_match ) { |
|
651 | + foreach ($fontfaces[0] as $full_match) { |
|
652 | 652 | // Keep original match so we can search/replace it. |
653 | 653 | $match_search = $full_match; |
654 | 654 | |
655 | 655 | // Do font cdn if needed. |
656 | - if ( $do_font_cdn ) { |
|
657 | - $full_match = $this->replace_urls( $full_match ); |
|
656 | + if ($do_font_cdn) { |
|
657 | + $full_match = $this->replace_urls($full_match); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Replace declaration with its base64 encoded string. |
661 | - $replacement = self::build_marker( 'FONTFACE', $full_match ); |
|
662 | - $code = str_replace( $match_search, $replacement, $code ); |
|
661 | + $replacement = self::build_marker('FONTFACE', $full_match); |
|
662 | + $code = str_replace($match_search, $replacement, $code); |
|
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
@@ -673,9 +673,9 @@ discard block |
||
673 | 673 | * @param string $code HTML being processed to unhide fonts. |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - public function restore_fontface( $code ) |
|
676 | + public function restore_fontface($code) |
|
677 | 677 | { |
678 | - return $this->restore_marked_content( 'FONTFACE', $code ); |
|
678 | + return $this->restore_marked_content('FONTFACE', $code); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | * @param string $code HTML being processed rewrite assets. |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public function rewrite_assets( $code ) |
|
687 | + public function rewrite_assets($code) |
|
688 | 688 | { |
689 | 689 | // Handle @font-face rules by hiding and processing them separately. |
690 | - $code = $this->hide_fontface_and_maybe_cdn( $code ); |
|
690 | + $code = $this->hide_fontface_and_maybe_cdn($code); |
|
691 | 691 | |
692 | 692 | /** |
693 | 693 | * TODO/FIXME: |
@@ -704,35 +704,35 @@ discard block |
||
704 | 704 | $imgreplace = array(); |
705 | 705 | |
706 | 706 | // Matches and captures anything specified within the literal `url()` and excludes those containing data: URIs. |
707 | - preg_match_all( self::ASSETS_REGEX, $code, $url_src_matches ); |
|
708 | - if ( is_array( $url_src_matches ) && ! empty( $url_src_matches ) ) { |
|
709 | - foreach ( $url_src_matches[1] as $count => $original_url ) { |
|
707 | + preg_match_all(self::ASSETS_REGEX, $code, $url_src_matches); |
|
708 | + if (is_array($url_src_matches) && !empty($url_src_matches)) { |
|
709 | + foreach ($url_src_matches[1] as $count => $original_url) { |
|
710 | 710 | // Removes quotes and other cruft. |
711 | - $url = trim( $original_url, " \t\n\r\0\x0B\"'" ); |
|
711 | + $url = trim($original_url, " \t\n\r\0\x0B\"'"); |
|
712 | 712 | |
713 | 713 | // If datauri inlining is turned on, do it. |
714 | 714 | $inlined = false; |
715 | - if ( $this->datauris ) { |
|
715 | + if ($this->datauris) { |
|
716 | 716 | $iurl = $url; |
717 | - if ( false !== strpos( $iurl, '?' ) ) { |
|
718 | - $iurl = strtok( $iurl, '?' ); |
|
717 | + if (false !== strpos($iurl, '?')) { |
|
718 | + $iurl = strtok($iurl, '?'); |
|
719 | 719 | } |
720 | 720 | |
721 | - $ipath = $this->getpath( $iurl ); |
|
721 | + $ipath = $this->getpath($iurl); |
|
722 | 722 | |
723 | - $excluded = $this->check_datauri_exclude_list( $ipath ); |
|
724 | - if ( ! $excluded ) { |
|
725 | - $is_datauri_candidate = $this->is_datauri_candidate( $ipath ); |
|
726 | - if ( $is_datauri_candidate ) { |
|
727 | - $datauri = $this->build_or_get_datauri_image( $ipath ); |
|
723 | + $excluded = $this->check_datauri_exclude_list($ipath); |
|
724 | + if (!$excluded) { |
|
725 | + $is_datauri_candidate = $this->is_datauri_candidate($ipath); |
|
726 | + if ($is_datauri_candidate) { |
|
727 | + $datauri = $this->build_or_get_datauri_image($ipath); |
|
728 | 728 | $base64data = $datauri['base64data']; |
729 | 729 | // Add it to the list for replacement. |
730 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
730 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
731 | 731 | $original_url, |
732 | 732 | $datauri['full'], |
733 | - $url_src_matches[1][ $count ] |
|
733 | + $url_src_matches[1][$count] |
|
734 | 734 | ); |
735 | - $inlined = true; |
|
735 | + $inlined = true; |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | } |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * inlining isn't turned on, or if a resource is skipped from |
744 | 744 | * being inlined for whatever reason above. |
745 | 745 | */ |
746 | - if ( ! $inlined && ( ! empty( $this->cdn_url ) || has_filter( 'autoptimize_filter_base_replace_cdn' ) ) ) { |
|
746 | + if (!$inlined && (!empty($this->cdn_url) || has_filter('autoptimize_filter_base_replace_cdn'))) { |
|
747 | 747 | // Just do the "simple" CDN replacement. |
748 | - $replacement_url = $this->url_replace_cdn( $url ); |
|
749 | - $imgreplace[ $url_src_matches[1][ $count ] ] = str_replace( |
|
750 | - $original_url, $replacement_url, $url_src_matches[1][ $count ] |
|
748 | + $replacement_url = $this->url_replace_cdn($url); |
|
749 | + $imgreplace[$url_src_matches[1][$count]] = str_replace( |
|
750 | + $original_url, $replacement_url, $url_src_matches[1][$count] |
|
751 | 751 | ); |
752 | 752 | } |
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
756 | - $code = self::replace_longest_matches_first( $code, $imgreplace ); |
|
756 | + $code = self::replace_longest_matches_first($code, $imgreplace); |
|
757 | 757 | |
758 | 758 | // Replace back font-face markers with actual font-face declarations. |
759 | - $code = $this->restore_fontface( $code ); |
|
759 | + $code = $this->restore_fontface($code); |
|
760 | 760 | |
761 | 761 | return $code; |
762 | 762 | } |
@@ -766,29 +766,29 @@ discard block |
||
766 | 766 | */ |
767 | 767 | public function minify() |
768 | 768 | { |
769 | - foreach ( $this->css as $group ) { |
|
770 | - list( $media, $css ) = $group; |
|
771 | - if ( preg_match( '#^INLINE;#', $css ) ) { |
|
769 | + foreach ($this->css as $group) { |
|
770 | + list($media, $css) = $group; |
|
771 | + if (preg_match('#^INLINE;#', $css)) { |
|
772 | 772 | // <style>. |
773 | - $css = preg_replace( '#^INLINE;#', '', $css ); |
|
774 | - $css = self::fixurls( ABSPATH . 'index.php', $css ); // ABSPATH already contains a trailing slash. |
|
775 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, '' ); |
|
776 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
773 | + $css = preg_replace('#^INLINE;#', '', $css); |
|
774 | + $css = self::fixurls(ABSPATH.'index.php', $css); // ABSPATH already contains a trailing slash. |
|
775 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, ''); |
|
776 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
777 | 777 | $css = $tmpstyle; |
778 | 778 | $this->alreadyminified = true; |
779 | 779 | } |
780 | 780 | } else { |
781 | 781 | // <link> |
782 | - if ( false !== $css && file_exists( $css ) && is_readable( $css ) ) { |
|
782 | + if (false !== $css && file_exists($css) && is_readable($css)) { |
|
783 | 783 | $css_path = $css; |
784 | - $css = self::fixurls( $css_path, file_get_contents( $css_path ) ); |
|
785 | - $css = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $css ); |
|
786 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $css, $css_path ); |
|
787 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
784 | + $css = self::fixurls($css_path, file_get_contents($css_path)); |
|
785 | + $css = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $css); |
|
786 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $css, $css_path); |
|
787 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
788 | 788 | $css = $tmpstyle; |
789 | 789 | $this->alreadyminified = true; |
790 | - } elseif ( $this->can_inject_late( $css_path, $css ) ) { |
|
791 | - $css = self::build_injectlater_marker( $css_path, md5( $css ) ); |
|
790 | + } elseif ($this->can_inject_late($css_path, $css)) { |
|
791 | + $css = self::build_injectlater_marker($css_path, md5($css)); |
|
792 | 792 | } |
793 | 793 | } else { |
794 | 794 | // Couldn't read CSS. Maybe getpath isn't working? |
@@ -796,12 +796,12 @@ discard block |
||
796 | 796 | } |
797 | 797 | } |
798 | 798 | |
799 | - foreach ( $media as $elem ) { |
|
800 | - if ( ! empty( $css ) ) { |
|
801 | - if ( ! isset( $this->csscode[ $elem ] ) ) { |
|
802 | - $this->csscode[ $elem ] = ''; |
|
799 | + foreach ($media as $elem) { |
|
800 | + if (!empty($css)) { |
|
801 | + if (!isset($this->csscode[$elem])) { |
|
802 | + $this->csscode[$elem] = ''; |
|
803 | 803 | } |
804 | - $this->csscode[ $elem ] .= "\n/*FILESTART*/" . $css; |
|
804 | + $this->csscode[$elem] .= "\n/*FILESTART*/".$css; |
|
805 | 805 | } |
806 | 806 | } |
807 | 807 | } |
@@ -809,133 +809,133 @@ discard block |
||
809 | 809 | // Check for duplicate code. |
810 | 810 | $md5list = array(); |
811 | 811 | $tmpcss = $this->csscode; |
812 | - foreach ( $tmpcss as $media => $code ) { |
|
813 | - $md5sum = md5( $code ); |
|
812 | + foreach ($tmpcss as $media => $code) { |
|
813 | + $md5sum = md5($code); |
|
814 | 814 | $medianame = $media; |
815 | - foreach ( $md5list as $med => $sum ) { |
|
815 | + foreach ($md5list as $med => $sum) { |
|
816 | 816 | // If same code. |
817 | - if ( $sum === $md5sum ) { |
|
817 | + if ($sum === $md5sum) { |
|
818 | 818 | // Add the merged code. |
819 | - $medianame = $med . ', ' . $media; |
|
820 | - $this->csscode[ $medianame ] = $code; |
|
821 | - $md5list[ $medianame ] = $md5list[ $med ]; |
|
822 | - unset( $this->csscode[ $med ], $this->csscode[ $media ], $md5list[ $med ] ); |
|
819 | + $medianame = $med.', '.$media; |
|
820 | + $this->csscode[$medianame] = $code; |
|
821 | + $md5list[$medianame] = $md5list[$med]; |
|
822 | + unset($this->csscode[$med], $this->csscode[$media], $md5list[$med]); |
|
823 | 823 | } |
824 | 824 | } |
825 | - $md5list[ $medianame ] = $md5sum; |
|
825 | + $md5list[$medianame] = $md5sum; |
|
826 | 826 | } |
827 | - unset( $tmpcss ); |
|
827 | + unset($tmpcss); |
|
828 | 828 | |
829 | 829 | // Manage @imports, while is for recursive import management. |
830 | - foreach ( $this->csscode as &$thiscss ) { |
|
830 | + foreach ($this->csscode as &$thiscss) { |
|
831 | 831 | // Flag to trigger import reconstitution and var to hold external imports. |
832 | 832 | $fiximports = false; |
833 | 833 | $external_imports = ''; |
834 | 834 | |
835 | 835 | // remove comments to avoid importing commented-out imports. |
836 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
837 | - while ( preg_match_all( '#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches ) ) { |
|
838 | - foreach ( $matches[0] as $import ) { |
|
839 | - if ( $this->isremovable( $import, $this->cssremovables ) ) { |
|
840 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
836 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
837 | + while (preg_match_all('#@import +(?:url)?(?:(?:\((["\']?)(?:[^"\')]+)\1\)|(["\'])(?:[^"\']+)\2)(?:[^,;"\']+(?:,[^,;"\']+)*)?)(?:;)#mi', $thiscss_nocomments, $matches)) { |
|
838 | + foreach ($matches[0] as $import) { |
|
839 | + if ($this->isremovable($import, $this->cssremovables)) { |
|
840 | + $thiscss = str_replace($import, '', $thiscss); |
|
841 | 841 | $import_ok = true; |
842 | 842 | } else { |
843 | - $url = trim( preg_replace( '#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim( $import ) ), " \t\n\r\0\x0B\"'" ); |
|
844 | - $path = $this->getpath( $url ); |
|
843 | + $url = trim(preg_replace('#^.*((?:https?:|ftp:)?//.*\.css).*$#', '$1', trim($import)), " \t\n\r\0\x0B\"'"); |
|
844 | + $path = $this->getpath($url); |
|
845 | 845 | $import_ok = false; |
846 | - if ( file_exists( $path ) && is_readable( $path ) ) { |
|
847 | - $code = addcslashes( self::fixurls( $path, file_get_contents( $path ) ), '\\' ); |
|
848 | - $code = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $code ); |
|
849 | - $tmpstyle = apply_filters( 'autoptimize_css_individual_style', $code, '' ); |
|
850 | - if ( has_filter( 'autoptimize_css_individual_style' ) && ! empty( $tmpstyle ) ) { |
|
846 | + if (file_exists($path) && is_readable($path)) { |
|
847 | + $code = addcslashes(self::fixurls($path, file_get_contents($path)), '\\'); |
|
848 | + $code = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $code); |
|
849 | + $tmpstyle = apply_filters('autoptimize_css_individual_style', $code, ''); |
|
850 | + if (has_filter('autoptimize_css_individual_style') && !empty($tmpstyle)) { |
|
851 | 851 | $code = $tmpstyle; |
852 | 852 | $this->alreadyminified = true; |
853 | - } elseif ( $this->can_inject_late( $path, $code ) ) { |
|
854 | - $code = self::build_injectlater_marker( $path, md5( $code ) ); |
|
853 | + } elseif ($this->can_inject_late($path, $code)) { |
|
854 | + $code = self::build_injectlater_marker($path, md5($code)); |
|
855 | 855 | } |
856 | 856 | |
857 | - if ( ! empty( $code ) ) { |
|
858 | - $tmp_thiscss = preg_replace( '#(/\*FILESTART\*/.*)' . preg_quote( $import, '#' ) . '#Us', '/*FILESTART2*/' . $code . '$1', $thiscss ); |
|
859 | - if ( ! empty( $tmp_thiscss ) ) { |
|
857 | + if (!empty($code)) { |
|
858 | + $tmp_thiscss = preg_replace('#(/\*FILESTART\*/.*)'.preg_quote($import, '#').'#Us', '/*FILESTART2*/'.$code.'$1', $thiscss); |
|
859 | + if (!empty($tmp_thiscss)) { |
|
860 | 860 | $thiscss = $tmp_thiscss; |
861 | 861 | $import_ok = true; |
862 | - unset( $tmp_thiscss ); |
|
862 | + unset($tmp_thiscss); |
|
863 | 863 | } |
864 | 864 | } |
865 | - unset( $code ); |
|
865 | + unset($code); |
|
866 | 866 | } |
867 | 867 | } |
868 | - if ( ! $import_ok ) { |
|
868 | + if (!$import_ok) { |
|
869 | 869 | // External imports and general fall-back. |
870 | 870 | $external_imports .= $import; |
871 | 871 | |
872 | - $thiscss = str_replace( $import, '', $thiscss ); |
|
872 | + $thiscss = str_replace($import, '', $thiscss); |
|
873 | 873 | $fiximports = true; |
874 | 874 | } |
875 | 875 | } |
876 | - $thiscss = preg_replace( '#/\*FILESTART\*/#', '', $thiscss ); |
|
877 | - $thiscss = preg_replace( '#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss ); |
|
876 | + $thiscss = preg_replace('#/\*FILESTART\*/#', '', $thiscss); |
|
877 | + $thiscss = preg_replace('#/\*FILESTART2\*/#', '/*FILESTART*/', $thiscss); |
|
878 | 878 | |
879 | 879 | // and update $thiscss_nocomments before going into next iteration in while loop. |
880 | - $thiscss_nocomments = preg_replace( '#/\*.*\*/#Us', '', $thiscss ); |
|
880 | + $thiscss_nocomments = preg_replace('#/\*.*\*/#Us', '', $thiscss); |
|
881 | 881 | } |
882 | - unset( $thiscss_nocomments ); |
|
882 | + unset($thiscss_nocomments); |
|
883 | 883 | |
884 | 884 | // Add external imports to top of aggregated CSS. |
885 | - if ( $fiximports ) { |
|
886 | - $thiscss = $external_imports . $thiscss; |
|
885 | + if ($fiximports) { |
|
886 | + $thiscss = $external_imports.$thiscss; |
|
887 | 887 | } |
888 | 888 | } |
889 | - unset( $thiscss ); |
|
889 | + unset($thiscss); |
|
890 | 890 | |
891 | 891 | // $this->csscode has all the uncompressed code now. |
892 | - foreach ( $this->csscode as &$code ) { |
|
892 | + foreach ($this->csscode as &$code) { |
|
893 | 893 | // Check for already-minified code. |
894 | - $hash = md5( $code ); |
|
895 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
896 | - $ccheck = new autoptimizeCache( $hash, 'css' ); |
|
897 | - if ( $ccheck->check() ) { |
|
894 | + $hash = md5($code); |
|
895 | + do_action('autoptimize_action_css_hash', $hash); |
|
896 | + $ccheck = new autoptimizeCache($hash, 'css'); |
|
897 | + if ($ccheck->check()) { |
|
898 | 898 | $code = $ccheck->retrieve(); |
899 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
899 | + $this->hashmap[md5($code)] = $hash; |
|
900 | 900 | continue; |
901 | 901 | } |
902 | - unset( $ccheck ); |
|
902 | + unset($ccheck); |
|
903 | 903 | |
904 | 904 | // Rewrite and/or inline referenced assets. |
905 | - $code = $this->rewrite_assets( $code ); |
|
905 | + $code = $this->rewrite_assets($code); |
|
906 | 906 | |
907 | 907 | // Minify. |
908 | - $code = $this->run_minifier_on( $code ); |
|
908 | + $code = $this->run_minifier_on($code); |
|
909 | 909 | |
910 | 910 | // Bring back INJECTLATER stuff. |
911 | - $code = $this->inject_minified( $code ); |
|
911 | + $code = $this->inject_minified($code); |
|
912 | 912 | |
913 | 913 | // Filter results. |
914 | - $tmp_code = apply_filters( 'autoptimize_css_after_minify', $code ); |
|
915 | - if ( ! empty( $tmp_code ) ) { |
|
914 | + $tmp_code = apply_filters('autoptimize_css_after_minify', $code); |
|
915 | + if (!empty($tmp_code)) { |
|
916 | 916 | $code = $tmp_code; |
917 | - unset( $tmp_code ); |
|
917 | + unset($tmp_code); |
|
918 | 918 | } |
919 | 919 | |
920 | - $this->hashmap[ md5( $code ) ] = $hash; |
|
920 | + $this->hashmap[md5($code)] = $hash; |
|
921 | 921 | } |
922 | 922 | |
923 | - unset( $code ); |
|
923 | + unset($code); |
|
924 | 924 | return true; |
925 | 925 | } |
926 | 926 | |
927 | - public function run_minifier_on( $code ) |
|
927 | + public function run_minifier_on($code) |
|
928 | 928 | { |
929 | - if ( ! $this->alreadyminified ) { |
|
930 | - $do_minify = apply_filters( 'autoptimize_css_do_minify', true ); |
|
929 | + if (!$this->alreadyminified) { |
|
930 | + $do_minify = apply_filters('autoptimize_css_do_minify', true); |
|
931 | 931 | |
932 | - if ( $do_minify ) { |
|
932 | + if ($do_minify) { |
|
933 | 933 | $cssmin = new autoptimizeCSSmin(); |
934 | - $tmp_code = trim( $cssmin->run( $code ) ); |
|
934 | + $tmp_code = trim($cssmin->run($code)); |
|
935 | 935 | |
936 | - if ( ! empty( $tmp_code ) ) { |
|
936 | + if (!empty($tmp_code)) { |
|
937 | 937 | $code = $tmp_code; |
938 | - unset( $tmp_code ); |
|
938 | + unset($tmp_code); |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | } |
@@ -949,18 +949,18 @@ discard block |
||
949 | 949 | public function cache() |
950 | 950 | { |
951 | 951 | // CSS cache. |
952 | - foreach ( $this->csscode as $media => $code ) { |
|
953 | - if ( empty( $code ) ) { |
|
952 | + foreach ($this->csscode as $media => $code) { |
|
953 | + if (empty($code)) { |
|
954 | 954 | continue; |
955 | 955 | } |
956 | 956 | |
957 | - $md5 = $this->hashmap[ md5( $code ) ]; |
|
958 | - $cache = new autoptimizeCache( $md5, 'css' ); |
|
959 | - if ( ! $cache->check() ) { |
|
957 | + $md5 = $this->hashmap[md5($code)]; |
|
958 | + $cache = new autoptimizeCache($md5, 'css'); |
|
959 | + if (!$cache->check()) { |
|
960 | 960 | // Cache our code. |
961 | - $cache->cache( $code, 'text/css' ); |
|
961 | + $cache->cache($code, 'text/css'); |
|
962 | 962 | } |
963 | - $this->url[ $media ] = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
963 | + $this->url[$media] = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | |
@@ -970,95 +970,95 @@ discard block |
||
970 | 970 | public function getcontent() |
971 | 971 | { |
972 | 972 | // Restore the full content (only applies when "autoptimize_filter_css_justhead" filter is true). |
973 | - if ( ! empty( $this->restofcontent ) ) { |
|
973 | + if (!empty($this->restofcontent)) { |
|
974 | 974 | $this->content .= $this->restofcontent; |
975 | 975 | $this->restofcontent = ''; |
976 | 976 | } |
977 | 977 | |
978 | 978 | // type is not added by default. |
979 | 979 | $type_css = ''; |
980 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
980 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
981 | 981 | $type_css = 'type="text/css" '; |
982 | 982 | } |
983 | 983 | |
984 | 984 | // Inject the new stylesheets. |
985 | - $replace_tag = array( '<title', 'before' ); |
|
986 | - $replace_tag = apply_filters( 'autoptimize_filter_css_replacetag', $replace_tag, $this->content ); |
|
985 | + $replace_tag = array('<title', 'before'); |
|
986 | + $replace_tag = apply_filters('autoptimize_filter_css_replacetag', $replace_tag, $this->content); |
|
987 | 987 | |
988 | - if ( $this->inline ) { |
|
989 | - foreach ( $this->csscode as $media => $code ) { |
|
990 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $code . '</style>' ), $replace_tag ); |
|
988 | + if ($this->inline) { |
|
989 | + foreach ($this->csscode as $media => $code) { |
|
990 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$code.'</style>'), $replace_tag); |
|
991 | 991 | } |
992 | 992 | } else { |
993 | - if ( $this->defer ) { |
|
993 | + if ($this->defer) { |
|
994 | 994 | $preload_css_block = ''; |
995 | 995 | $inlined_ccss_block = ''; |
996 | 996 | $noscript_css_block = '<noscript id="aonoscrcss">'; |
997 | 997 | |
998 | 998 | $defer_inline_code = $this->defer_inline; |
999 | - if ( ! empty( $defer_inline_code ) ) { |
|
1000 | - if ( apply_filters( 'autoptimize_filter_css_critcss_minify', true ) ) { |
|
1001 | - $icss_hash = md5( $defer_inline_code ); |
|
1002 | - $icss_cache = new autoptimizeCache( $icss_hash, 'css' ); |
|
1003 | - if ( $icss_cache->check() ) { |
|
999 | + if (!empty($defer_inline_code)) { |
|
1000 | + if (apply_filters('autoptimize_filter_css_critcss_minify', true)) { |
|
1001 | + $icss_hash = md5($defer_inline_code); |
|
1002 | + $icss_cache = new autoptimizeCache($icss_hash, 'css'); |
|
1003 | + if ($icss_cache->check()) { |
|
1004 | 1004 | // we have the optimized inline CSS in cache. |
1005 | 1005 | $defer_inline_code = $icss_cache->retrieve(); |
1006 | 1006 | } else { |
1007 | 1007 | $cssmin = new autoptimizeCSSmin(); |
1008 | - $tmp_code = trim( $cssmin->run( $defer_inline_code ) ); |
|
1008 | + $tmp_code = trim($cssmin->run($defer_inline_code)); |
|
1009 | 1009 | |
1010 | - if ( ! empty( $tmp_code ) ) { |
|
1010 | + if (!empty($tmp_code)) { |
|
1011 | 1011 | $defer_inline_code = $tmp_code; |
1012 | - $icss_cache->cache( $defer_inline_code, 'text/css' ); |
|
1013 | - unset( $tmp_code ); |
|
1012 | + $icss_cache->cache($defer_inline_code, 'text/css'); |
|
1013 | + unset($tmp_code); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | // inlined critical css set here, but injected when full CSS is injected |
1018 | 1018 | // to avoid CSS containing SVG with <title tag receiving the full CSS link. |
1019 | - $inlined_ccss_block = '<style ' . $type_css . 'id="aoatfcss" media="all">' . $defer_inline_code . '</style>'; |
|
1019 | + $inlined_ccss_block = '<style '.$type_css.'id="aoatfcss" media="all">'.$defer_inline_code.'</style>'; |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | |
1023 | - foreach ( $this->url as $media => $url ) { |
|
1024 | - $url = $this->url_replace_cdn( $url ); |
|
1023 | + foreach ($this->url as $media => $url) { |
|
1024 | + $url = $this->url_replace_cdn($url); |
|
1025 | 1025 | |
1026 | 1026 | // Add the stylesheet either deferred (import at bottom) or normal links in head. |
1027 | - if ( $this->defer && 'print' !== $media ) { |
|
1028 | - $preload_onload = autoptimizeConfig::get_ao_css_preload_onload( $media ); |
|
1027 | + if ($this->defer && 'print' !== $media) { |
|
1028 | + $preload_onload = autoptimizeConfig::get_ao_css_preload_onload($media); |
|
1029 | 1029 | |
1030 | - $preload_css_block .= '<link rel="stylesheet" media="print" href="' . $url . '" onload="' . $preload_onload . '" />'; |
|
1031 | - if ( apply_filters( 'autoptimize_fitler_css_preload_and_print', false ) ) { |
|
1032 | - $preload_css_block = '<link rel="preload" as="stylesheet" href="' . $url . '"/>' . $preload_css_block; |
|
1030 | + $preload_css_block .= '<link rel="stylesheet" media="print" href="'.$url.'" onload="'.$preload_onload.'" />'; |
|
1031 | + if (apply_filters('autoptimize_fitler_css_preload_and_print', false)) { |
|
1032 | + $preload_css_block = '<link rel="preload" as="stylesheet" href="'.$url.'"/>'.$preload_css_block; |
|
1033 | 1033 | } |
1034 | - $noscript_css_block .= '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />'; |
|
1034 | + $noscript_css_block .= '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'; |
|
1035 | 1035 | } else { |
1036 | - if ( strlen( $this->csscode[ $media ] ) > $this->cssinlinesize ) { |
|
1037 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<link ' . $type_css . 'media="' . $media . '" href="' . $url . '" rel="stylesheet" />' ), $replace_tag ); |
|
1038 | - } elseif ( strlen( $this->csscode[ $media ] ) > 0 ) { |
|
1039 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', '<style ' . $type_css . 'media="' . $media . '">' . $this->csscode[ $media ] . '</style>' ), $replace_tag ); |
|
1036 | + if (strlen($this->csscode[$media]) > $this->cssinlinesize) { |
|
1037 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<link '.$type_css.'media="'.$media.'" href="'.$url.'" rel="stylesheet" />'), $replace_tag); |
|
1038 | + } elseif (strlen($this->csscode[$media]) > 0) { |
|
1039 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', '<style '.$type_css.'media="'.$media.'">'.$this->csscode[$media].'</style>'), $replace_tag); |
|
1040 | 1040 | } |
1041 | 1041 | } |
1042 | 1042 | } |
1043 | 1043 | |
1044 | - if ( $this->defer ) { |
|
1044 | + if ($this->defer) { |
|
1045 | 1045 | $noscript_css_block .= '</noscript>'; |
1046 | 1046 | // Inject inline critical CSS, the preloaded full CSS and the noscript-CSS. |
1047 | - $this->inject_in_html( apply_filters( 'autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block . $preload_css_block . $noscript_css_block ), $replace_tag ); |
|
1047 | + $this->inject_in_html(apply_filters('autoptimize_filter_css_bodyreplacementpayload', $inlined_ccss_block.$preload_css_block.$noscript_css_block), $replace_tag); |
|
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | // restore comments. |
1052 | - $this->content = $this->restore_comments( $this->content ); |
|
1052 | + $this->content = $this->restore_comments($this->content); |
|
1053 | 1053 | |
1054 | 1054 | // restore IE hacks. |
1055 | - $this->content = $this->restore_iehacks( $this->content ); |
|
1055 | + $this->content = $this->restore_iehacks($this->content); |
|
1056 | 1056 | |
1057 | 1057 | // restore (no)script. |
1058 | - $this->content = $this->restore_marked_content( 'SCRIPT', $this->content ); |
|
1058 | + $this->content = $this->restore_marked_content('SCRIPT', $this->content); |
|
1059 | 1059 | |
1060 | 1060 | // Restore noptimize. |
1061 | - $this->content = $this->restore_noptimize( $this->content ); |
|
1061 | + $this->content = $this->restore_noptimize($this->content); |
|
1062 | 1062 | |
1063 | 1063 | // Return the modified stylesheet. |
1064 | 1064 | return $this->content; |
@@ -1070,44 +1070,44 @@ discard block |
||
1070 | 1070 | * @param string $file filename of optimized CSS-file. |
1071 | 1071 | * @param string $code CSS-code in which to fix URL's. |
1072 | 1072 | */ |
1073 | - static function fixurls( $file, $code ) |
|
1073 | + static function fixurls($file, $code) |
|
1074 | 1074 | { |
1075 | 1075 | // Switch all imports to the url() syntax. |
1076 | - $code = preg_replace( '#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code ); |
|
1076 | + $code = preg_replace('#@import ("|\')(.+?)\.css.*?("|\')#', '@import url("${2}.css")', $code); |
|
1077 | 1077 | |
1078 | - if ( preg_match_all( self::ASSETS_REGEX, $code, $matches ) ) { |
|
1079 | - $file = str_replace( WP_ROOT_DIR, '/', $file ); |
|
1078 | + if (preg_match_all(self::ASSETS_REGEX, $code, $matches)) { |
|
1079 | + $file = str_replace(WP_ROOT_DIR, '/', $file); |
|
1080 | 1080 | /** |
1081 | 1081 | * Rollback as per https://github.com/futtta/autoptimize/issues/94 |
1082 | 1082 | * $file = str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', $file ); |
1083 | 1083 | */ |
1084 | - $dir = dirname( $file ); // Like /themes/expound/css. |
|
1084 | + $dir = dirname($file); // Like /themes/expound/css. |
|
1085 | 1085 | |
1086 | 1086 | /** |
1087 | 1087 | * $dir should not contain backslashes, since it's used to replace |
1088 | 1088 | * urls, but it can contain them when running on Windows because |
1089 | 1089 | * fixurls() is sometimes called with `ABSPATH . 'index.php'` |
1090 | 1090 | */ |
1091 | - $dir = str_replace( '\\', '/', $dir ); |
|
1092 | - unset( $file ); // not used below at all. |
|
1091 | + $dir = str_replace('\\', '/', $dir); |
|
1092 | + unset($file); // not used below at all. |
|
1093 | 1093 | |
1094 | 1094 | $replace = array(); |
1095 | - foreach ( $matches[1] as $k => $url ) { |
|
1095 | + foreach ($matches[1] as $k => $url) { |
|
1096 | 1096 | // Remove quotes. |
1097 | - $url = trim( $url, " \t\n\r\0\x0B\"'" ); |
|
1098 | - $no_q_url = trim( $url, "\"'" ); |
|
1099 | - if ( $url !== $no_q_url ) { |
|
1097 | + $url = trim($url, " \t\n\r\0\x0B\"'"); |
|
1098 | + $no_q_url = trim($url, "\"'"); |
|
1099 | + if ($url !== $no_q_url) { |
|
1100 | 1100 | $removed_quotes = true; |
1101 | 1101 | } else { |
1102 | 1102 | $removed_quotes = false; |
1103 | 1103 | } |
1104 | 1104 | |
1105 | - if ( '' === $no_q_url ) { |
|
1105 | + if ('' === $no_q_url) { |
|
1106 | 1106 | continue; |
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | $url = $no_q_url; |
1110 | - if ( '/' === $url[0] || preg_match( '#^(https?://|ftp://|data:)#i', $url ) ) { |
|
1110 | + if ('/' === $url[0] || preg_match('#^(https?://|ftp://|data:)#i', $url)) { |
|
1111 | 1111 | // URL is protocol-relative, host-relative or something we don't touch. |
1112 | 1112 | continue; |
1113 | 1113 | } else { // Relative URL. |
@@ -1116,49 +1116,49 @@ discard block |
||
1116 | 1116 | * rollback as per https://github.com/futtta/autoptimize/issues/94 |
1117 | 1117 | * $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_CONTENT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
1118 | 1118 | */ |
1119 | - $newurl = preg_replace( '/https?:/', '', str_replace( ' ', '%20', AUTOPTIMIZE_WP_ROOT_URL . str_replace( '//', '/', $dir . '/' . $url ) ) ); |
|
1120 | - $newurl = apply_filters( 'autoptimize_filter_css_fixurl_newurl', $newurl ); |
|
1119 | + $newurl = preg_replace('/https?:/', '', str_replace(' ', '%20', AUTOPTIMIZE_WP_ROOT_URL.str_replace('//', '/', $dir.'/'.$url))); |
|
1120 | + $newurl = apply_filters('autoptimize_filter_css_fixurl_newurl', $newurl); |
|
1121 | 1121 | |
1122 | 1122 | /** |
1123 | 1123 | * Hash the url + whatever was behind potentially for replacement |
1124 | 1124 | * We must do this, or different css classes referencing the same bg image (but |
1125 | 1125 | * different parts of it, say, in sprites and such) loose their stuff... |
1126 | 1126 | */ |
1127 | - $hash = md5( $url . $matches[2][ $k ] ); |
|
1128 | - $code = str_replace( $matches[0][ $k ], $hash, $code ); |
|
1127 | + $hash = md5($url.$matches[2][$k]); |
|
1128 | + $code = str_replace($matches[0][$k], $hash, $code); |
|
1129 | 1129 | |
1130 | - if ( $removed_quotes ) { |
|
1131 | - $replace[ $hash ] = "url('" . $newurl . "')" . $matches[2][ $k ]; |
|
1130 | + if ($removed_quotes) { |
|
1131 | + $replace[$hash] = "url('".$newurl."')".$matches[2][$k]; |
|
1132 | 1132 | } else { |
1133 | - $replace[ $hash ] = 'url(' . $newurl . ')' . $matches[2][ $k ]; |
|
1133 | + $replace[$hash] = 'url('.$newurl.')'.$matches[2][$k]; |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - $code = self::replace_longest_matches_first( $code, $replace ); |
|
1138 | + $code = self::replace_longest_matches_first($code, $replace); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | return $code; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - private function ismovable( $tag ) |
|
1144 | + private function ismovable($tag) |
|
1145 | 1145 | { |
1146 | - if ( ! $this->aggregate ) { |
|
1146 | + if (!$this->aggregate) { |
|
1147 | 1147 | return false; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - if ( ! empty( $this->allowlist ) ) { |
|
1151 | - foreach ( $this->allowlist as $match ) { |
|
1152 | - if ( false !== strpos( $tag, $match ) ) { |
|
1150 | + if (!empty($this->allowlist)) { |
|
1151 | + foreach ($this->allowlist as $match) { |
|
1152 | + if (false !== strpos($tag, $match)) { |
|
1153 | 1153 | return true; |
1154 | 1154 | } |
1155 | 1155 | } |
1156 | 1156 | // no match with allowlist. |
1157 | 1157 | return false; |
1158 | 1158 | } else { |
1159 | - if ( is_array( $this->dontmove ) && ! empty( $this->dontmove ) ) { |
|
1160 | - foreach ( $this->dontmove as $match ) { |
|
1161 | - if ( false !== strpos( $tag, $match ) ) { |
|
1159 | + if (is_array($this->dontmove) && !empty($this->dontmove)) { |
|
1160 | + foreach ($this->dontmove as $match) { |
|
1161 | + if (false !== strpos($tag, $match)) { |
|
1162 | 1162 | // Matched something. |
1163 | 1163 | return false; |
1164 | 1164 | } |
@@ -1170,22 +1170,22 @@ discard block |
||
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - private function can_inject_late( $css_path, $css ) |
|
1173 | + private function can_inject_late($css_path, $css) |
|
1174 | 1174 | { |
1175 | - $consider_minified_array = apply_filters( 'autoptimize_filter_css_consider_minified', false, $css_path ); |
|
1176 | - if ( true !== $this->inject_min_late ) { |
|
1175 | + $consider_minified_array = apply_filters('autoptimize_filter_css_consider_minified', false, $css_path); |
|
1176 | + if (true !== $this->inject_min_late) { |
|
1177 | 1177 | // late-inject turned off. |
1178 | 1178 | return false; |
1179 | - } elseif ( ( false === strpos( $css_path, 'min.css' ) ) && ( str_replace( $consider_minified_array, '', $css_path ) === $css_path ) ) { |
|
1179 | + } elseif ((false === strpos($css_path, 'min.css')) && (str_replace($consider_minified_array, '', $css_path) === $css_path)) { |
|
1180 | 1180 | // file not minified based on filename & filter. |
1181 | 1181 | return false; |
1182 | - } elseif ( false !== strpos( $css, '@import' ) ) { |
|
1182 | + } elseif (false !== strpos($css, '@import')) { |
|
1183 | 1183 | // can't late-inject files with imports as those need to be aggregated. |
1184 | 1184 | return false; |
1185 | - } elseif ( ( false !== strpos( $css, '@font-face' ) ) && ( apply_filters( 'autoptimize_filter_css_fonts_cdn', false ) === true ) && ( ! empty( $this->cdn_url ) ) ) { |
|
1185 | + } elseif ((false !== strpos($css, '@font-face')) && (apply_filters('autoptimize_filter_css_fonts_cdn', false) === true) && (!empty($this->cdn_url))) { |
|
1186 | 1186 | // don't late-inject CSS with font-src's if fonts are set to be CDN'ed. |
1187 | 1187 | return false; |
1188 | - } elseif ( ( ( true == $this->datauris ) || ( ! empty( $this->cdn_url ) ) ) && preg_match( '#background[^;}]*url\(#Ui', $css ) ) { |
|
1188 | + } elseif (((true == $this->datauris) || (!empty($this->cdn_url))) && preg_match('#background[^;}]*url\(#Ui', $css)) { |
|
1189 | 1189 | // don't late-inject CSS with images if CDN is set OR if image inlining is on. |
1190 | 1190 | return false; |
1191 | 1191 | } else { |
@@ -1203,44 +1203,44 @@ discard block |
||
1203 | 1203 | * |
1204 | 1204 | * @return bool|string Url pointing to the minified css file or false. |
1205 | 1205 | */ |
1206 | - public function minify_single( $filepath, $cache_miss = false ) |
|
1206 | + public function minify_single($filepath, $cache_miss = false) |
|
1207 | 1207 | { |
1208 | - $contents = $this->prepare_minify_single( $filepath ); |
|
1208 | + $contents = $this->prepare_minify_single($filepath); |
|
1209 | 1209 | |
1210 | - if ( empty( $contents ) ) { |
|
1210 | + if (empty($contents)) { |
|
1211 | 1211 | return false; |
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Check cache. |
1215 | - $hash = 'single_' . md5( $contents ); |
|
1216 | - $cache = new autoptimizeCache( $hash, 'css' ); |
|
1217 | - do_action( 'autoptimize_action_css_hash', $hash ); |
|
1215 | + $hash = 'single_'.md5($contents); |
|
1216 | + $cache = new autoptimizeCache($hash, 'css'); |
|
1217 | + do_action('autoptimize_action_css_hash', $hash); |
|
1218 | 1218 | |
1219 | 1219 | // If not in cache already, minify... |
1220 | - if ( ! $cache->check() || $cache_miss ) { |
|
1220 | + if (!$cache->check() || $cache_miss) { |
|
1221 | 1221 | // Fixurls... |
1222 | - $contents = self::fixurls( $filepath, $contents ); |
|
1222 | + $contents = self::fixurls($filepath, $contents); |
|
1223 | 1223 | // CDN-replace any referenced assets if needed... |
1224 | - $contents = $this->hide_fontface_and_maybe_cdn( $contents ); |
|
1225 | - $contents = $this->replace_urls( $contents ); |
|
1226 | - $contents = $this->restore_fontface( $contents ); |
|
1224 | + $contents = $this->hide_fontface_and_maybe_cdn($contents); |
|
1225 | + $contents = $this->replace_urls($contents); |
|
1226 | + $contents = $this->restore_fontface($contents); |
|
1227 | 1227 | // Now minify... |
1228 | 1228 | $cssmin = new autoptimizeCSSmin(); |
1229 | - $contents = trim( $cssmin->run( $contents ) ); |
|
1229 | + $contents = trim($cssmin->run($contents)); |
|
1230 | 1230 | |
1231 | 1231 | // Check if minified cache content is empty. |
1232 | - if ( empty( $contents ) ) { |
|
1232 | + if (empty($contents)) { |
|
1233 | 1233 | return false; |
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | // Filter contents of excluded minified CSS. |
1237 | - $contents = apply_filters( 'autoptimize_filter_css_single_after_minify', $contents ); |
|
1237 | + $contents = apply_filters('autoptimize_filter_css_single_after_minify', $contents); |
|
1238 | 1238 | |
1239 | 1239 | // Store in cache. |
1240 | - $cache->cache( $contents, 'text/css' ); |
|
1240 | + $cache->cache($contents, 'text/css'); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | - $url = $this->build_minify_single_url( $cache ); |
|
1243 | + $url = $this->build_minify_single_url($cache); |
|
1244 | 1244 | |
1245 | 1245 | return $url; |
1246 | 1246 | } |
@@ -1260,19 +1260,19 @@ discard block |
||
1260 | 1260 | return $this->options; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - public function replaceOptions( $options ) |
|
1263 | + public function replaceOptions($options) |
|
1264 | 1264 | { |
1265 | 1265 | $this->options = $options; |
1266 | 1266 | } |
1267 | 1267 | |
1268 | - public function setOption( $name, $value ) |
|
1268 | + public function setOption($name, $value) |
|
1269 | 1269 | { |
1270 | - $this->options[ $name ] = $value; |
|
1270 | + $this->options[$name] = $value; |
|
1271 | 1271 | $this->$name = $value; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - public function getOption( $name ) |
|
1274 | + public function getOption($name) |
|
1275 | 1275 | { |
1276 | - return $this->options[ $name ]; |
|
1276 | + return $this->options[$name]; |
|
1277 | 1277 | } |
1278 | 1278 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param string $version Version. |
34 | 34 | * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks. |
35 | 35 | */ |
36 | - public function __construct( $version, $filepath ) |
|
36 | + public function __construct($version, $filepath) |
|
37 | 37 | { |
38 | 38 | $this->version = $version; |
39 | 39 | $this->filepath = $filepath; |
@@ -50,102 +50,102 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function add_hooks() |
52 | 52 | { |
53 | - if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) { |
|
54 | - define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' ); |
|
53 | + if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) { |
|
54 | + define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded'); |
|
55 | 55 | } |
56 | 56 | |
57 | - add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) ); |
|
58 | - add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) ); |
|
57 | + add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup')); |
|
58 | + add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge')); |
|
59 | 59 | |
60 | - add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) ); |
|
61 | - add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) ); |
|
62 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ), 15 ); |
|
63 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ), 20 ); |
|
64 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss' ), 11 ); |
|
65 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_notfound_fallback' ), 10 ); |
|
60 | + add_action('autoptimize_setup_done', array($this, 'version_upgrades_check')); |
|
61 | + add_action('autoptimize_setup_done', array($this, 'check_cache_and_run')); |
|
62 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'), 15); |
|
63 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'), 20); |
|
64 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_criticalcss'), 11); |
|
65 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_notfound_fallback'), 10); |
|
66 | 66 | |
67 | - add_action( 'init', array( $this, 'load_textdomain' ) ); |
|
68 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); |
|
67 | + add_action('init', array($this, 'load_textdomain')); |
|
68 | + add_action('admin_init', array('PAnD', 'init')); |
|
69 | 69 | |
70 | - if ( is_multisite() && is_admin() ) { |
|
70 | + if (is_multisite() && is_admin()) { |
|
71 | 71 | // Only if multisite and if in admin we want to check if we need to save options on network level. |
72 | - add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' ); |
|
72 | + add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // register uninstall & deactivation hooks. |
76 | - register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' ); |
|
77 | - register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' ); |
|
76 | + register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall'); |
|
77 | + register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function load_textdomain() |
81 | 81 | { |
82 | - load_plugin_textdomain( 'autoptimize' ); |
|
82 | + load_plugin_textdomain('autoptimize'); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | public function setup() |
86 | 86 | { |
87 | 87 | // Do we gzip in php when caching or is the webserver doing it? |
88 | - define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) ); |
|
88 | + define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip')); |
|
89 | 89 | |
90 | 90 | // These can be overridden by specifying them in wp-config.php or such. |
91 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) { |
|
92 | - define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) ); |
|
91 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { |
|
92 | + define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); |
|
93 | 93 | } |
94 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) { |
|
95 | - define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' ); |
|
94 | + if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { |
|
95 | + define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); |
|
96 | 96 | } |
97 | - if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) { |
|
98 | - define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' ); |
|
97 | + if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { |
|
98 | + define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); |
|
99 | 99 | } |
100 | 100 | // Note: trailing slash is not optional! |
101 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
102 | - define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() ); |
|
101 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
102 | + define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname()); |
|
103 | 103 | } |
104 | 104 | |
105 | - define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) ); |
|
105 | + define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
106 | 106 | |
107 | - if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) { |
|
108 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
109 | - define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) ); |
|
107 | + if (!defined('AUTOPTIMIZE_WP_SITE_URL')) { |
|
108 | + if (function_exists('domain_mapping_siteurl')) { |
|
109 | + define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id())); |
|
110 | 110 | } else { |
111 | - define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() ); |
|
111 | + define('AUTOPTIMIZE_WP_SITE_URL', site_url()); |
|
112 | 112 | } |
113 | 113 | } |
114 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) { |
|
115 | - if ( function_exists( 'get_original_url' ) ) { |
|
116 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) ); |
|
114 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) { |
|
115 | + if (function_exists('get_original_url')) { |
|
116 | + define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url())); |
|
117 | 117 | } else { |
118 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() ); |
|
118 | + define('AUTOPTIMIZE_WP_CONTENT_URL', content_url()); |
|
119 | 119 | } |
120 | 120 | } |
121 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) { |
|
122 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
121 | + if (!defined('AUTOPTIMIZE_CACHE_URL')) { |
|
122 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
123 | 123 | $blog_id = get_current_blog_id(); |
124 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' ); |
|
124 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
125 | 125 | } else { |
126 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR ); |
|
126 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
127 | 127 | } |
128 | 128 | } |
129 | - if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) { |
|
130 | - define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) ); |
|
129 | + if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) { |
|
130 | + define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL)); |
|
131 | 131 | } |
132 | - if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) { |
|
133 | - define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) ); |
|
132 | + if (!defined('AUTOPTIMIZE_HASH')) { |
|
133 | + define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL)); |
|
134 | 134 | } |
135 | - if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) { |
|
136 | - define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ); |
|
135 | + if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) { |
|
136 | + define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | // Multibyte-capable string replacements are available with a filter. |
140 | 140 | // Also requires 'mbstring' extension. |
141 | - $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false ); |
|
142 | - if ( $with_mbstring ) { |
|
143 | - autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) ); |
|
141 | + $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false); |
|
142 | + if ($with_mbstring) { |
|
143 | + autoptimizeUtils::mbstring_available(\extension_loaded('mbstring')); |
|
144 | 144 | } else { |
145 | - autoptimizeUtils::mbstring_available( false ); |
|
145 | + autoptimizeUtils::mbstring_available(false); |
|
146 | 146 | } |
147 | 147 | |
148 | - do_action( 'autoptimize_setup_done' ); |
|
148 | + do_action('autoptimize_setup_done'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -155,61 +155,61 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function version_upgrades_check() |
157 | 157 | { |
158 | - autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version ); |
|
158 | + autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | public function check_cache_and_run() |
162 | 162 | { |
163 | - if ( autoptimizeCache::cacheavail() ) { |
|
163 | + if (autoptimizeCache::cacheavail()) { |
|
164 | 164 | $conf = autoptimizeConfig::instance(); |
165 | - if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) { |
|
166 | - if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) { |
|
165 | + if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) { |
|
166 | + if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) { |
|
167 | 167 | // Hook into WordPress frontend. |
168 | - if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) { |
|
168 | + if (defined('AUTOPTIMIZE_INIT_EARLIER')) { |
|
169 | 169 | add_action( |
170 | 170 | 'init', |
171 | - array( $this, 'start_buffering' ), |
|
171 | + array($this, 'start_buffering'), |
|
172 | 172 | self::INIT_EARLIER_PRIORITY |
173 | 173 | ); |
174 | 174 | } else { |
175 | - if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) { |
|
176 | - define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' ); |
|
175 | + if (!defined('AUTOPTIMIZE_HOOK_INTO')) { |
|
176 | + define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); |
|
177 | 177 | } |
178 | 178 | add_action( |
179 | - constant( 'AUTOPTIMIZE_HOOK_INTO' ), |
|
180 | - array( $this, 'start_buffering' ), |
|
179 | + constant('AUTOPTIMIZE_HOOK_INTO'), |
|
180 | + array($this, 'start_buffering'), |
|
181 | 181 | self::DEFAULT_HOOK_PRIORITY |
182 | 182 | ); |
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | 186 | // And disable Jetpack's site accelerator if JS or CSS opt. are active. |
187 | - if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) { |
|
188 | - add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' ); |
|
187 | + if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) { |
|
188 | + add_filter('jetpack_force_disable_site_accelerator', '__return_true'); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } else { |
192 | - add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' ); |
|
192 | + add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable'); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | 196 | public function maybe_run_ao_extra() |
197 | 197 | { |
198 | - if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) { |
|
198 | + if (apply_filters('autoptimize_filter_extra_activate', true)) { |
|
199 | 199 | $ao_imgopt = new autoptimizeImages(); |
200 | 200 | $ao_imgopt->run(); |
201 | 201 | $ao_extra = new autoptimizeExtra(); |
202 | 202 | $ao_extra->run(); |
203 | 203 | |
204 | 204 | // And show the imgopt notice. |
205 | - add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' ); |
|
205 | + add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt'); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | 209 | public function maybe_run_partners_tab() |
210 | 210 | { |
211 | 211 | // Loads partners tab code if in admin (and not in admin-ajax.php)! |
212 | - if ( autoptimizeConfig::is_admin_and_not_ajax() ) { |
|
212 | + if (autoptimizeConfig::is_admin_and_not_ajax()) { |
|
213 | 213 | new autoptimizePartners(); |
214 | 214 | } |
215 | 215 | } |
@@ -217,22 +217,22 @@ discard block |
||
217 | 217 | public function maybe_run_criticalcss() |
218 | 218 | { |
219 | 219 | // Loads criticalcss if the power-up is not active and if the filter returns true. |
220 | - if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { |
|
220 | + if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { |
|
221 | 221 | new autoptimizeCriticalCSSBase(); |
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
225 | 225 | public function maybe_run_notfound_fallback() |
226 | 226 | { |
227 | - if ( autoptimizeCache::do_fallback() ) { |
|
228 | - add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) ); |
|
227 | + if (autoptimizeCache::do_fallback()) { |
|
228 | + add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback')); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | public function hook_page_cache_purge() |
233 | 233 | { |
234 | 234 | // hook into a collection of page cache purge actions if filter allows. |
235 | - if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) { |
|
235 | + if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) { |
|
236 | 236 | $page_cache_purge_actions = array( |
237 | 237 | 'after_rocket_clean_domain', // exists. |
238 | 238 | 'hyper_cache_purged', // Stefano confirmed this will be added. |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | 'wpo_cache_flush', // wp-optimize. |
248 | 248 | 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper. |
249 | 249 | ); |
250 | - $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions ); |
|
251 | - foreach ( $page_cache_purge_actions as $purge_action ) { |
|
252 | - add_action( $purge_action, 'autoptimizeCache::clearall_actionless' ); |
|
250 | + $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions); |
|
251 | + foreach ($page_cache_purge_actions as $purge_action) { |
|
252 | + add_action($purge_action, 'autoptimizeCache::clearall_actionless'); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | } |
@@ -261,38 +261,38 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function start_buffering() |
263 | 263 | { |
264 | - if ( $this->should_buffer() ) { |
|
264 | + if ($this->should_buffer()) { |
|
265 | 265 | |
266 | 266 | // Load speedupper conditionally (true by default). |
267 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
267 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
268 | 268 | $ao_speedupper = new autoptimizeSpeedupper(); |
269 | 269 | } |
270 | 270 | |
271 | 271 | $conf = autoptimizeConfig::instance(); |
272 | 272 | |
273 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
274 | - if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) { |
|
275 | - define( 'CONCATENATE_SCRIPTS', false ); |
|
273 | + if ($conf->get('autoptimize_js')) { |
|
274 | + if (!defined('CONCATENATE_SCRIPTS')) { |
|
275 | + define('CONCATENATE_SCRIPTS', false); |
|
276 | 276 | } |
277 | - if ( ! defined( 'COMPRESS_SCRIPTS' ) ) { |
|
278 | - define( 'COMPRESS_SCRIPTS', false ); |
|
277 | + if (!defined('COMPRESS_SCRIPTS')) { |
|
278 | + define('COMPRESS_SCRIPTS', false); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
283 | - if ( ! defined( 'COMPRESS_CSS' ) ) { |
|
284 | - define( 'COMPRESS_CSS', false ); |
|
282 | + if ($conf->get('autoptimize_css')) { |
|
283 | + if (!defined('COMPRESS_CSS')) { |
|
284 | + define('COMPRESS_CSS', false); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
288 | - if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) { |
|
289 | - while ( ob_get_level() > 0 ) { |
|
288 | + if (apply_filters('autoptimize_filter_obkiller', false)) { |
|
289 | + while (ob_get_level() > 0) { |
|
290 | 290 | ob_end_clean(); |
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | 294 | // Now, start the real thing! |
295 | - ob_start( array( $this, 'end_buffering' ) ); |
|
295 | + ob_start(array($this, 'end_buffering')); |
|
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
@@ -303,31 +303,31 @@ discard block |
||
303 | 303 | * deciding once per request (for use in tests). |
304 | 304 | * @return bool |
305 | 305 | */ |
306 | - public static function should_buffer( $doing_tests = false ) |
|
306 | + public static function should_buffer($doing_tests = false) |
|
307 | 307 | { |
308 | 308 | static $do_buffering = null; |
309 | 309 | |
310 | 310 | // Only check once in case we're called multiple times by others but |
311 | 311 | // still allows multiple calls when doing tests. |
312 | - if ( null === $do_buffering || $doing_tests ) { |
|
312 | + if (null === $do_buffering || $doing_tests) { |
|
313 | 313 | |
314 | 314 | $ao_noptimize = false; |
315 | 315 | |
316 | 316 | // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS. |
317 | - if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) { |
|
317 | + if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) { |
|
318 | 318 | $ao_noptimize = true; |
319 | 319 | } |
320 | 320 | |
321 | 321 | // Skip checking query strings if they're disabled. |
322 | - if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) { |
|
322 | + if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) { |
|
323 | 323 | // Check for `ao_noptimize` (and other) keys in the query string |
324 | 324 | // to get non-optimized page for debugging. |
325 | 325 | $keys = array( |
326 | 326 | 'ao_noptimize', |
327 | 327 | 'ao_noptirocket', |
328 | 328 | ); |
329 | - foreach ( $keys as $key ) { |
|
330 | - if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) { |
|
329 | + foreach ($keys as $key) { |
|
330 | + if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) { |
|
331 | 331 | $ao_noptimize = true; |
332 | 332 | break; |
333 | 333 | } |
@@ -335,15 +335,15 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // If setting says not to optimize logged in user and user is logged in... |
338 | - if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { |
|
338 | + if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) { |
|
339 | 339 | $ao_noptimize = true; |
340 | 340 | } |
341 | 341 | |
342 | 342 | // If setting says not to optimize cart/checkout. |
343 | - if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) { |
|
343 | + if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) { |
|
344 | 344 | // Checking for woocommerce, easy digital downloads and wp ecommerce... |
345 | - foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { |
|
346 | - if ( function_exists( $func ) && $func() ) { |
|
345 | + foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) { |
|
346 | + if (function_exists($func) && $func()) { |
|
347 | 347 | $ao_noptimize = true; |
348 | 348 | break; |
349 | 349 | } |
@@ -351,10 +351,10 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ... |
354 | - if ( false === $ao_noptimize ) { |
|
355 | - $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' ); |
|
356 | - foreach ( $_qs_pagebuilders as $_pagebuilder ) { |
|
357 | - if ( array_key_exists( $_pagebuilder, $_GET ) ) { |
|
354 | + if (false === $ao_noptimize) { |
|
355 | + $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor'); |
|
356 | + foreach ($_qs_pagebuilders as $_pagebuilder) { |
|
357 | + if (array_key_exists($_pagebuilder, $_GET)) { |
|
358 | 358 | $ao_noptimize = true; |
359 | 359 | break; |
360 | 360 | } |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | |
364 | 364 | // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders, |
365 | 365 | // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that. |
366 | - if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) { |
|
366 | + if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) { |
|
367 | 367 | $ao_noptimize = true; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // And finally allows blocking of autoptimization on your own terms regardless of above decisions. |
371 | - $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
|
371 | + $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize); |
|
372 | 372 | |
373 | 373 | // Check for site being previewed in the Customizer (available since WP 4.0). |
374 | 374 | $is_customize_preview = false; |
375 | - if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) { |
|
375 | + if (function_exists('is_customize_preview') && is_customize_preview()) { |
|
376 | 376 | $is_customize_preview = is_customize_preview(); |
377 | 377 | } |
378 | 378 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * while the main query hasn't been ran yet. Thats why we use |
384 | 384 | * AUTOPTIMIZE_INIT_EARLIER in tests. |
385 | 385 | */ |
386 | - $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview ); |
|
386 | + $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | return $do_buffering; |
@@ -396,25 +396,25 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @return bool |
398 | 398 | */ |
399 | - public function is_valid_buffer( $content ) |
|
399 | + public function is_valid_buffer($content) |
|
400 | 400 | { |
401 | 401 | // Defaults to true. |
402 | 402 | $valid = true; |
403 | 403 | |
404 | - $has_no_html_tag = ( false === stripos( $content, '<html' ) ); |
|
405 | - $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) ); |
|
406 | - $has_html5_doctype = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 ); |
|
407 | - $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) ); |
|
404 | + $has_no_html_tag = (false === stripos($content, '<html')); |
|
405 | + $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet')); |
|
406 | + $has_html5_doctype = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0); |
|
407 | + $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->')); |
|
408 | 408 | |
409 | - if ( $has_no_html_tag ) { |
|
409 | + if ($has_no_html_tag) { |
|
410 | 410 | // Can't be valid amp markup without an html tag preceding it. |
411 | 411 | $is_amp_markup = false; |
412 | 412 | } else { |
413 | - $is_amp_markup = self::is_amp_markup( $content ); |
|
413 | + $is_amp_markup = self::is_amp_markup($content); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it. |
417 | - if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) { |
|
417 | + if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) { |
|
418 | 418 | $valid = false; |
419 | 419 | } |
420 | 420 | |
@@ -429,14 +429,14 @@ discard block |
||
429 | 429 | * |
430 | 430 | * @return bool |
431 | 431 | */ |
432 | - public static function is_amp_markup( $content ) |
|
432 | + public static function is_amp_markup($content) |
|
433 | 433 | { |
434 | 434 | // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page. |
435 | - if ( function_exists( 'is_amp_endpoint' ) ) { |
|
435 | + if (function_exists('is_amp_endpoint')) { |
|
436 | 436 | return is_amp_endpoint(); |
437 | 437 | } |
438 | 438 | |
439 | - $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content ); |
|
439 | + $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content); |
|
440 | 440 | |
441 | 441 | return (bool) $is_amp_markup; |
442 | 442 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @return string |
451 | 451 | */ |
452 | - public function end_buffering( $content ) |
|
452 | + public function end_buffering($content) |
|
453 | 453 | { |
454 | 454 | // Bail early without modifying anything if we can't handle the content. |
455 | - if ( ! $this->is_valid_buffer( $content ) ) { |
|
455 | + if (!$this->is_valid_buffer($content)) { |
|
456 | 456 | return $content; |
457 | 457 | } |
458 | 458 | |
@@ -460,73 +460,73 @@ discard block |
||
460 | 460 | |
461 | 461 | // Determine what needs to be ran. |
462 | 462 | $classes = array(); |
463 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
463 | + if ($conf->get('autoptimize_js')) { |
|
464 | 464 | $classes[] = 'autoptimizeScripts'; |
465 | 465 | } |
466 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
466 | + if ($conf->get('autoptimize_css')) { |
|
467 | 467 | $classes[] = 'autoptimizeStyles'; |
468 | 468 | } |
469 | - if ( $conf->get( 'autoptimize_html' ) ) { |
|
469 | + if ($conf->get('autoptimize_html')) { |
|
470 | 470 | $classes[] = 'autoptimizeHTML'; |
471 | 471 | } |
472 | 472 | |
473 | 473 | $classoptions = array( |
474 | 474 | 'autoptimizeScripts' => array( |
475 | - 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), |
|
476 | - 'justhead' => $conf->get( 'autoptimize_js_justhead' ), |
|
477 | - 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), |
|
478 | - 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), |
|
479 | - 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), |
|
480 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
481 | - 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), |
|
482 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), |
|
475 | + 'aggregate' => $conf->get('autoptimize_js_aggregate'), |
|
476 | + 'justhead' => $conf->get('autoptimize_js_justhead'), |
|
477 | + 'forcehead' => $conf->get('autoptimize_js_forcehead'), |
|
478 | + 'trycatch' => $conf->get('autoptimize_js_trycatch'), |
|
479 | + 'js_exclude' => $conf->get('autoptimize_js_exclude'), |
|
480 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
481 | + 'include_inline' => $conf->get('autoptimize_js_include_inline'), |
|
482 | + 'minify_excluded' => $conf->get('autoptimize_minify_excluded'), |
|
483 | 483 | ), |
484 | 484 | 'autoptimizeStyles' => array( |
485 | - 'aggregate' => $conf->get( 'autoptimize_css_aggregate' ), |
|
486 | - 'justhead' => $conf->get( 'autoptimize_css_justhead' ), |
|
487 | - 'datauris' => $conf->get( 'autoptimize_css_datauris' ), |
|
488 | - 'defer' => $conf->get( 'autoptimize_css_defer' ), |
|
489 | - 'defer_inline' => $conf->get( 'autoptimize_css_defer_inline' ), |
|
490 | - 'inline' => $conf->get( 'autoptimize_css_inline' ), |
|
491 | - 'css_exclude' => $conf->get( 'autoptimize_css_exclude' ), |
|
492 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
493 | - 'include_inline' => $conf->get( 'autoptimize_css_include_inline' ), |
|
494 | - 'nogooglefont' => $conf->get( 'autoptimize_css_nogooglefont' ), |
|
495 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), |
|
485 | + 'aggregate' => $conf->get('autoptimize_css_aggregate'), |
|
486 | + 'justhead' => $conf->get('autoptimize_css_justhead'), |
|
487 | + 'datauris' => $conf->get('autoptimize_css_datauris'), |
|
488 | + 'defer' => $conf->get('autoptimize_css_defer'), |
|
489 | + 'defer_inline' => $conf->get('autoptimize_css_defer_inline'), |
|
490 | + 'inline' => $conf->get('autoptimize_css_inline'), |
|
491 | + 'css_exclude' => $conf->get('autoptimize_css_exclude'), |
|
492 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
493 | + 'include_inline' => $conf->get('autoptimize_css_include_inline'), |
|
494 | + 'nogooglefont' => $conf->get('autoptimize_css_nogooglefont'), |
|
495 | + 'minify_excluded' => $conf->get('autoptimize_minify_excluded'), |
|
496 | 496 | ), |
497 | 497 | 'autoptimizeHTML' => array( |
498 | - 'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ), |
|
498 | + 'keepcomments' => $conf->get('autoptimize_html_keepcomments'), |
|
499 | 499 | ), |
500 | 500 | ); |
501 | 501 | |
502 | - $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); |
|
502 | + $content = apply_filters('autoptimize_filter_html_before_minify', $content); |
|
503 | 503 | |
504 | 504 | // Run the classes! |
505 | - foreach ( $classes as $name ) { |
|
506 | - $instance = new $name( $content ); |
|
507 | - if ( $instance->read( $classoptions[ $name ] ) ) { |
|
505 | + foreach ($classes as $name) { |
|
506 | + $instance = new $name($content); |
|
507 | + if ($instance->read($classoptions[$name])) { |
|
508 | 508 | $instance->minify(); |
509 | 509 | $instance->cache(); |
510 | 510 | $content = $instance->getcontent(); |
511 | 511 | } |
512 | - unset( $instance ); |
|
512 | + unset($instance); |
|
513 | 513 | } |
514 | 514 | |
515 | - $content = apply_filters( 'autoptimize_html_after_minify', $content ); |
|
515 | + $content = apply_filters('autoptimize_html_after_minify', $content); |
|
516 | 516 | |
517 | 517 | return $content; |
518 | 518 | } |
519 | 519 | |
520 | - public static function autoptimize_nobuffer_optimize( $html_in ) { |
|
520 | + public static function autoptimize_nobuffer_optimize($html_in) { |
|
521 | 521 | $html_out = $html_in; |
522 | 522 | |
523 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
523 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
524 | 524 | $ao_speedupper = new autoptimizeSpeedupper(); |
525 | 525 | } |
526 | 526 | |
527 | - $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
528 | - if ( $self->should_buffer() ) { |
|
529 | - $html_out = $self->end_buffering( $html_in ); |
|
527 | + $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
528 | + if ($self->should_buffer()) { |
|
529 | + $html_out = $self->end_buffering($html_in); |
|
530 | 530 | } |
531 | 531 | return $html_out; |
532 | 532 | } |
@@ -588,45 +588,45 @@ discard block |
||
588 | 588 | 'autoptimize_ccss_unloadccss', |
589 | 589 | ); |
590 | 590 | |
591 | - if ( ! is_multisite() ) { |
|
592 | - foreach ( $delete_options as $del_opt ) { |
|
593 | - delete_option( $del_opt ); |
|
591 | + if (!is_multisite()) { |
|
592 | + foreach ($delete_options as $del_opt) { |
|
593 | + delete_option($del_opt); |
|
594 | 594 | } |
595 | 595 | autoptimizeMain::remove_cronjobs(); |
596 | 596 | } else { |
597 | 597 | global $wpdb; |
598 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
598 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
599 | 599 | $original_blog_id = get_current_blog_id(); |
600 | - foreach ( $blog_ids as $blog_id ) { |
|
601 | - switch_to_blog( $blog_id ); |
|
602 | - foreach ( $delete_options as $del_opt ) { |
|
603 | - delete_option( $del_opt ); |
|
600 | + foreach ($blog_ids as $blog_id) { |
|
601 | + switch_to_blog($blog_id); |
|
602 | + foreach ($delete_options as $del_opt) { |
|
603 | + delete_option($del_opt); |
|
604 | 604 | } |
605 | 605 | autoptimizeMain::remove_cronjobs(); |
606 | 606 | } |
607 | - switch_to_blog( $original_blog_id ); |
|
607 | + switch_to_blog($original_blog_id); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | // Remove AO CCSS cached files and directory. |
611 | - $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/'; |
|
612 | - if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) { |
|
611 | + $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/'; |
|
612 | + if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) { |
|
613 | 613 | // fixme: should check for subdirs when in multisite and remove contents of those as well. |
614 | - array_map( 'unlink', glob( AO_CCSS_DIR . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) ); |
|
615 | - rmdir( AO_CCSS_DIR ); |
|
614 | + array_map('unlink', glob(AO_CCSS_DIR.'*.{css,html,json,log,zip,lock}', GLOB_BRACE)); |
|
615 | + rmdir(AO_CCSS_DIR); |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
619 | 619 | public static function on_deactivation() |
620 | 620 | { |
621 | - if ( is_multisite() && is_network_admin() ) { |
|
621 | + if (is_multisite() && is_network_admin()) { |
|
622 | 622 | global $wpdb; |
623 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
623 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
624 | 624 | $original_blog_id = get_current_blog_id(); |
625 | - foreach ( $blog_ids as $blog_id ) { |
|
626 | - switch_to_blog( $blog_id ); |
|
625 | + foreach ($blog_ids as $blog_id) { |
|
626 | + switch_to_blog($blog_id); |
|
627 | 627 | autoptimizeMain::remove_cronjobs(); |
628 | 628 | } |
629 | - switch_to_blog( $original_blog_id ); |
|
629 | + switch_to_blog($original_blog_id); |
|
630 | 630 | } else { |
631 | 631 | autoptimizeMain::remove_cronjobs(); |
632 | 632 | } |
@@ -635,9 +635,9 @@ discard block |
||
635 | 635 | |
636 | 636 | public static function remove_cronjobs() { |
637 | 637 | // Remove scheduled events. |
638 | - foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) { |
|
639 | - if ( wp_get_schedule( $_event ) ) { |
|
640 | - wp_clear_scheduled_hook( $_event ); |
|
638 | + foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) { |
|
639 | + if (wp_get_schedule($_event)) { |
|
640 | + wp_clear_scheduled_hook($_event); |
|
641 | 641 | } |
642 | 642 | } |
643 | 643 | } |
@@ -646,35 +646,35 @@ discard block |
||
646 | 646 | { |
647 | 647 | echo '<div class="error"><p>'; |
648 | 648 | // Translators: %s is the cache directory location. |
649 | - printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); |
|
649 | + printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR); |
|
650 | 650 | echo '</p></div>'; |
651 | 651 | } |
652 | 652 | |
653 | 653 | public static function notice_installed() |
654 | 654 | { |
655 | 655 | echo '<div class="updated"><p>'; |
656 | - _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); |
|
656 | + _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize'); |
|
657 | 657 | echo '</p></div>'; |
658 | 658 | } |
659 | 659 | |
660 | 660 | public static function notice_updated() |
661 | 661 | { |
662 | 662 | echo '<div class="updated"><p>'; |
663 | - _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' ); |
|
663 | + _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize'); |
|
664 | 664 | echo '</p></div>'; |
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function notice_plug_imgopt() |
668 | 668 | { |
669 | 669 | // Translators: the URL added points to the Autopmize Extra settings. |
670 | - $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' ); |
|
671 | - $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); |
|
670 | + $_ao_imgopt_plug_notice = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>'); |
|
671 | + $_ao_imgopt_plug_notice = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice); |
|
672 | 672 | $_ao_imgopt_launch_ok = autoptimizeImages::launch_ok_wrapper(); |
673 | 673 | $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; |
674 | 674 | $_ao_imgopt_active = autoptimizeImages::imgopt_active(); |
675 | 675 | |
676 | - if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { |
|
677 | - echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>'; |
|
676 | + if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) { |
|
677 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>'; |
|
678 | 678 | echo $_ao_imgopt_plug_notice; |
679 | 679 | echo '</p></div>'; |
680 | 680 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Class for JS optimization. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -198,128 +198,128 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @param array $options all options. |
200 | 200 | */ |
201 | - public function read( $options ) |
|
201 | + public function read($options) |
|
202 | 202 | { |
203 | - $noptimize_js = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content ); |
|
204 | - if ( $noptimize_js ) { |
|
203 | + $noptimize_js = apply_filters('autoptimize_filter_js_noptimize', false, $this->content); |
|
204 | + if ($noptimize_js) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // only optimize known good JS? |
209 | - $allowlist_js = apply_filters( 'autoptimize_filter_js_allowlist', '', $this->content ); |
|
210 | - $allowlist_js = apply_filters( 'autoptimize_filter_js_whitelist', $allowlist_js, $this->content ); // fixme: to be removed in next version. |
|
211 | - if ( ! empty( $allowlist_js ) ) { |
|
212 | - $this->allowlist = array_filter( array_map( 'trim', explode( ',', $allowlist_js ) ) ); |
|
209 | + $allowlist_js = apply_filters('autoptimize_filter_js_allowlist', '', $this->content); |
|
210 | + $allowlist_js = apply_filters('autoptimize_filter_js_whitelist', $allowlist_js, $this->content); // fixme: to be removed in next version. |
|
211 | + if (!empty($allowlist_js)) { |
|
212 | + $this->allowlist = array_filter(array_map('trim', explode(',', $allowlist_js))); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | // is there JS we should simply remove? |
216 | - $removable_js = apply_filters( 'autoptimize_filter_js_removables', '', $this->content ); |
|
217 | - if ( ! empty( $removable_js ) ) { |
|
218 | - $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removable_js ) ) ); |
|
216 | + $removable_js = apply_filters('autoptimize_filter_js_removables', '', $this->content); |
|
217 | + if (!empty($removable_js)) { |
|
218 | + $this->jsremovables = array_filter(array_map('trim', explode(',', $removable_js))); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | // only header? |
222 | - if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) { |
|
223 | - $content = explode( '</head>', $this->content, 2 ); |
|
224 | - $this->content = $content[0] . '</head>'; |
|
222 | + if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) { |
|
223 | + $content = explode('</head>', $this->content, 2); |
|
224 | + $this->content = $content[0].'</head>'; |
|
225 | 225 | $this->restofcontent = $content[1]; |
226 | 226 | } |
227 | 227 | |
228 | 228 | // Determine whether we're doing JS-files aggregation or not. |
229 | - if ( ! $options['aggregate'] ) { |
|
229 | + if (!$options['aggregate']) { |
|
230 | 230 | $this->aggregate = false; |
231 | 231 | } |
232 | 232 | // Returning true for "dontaggregate" turns off aggregation. |
233 | - if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) { |
|
233 | + if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) { |
|
234 | 234 | $this->aggregate = false; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // include inline? |
238 | - if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) { |
|
238 | + if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) { |
|
239 | 239 | $this->include_inline = true; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // filter to "late inject minified JS", default to true for now (it is faster). |
243 | - $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true ); |
|
243 | + $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true); |
|
244 | 244 | |
245 | 245 | // filters to override hardcoded do(nt)move(last) array contents (array in, array out!). |
246 | - $this->dontmove = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove ); |
|
247 | - $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast ); |
|
248 | - $this->domove = apply_filters( 'autoptimize_filter_js_domove', $this->domove ); |
|
246 | + $this->dontmove = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove); |
|
247 | + $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast); |
|
248 | + $this->domove = apply_filters('autoptimize_filter_js_domove', $this->domove); |
|
249 | 249 | |
250 | 250 | // Determine whether excluded files should be minified if not yet so. |
251 | - if ( ! $options['minify_excluded'] && $options['aggregate'] ) { |
|
251 | + if (!$options['minify_excluded'] && $options['aggregate']) { |
|
252 | 252 | $this->minify_excluded = false; |
253 | 253 | } |
254 | - $this->minify_excluded = apply_filters( 'autoptimize_filter_js_minify_excluded', $this->minify_excluded, '' ); |
|
254 | + $this->minify_excluded = apply_filters('autoptimize_filter_js_minify_excluded', $this->minify_excluded, ''); |
|
255 | 255 | |
256 | 256 | // get extra exclusions settings or filter. |
257 | 257 | $exclude_js = $options['js_exclude']; |
258 | - $exclude_js = apply_filters( 'autoptimize_filter_js_exclude', $exclude_js, $this->content ); |
|
259 | - |
|
260 | - if ( '' !== $exclude_js ) { |
|
261 | - if ( is_array( $exclude_js ) ) { |
|
262 | - $remove_keys = array_keys( $exclude_js, 'remove' ); |
|
263 | - if ( false !== $remove_keys ) { |
|
264 | - foreach ( $remove_keys as $remove_key ) { |
|
265 | - unset( $exclude_js[ $remove_key ] ); |
|
258 | + $exclude_js = apply_filters('autoptimize_filter_js_exclude', $exclude_js, $this->content); |
|
259 | + |
|
260 | + if ('' !== $exclude_js) { |
|
261 | + if (is_array($exclude_js)) { |
|
262 | + $remove_keys = array_keys($exclude_js, 'remove'); |
|
263 | + if (false !== $remove_keys) { |
|
264 | + foreach ($remove_keys as $remove_key) { |
|
265 | + unset($exclude_js[$remove_key]); |
|
266 | 266 | $this->jsremovables[] = $remove_key; |
267 | 267 | } |
268 | 268 | } |
269 | - $excl_js_arr = array_keys( $exclude_js ); |
|
269 | + $excl_js_arr = array_keys($exclude_js); |
|
270 | 270 | } else { |
271 | - $excl_js_arr = array_filter( array_map( 'trim', explode( ',', $exclude_js ) ) ); |
|
271 | + $excl_js_arr = array_filter(array_map('trim', explode(',', $exclude_js))); |
|
272 | 272 | } |
273 | - $this->dontmove = array_merge( $excl_js_arr, $this->dontmove ); |
|
273 | + $this->dontmove = array_merge($excl_js_arr, $this->dontmove); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | // Should we add try-catch? |
277 | - if ( $options['trycatch'] ) { |
|
277 | + if ($options['trycatch']) { |
|
278 | 278 | $this->trycatch = true; |
279 | 279 | } |
280 | 280 | |
281 | 281 | // force js in head? |
282 | - if ( $options['forcehead'] ) { |
|
282 | + if ($options['forcehead']) { |
|
283 | 283 | $this->forcehead = true; |
284 | 284 | } else { |
285 | 285 | $this->forcehead = false; |
286 | 286 | } |
287 | 287 | |
288 | - $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead ); |
|
288 | + $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead); |
|
289 | 289 | |
290 | 290 | // get cdn url. |
291 | 291 | $this->cdn_url = $options['cdn_url']; |
292 | 292 | |
293 | 293 | // noptimize me. |
294 | - $this->content = $this->hide_noptimize( $this->content ); |
|
294 | + $this->content = $this->hide_noptimize($this->content); |
|
295 | 295 | |
296 | 296 | // Save IE hacks. |
297 | - $this->content = $this->hide_iehacks( $this->content ); |
|
297 | + $this->content = $this->hide_iehacks($this->content); |
|
298 | 298 | |
299 | 299 | // comments. |
300 | - $this->content = $this->hide_comments( $this->content ); |
|
300 | + $this->content = $this->hide_comments($this->content); |
|
301 | 301 | |
302 | 302 | // Get script files. |
303 | - if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) { |
|
304 | - foreach ( $matches[0] as $tag ) { |
|
303 | + if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) { |
|
304 | + foreach ($matches[0] as $tag) { |
|
305 | 305 | // only consider script aggregation for types allowlisted in should_aggregate-function. |
306 | - $should_aggregate = $this->should_aggregate( $tag ); |
|
307 | - if ( ! $should_aggregate ) { |
|
306 | + $should_aggregate = $this->should_aggregate($tag); |
|
307 | + if (!$should_aggregate) { |
|
308 | 308 | $tag = ''; |
309 | 309 | continue; |
310 | 310 | } |
311 | 311 | |
312 | - if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) { |
|
312 | + if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) { |
|
313 | 313 | // non-inline script. |
314 | - if ( $this->isremovable( $tag, $this->jsremovables ) ) { |
|
315 | - $this->content = str_replace( $tag, '', $this->content ); |
|
314 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
315 | + $this->content = str_replace($tag, '', $this->content); |
|
316 | 316 | continue; |
317 | 317 | } |
318 | 318 | |
319 | 319 | $orig_tag = null; |
320 | - $url = current( explode( '?', $source[2], 2 ) ); |
|
321 | - $path = $this->getpath( $url ); |
|
322 | - if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable( $tag ) ) { |
|
320 | + $url = current(explode('?', $source[2], 2)); |
|
321 | + $path = $this->getpath($url); |
|
322 | + if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) { |
|
323 | 323 | // ok to optimize, add to array. |
324 | 324 | $this->scripts[] = $path; |
325 | 325 | } else { |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | $new_tag = $tag; |
328 | 328 | |
329 | 329 | // non-mergeable script (excluded or dynamic or external). |
330 | - if ( is_array( $exclude_js ) ) { |
|
330 | + if (is_array($exclude_js)) { |
|
331 | 331 | // should we add flags? |
332 | - foreach ( $exclude_js as $excl_tag => $excl_flags ) { |
|
333 | - if ( false !== strpos( $orig_tag, $excl_tag ) && in_array( $excl_flags, array( 'async', 'defer' ) ) ) { |
|
334 | - $new_tag = str_replace( '<script ', '<script ' . $excl_flags . ' ', $new_tag ); |
|
332 | + foreach ($exclude_js as $excl_tag => $excl_flags) { |
|
333 | + if (false !== strpos($orig_tag, $excl_tag) && in_array($excl_flags, array('async', 'defer'))) { |
|
334 | + $new_tag = str_replace('<script ', '<script '.$excl_flags.' ', $new_tag); |
|
335 | 335 | } |
336 | 336 | } |
337 | 337 | } |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | // Should we minify the non-aggregated script? |
340 | 340 | // -> if aggregate is on and exclude minify is on |
341 | 341 | // -> if aggregate is off and the file is not in dontmove. |
342 | - if ( $path && $this->minify_excluded ) { |
|
343 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
344 | - if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) { |
|
345 | - $minified_url = $this->minify_single( $path ); |
|
346 | - if ( ! empty( $minified_url ) ) { |
|
342 | + if ($path && $this->minify_excluded) { |
|
343 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
344 | + if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) { |
|
345 | + $minified_url = $this->minify_single($path); |
|
346 | + if (!empty($minified_url)) { |
|
347 | 347 | // Replace original URL with minified URL from cache. |
348 | - $new_tag = str_replace( $url, $minified_url, $new_tag ); |
|
349 | - } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) { |
|
348 | + $new_tag = str_replace($url, $minified_url, $new_tag); |
|
349 | + } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) { |
|
350 | 350 | // Remove the original script tag, because cache content is empty but only if filter |
351 | 351 | // is trued because $minified_url is also false if original JS is minified already. |
352 | 352 | $new_tag = ''; |
@@ -354,17 +354,17 @@ discard block |
||
354 | 354 | } |
355 | 355 | } |
356 | 356 | |
357 | - if ( $this->ismovable( $new_tag ) ) { |
|
357 | + if ($this->ismovable($new_tag)) { |
|
358 | 358 | // can be moved, flags and all. |
359 | - if ( $this->movetolast( $new_tag ) ) { |
|
359 | + if ($this->movetolast($new_tag)) { |
|
360 | 360 | $this->move['last'][] = $new_tag; |
361 | 361 | } else { |
362 | 362 | $this->move['first'][] = $new_tag; |
363 | 363 | } |
364 | 364 | } else { |
365 | 365 | // cannot be moved, so if flag was added re-inject altered tag immediately. |
366 | - if ( ( '' !== $new_tag && $orig_tag !== $new_tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_js_remove_empty_files', false ) ) ) { |
|
367 | - $this->content = str_replace( $orig_tag, $new_tag, $this->content ); |
|
366 | + if (('' !== $new_tag && $orig_tag !== $new_tag) || ('' === $new_tag && apply_filters('autoptimize_filter_js_remove_empty_files', false))) { |
|
367 | + $this->content = str_replace($orig_tag, $new_tag, $this->content); |
|
368 | 368 | $orig_tag = ''; |
369 | 369 | } |
370 | 370 | // and forget about the $tag (not to be touched any more). |
@@ -373,23 +373,23 @@ discard block |
||
373 | 373 | } |
374 | 374 | } else { |
375 | 375 | // Inline script. |
376 | - if ( $this->isremovable( $tag, $this->jsremovables ) ) { |
|
377 | - $this->content = str_replace( $tag, '', $this->content ); |
|
376 | + if ($this->isremovable($tag, $this->jsremovables)) { |
|
377 | + $this->content = str_replace($tag, '', $this->content); |
|
378 | 378 | continue; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // unhide comments, as javascript may be wrapped in comment-tags for old times' sake. |
382 | - $tag = $this->restore_comments( $tag ); |
|
383 | - if ( $this->ismergeable( $tag ) && $this->include_inline ) { |
|
384 | - preg_match( '#<script.*>(.*)</script>#Usmi', $tag, $code ); |
|
385 | - $code = preg_replace( '#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] ); |
|
386 | - $code = preg_replace( '/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code ); |
|
387 | - $this->scripts[] = 'INLINE;' . $code; |
|
382 | + $tag = $this->restore_comments($tag); |
|
383 | + if ($this->ismergeable($tag) && $this->include_inline) { |
|
384 | + preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code); |
|
385 | + $code = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]); |
|
386 | + $code = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code); |
|
387 | + $this->scripts[] = 'INLINE;'.$code; |
|
388 | 388 | } else { |
389 | 389 | // Can we move this? |
390 | - $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag ); |
|
391 | - if ( $this->ismovable( $tag ) || '' !== $autoptimize_js_moveable ) { |
|
392 | - if ( $this->movetolast( $tag ) || 'last' === $autoptimize_js_moveable ) { |
|
390 | + $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag); |
|
391 | + if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) { |
|
392 | + if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) { |
|
393 | 393 | $this->move['last'][] = $tag; |
394 | 394 | } else { |
395 | 395 | $this->move['first'][] = $tag; |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | } |
401 | 401 | } |
402 | 402 | // Re-hide comments to be able to do the removal based on tag from $this->content. |
403 | - $tag = $this->hide_comments( $tag ); |
|
403 | + $tag = $this->hide_comments($tag); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | // Remove the original script tag. |
407 | - $this->content = str_replace( $tag, '', $this->content ); |
|
407 | + $this->content = str_replace($tag, '', $this->content); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | return true; |
@@ -429,30 +429,30 @@ discard block |
||
429 | 429 | * @param string $tag Script node & child(ren). |
430 | 430 | * @return bool |
431 | 431 | */ |
432 | - public function should_aggregate( $tag ) |
|
432 | + public function should_aggregate($tag) |
|
433 | 433 | { |
434 | - if ( empty( $tag ) ) { |
|
434 | + if (empty($tag)) { |
|
435 | 435 | return false; |
436 | 436 | } |
437 | 437 | |
438 | 438 | // We're only interested in the type attribute of the <script> tag itself, not any possible |
439 | 439 | // inline code that might just contain the 'type=' string... |
440 | 440 | $tag_parts = array(); |
441 | - preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts ); |
|
441 | + preg_match('#<(script[^>]*)>#i', $tag, $tag_parts); |
|
442 | 442 | $tag_without_contents = null; |
443 | - if ( ! empty( $tag_parts[1] ) ) { |
|
443 | + if (!empty($tag_parts[1])) { |
|
444 | 444 | $tag_without_contents = $tag_parts[1]; |
445 | 445 | } |
446 | 446 | |
447 | - $has_type = ( strpos( $tag_without_contents, 'type' ) !== false ); |
|
447 | + $has_type = (strpos($tag_without_contents, 'type') !== false); |
|
448 | 448 | |
449 | 449 | $type_valid = false; |
450 | - if ( $has_type ) { |
|
451 | - $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents ); |
|
450 | + if ($has_type) { |
|
451 | + $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | $should_aggregate = false; |
455 | - if ( ! $has_type || $type_valid ) { |
|
455 | + if (!$has_type || $type_valid) { |
|
456 | 456 | $should_aggregate = true; |
457 | 457 | } |
458 | 458 | |
@@ -464,75 +464,75 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function minify() |
466 | 466 | { |
467 | - foreach ( $this->scripts as $script ) { |
|
468 | - if ( empty( $script ) ) { |
|
467 | + foreach ($this->scripts as $script) { |
|
468 | + if (empty($script)) { |
|
469 | 469 | continue; |
470 | 470 | } |
471 | 471 | |
472 | 472 | // TODO/FIXME: some duplicate code here, can be reduced/simplified. |
473 | - if ( preg_match( '#^INLINE;#', $script ) ) { |
|
473 | + if (preg_match('#^INLINE;#', $script)) { |
|
474 | 474 | // Inline script. |
475 | - $script = preg_replace( '#^INLINE;#', '', $script ); |
|
476 | - $script = rtrim( $script, ";\n\t\r" ) . ';'; |
|
475 | + $script = preg_replace('#^INLINE;#', '', $script); |
|
476 | + $script = rtrim($script, ";\n\t\r").';'; |
|
477 | 477 | // Add try-catch? |
478 | - if ( $this->trycatch ) { |
|
479 | - $script = 'try{' . $script . '}catch(e){}'; |
|
478 | + if ($this->trycatch) { |
|
479 | + $script = 'try{'.$script.'}catch(e){}'; |
|
480 | 480 | } |
481 | - $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' ); |
|
482 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) { |
|
481 | + $tmpscript = apply_filters('autoptimize_js_individual_script', $script, ''); |
|
482 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) { |
|
483 | 483 | $script = $tmpscript; |
484 | 484 | $this->alreadyminified = true; |
485 | 485 | } |
486 | - $this->jscode .= "\n" . $script; |
|
486 | + $this->jscode .= "\n".$script; |
|
487 | 487 | } else { |
488 | 488 | // External script. |
489 | - if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) { |
|
490 | - $scriptsrc = file_get_contents( $script ); |
|
491 | - $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc ); |
|
492 | - $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';'; |
|
489 | + if (false !== $script && file_exists($script) && is_readable($script)) { |
|
490 | + $scriptsrc = file_get_contents($script); |
|
491 | + $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc); |
|
492 | + $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';'; |
|
493 | 493 | // Add try-catch? |
494 | - if ( $this->trycatch ) { |
|
495 | - $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}'; |
|
494 | + if ($this->trycatch) { |
|
495 | + $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}'; |
|
496 | 496 | } |
497 | - $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script ); |
|
498 | - if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) { |
|
497 | + $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script); |
|
498 | + if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) { |
|
499 | 499 | $scriptsrc = $tmpscriptsrc; |
500 | 500 | $this->alreadyminified = true; |
501 | - } elseif ( $this->can_inject_late( $script ) ) { |
|
502 | - $scriptsrc = self::build_injectlater_marker( $script, md5( $scriptsrc ) ); |
|
501 | + } elseif ($this->can_inject_late($script)) { |
|
502 | + $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc)); |
|
503 | 503 | } |
504 | - $this->jscode .= "\n" . $scriptsrc; |
|
504 | + $this->jscode .= "\n".$scriptsrc; |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | } |
508 | 508 | |
509 | 509 | // Check for already-minified code. |
510 | - $this->md5hash = md5( $this->jscode ); |
|
511 | - $ccheck = new autoptimizeCache( $this->md5hash, 'js' ); |
|
512 | - if ( $ccheck->check() ) { |
|
510 | + $this->md5hash = md5($this->jscode); |
|
511 | + $ccheck = new autoptimizeCache($this->md5hash, 'js'); |
|
512 | + if ($ccheck->check()) { |
|
513 | 513 | $this->jscode = $ccheck->retrieve(); |
514 | 514 | return true; |
515 | 515 | } |
516 | - unset( $ccheck ); |
|
516 | + unset($ccheck); |
|
517 | 517 | |
518 | 518 | // $this->jscode has all the uncompressed code now. |
519 | - if ( true !== $this->alreadyminified ) { |
|
520 | - if ( apply_filters( 'autoptimize_js_do_minify', true ) ) { |
|
521 | - $tmp_jscode = trim( JSMin::minify( $this->jscode ) ); |
|
522 | - if ( ! empty( $tmp_jscode ) ) { |
|
519 | + if (true !== $this->alreadyminified) { |
|
520 | + if (apply_filters('autoptimize_js_do_minify', true)) { |
|
521 | + $tmp_jscode = trim(JSMin::minify($this->jscode)); |
|
522 | + if (!empty($tmp_jscode)) { |
|
523 | 523 | $this->jscode = $tmp_jscode; |
524 | - unset( $tmp_jscode ); |
|
524 | + unset($tmp_jscode); |
|
525 | 525 | } |
526 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
527 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
526 | + $this->jscode = $this->inject_minified($this->jscode); |
|
527 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
528 | 528 | return true; |
529 | 529 | } else { |
530 | - $this->jscode = $this->inject_minified( $this->jscode ); |
|
530 | + $this->jscode = $this->inject_minified($this->jscode); |
|
531 | 531 | return false; |
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | - $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode ); |
|
535 | + $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode); |
|
536 | 536 | return true; |
537 | 537 | } |
538 | 538 | |
@@ -541,13 +541,13 @@ discard block |
||
541 | 541 | */ |
542 | 542 | public function cache() |
543 | 543 | { |
544 | - $cache = new autoptimizeCache( $this->md5hash, 'js' ); |
|
545 | - if ( ! $cache->check() ) { |
|
544 | + $cache = new autoptimizeCache($this->md5hash, 'js'); |
|
545 | + if (!$cache->check()) { |
|
546 | 546 | // Cache our code. |
547 | - $cache->cache( $this->jscode, 'text/javascript' ); |
|
547 | + $cache->cache($this->jscode, 'text/javascript'); |
|
548 | 548 | } |
549 | - $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname(); |
|
550 | - $this->url = $this->url_replace_cdn( $this->url ); |
|
549 | + $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname(); |
|
550 | + $this->url = $this->url_replace_cdn($this->url); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -556,47 +556,47 @@ discard block |
||
556 | 556 | public function getcontent() |
557 | 557 | { |
558 | 558 | // Restore the full content. |
559 | - if ( ! empty( $this->restofcontent ) ) { |
|
559 | + if (!empty($this->restofcontent)) { |
|
560 | 560 | $this->content .= $this->restofcontent; |
561 | 561 | $this->restofcontent = ''; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Add the scripts taking forcehead/ deferred (default) into account. |
565 | - if ( $this->forcehead ) { |
|
566 | - $replace_tag = array( '</head>', 'before' ); |
|
565 | + if ($this->forcehead) { |
|
566 | + $replace_tag = array('</head>', 'before'); |
|
567 | 567 | $defer = ''; |
568 | 568 | } else { |
569 | - $replace_tag = array( '</body>', 'before' ); |
|
569 | + $replace_tag = array('</body>', 'before'); |
|
570 | 570 | $defer = 'defer '; |
571 | 571 | } |
572 | 572 | |
573 | - $defer = apply_filters( 'autoptimize_filter_js_defer', $defer ); |
|
573 | + $defer = apply_filters('autoptimize_filter_js_defer', $defer); |
|
574 | 574 | $type_js = ''; |
575 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
575 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
576 | 576 | $type_js = 'type="text/javascript" '; |
577 | 577 | } |
578 | 578 | |
579 | - $bodyreplacementpayload = '<script ' . $type_js . $defer . 'src="' . $this->url . '"></script>'; |
|
580 | - $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload ); |
|
579 | + $bodyreplacementpayload = '<script '.$type_js.$defer.'src="'.$this->url.'"></script>'; |
|
580 | + $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload); |
|
581 | 581 | |
582 | - $bodyreplacement = implode( '', $this->move['first'] ); |
|
582 | + $bodyreplacement = implode('', $this->move['first']); |
|
583 | 583 | $bodyreplacement .= $bodyreplacementpayload; |
584 | - $bodyreplacement .= implode( '', $this->move['last'] ); |
|
584 | + $bodyreplacement .= implode('', $this->move['last']); |
|
585 | 585 | |
586 | - $replace_tag = apply_filters( 'autoptimize_filter_js_replacetag', $replace_tag ); |
|
586 | + $replace_tag = apply_filters('autoptimize_filter_js_replacetag', $replace_tag); |
|
587 | 587 | |
588 | - if ( strlen( $this->jscode ) > 0 ) { |
|
589 | - $this->inject_in_html( $bodyreplacement, $replace_tag ); |
|
588 | + if (strlen($this->jscode) > 0) { |
|
589 | + $this->inject_in_html($bodyreplacement, $replace_tag); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | // Restore comments. |
593 | - $this->content = $this->restore_comments( $this->content ); |
|
593 | + $this->content = $this->restore_comments($this->content); |
|
594 | 594 | |
595 | 595 | // Restore IE hacks. |
596 | - $this->content = $this->restore_iehacks( $this->content ); |
|
596 | + $this->content = $this->restore_iehacks($this->content); |
|
597 | 597 | |
598 | 598 | // Restore noptimize. |
599 | - $this->content = $this->restore_noptimize( $this->content ); |
|
599 | + $this->content = $this->restore_noptimize($this->content); |
|
600 | 600 | |
601 | 601 | // Return the modified HTML. |
602 | 602 | return $this->content; |
@@ -607,34 +607,34 @@ discard block |
||
607 | 607 | * |
608 | 608 | * @param string $tag JS tag. |
609 | 609 | */ |
610 | - private function ismergeable( $tag ) |
|
610 | + private function ismergeable($tag) |
|
611 | 611 | { |
612 | - if ( empty( $tag ) || ! $this->aggregate ) { |
|
612 | + if (empty($tag) || !$this->aggregate) { |
|
613 | 613 | return false; |
614 | 614 | } |
615 | 615 | |
616 | - if ( ! empty( $this->allowlist ) ) { |
|
617 | - foreach ( $this->allowlist as $match ) { |
|
618 | - if ( false !== strpos( $tag, $match ) ) { |
|
616 | + if (!empty($this->allowlist)) { |
|
617 | + foreach ($this->allowlist as $match) { |
|
618 | + if (false !== strpos($tag, $match)) { |
|
619 | 619 | return true; |
620 | 620 | } |
621 | 621 | } |
622 | 622 | // No match with allowlist. |
623 | 623 | return false; |
624 | 624 | } else { |
625 | - foreach ( $this->domove as $match ) { |
|
626 | - if ( false !== strpos( $tag, $match ) ) { |
|
625 | + foreach ($this->domove as $match) { |
|
626 | + if (false !== strpos($tag, $match)) { |
|
627 | 627 | // Matched something. |
628 | 628 | return false; |
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | - if ( $this->movetolast( $tag ) ) { |
|
632 | + if ($this->movetolast($tag)) { |
|
633 | 633 | return false; |
634 | 634 | } |
635 | 635 | |
636 | - foreach ( $this->dontmove as $match ) { |
|
637 | - if ( false !== strpos( $tag, $match ) ) { |
|
636 | + foreach ($this->dontmove as $match) { |
|
637 | + if (false !== strpos($tag, $match)) { |
|
638 | 638 | // Matched something. |
639 | 639 | return false; |
640 | 640 | } |
@@ -650,25 +650,25 @@ discard block |
||
650 | 650 | * |
651 | 651 | * @param string $tag tag to check for blocklist (exclusions). |
652 | 652 | */ |
653 | - private function ismovable( $tag ) |
|
653 | + private function ismovable($tag) |
|
654 | 654 | { |
655 | - if ( empty( $tag ) || true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) { |
|
655 | + if (empty($tag) || true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) { |
|
656 | 656 | return false; |
657 | 657 | } |
658 | 658 | |
659 | - foreach ( $this->domove as $match ) { |
|
660 | - if ( false !== strpos( $tag, $match ) ) { |
|
659 | + foreach ($this->domove as $match) { |
|
660 | + if (false !== strpos($tag, $match)) { |
|
661 | 661 | // Matched something. |
662 | 662 | return true; |
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
666 | - if ( $this->movetolast( $tag ) ) { |
|
666 | + if ($this->movetolast($tag)) { |
|
667 | 667 | return true; |
668 | 668 | } |
669 | 669 | |
670 | - foreach ( $this->dontmove as $match ) { |
|
671 | - if ( false !== strpos( $tag, $match ) ) { |
|
670 | + foreach ($this->dontmove as $match) { |
|
671 | + if (false !== strpos($tag, $match)) { |
|
672 | 672 | // Matched something. |
673 | 673 | return false; |
674 | 674 | } |
@@ -678,14 +678,14 @@ discard block |
||
678 | 678 | return true; |
679 | 679 | } |
680 | 680 | |
681 | - private function movetolast( $tag ) |
|
681 | + private function movetolast($tag) |
|
682 | 682 | { |
683 | - if ( empty( $tag ) ) { |
|
683 | + if (empty($tag)) { |
|
684 | 684 | return false; |
685 | 685 | } |
686 | 686 | |
687 | - foreach ( $this->domovelast as $match ) { |
|
688 | - if ( false !== strpos( $tag, $match ) ) { |
|
687 | + foreach ($this->domovelast as $match) { |
|
688 | + if (false !== strpos($tag, $match)) { |
|
689 | 689 | // Matched, return true. |
690 | 690 | return true; |
691 | 691 | } |
@@ -705,12 +705,12 @@ discard block |
||
705 | 705 | * @param string $js_path Path to JS file. |
706 | 706 | * @return bool |
707 | 707 | */ |
708 | - private function can_inject_late( $js_path ) { |
|
709 | - $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false ); |
|
710 | - if ( true !== $this->inject_min_late ) { |
|
708 | + private function can_inject_late($js_path) { |
|
709 | + $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false); |
|
710 | + if (true !== $this->inject_min_late) { |
|
711 | 711 | // late-inject turned off. |
712 | 712 | return false; |
713 | - } elseif ( ( false === strpos( $js_path, 'min.js' ) ) && ( false === strpos( $js_path, 'wp-includes/js/jquery/jquery.js' ) ) && ( str_replace( $consider_minified_array, '', $js_path ) === $js_path ) ) { |
|
713 | + } elseif ((false === strpos($js_path, 'min.js')) && (false === strpos($js_path, 'wp-includes/js/jquery/jquery.js')) && (str_replace($consider_minified_array, '', $js_path) === $js_path)) { |
|
714 | 714 | // file not minified based on filename & filter. |
715 | 715 | return false; |
716 | 716 | } else { |
@@ -737,35 +737,35 @@ discard block |
||
737 | 737 | * |
738 | 738 | * @return bool|string Url pointing to the minified js file or false. |
739 | 739 | */ |
740 | - public function minify_single( $filepath, $cache_miss = false ) |
|
740 | + public function minify_single($filepath, $cache_miss = false) |
|
741 | 741 | { |
742 | - $contents = $this->prepare_minify_single( $filepath ); |
|
742 | + $contents = $this->prepare_minify_single($filepath); |
|
743 | 743 | |
744 | - if ( empty( $contents ) ) { |
|
744 | + if (empty($contents)) { |
|
745 | 745 | return false; |
746 | 746 | } |
747 | 747 | |
748 | 748 | // Check cache. |
749 | - $hash = 'single_' . md5( $contents ); |
|
750 | - $cache = new autoptimizeCache( $hash, 'js' ); |
|
749 | + $hash = 'single_'.md5($contents); |
|
750 | + $cache = new autoptimizeCache($hash, 'js'); |
|
751 | 751 | |
752 | 752 | // If not in cache already, minify... |
753 | - if ( ! $cache->check() || $cache_miss ) { |
|
754 | - $contents = trim( JSMin::minify( $contents ) ); |
|
753 | + if (!$cache->check() || $cache_miss) { |
|
754 | + $contents = trim(JSMin::minify($contents)); |
|
755 | 755 | |
756 | 756 | // Check if minified cache content is empty. |
757 | - if ( empty( $contents ) ) { |
|
757 | + if (empty($contents)) { |
|
758 | 758 | return false; |
759 | 759 | } |
760 | 760 | |
761 | 761 | // Filter contents of excluded minified CSS. |
762 | - $contents = apply_filters( 'autoptimize_filter_js_single_after_minify', $contents ); |
|
762 | + $contents = apply_filters('autoptimize_filter_js_single_after_minify', $contents); |
|
763 | 763 | |
764 | 764 | // Store in cache. |
765 | - $cache->cache( $contents, 'text/javascript' ); |
|
765 | + $cache->cache($contents, 'text/javascript'); |
|
766 | 766 | } |
767 | 767 | |
768 | - $url = $this->build_minify_single_url( $cache ); |
|
768 | + $url = $this->build_minify_single_url($cache); |
|
769 | 769 | |
770 | 770 | return $url; |
771 | 771 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handles autoptimizeExtra frontend features + admin options page |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param array $options Optional. Allows overriding options without having to specify them via admin options page. |
30 | 30 | */ |
31 | - public function __construct( $options = array() ) |
|
31 | + public function __construct($options = array()) |
|
32 | 32 | { |
33 | - if ( empty( $options ) ) { |
|
33 | + if (empty($options)) { |
|
34 | 34 | $options = self::fetch_options(); |
35 | 35 | } |
36 | 36 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public static function instance() |
49 | 49 | { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | |
@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | |
57 | 57 | public function run() |
58 | 58 | { |
59 | - if ( is_admin() ) { |
|
60 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
61 | - add_action( 'network_admin_menu', array( $this, 'admin_menu' ) ); |
|
59 | + if (is_admin()) { |
|
60 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
61 | + add_action('network_admin_menu', array($this, 'admin_menu')); |
|
62 | 62 | } else { |
63 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
63 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
64 | 64 | } |
65 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) ); |
|
65 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab')); |
|
66 | 66 | } else { |
67 | - add_action( 'wp', array( $this, 'run_on_frontend' ) ); |
|
67 | + add_action('wp', array($this, 'run_on_frontend')); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - public function set_options( array $options ) |
|
71 | + public function set_options(array $options) |
|
72 | 72 | { |
73 | 73 | $this->options = $options; |
74 | 74 | |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | |
78 | 78 | public static function fetch_options() |
79 | 79 | { |
80 | - $value = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings' ); |
|
81 | - if ( empty( $value ) ) { |
|
80 | + $value = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings'); |
|
81 | + if (empty($value)) { |
|
82 | 82 | // Fallback to returning defaults when no stored option exists yet. |
83 | 83 | $value = autoptimizeConfig::get_ao_extra_default_options(); |
84 | 84 | } |
@@ -89,55 +89,55 @@ discard block |
||
89 | 89 | public function disable_emojis() |
90 | 90 | { |
91 | 91 | // Removing all actions related to emojis! |
92 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
93 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
94 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
95 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
96 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
97 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
98 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
92 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
93 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
94 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
95 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
96 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
97 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
98 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
99 | 99 | |
100 | 100 | // Removes TinyMCE emojis. |
101 | - add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) ); |
|
101 | + add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce')); |
|
102 | 102 | |
103 | 103 | // Removes emoji dns-preftech. |
104 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 ); |
|
104 | + add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2); |
|
105 | 105 | } |
106 | 106 | |
107 | - public function filter_disable_emojis_tinymce( $plugins ) |
|
107 | + public function filter_disable_emojis_tinymce($plugins) |
|
108 | 108 | { |
109 | - if ( is_array( $plugins ) ) { |
|
110 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
109 | + if (is_array($plugins)) { |
|
110 | + return array_diff($plugins, array('wpemoji')); |
|
111 | 111 | } else { |
112 | 112 | return array(); |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - public function filter_remove_qs( $src ) |
|
116 | + public function filter_remove_qs($src) |
|
117 | 117 | { |
118 | - if ( strpos( $src, '?ver=' ) ) { |
|
119 | - $src = remove_query_arg( 'ver', $src ); |
|
118 | + if (strpos($src, '?ver=')) { |
|
119 | + $src = remove_query_arg('ver', $src); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return $src; |
123 | 123 | } |
124 | 124 | |
125 | - public function extra_async_js( $in ) |
|
125 | + public function extra_async_js($in) |
|
126 | 126 | { |
127 | 127 | $exclusions = array(); |
128 | - if ( ! empty( $in ) ) { |
|
129 | - $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' ); |
|
128 | + if (!empty($in)) { |
|
129 | + $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), ''); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $settings = $this->options['autoptimize_extra_text_field_3']; |
133 | - $async = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' ); |
|
134 | - $attr = apply_filters( 'autoptimize_filter_extra_async', 'async' ); |
|
135 | - foreach ( $async as $k => $v ) { |
|
136 | - $async[ $k ] = $attr; |
|
133 | + $async = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), ''); |
|
134 | + $attr = apply_filters('autoptimize_filter_extra_async', 'async'); |
|
135 | + foreach ($async as $k => $v) { |
|
136 | + $async[$k] = $attr; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | // Merge exclusions & asyncs in one array and return to AO API. |
140 | - $merged = array_merge( $exclusions, $async ); |
|
140 | + $merged = array_merge($exclusions, $async); |
|
141 | 141 | |
142 | 142 | return $merged; |
143 | 143 | } |
@@ -148,68 +148,68 @@ discard block |
||
148 | 148 | // for optimizations are met, this to ensure e.g. removing querystrings |
149 | 149 | // is not done when optimizing for logged in users is off, breaking |
150 | 150 | // some pagebuilders (Divi & Elementor). |
151 | - if ( false === autoptimizeMain::should_buffer() ) { |
|
151 | + if (false === autoptimizeMain::should_buffer()) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $options = $this->options; |
156 | 156 | |
157 | 157 | // Disable emojis if specified. |
158 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) { |
|
158 | + if (!empty($options['autoptimize_extra_checkbox_field_1'])) { |
|
159 | 159 | $this->disable_emojis(); |
160 | 160 | } |
161 | 161 | |
162 | 162 | // Remove version query parameters. |
163 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) { |
|
164 | - add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
165 | - add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
163 | + if (!empty($options['autoptimize_extra_checkbox_field_0'])) { |
|
164 | + add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
165 | + add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Avoiding conflicts of interest when async-javascript plugin is active! |
169 | - $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ); |
|
170 | - if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) { |
|
171 | - add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 ); |
|
169 | + $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php'); |
|
170 | + if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) { |
|
171 | + add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Optimize google fonts! |
175 | - if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) { |
|
176 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 ); |
|
177 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 ); |
|
178 | - add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 ); |
|
175 | + if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) { |
|
176 | + add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2); |
|
177 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1); |
|
178 | + add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Preconnect! |
182 | - if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) { |
|
183 | - add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 ); |
|
182 | + if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
183 | + add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Preload! |
187 | - if ( ! empty( $options['autoptimize_extra_text_field_7'] ) || has_filter( 'autoptimize_filter_extra_tobepreloaded' ) ) { |
|
188 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 ); |
|
187 | + if (!empty($options['autoptimize_extra_text_field_7']) || has_filter('autoptimize_filter_extra_tobepreloaded')) { |
|
188 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_preload'), 10, 2); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - public function filter_remove_emoji_dns_prefetch( $urls, $relation_type ) |
|
192 | + public function filter_remove_emoji_dns_prefetch($urls, $relation_type) |
|
193 | 193 | { |
194 | - $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' ); |
|
194 | + $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/'); |
|
195 | 195 | |
196 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url ); |
|
196 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url); |
|
197 | 197 | } |
198 | 198 | |
199 | - public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type ) |
|
199 | + public function filter_remove_gfonts_dnsprefetch($urls, $relation_type) |
|
200 | 200 | { |
201 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' ); |
|
201 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com'); |
|
202 | 202 | } |
203 | 203 | |
204 | - public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove ) |
|
204 | + public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove) |
|
205 | 205 | { |
206 | 206 | $url_to_remove = (string) $url_to_remove; |
207 | 207 | |
208 | - if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) { |
|
208 | + if (!empty($url_to_remove) && 'dns-prefetch' === $relation_type) { |
|
209 | 209 | $cnt = 0; |
210 | - foreach ( $urls as $url ) { |
|
211 | - if ( false !== strpos( $url, $url_to_remove ) ) { |
|
212 | - unset( $urls[ $cnt ] ); |
|
210 | + foreach ($urls as $url) { |
|
211 | + if (false !== strpos($url, $url_to_remove)) { |
|
212 | + unset($urls[$cnt]); |
|
213 | 213 | } |
214 | 214 | $cnt++; |
215 | 215 | } |
@@ -218,151 +218,151 @@ discard block |
||
218 | 218 | return $urls; |
219 | 219 | } |
220 | 220 | |
221 | - public function filter_optimize_google_fonts( $in ) |
|
221 | + public function filter_optimize_google_fonts($in) |
|
222 | 222 | { |
223 | 223 | // Extract fonts, partly based on wp rocket's extraction code. |
224 | - $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
225 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches ); |
|
224 | + $markup = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
225 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches); |
|
226 | 226 | |
227 | 227 | $fonts_collection = array(); |
228 | - if ( ! $matches[2] ) { |
|
228 | + if (!$matches[2]) { |
|
229 | 229 | return $in; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Store them in $fonts array. |
233 | 233 | $i = 0; |
234 | - foreach ( $matches[2] as $font ) { |
|
235 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
234 | + foreach ($matches[2] as $font) { |
|
235 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
236 | 236 | // Get fonts name. |
237 | - $font = str_replace( array( '%7C', '%7c' ), '|', $font ); |
|
238 | - if ( strpos( $font, 'fonts.googleapis.com/css2' ) !== false ) { |
|
237 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
238 | + if (strpos($font, 'fonts.googleapis.com/css2') !== false) { |
|
239 | 239 | // (Somewhat) change Google Fonts APIv2 syntax back to v1. |
240 | - $font = str_replace( array( 'wght@', 'wght%40', ';', '%3B' ), array( '', '', ',', ',' ), $font ); |
|
240 | + $font = str_replace(array('wght@', 'wght%40', ';', '%3B'), array('', '', ',', ','), $font); |
|
241 | 241 | } |
242 | - $font = explode( 'family=', $font ); |
|
243 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
242 | + $font = explode('family=', $font); |
|
243 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
244 | 244 | // Add font to $fonts[$i] but make sure not to pollute with an empty family! |
245 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
246 | - if ( ! empty( $_thisfont ) ) { |
|
247 | - $fonts_collection[ $i ]['fonts'] = $_thisfont; |
|
245 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
246 | + if (!empty($_thisfont)) { |
|
247 | + $fonts_collection[$i]['fonts'] = $_thisfont; |
|
248 | 248 | // And add subset if any! |
249 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
250 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
251 | - $subset = str_replace( array( '%2C', '%2c' ), ',', $subset ); |
|
252 | - $subset = explode( 'subset=', $subset ); |
|
253 | - $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] ); |
|
249 | + $subset = (is_array($font)) ? end($font) : ''; |
|
250 | + if (false !== strpos($subset, 'subset=')) { |
|
251 | + $subset = str_replace(array('%2C', '%2c'), ',', $subset); |
|
252 | + $subset = explode('subset=', $subset); |
|
253 | + $fonts_collection[$i]['subsets'] = explode(',', $subset[1]); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | // And remove Google Fonts. |
257 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
257 | + $in = str_replace($matches[0][$i], '', $in); |
|
258 | 258 | } |
259 | 259 | $i++; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $options = $this->options; |
263 | 263 | $fonts_markup = ''; |
264 | - if ( '2' === $options['autoptimize_extra_radio_field_4'] ) { |
|
264 | + if ('2' === $options['autoptimize_extra_radio_field_4']) { |
|
265 | 265 | // Remove Google Fonts. |
266 | - unset( $fonts_collection ); |
|
266 | + unset($fonts_collection); |
|
267 | 267 | return $in; |
268 | - } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
268 | + } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) { |
|
269 | 269 | // Aggregate & link! |
270 | 270 | $fonts_string = ''; |
271 | 271 | $subset_string = ''; |
272 | - foreach ( $fonts_collection as $font ) { |
|
273 | - $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' ); |
|
274 | - if ( ! empty( $font['subsets'] ) ) { |
|
275 | - $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' ); |
|
272 | + foreach ($fonts_collection as $font) { |
|
273 | + $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|'); |
|
274 | + if (!empty($font['subsets'])) { |
|
275 | + $subset_string .= ','.trim(implode(',', $font['subsets']), ','); |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
279 | - if ( ! empty( $subset_string ) ) { |
|
280 | - $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) ); |
|
281 | - $fonts_string = $fonts_string . '&subset=' . $subset_string; |
|
279 | + if (!empty($subset_string)) { |
|
280 | + $subset_string = str_replace(',', '%2C', ltrim($subset_string, ',')); |
|
281 | + $fonts_string = $fonts_string.'&subset='.$subset_string; |
|
282 | 282 | } |
283 | 283 | |
284 | - $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) ); |
|
284 | + $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|'))); |
|
285 | 285 | // only add display parameter if there is none in $fonts_string (by virtue of the filter). |
286 | - if ( strpos( $fonts_string, 'display=' ) === false ) { |
|
287 | - $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&display=swap' ); |
|
286 | + if (strpos($fonts_string, 'display=') === false) { |
|
287 | + $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&display=swap'); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $fonts_string ) ) { |
|
291 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
292 | - $rel_string = 'rel="stylesheet" media="print" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"'; |
|
290 | + if (!empty($fonts_string)) { |
|
291 | + if ('5' === $options['autoptimize_extra_radio_field_4']) { |
|
292 | + $rel_string = 'rel="stylesheet" media="print" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"'; |
|
293 | 293 | } else { |
294 | 294 | $rel_string = 'rel="stylesheet"'; |
295 | 295 | } |
296 | - $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />'; |
|
296 | + $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />'; |
|
297 | 297 | } |
298 | - } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) { |
|
298 | + } elseif ('4' === $options['autoptimize_extra_radio_field_4']) { |
|
299 | 299 | // Aggregate & load async (webfont.js impl.)! |
300 | 300 | $fonts_array = array(); |
301 | - foreach ( $fonts_collection as $_fonts ) { |
|
302 | - if ( ! empty( $_fonts['subsets'] ) ) { |
|
303 | - $_subset = implode( ',', $_fonts['subsets'] ); |
|
304 | - foreach ( $_fonts['fonts'] as $key => $_one_font ) { |
|
305 | - $_one_font = $_one_font . ':' . $_subset; |
|
306 | - $_fonts['fonts'][ $key ] = $_one_font; |
|
301 | + foreach ($fonts_collection as $_fonts) { |
|
302 | + if (!empty($_fonts['subsets'])) { |
|
303 | + $_subset = implode(',', $_fonts['subsets']); |
|
304 | + foreach ($_fonts['fonts'] as $key => $_one_font) { |
|
305 | + $_one_font = $_one_font.':'.$_subset; |
|
306 | + $_fonts['fonts'][$key] = $_one_font; |
|
307 | 307 | } |
308 | 308 | } |
309 | - $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] ); |
|
309 | + $fonts_array = array_merge($fonts_array, $_fonts['fonts']); |
|
310 | 310 | } |
311 | 311 | |
312 | - $fonts_array = array_map( 'urldecode', $fonts_array ); |
|
312 | + $fonts_array = array_map('urldecode', $fonts_array); |
|
313 | 313 | $fonts_array = array_map( |
314 | - function( $_f ) { |
|
315 | - return trim( $_f, ',' ); |
|
314 | + function($_f) { |
|
315 | + return trim($_f, ','); |
|
316 | 316 | }, |
317 | 317 | $fonts_array |
318 | 318 | ); |
319 | 319 | |
320 | 320 | // type attrib on <script not added by default. |
321 | 321 | $type_js = ''; |
322 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
322 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
323 | 323 | $type_js = 'type="text/javascript" '; |
324 | 324 | } |
325 | 325 | |
326 | - $fonts_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>'; |
|
327 | - $fonts_library_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
|
328 | - $in = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) ); |
|
326 | + $fonts_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>'; |
|
327 | + $fonts_library_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
|
328 | + $in = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>')); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Replace back in markup. |
332 | - $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' ); |
|
333 | - $out = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) ); |
|
334 | - unset( $fonts_collection ); |
|
332 | + $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link'); |
|
333 | + $out = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point)); |
|
334 | + unset($fonts_collection); |
|
335 | 335 | |
336 | 336 | return $out; |
337 | 337 | } |
338 | 338 | |
339 | - public function filter_preconnect( $hints, $relation_type ) |
|
339 | + public function filter_preconnect($hints, $relation_type) |
|
340 | 340 | { |
341 | 341 | $options = $this->options; |
342 | 342 | $preconns = array(); |
343 | 343 | |
344 | 344 | // Get settings and store in array. |
345 | - if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { |
|
346 | - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) ); |
|
345 | + if (array_key_exists('autoptimize_extra_text_field_2', $options)) { |
|
346 | + $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2']))); |
|
347 | 347 | } |
348 | - $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns ); |
|
348 | + $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns); |
|
349 | 349 | |
350 | 350 | // Walk array, extract domain and add to new array with crossorigin attribute. |
351 | - foreach ( $preconns as $preconn ) { |
|
351 | + foreach ($preconns as $preconn) { |
|
352 | 352 | $domain = ''; |
353 | - $parsed = parse_url( $preconn ); |
|
354 | - if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) { |
|
355 | - $domain = '//' . $parsed['host']; |
|
356 | - } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) { |
|
357 | - $domain = $parsed['scheme'] . '://' . $parsed['host']; |
|
353 | + $parsed = parse_url($preconn); |
|
354 | + if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) { |
|
355 | + $domain = '//'.$parsed['host']; |
|
356 | + } elseif (is_array($parsed) && !empty($parsed['host'])) { |
|
357 | + $domain = $parsed['scheme'].'://'.$parsed['host']; |
|
358 | 358 | } |
359 | 359 | |
360 | - if ( ! empty( $domain ) ) { |
|
361 | - $hint = array( 'href' => $domain ); |
|
360 | + if (!empty($domain)) { |
|
361 | + $hint = array('href' => $domain); |
|
362 | 362 | // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
363 | 363 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed. |
364 | - $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) ); |
|
365 | - if ( in_array( $domain, $crossorigins ) ) { |
|
364 | + $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
365 | + if (in_array($domain, $crossorigins)) { |
|
366 | 366 | $hint['crossorigin'] = 'anonymous'; |
367 | 367 | } |
368 | 368 | $new_hints[] = $hint; |
@@ -370,21 +370,21 @@ discard block |
||
370 | 370 | } |
371 | 371 | |
372 | 372 | // Merge in WP's preconnect hints. |
373 | - if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) { |
|
374 | - $hints = array_merge( $hints, $new_hints ); |
|
373 | + if ('preconnect' === $relation_type && !empty($new_hints)) { |
|
374 | + $hints = array_merge($hints, $new_hints); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | return $hints; |
378 | 378 | } |
379 | 379 | |
380 | - public function filter_preconnect_google_fonts( $in ) |
|
380 | + public function filter_preconnect_google_fonts($in) |
|
381 | 381 | { |
382 | - if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) { |
|
382 | + if ('2' !== $this->options['autoptimize_extra_radio_field_4']) { |
|
383 | 383 | // Preconnect to fonts.gstatic.com unless we remove gfonts. |
384 | 384 | $in[] = 'https://fonts.gstatic.com'; |
385 | 385 | } |
386 | 386 | |
387 | - if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) { |
|
387 | + if ('4' === $this->options['autoptimize_extra_radio_field_4']) { |
|
388 | 388 | // Preconnect even more hosts for webfont.js! |
389 | 389 | $in[] = 'https://ajax.googleapis.com'; |
390 | 390 | $in[] = 'https://fonts.googleapis.com'; |
@@ -393,76 +393,76 @@ discard block |
||
393 | 393 | return $in; |
394 | 394 | } |
395 | 395 | |
396 | - public function filter_preload( $in ) { |
|
396 | + public function filter_preload($in) { |
|
397 | 397 | // make array from comma separated list. |
398 | 398 | $options = $this->options; |
399 | 399 | $preloads = array(); |
400 | - if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { |
|
401 | - $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) ); |
|
400 | + if (array_key_exists('autoptimize_extra_text_field_7', $options)) { |
|
401 | + $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7']))); |
|
402 | 402 | } |
403 | - $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads ); |
|
403 | + $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads); |
|
404 | 404 | |
405 | 405 | // immediately return if nothing to be preloaded. |
406 | - if ( empty( $preloads ) ) { |
|
406 | + if (empty($preloads)) { |
|
407 | 407 | return $in; |
408 | 408 | } |
409 | 409 | |
410 | 410 | // iterate through array and add preload link to tmp string. |
411 | 411 | $preload_output = ''; |
412 | - foreach ( $preloads as $preload ) { |
|
412 | + foreach ($preloads as $preload) { |
|
413 | 413 | $crossorigin = ''; |
414 | 414 | $preload_as = ''; |
415 | 415 | $mime_type = ''; |
416 | - $_preload = strtok( $preload, '?' ); |
|
416 | + $_preload = strtok($preload, '?'); |
|
417 | 417 | |
418 | - if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) { |
|
418 | + if (autoptimizeUtils::str_ends_in($_preload, '.css')) { |
|
419 | 419 | $preload_as = 'style'; |
420 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) { |
|
420 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) { |
|
421 | 421 | $preload_as = 'script'; |
422 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.woff' ) || autoptimizeUtils::str_ends_in( $_preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $_preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $_preload, '.eot' ) ) { |
|
422 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.woff') || autoptimizeUtils::str_ends_in($_preload, '.woff2') || autoptimizeUtils::str_ends_in($_preload, '.ttf') || autoptimizeUtils::str_ends_in($_preload, '.eot')) { |
|
423 | 423 | $preload_as = 'font'; |
424 | 424 | $crossorigin = ' crossorigin'; |
425 | - $mime_type = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"'; |
|
426 | - if ( ' type="font/eot"' === $mime_type ) { |
|
425 | + $mime_type = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"'; |
|
426 | + if (' type="font/eot"' === $mime_type) { |
|
427 | 427 | $mime_type = 'application/vnd.ms-fontobject'; |
428 | 428 | } |
429 | - } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $_preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $_preload, '.webp' ) || autoptimizeUtils::str_ends_in( $_preload, '.png' ) || autoptimizeUtils::str_ends_in( $_preload, '.gif' ) ) { |
|
429 | + } elseif (autoptimizeUtils::str_ends_in($_preload, '.jpeg') || autoptimizeUtils::str_ends_in($_preload, '.jpg') || autoptimizeUtils::str_ends_in($_preload, '.webp') || autoptimizeUtils::str_ends_in($_preload, '.png') || autoptimizeUtils::str_ends_in($_preload, '.gif')) { |
|
430 | 430 | $preload_as = 'image'; |
431 | 431 | } else { |
432 | 432 | $preload_as = 'other'; |
433 | 433 | } |
434 | 434 | |
435 | - $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>'; |
|
435 | + $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>'; |
|
436 | 436 | } |
437 | - $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output ); |
|
437 | + $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output); |
|
438 | 438 | |
439 | 439 | // add string to head (before first link node by default). |
440 | - $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' ); |
|
441 | - $position = autoptimizeUtils::strpos( $in, $preload_inject ); |
|
440 | + $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link'); |
|
441 | + $position = autoptimizeUtils::strpos($in, $preload_inject); |
|
442 | 442 | |
443 | - return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) ); |
|
443 | + return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject)); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | public function admin_menu() |
447 | 447 | { |
448 | 448 | // no acces if multisite and not network admin and no site config allowed. |
449 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
449 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
450 | 450 | add_submenu_page( |
451 | 451 | null, |
452 | 452 | 'autoptimize_extra', |
453 | 453 | 'autoptimize_extra', |
454 | 454 | 'manage_options', |
455 | 455 | 'autoptimize_extra', |
456 | - array( $this, 'options_page' ) |
|
456 | + array($this, 'options_page') |
|
457 | 457 | ); |
458 | 458 | } |
459 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
459 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
460 | 460 | } |
461 | 461 | |
462 | - public function add_extra_tab( $in ) |
|
462 | + public function add_extra_tab($in) |
|
463 | 463 | { |
464 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
465 | - $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) ); |
|
464 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
465 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return $in; |
@@ -482,97 +482,97 @@ discard block |
||
482 | 482 | #ao_settings_form .form-table th {font-weight: normal;} |
483 | 483 | #autoptimize_extra_descr{font-size: 120%;} |
484 | 484 | </style> |
485 | - <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script> |
|
485 | + <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script> |
|
486 | 486 | <div class="wrap"> |
487 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
487 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
488 | 488 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
489 | - <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?> |
|
489 | + <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?> |
|
490 | 490 | <div class="notice-warning notice"><p> |
491 | - <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?> |
|
491 | + <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?> |
|
492 | 492 | </p></div> |
493 | 493 | <?php } ?> |
494 | 494 | |
495 | - <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'> |
|
496 | - <?php settings_fields( 'autoptimize_extra_settings' ); ?> |
|
497 | - <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2> |
|
498 | - <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span> |
|
495 | + <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'> |
|
496 | + <?php settings_fields('autoptimize_extra_settings'); ?> |
|
497 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
498 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
499 | 499 | <table class="form-table"> |
500 | 500 | <tr> |
501 | - <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th> |
|
501 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
502 | 502 | <td> |
503 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/> |
|
504 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/> |
|
503 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/> |
|
504 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/> |
|
505 | 505 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
506 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo __( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
506 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php echo __('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
507 | 507 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
508 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
509 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php echo __( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ) . ' ' . __( '(deprecated)', 'autoptimize' ); ?><br/> |
|
508 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php echo __('Combine and link deferred in head (fonts load late, but are not render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
509 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php echo __('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize').' '.__('(deprecated)', 'autoptimize'); ?><br/> |
|
510 | 510 | </td> |
511 | 511 | </tr> |
512 | 512 | <tr> |
513 | - <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th> |
|
513 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
514 | 514 | <td> |
515 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label> |
|
515 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label> |
|
516 | 516 | </td> |
517 | 517 | </tr> |
518 | 518 | <tr> |
519 | - <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th> |
|
519 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
520 | 520 | <td> |
521 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label> |
|
521 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label> |
|
522 | 522 | </td> |
523 | 523 | </tr> |
524 | 524 | <tr> |
525 | - <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
525 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
526 | 526 | <td> |
527 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label> |
|
527 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label> |
|
528 | 528 | </td> |
529 | 529 | </tr> |
530 | 530 | <tr> |
531 | - <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
531 | + <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
532 | 532 | <td> |
533 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php _e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label> |
|
533 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if (array_key_exists('autoptimize_extra_text_field_7', $options)) { echo esc_attr($options['autoptimize_extra_text_field_7']); } ?>'><br /><?php _e('Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize'); ?></label> |
|
534 | 534 | </td> |
535 | 535 | </tr> |
536 | 536 | <tr> |
537 | - <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
537 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
538 | 538 | <td> |
539 | 539 | <?php |
540 | - if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) { |
|
540 | + if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) { |
|
541 | 541 | // translators: link points Async Javascript settings page. |
542 | - printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' ); |
|
542 | + printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>'); |
|
543 | 543 | } else { |
544 | 544 | ?> |
545 | - <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'> |
|
545 | + <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'> |
|
546 | 546 | <br /> |
547 | 547 | <?php |
548 | - _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' ); |
|
548 | + _e('Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize'); |
|
549 | 549 | // translators: %s will be replaced by a link to the "async javascript" plugin. |
550 | - echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' ); |
|
551 | - $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
552 | - echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
550 | + echo sprintf(__('Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize'), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"'); |
|
551 | + $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
552 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
553 | 553 | } |
554 | 554 | ?> |
555 | 555 | </td> |
556 | 556 | </tr> |
557 | 557 | <tr> |
558 | - <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th> |
|
558 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
559 | 559 | <td> |
560 | 560 | <?php |
561 | - if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) { |
|
562 | - _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' ); |
|
561 | + if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
562 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
563 | 563 | $lyte_config_url = 'options-general.php?page=lyte_settings_page'; |
564 | - echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) ); |
|
564 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
565 | 565 | } else { |
566 | 566 | // translators: %s will be replaced by a link to "wp youtube lyte" plugin. |
567 | - echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' ); |
|
568 | - $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term'; |
|
569 | - echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
567 | + echo sprintf(__('%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize'), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>'); |
|
568 | + $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term'; |
|
569 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
570 | 570 | } |
571 | 571 | ?> |
572 | 572 | </td> |
573 | 573 | </tr> |
574 | 574 | </table> |
575 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
575 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
576 | 576 | </form> |
577 | 577 | <?php |
578 | 578 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Critical CSS job enqueue logic. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -12,27 +12,27 @@ discard block |
||
12 | 12 | { |
13 | 13 | // fetch all options at once and populate them individually explicitely as globals. |
14 | 14 | $all_options = autoptimizeCriticalCSSBase::fetch_options(); |
15 | - foreach ( $all_options as $_option => $_value ) { |
|
15 | + foreach ($all_options as $_option => $_value) { |
|
16 | 16 | global ${$_option}; |
17 | 17 | ${$_option} = $_value; |
18 | 18 | } |
19 | 19 | } |
20 | 20 | |
21 | - public static function ao_ccss_enqueue( $hash ) { |
|
21 | + public static function ao_ccss_enqueue($hash) { |
|
22 | 22 | $self = new self(); |
23 | 23 | // Get key status. |
24 | - $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( false ); |
|
24 | + $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(false); |
|
25 | 25 | |
26 | 26 | // Queue is available to anyone... |
27 | 27 | $enqueue = true; |
28 | 28 | |
29 | 29 | // ... which are not the ones below. |
30 | - if ( is_user_logged_in() || is_feed() || is_404() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters( 'autoptimize_filter_ccss_enqueue_should_enqueue', true ) ) { |
|
30 | + if (is_user_logged_in() || is_feed() || is_404() || (defined('DOING_AJAX') && DOING_AJAX) || $self->ao_ccss_ua() || 'nokey' == $key['status'] || 'invalid' == $key['status'] || false === apply_filters('autoptimize_filter_ccss_enqueue_should_enqueue', true)) { |
|
31 | 31 | $enqueue = false; |
32 | - autoptimizeCriticalCSSCore::ao_ccss_log( "Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3 ); |
|
32 | + autoptimizeCriticalCSSCore::ao_ccss_log("Job queuing is not available for WordPress's logged in users, feeds, error pages, ajax calls, to criticalcss.com itself or when a valid API key is not found", 3); |
|
33 | 33 | } |
34 | 34 | |
35 | - if ( $enqueue ) { |
|
35 | + if ($enqueue) { |
|
36 | 36 | // Continue if queue is available |
37 | 37 | // Attach required arrays/ vars. |
38 | 38 | global $ao_ccss_rules; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | global $ao_ccss_forcepath; |
42 | 42 | |
43 | 43 | // Get request path and page type, and initialize the queue update flag. |
44 | - $req_path = strtok( $_SERVER['REQUEST_URI'], '?' ); |
|
44 | + $req_path = strtok($_SERVER['REQUEST_URI'], '?'); |
|
45 | 45 | $req_type = $self->ao_ccss_get_type(); |
46 | 46 | $job_qualify = false; |
47 | 47 | $target_rule = false; |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | $queue_update = false; |
50 | 50 | |
51 | 51 | // Match for paths in rules. |
52 | - foreach ( $ao_ccss_rules['paths'] as $path => $props ) { |
|
52 | + foreach ($ao_ccss_rules['paths'] as $path => $props) { |
|
53 | 53 | |
54 | 54 | // Prepare rule target and log. |
55 | - $target_rule = 'paths|' . $path; |
|
56 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 ); |
|
55 | + $target_rule = 'paths|'.$path; |
|
56 | + autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3); |
|
57 | 57 | |
58 | 58 | // Path match |
59 | 59 | // -> exact match needed for AUTO rules |
60 | 60 | // -> partial match OK for MANUAL rules (which have empty hash and a file with CCSS). |
61 | - if ( $path === $req_path || ( false == $props['hash'] && false != $props['file'] && preg_match( '|' . $path . '|', $req_path ) ) ) { |
|
61 | + if ($path === $req_path || (false == $props['hash'] && false != $props['file'] && preg_match('|'.$path.'|', $req_path))) { |
|
62 | 62 | |
63 | 63 | // There's a path match in the rule, so job QUALIFIES with a path rule match. |
64 | 64 | $job_qualify = true; |
65 | 65 | $rule_properties = $props; |
66 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 ); |
|
66 | + autoptimizeCriticalCSSCore::ao_ccss_log('Path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3); |
|
67 | 67 | |
68 | 68 | // Stop processing other path rules. |
69 | 69 | break; |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | // Match for types in rules if no path rule matches and if we're not enforcing paths. |
74 | - if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) { |
|
75 | - foreach ( $ao_ccss_rules['types'] as $type => $props ) { |
|
74 | + if (!$job_qualify && (!$ao_ccss_forcepath || !in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page'))) || !apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false))) { |
|
75 | + foreach ($ao_ccss_rules['types'] as $type => $props) { |
|
76 | 76 | |
77 | 77 | // Prepare rule target and log. |
78 | - $target_rule = 'types|' . $type; |
|
79 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Qualifying page type <' . $req_type . '> on path <' . $req_path . '> for job submission by rule <' . $target_rule . '>', 3 ); |
|
78 | + $target_rule = 'types|'.$type; |
|
79 | + autoptimizeCriticalCSSCore::ao_ccss_log('Qualifying page type <'.$req_type.'> on path <'.$req_path.'> for job submission by rule <'.$target_rule.'>', 3); |
|
80 | 80 | |
81 | - if ( $req_type == $type ) { |
|
81 | + if ($req_type == $type) { |
|
82 | 82 | // Type match. |
83 | 83 | // There's a type match in the rule, so job QUALIFIES with a type rule match. |
84 | 84 | $job_qualify = true; |
85 | 85 | $rule_properties = $props; |
86 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Page type <' . $req_type . '> on path <' . $req_path . '> QUALIFIED for job submission by rule <' . $target_rule . '>', 3 ); |
|
86 | + autoptimizeCriticalCSSCore::ao_ccss_log('Page type <'.$req_type.'> on path <'.$req_path.'> QUALIFIED for job submission by rule <'.$target_rule.'>', 3); |
|
87 | 87 | |
88 | 88 | // Stop processing other type rules. |
89 | 89 | break; |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - if ( $job_qualify && ( ( false == $rule_properties['hash'] && false != $rule_properties['file'] ) || strpos( $req_type, 'template_' ) !== false ) ) { |
|
94 | + if ($job_qualify && ((false == $rule_properties['hash'] && false != $rule_properties['file']) || strpos($req_type, 'template_') !== false)) { |
|
95 | 95 | // If job qualifies but rule hash is false and file isn't false (MANUAL rule) or if template, job does not qualify despite what previous evaluations says. |
96 | 96 | $job_qualify = false; |
97 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission DISQUALIFIED by MANUAL rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 ); |
|
98 | - } elseif ( ! $job_qualify && empty( $rule_properties ) ) { |
|
97 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job submission DISQUALIFIED by MANUAL rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3); |
|
98 | + } elseif (!$job_qualify && empty($rule_properties)) { |
|
99 | 99 | // But if job does not qualify and rule properties are set, job qualifies as there is no matching rule for it yet |
100 | 100 | // Fill-in the new target rule. |
101 | 101 | $job_qualify = true; |
@@ -103,28 +103,28 @@ discard block |
||
103 | 103 | // Should we switch to path-base AUTO-rules? Conditions: |
104 | 104 | // 1. forcepath option has to be enabled (off by default) |
105 | 105 | // 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category). |
106 | - if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) { |
|
107 | - if ( '/' !== $req_path ) { |
|
108 | - $target_rule = 'paths|' . $req_path; |
|
106 | + if (($ao_ccss_forcepath && in_array($req_type, apply_filters('autoptimize_filter_ccss_coreenqueue_forcepathfortype', array('is_page')))) || apply_filters('autoptimize_filter_ccss_coreenqueue_ignorealltypes', false)) { |
|
107 | + if ('/' !== $req_path) { |
|
108 | + $target_rule = 'paths|'.$req_path; |
|
109 | 109 | } else { |
110 | 110 | // Exception; we don't want a path-based rule for "/" as that messes things up, hard-switch this to a type-based is_front_page rule. |
111 | - $target_rule = 'types|' . 'is_front_page'; |
|
111 | + $target_rule = 'types|'.'is_front_page'; |
|
112 | 112 | } |
113 | 113 | } else { |
114 | - $target_rule = 'types|' . $req_type; |
|
114 | + $target_rule = 'types|'.$req_type; |
|
115 | 115 | } |
116 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by MISSING rule for page type <' . $req_type . '> on path <' . $req_path . '>, new rule target is <' . $target_rule . '>', 3 ); |
|
116 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by MISSING rule for page type <'.$req_type.'> on path <'.$req_path.'>, new rule target is <'.$target_rule.'>', 3); |
|
117 | 117 | } else { |
118 | 118 | // Or just log a job qualified by a matching rule. |
119 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job submission QUALIFIED by AUTO rule <' . $target_rule . '> with hash <' . $rule_properties['hash'] . '> and file <' . $rule_properties['file'] . '>', 3 ); |
|
119 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job submission QUALIFIED by AUTO rule <'.$target_rule.'> with hash <'.$rule_properties['hash'].'> and file <'.$rule_properties['file'].'>', 3); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // Submit job. |
123 | - if ( $job_qualify ) { |
|
124 | - if ( ! array_key_exists( $req_path, $ao_ccss_queue ) ) { |
|
123 | + if ($job_qualify) { |
|
124 | + if (!array_key_exists($req_path, $ao_ccss_queue)) { |
|
125 | 125 | // This is a NEW job |
126 | 126 | // Merge job into the queue. |
127 | - $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job( |
|
127 | + $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job( |
|
128 | 128 | $req_path, |
129 | 129 | $target_rule, |
130 | 130 | $req_type, |
@@ -140,30 +140,30 @@ discard block |
||
140 | 140 | } else { |
141 | 141 | // This is an existing job |
142 | 142 | // The job is still NEW, most likely this is extra CSS file for the same page that needs a hash. |
143 | - if ( 'NEW' == $ao_ccss_queue[ $req_path ]['jqstat'] ) { |
|
143 | + if ('NEW' == $ao_ccss_queue[$req_path]['jqstat']) { |
|
144 | 144 | // Add hash if it's not already in the job. |
145 | - if ( ! in_array( $hash, $ao_ccss_queue[ $req_path ]['hashes'] ) ) { |
|
145 | + if (!in_array($hash, $ao_ccss_queue[$req_path]['hashes'])) { |
|
146 | 146 | // Push new hash to its array and update flag. |
147 | - $queue_update = array_push( $ao_ccss_queue[ $req_path ]['hashes'], $hash ); |
|
147 | + $queue_update = array_push($ao_ccss_queue[$req_path]['hashes'], $hash); |
|
148 | 148 | |
149 | 149 | // Log job update. |
150 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Hashes UPDATED on local job id <' . $ao_ccss_queue[ $req_path ]['ljid'] . '>, job status NEW, target rule <' . $ao_ccss_queue[ $req_path ]['rtarget'] . '>, hash added: ' . $hash, 3 ); |
|
150 | + autoptimizeCriticalCSSCore::ao_ccss_log('Hashes UPDATED on local job id <'.$ao_ccss_queue[$req_path]['ljid'].'>, job status NEW, target rule <'.$ao_ccss_queue[$req_path]['rtarget'].'>, hash added: '.$hash, 3); |
|
151 | 151 | |
152 | 152 | // Return from here as the hash array is already updated. |
153 | 153 | return true; |
154 | 154 | } |
155 | - } elseif ( 'NEW' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[ $req_path ]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[ $req_path ]['jqstat'] ) { |
|
155 | + } elseif ('NEW' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_QUEUED' != $ao_ccss_queue[$req_path]['jqstat'] && 'JOB_ONGOING' != $ao_ccss_queue[$req_path]['jqstat']) { |
|
156 | 156 | // Allow requeuing jobs that are not NEW, JOB_QUEUED or JOB_ONGOING |
157 | 157 | // Merge new job keeping some previous job values. |
158 | - $ao_ccss_queue[ $req_path ] = $self->ao_ccss_define_job( |
|
158 | + $ao_ccss_queue[$req_path] = $self->ao_ccss_define_job( |
|
159 | 159 | $req_path, |
160 | 160 | $target_rule, |
161 | 161 | $req_type, |
162 | 162 | $hash, |
163 | - $ao_ccss_queue[ $req_path ]['file'], |
|
164 | - $ao_ccss_queue[ $req_path ]['jid'], |
|
165 | - $ao_ccss_queue[ $req_path ]['jrstat'], |
|
166 | - $ao_ccss_queue[ $req_path ]['jvstat'], |
|
163 | + $ao_ccss_queue[$req_path]['file'], |
|
164 | + $ao_ccss_queue[$req_path]['jid'], |
|
165 | + $ao_ccss_queue[$req_path]['jrstat'], |
|
166 | + $ao_ccss_queue[$req_path]['jvstat'], |
|
167 | 167 | false |
168 | 168 | ); |
169 | 169 | // Set update flag. |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | - if ( $queue_update ) { |
|
174 | + if ($queue_update) { |
|
175 | 175 | // Persist the job to the queue and return. |
176 | - $ao_ccss_queue_raw = json_encode( $ao_ccss_queue ); |
|
177 | - update_option( 'autoptimize_ccss_queue', $ao_ccss_queue_raw, false ); |
|
176 | + $ao_ccss_queue_raw = json_encode($ao_ccss_queue); |
|
177 | + update_option('autoptimize_ccss_queue', $ao_ccss_queue_raw, false); |
|
178 | 178 | return true; |
179 | 179 | } else { |
180 | 180 | // Or just return false if no job was added. |
181 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'A job for path <' . $req_path . '> already exist with NEW or PENDING status, skipping job creation', 3 ); |
|
181 | + autoptimizeCriticalCSSCore::ao_ccss_log('A job for path <'.$req_path.'> already exist with NEW or PENDING status, skipping job creation', 3); |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | } |
@@ -194,29 +194,29 @@ discard block |
||
194 | 194 | $page_type = false; |
195 | 195 | |
196 | 196 | // Iterates over the array to match a type. |
197 | - foreach ( $ao_ccss_types as $type ) { |
|
198 | - if ( is_404() ) { |
|
197 | + foreach ($ao_ccss_types as $type) { |
|
198 | + if (is_404()) { |
|
199 | 199 | $page_type = 'is_404'; |
200 | 200 | break; |
201 | - } elseif ( strpos( $type, 'custom_post_' ) !== false ) { |
|
201 | + } elseif (strpos($type, 'custom_post_') !== false) { |
|
202 | 202 | // Match custom post types. |
203 | - if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) { |
|
203 | + if (get_post_type(get_the_ID()) === substr($type, 12)) { |
|
204 | 204 | $page_type = $type; |
205 | 205 | break; |
206 | 206 | } |
207 | - } elseif ( strpos( $type, 'template_' ) !== false ) { |
|
207 | + } elseif (strpos($type, 'template_') !== false) { |
|
208 | 208 | // Match templates. |
209 | - if ( is_page_template( substr( $type, 9 ) ) ) { |
|
209 | + if (is_page_template(substr($type, 9))) { |
|
210 | 210 | $page_type = $type; |
211 | 211 | break; |
212 | 212 | } |
213 | 213 | } else { |
214 | 214 | // Match all other existing types |
215 | 215 | // but remove prefix to be able to check if the function exists & returns true. |
216 | - $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type ); |
|
217 | - if ( function_exists( $_type ) && call_user_func( $_type ) ) { |
|
216 | + $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type); |
|
217 | + if (function_exists($_type) && call_user_func($_type)) { |
|
218 | 218 | // Make sure we only return is_front_page (and is_home) for one page, not for the "paged frontpage" (/page/2 ..). |
219 | - if ( ( 'is_front_page' !== $_type && 'is_home' !== $_type ) || ! is_paged() ) { |
|
219 | + if (('is_front_page' !== $_type && 'is_home' !== $_type) || !is_paged()) { |
|
220 | 220 | $page_type = $type; |
221 | 221 | break; |
222 | 222 | } |
@@ -228,44 +228,44 @@ discard block |
||
228 | 228 | return $page_type; |
229 | 229 | } |
230 | 230 | |
231 | - public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) { |
|
231 | + public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) { |
|
232 | 232 | // Define a job entry to be created or updated |
233 | 233 | // Define commom job properties. |
234 | 234 | $path = array(); |
235 | 235 | $path['ljid'] = $this->ao_ccss_job_id(); |
236 | 236 | $path['rtarget'] = $target; |
237 | 237 | $path['ptype'] = $type; |
238 | - $path['hashes'] = array( $hash ); |
|
238 | + $path['hashes'] = array($hash); |
|
239 | 239 | $path['hash'] = $hash; |
240 | 240 | $path['file'] = $file; |
241 | 241 | $path['jid'] = $jid; |
242 | 242 | $path['jqstat'] = 'NEW'; |
243 | 243 | $path['jrstat'] = $jrstat; |
244 | 244 | $path['jvstat'] = $jvstat; |
245 | - $path['jctime'] = microtime( true ); |
|
245 | + $path['jctime'] = microtime(true); |
|
246 | 246 | $path['jftime'] = null; |
247 | 247 | |
248 | 248 | // Set operation requested. |
249 | - if ( $create ) { |
|
249 | + if ($create) { |
|
250 | 250 | $operation = 'CREATED'; |
251 | 251 | } else { |
252 | 252 | $operation = 'UPDATED'; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // Log job creation. |
256 | - autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 ); |
|
256 | + autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3); |
|
257 | 257 | |
258 | 258 | return $path; |
259 | 259 | } |
260 | 260 | |
261 | - public function ao_ccss_job_id( $length = 6 ) { |
|
261 | + public function ao_ccss_job_id($length = 6) { |
|
262 | 262 | // Generate random strings for the local job ID |
263 | 263 | // Based on https://stackoverflow.com/a/4356295 . |
264 | 264 | $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; |
265 | - $characters_length = strlen( $characters ); |
|
265 | + $characters_length = strlen($characters); |
|
266 | 266 | $random_string = 'j-'; |
267 | - for ( $i = 0; $i < $length; $i++ ) { |
|
268 | - $random_string .= $characters[ rand( 0, $characters_length - 1 ) ]; |
|
267 | + for ($i = 0; $i < $length; $i++) { |
|
268 | + $random_string .= $characters[rand(0, $characters_length - 1)]; |
|
269 | 269 | } |
270 | 270 | return $random_string; |
271 | 271 | } |
@@ -273,17 +273,17 @@ discard block |
||
273 | 273 | public function ao_ccss_ua() { |
274 | 274 | // Check for criticalcss.com user agent. |
275 | 275 | $agent = ''; |
276 | - if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
276 | + if (isset($_SERVER['HTTP_USER_AGENT'])) { |
|
277 | 277 | $agent = $_SERVER['HTTP_USER_AGENT']; |
278 | 278 | } |
279 | 279 | |
280 | 280 | // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not. |
281 | - $rtn = strpos( $agent, AO_CCSS_URL ); |
|
282 | - if ( 0 === $rtn ) { |
|
281 | + $rtn = strpos($agent, AO_CCSS_URL); |
|
282 | + if (0 === $rtn) { |
|
283 | 283 | $rtn = true; |
284 | 284 | } else { |
285 | 285 | $rtn = false; |
286 | 286 | } |
287 | - return ( $rtn ); |
|
287 | + return ($rtn); |
|
288 | 288 | } |
289 | 289 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | global $ao_ccss_unloadccss; |
20 | 20 | |
21 | 21 | // In case domain is not set yet (done in cron.php). |
22 | - if ( empty( $ao_ccss_domain ) ) { |
|
22 | + if (empty($ao_ccss_domain)) { |
|
23 | 23 | $ao_ccss_domain = get_site_url(); |
24 | 24 | } |
25 | 25 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | ?> |
29 | 29 | <ul id="adv-panel"> |
30 | 30 | <li class="itemDetail"> |
31 | - <h2 class="itemTitle fleft"><?php _e( 'Advanced Settings', 'autoptimize' ); ?></h2> |
|
31 | + <h2 class="itemTitle fleft"><?php _e('Advanced Settings', 'autoptimize'); ?></h2> |
|
32 | 32 | <button type="button" class="toggle-btn"> |
33 | 33 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
34 | 34 | </button> |
@@ -36,114 +36,114 @@ discard block |
||
36 | 36 | <table id="key" class="form-table"> |
37 | 37 | <tr> |
38 | 38 | <th scope="row"> |
39 | - <?php _e( 'Viewport Size', 'autoptimize' ); ?> |
|
39 | + <?php _e('Viewport Size', 'autoptimize'); ?> |
|
40 | 40 | </th> |
41 | 41 | <td> |
42 | - <label for="autoptimize_ccss_vw"><?php _e( 'Width', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" /> |
|
43 | - <label for="autoptimize_ccss_vh"><?php _e( 'Height', 'autoptimize' ); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" /> |
|
42 | + <label for="autoptimize_ccss_vw"><?php _e('Width', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vw" name="autoptimize_ccss_viewport[w]" min="800" max="4096" placeholder="1400" value="<?php echo $viewport['w']; ?>" /> |
|
43 | + <label for="autoptimize_ccss_vh"><?php _e('Height', 'autoptimize'); ?>:</label> <input type="number" id="autoptimize_ccss_vh" name="autoptimize_ccss_viewport[h]" min="600" max="2160" placeholder="1080" value="<?php echo $viewport['h']; ?>" /> |
|
44 | 44 | <p class="notes"> |
45 | - <?php _e( '<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize' ); ?> |
|
45 | + <?php _e('<a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> default viewport size is 1400x1080 pixels (width x height). You can change this size by typing a desired width and height values above. Allowed value ranges are from 800 to 4096 for width and from 600 to 2160 for height.', 'autoptimize'); ?> |
|
46 | 46 | </p> |
47 | 47 | </td> |
48 | 48 | </tr> |
49 | 49 | <tr> |
50 | 50 | <th scope="row"> |
51 | - <?php _e( 'Force Include CSS selectors', 'autoptimize' ); ?> |
|
51 | + <?php _e('Force Include CSS selectors', 'autoptimize'); ?> |
|
52 | 52 | </th> |
53 | 53 | <td> |
54 | - <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e( '.button-special,//#footer', 'autoptimize' ); ?>"><?php echo trim( $ao_ccss_finclude ); ?></textarea> |
|
54 | + <textarea id="autoptimize_ccss_finclude" name="autoptimize_ccss_finclude" rows='3' maxlenght='500' style="width:100%;" placeholder="<?php _e('.button-special,//#footer', 'autoptimize'); ?>"><?php echo trim($ao_ccss_finclude); ?></textarea> |
|
55 | 55 | <p class="notes"> |
56 | - <?php _e( 'Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize' ); ?> |
|
56 | + <?php _e('Force include CSS selectors can be used to style dynamic content that is not part of the HTML that is seen during the Critical CSS generation. To use this feature, add comma separated values with both simple strings and/or regular expressions to match the desired selectors. Regular expressions must be preceeded by two forward slashes. For instance: <code>.button-special,//#footer</code>. In this example <code>.button-special</code> will match <code>.button-special</code> selector only, while <code>//#footer</code> will match <code>#footer</code>, <code>#footer-address</code> and <code>#footer-phone</code> selectors in case they exist.<br />Do take into account that changing this setting will only affect new/ updated rules, so you might want to remove old rules and clear your page cache to expedite the forceIncludes becoming used.', 'autoptimize'); ?> |
|
57 | 57 | </p> |
58 | 58 | </td> |
59 | 59 | </tr> |
60 | 60 | <tr> |
61 | 61 | <th scope="row"> |
62 | - <?php _e( 'Request Limit', 'autoptimize' ); ?> |
|
62 | + <?php _e('Request Limit', 'autoptimize'); ?> |
|
63 | 63 | </th> |
64 | 64 | <td> |
65 | 65 | <input type="number" id="autoptimize_ccss_rlimit" name="autoptimize_ccss_rlimit" min="1" max="240" placeholder="0" value="<?php echo $ao_ccss_rlimit; ?>" /> |
66 | 66 | <p class="notes"> |
67 | - <?php _e( 'Certain hosting services impose hard limitations to background processes on either execution time, requests made from your server to any third party services, or both. This could lead to a faulty operation of the queue background process triggered by WP-Cron. If automated rules are not being created, you may be facing this limitation from your hosting provider. In that case, set the request limit to a reasonable number between 1 and 240. The queue fire a request to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> on every 15 seconds (due to service limitations). If your hosting provider allows a 60 seconds time span to background processes runtime, set this value to 3 or 4 so the queue can operate within the boundaries. The maximum value of 240 allows enough requests for one hour long. To disable this limit and to let requests be made at will, just delete any values in this setting (a grey 0 will show).', 'autoptimize' ); ?> |
|
67 | + <?php _e('Certain hosting services impose hard limitations to background processes on either execution time, requests made from your server to any third party services, or both. This could lead to a faulty operation of the queue background process triggered by WP-Cron. If automated rules are not being created, you may be facing this limitation from your hosting provider. In that case, set the request limit to a reasonable number between 1 and 240. The queue fire a request to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> on every 15 seconds (due to service limitations). If your hosting provider allows a 60 seconds time span to background processes runtime, set this value to 3 or 4 so the queue can operate within the boundaries. The maximum value of 240 allows enough requests for one hour long. To disable this limit and to let requests be made at will, just delete any values in this setting (a grey 0 will show).', 'autoptimize'); ?> |
|
68 | 68 | </p> |
69 | 69 | </td> |
70 | 70 | </tr> |
71 | 71 | <tr> |
72 | 72 | <th scope="row"> |
73 | - <?php _e( 'Fetch Original CSS', 'autoptimize' ); ?> |
|
73 | + <?php _e('Fetch Original CSS', 'autoptimize'); ?> |
|
74 | 74 | </th> |
75 | 75 | <td> |
76 | - <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked( 1 == $ao_ccss_noptimize ); ?>> |
|
76 | + <input type="checkbox" id="autoptimize_ccss_noptimize" name="autoptimize_ccss_noptimize" value="1" <?php checked(1 == $ao_ccss_noptimize); ?>> |
|
77 | 77 | <p class="notes"> |
78 | - <?php _e( 'In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize' ); ?> |
|
78 | + <?php _e('In some (rare) cases the generation of critical CSS works better with the original CSS instead of the Autoptimized one, this option enables that behavior.', 'autoptimize'); ?> |
|
79 | 79 | </p> |
80 | 80 | </td> |
81 | 81 | </tr> |
82 | 82 | <tr> |
83 | 83 | <th scope="row"> |
84 | - <?php _e( 'Add CCSS for logged in users?', 'autoptimize' ); ?> |
|
84 | + <?php _e('Add CCSS for logged in users?', 'autoptimize'); ?> |
|
85 | 85 | </th> |
86 | 86 | <td> |
87 | - <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked( 1 == $ao_ccss_loggedin ); ?>> |
|
87 | + <input type="checkbox" id="autoptimize_ccss_loggedin" name="autoptimize_ccss_loggedin" value="1" <?php checked(1 == $ao_ccss_loggedin); ?>> |
|
88 | 88 | <p class="notes"> |
89 | - <?php _e( 'Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize' ); ?> |
|
89 | + <?php _e('Critical CSS is generated by criticalcss.com from your pages as seen be "anonymous visitor", disable this option if you don\'t want the "visitor" critical CSS to be used for logged on users.', 'autoptimize'); ?> |
|
90 | 90 | </p> |
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | <tr> |
94 | 94 | <th scope="row"> |
95 | - <?php _e( 'Force path-based rules to be generated for pages?', 'autoptimize' ); ?> |
|
95 | + <?php _e('Force path-based rules to be generated for pages?', 'autoptimize'); ?> |
|
96 | 96 | </th> |
97 | 97 | <td> |
98 | - <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked( 1 == $ao_ccss_forcepath ); ?>> |
|
98 | + <input type="checkbox" id="autoptimize_ccss_forcepath" name="autoptimize_ccss_forcepath" value="1" <?php checked(1 == $ao_ccss_forcepath); ?>> |
|
99 | 99 | <p class="notes"> |
100 | - <?php _e( 'By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize' ); ?> |
|
100 | + <?php _e('By default for each page a separate rule is generated. If your pages have (semi-)identical above the fold look and feel and you want to keep the rules lean, you can disable that so one rule is created to all pages.', 'autoptimize'); ?> |
|
101 | 101 | </p> |
102 | 102 | </td> |
103 | 103 | </tr> |
104 | 104 | <tr> |
105 | 105 | <th scope="row"> |
106 | - <?php _e( 'Defer jQuery and other non-aggregated JS-files?', 'autoptimize' ); ?> |
|
106 | + <?php _e('Defer jQuery and other non-aggregated JS-files?', 'autoptimize'); ?> |
|
107 | 107 | </th> |
108 | 108 | <td> |
109 | - <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked( 1 == $ao_ccss_deferjquery ); ?>> |
|
109 | + <input type="checkbox" id="autoptimize_ccss_deferjquery" name="autoptimize_ccss_deferjquery" value="1" <?php checked(1 == $ao_ccss_deferjquery); ?>> |
|
110 | 110 | <p class="notes"> |
111 | - <?php _e( 'Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize' ); ?> |
|
111 | + <?php _e('Defer all non-aggregated JS, including jQuery and inline JS to fix remaining render-blocking issues. Make sure to test your site thoroughly when activating this option!', 'autoptimize'); ?> |
|
112 | 112 | </p> |
113 | 113 | </td> |
114 | 114 | </tr> |
115 | 115 | <tr> |
116 | 116 | <th scope="row"> |
117 | - <?php _e( 'Unload critical CSS after page load?', 'autoptimize' ); ?> |
|
117 | + <?php _e('Unload critical CSS after page load?', 'autoptimize'); ?> |
|
118 | 118 | </th> |
119 | 119 | <td> |
120 | - <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked( 1 == $ao_ccss_unloadccss ); ?>> |
|
120 | + <input type="checkbox" id="autoptimize_ccss_unloadccss" name="autoptimize_ccss_unloadccss" value="1" <?php checked(1 == $ao_ccss_unloadccss); ?>> |
|
121 | 121 | <p class="notes"> |
122 | - <?php _e( 'In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize' ); ?> |
|
122 | + <?php _e('In rare cases the critical CSS needs to be removed once the full CSS loads, this option makes it so!', 'autoptimize'); ?> |
|
123 | 123 | </p> |
124 | 124 | </td> |
125 | 125 | </tr> |
126 | 126 | <tr> |
127 | 127 | <th scope="row"> |
128 | - <?php _e( 'Bound domain', 'autoptimize' ); ?> |
|
128 | + <?php _e('Bound domain', 'autoptimize'); ?> |
|
129 | 129 | </th> |
130 | 130 | <td> |
131 | - <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e( 'Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize' ); ?>" value="<?php echo trim( $ao_ccss_domain ); ?>"> |
|
131 | + <input type="text" id="autoptimize_ccss_domain" name="autoptimize_ccss_domain" style="width:100%;" placeholder="<?php _e('Don\'t leave this empty, put e.g. https://example.net/ or simply \'none\' to disable domain binding.', 'autoptimize'); ?>" value="<?php echo trim($ao_ccss_domain); ?>"> |
|
132 | 132 | <p class="notes"> |
133 | - <?php _e( 'Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize' ); ?> |
|
133 | + <?php _e('Only requests from this domain will be sent for Critical CSS generation (pricing is per domain/ month).', 'autoptimize'); ?> |
|
134 | 134 | </p> |
135 | 135 | </td> |
136 | 136 | </tr> |
137 | 137 | <tr> |
138 | 138 | <th scope="row"> |
139 | - <?php _e( 'Debug Mode', 'autoptimize' ); ?> |
|
139 | + <?php _e('Debug Mode', 'autoptimize'); ?> |
|
140 | 140 | </th> |
141 | 141 | <td> |
142 | - <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked( 1 == $ao_ccss_debug ); ?>> |
|
142 | + <input type="checkbox" id="autoptimize_ccss_debug" name="autoptimize_ccss_debug" value="1" <?php checked(1 == $ao_ccss_debug); ?>> |
|
143 | 143 | <p class="notes"> |
144 | 144 | <?php |
145 | - _e( '<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize' ); |
|
146 | - echo '<code>' . AO_CCSS_LOG . '</code>'; |
|
145 | + _e('<strong>CAUTION! Only use debug mode on production/live environments for ad-hoc troubleshooting and remember to turn it back off after</strong>, as this generates a lot of log-data.<br />Check the box above to enable Autoptimize CriticalCSS Power-Up debug mode. It provides debug facilities in this screen, to the browser console and to this file: ', 'autoptimize'); |
|
146 | + echo '<code>'.AO_CCSS_LOG.'</code>'; |
|
147 | 147 | ?> |
148 | 148 | </p> |
149 | 149 | </td> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Critical CSS Options page. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -17,34 +17,34 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
|
20 | + $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http); |
|
21 | 21 | $this->run(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | protected function enabled() |
25 | 25 | { |
26 | - return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true ); |
|
26 | + return apply_filters('autoptimize_filter_show_criticalcss_tabs', true); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function run() |
30 | 30 | { |
31 | - if ( $this->enabled() ) { |
|
32 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 ); |
|
33 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) ); |
|
31 | + if ($this->enabled()) { |
|
32 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1); |
|
33 | + add_action('admin_enqueue_scripts', array($this, 'admin_assets')); |
|
34 | 34 | |
35 | - if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
36 | - add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
|
35 | + if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
36 | + add_action('network_admin_menu', array($this, 'add_critcss_admin_menu')); |
|
37 | 37 | } else { |
38 | - add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
|
38 | + add_action('admin_menu', array($this, 'add_critcss_admin_menu')); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax(); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - public function add_critcss_tabs( $in ) |
|
45 | + public function add_critcss_tabs($in) |
|
46 | 46 | { |
47 | - $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) ); |
|
47 | + $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize'))); |
|
48 | 48 | |
49 | 49 | return $in; |
50 | 50 | } |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | public function add_critcss_admin_menu() |
53 | 53 | { |
54 | 54 | // Register settings. |
55 | - register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' ); |
|
56 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' ); |
|
57 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' ); |
|
58 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' ); |
|
59 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' ); |
|
60 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' ); |
|
61 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rlimit' ); |
|
62 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' ); |
|
63 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' ); |
|
64 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' ); |
|
65 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' ); |
|
66 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' ); |
|
67 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' ); |
|
68 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' ); |
|
69 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' ); |
|
70 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' ); |
|
55 | + register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline'); |
|
56 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules'); |
|
57 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional'); |
|
58 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue'); |
|
59 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport'); |
|
60 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude'); |
|
61 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_rlimit'); |
|
62 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize'); |
|
63 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug'); |
|
64 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_key'); |
|
65 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst'); |
|
66 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin'); |
|
67 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath'); |
|
68 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery'); |
|
69 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain'); |
|
70 | + register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss'); |
|
71 | 71 | |
72 | 72 | // And add submenu-page. |
73 | - add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) ); |
|
73 | + add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page')); |
|
74 | 74 | } |
75 | 75 | |
76 | - public function admin_assets( $hook ) { |
|
76 | + public function admin_assets($hook) { |
|
77 | 77 | // Return if plugin is not hooked. |
78 | - if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) { |
|
78 | + if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Stylesheets to add. |
83 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
84 | - wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) ); |
|
85 | - wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) ); |
|
83 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
84 | + wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__)); |
|
85 | + wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__)); |
|
86 | 86 | |
87 | 87 | // Scripts to add. |
88 | - wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) ); |
|
89 | - wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true ); |
|
90 | - wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
91 | - wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
88 | + wp_enqueue_script('jquery-ui-dialog', array('jquery')); |
|
89 | + wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true); |
|
90 | + wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true); |
|
91 | + wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function ao_criticalcsssettings_page() |
95 | 95 | { |
96 | 96 | // these are not OO yet, simply require for now. |
97 | - require_once( 'critcss-inc/admin_settings_rules.php' ); |
|
98 | - require_once( 'critcss-inc/admin_settings_queue.php' ); |
|
99 | - require_once( 'critcss-inc/admin_settings_key.php' ); |
|
100 | - require_once( 'critcss-inc/admin_settings_adv.php' ); |
|
101 | - require_once( 'critcss-inc/admin_settings_explain.php' ); |
|
97 | + require_once('critcss-inc/admin_settings_rules.php'); |
|
98 | + require_once('critcss-inc/admin_settings_queue.php'); |
|
99 | + require_once('critcss-inc/admin_settings_key.php'); |
|
100 | + require_once('critcss-inc/admin_settings_adv.php'); |
|
101 | + require_once('critcss-inc/admin_settings_explain.php'); |
|
102 | 102 | |
103 | 103 | // fetch all options at once and populate them individually explicitely as globals. |
104 | 104 | $all_options = autoptimizeCriticalCSSBase::fetch_options(); |
105 | - foreach ( $all_options as $_option => $_value ) { |
|
105 | + foreach ($all_options as $_option => $_value) { |
|
106 | 106 | global ${$_option}; |
107 | 107 | ${$_option} = $_value; |
108 | 108 | } |
109 | 109 | ?> |
110 | - <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script> |
|
110 | + <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script> |
|
111 | 111 | <div class="wrap"> |
112 | 112 | <div id="autoptimize_main"> |
113 | 113 | <div id="ao_title_and_button"> |
114 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
114 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
115 | 115 | </div> |
116 | 116 | |
117 | 117 | <?php |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | echo autoptimizeConfig::ao_admin_tabs(); |
120 | 120 | |
121 | 121 | // Make sure dir to write ao_ccss exists and is writable. |
122 | - if ( ! is_dir( AO_CCSS_DIR ) ) { |
|
123 | - $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine |
|
124 | - $fileresp = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); |
|
125 | - if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) { |
|
122 | + if (!is_dir(AO_CCSS_DIR)) { |
|
123 | + $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine |
|
124 | + $fileresp = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>'); |
|
125 | + if ((!$mkdirresp) || (!$fileresp)) { |
|
126 | 126 | ?> |
127 | 127 | <div class="notice-error notice"><p> |
128 | 128 | <?php |
129 | - _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' ); |
|
129 | + _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize'); |
|
130 | 130 | ?> |
131 | 131 | </p></div> |
132 | 132 | <?php |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | // Check for Autoptimize. |
137 | - if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) { |
|
137 | + if (!empty($ao_ccss_key) && !$ao_css_defer) { |
|
138 | 138 | ?> |
139 | 139 | <div class="notice-error notice"><p> |
140 | 140 | <?php |
141 | - _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' ); |
|
141 | + _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize'); |
|
142 | 142 | ?> |
143 | 143 | </p></div> |
144 | 144 | <?php |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | // check if WordPress cron is disabled and warn if so. |
149 | - if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) { |
|
149 | + if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) { |
|
150 | 150 | ?> |
151 | 151 | <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p> |
152 | 152 | <?php |
153 | - _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); |
|
153 | + _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize'); |
|
154 | 154 | ?> |
155 | 155 | </p></div> |
156 | 156 | <?php |
@@ -158,24 +158,24 @@ discard block |
||
158 | 158 | |
159 | 159 | // warn if it looks as though the queue processing job looks isn't running |
160 | 160 | // but store result in transient as to not to have to go through 2 arrays each and every time. |
161 | - $_warn_cron = get_transient( 'ao_ccss_cronwarning' ); |
|
162 | - if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) { |
|
161 | + $_warn_cron = get_transient('ao_ccss_cronwarning'); |
|
162 | + if (!empty($ao_ccss_key) && false === $_warn_cron) { |
|
163 | 163 | $_jobs_all_new = true; |
164 | - $_oldest_job_timestamp = microtime( true ); // now. |
|
164 | + $_oldest_job_timestamp = microtime(true); // now. |
|
165 | 165 | $_jobs_too_old = true; |
166 | 166 | |
167 | 167 | // go over queue array. |
168 | - if ( empty( $ao_ccss_queue ) ) { |
|
168 | + if (empty($ao_ccss_queue)) { |
|
169 | 169 | // no jobs, then no warning. |
170 | 170 | $_jobs_all_new = false; |
171 | 171 | } else { |
172 | - foreach ( $ao_ccss_queue as $job ) { |
|
173 | - if ( $job['jctime'] < $_oldest_job_timestamp ) { |
|
172 | + foreach ($ao_ccss_queue as $job) { |
|
173 | + if ($job['jctime'] < $_oldest_job_timestamp) { |
|
174 | 174 | // we need to catch the oldest job's timestamp. |
175 | 175 | $_oldest_job_timestamp = $job['jctime']; |
176 | 176 | } |
177 | 177 | |
178 | - if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) { |
|
178 | + if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) { |
|
179 | 179 | // we have a non-"NEW" job which is not our pending firstrun job either, break the loop. |
180 | 180 | $_jobs_all_new = false; |
181 | 181 | break; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | // is the oldest job too old (4h)? |
187 | - if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) { |
|
187 | + if ($_oldest_job_timestamp > microtime(true) - 60*60*4) { |
|
188 | 188 | $_jobs_too_old = false; |
189 | 189 | } |
190 | 190 | |
191 | - if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) { |
|
191 | + if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) { |
|
192 | 192 | $_warn_cron = 'on'; |
193 | 193 | $_transient_multiplier = 1; // store for 1 hour. |
194 | 194 | } else { |
@@ -196,33 +196,33 @@ discard block |
||
196 | 196 | $_transient_multiplier = 4; // store for 4 hours. |
197 | 197 | } |
198 | 198 | // and set transient. |
199 | - set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS ); |
|
199 | + set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS); |
|
200 | 200 | } |
201 | 201 | |
202 | - if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) { |
|
202 | + if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) { |
|
203 | 203 | ?> |
204 | 204 | <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p> |
205 | 205 | <?php |
206 | - _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); |
|
206 | + _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize'); |
|
207 | 207 | ?> |
208 | 208 | </p></div> |
209 | 209 | <?php |
210 | - } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) { |
|
210 | + } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) { |
|
211 | 211 | ?> |
212 | 212 | <div class="notice-success notice"><p> |
213 | 213 | <?php |
214 | - _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' ); |
|
214 | + _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize'); |
|
215 | 215 | ?> |
216 | 216 | </p></div> |
217 | 217 | <?php |
218 | 218 | } |
219 | 219 | |
220 | 220 | // warn if service is down. |
221 | - if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) { |
|
221 | + if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) { |
|
222 | 222 | ?> |
223 | 223 | <div class="notice-warning notice"><p> |
224 | 224 | <?php |
225 | - _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' ); |
|
225 | + _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize'); |
|
226 | 226 | ?> |
227 | 227 | </p></div> |
228 | 228 | <?php |
@@ -232,24 +232,24 @@ discard block |
||
232 | 232 | ?> |
233 | 233 | <form id="settings" method="post" action="options.php"> |
234 | 234 | <?php |
235 | - settings_fields( 'ao_ccss_options_group' ); |
|
235 | + settings_fields('ao_ccss_options_group'); |
|
236 | 236 | |
237 | 237 | // Get API key status. |
238 | - $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true ); |
|
238 | + $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true); |
|
239 | 239 | |
240 | - if ( $this->is_multisite_network_admin() ) { |
|
240 | + if ($this->is_multisite_network_admin()) { |
|
241 | 241 | ?> |
242 | 242 | <ul id="key-panel"> |
243 | 243 | <li class="itemDetail"> |
244 | 244 | <?php |
245 | 245 | // translators: the placesholder is for a line of code in wp-config.php. |
246 | - echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' ); |
|
246 | + echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>'); |
|
247 | 247 | ?> |
248 | 248 | </li> |
249 | 249 | </ul> |
250 | 250 | <?php |
251 | 251 | } else { |
252 | - if ( 'valid' == $key['status'] ) { |
|
252 | + if ('valid' == $key['status']) { |
|
253 | 253 | // If key status is valid, render other panels. |
254 | 254 | // Render rules section. |
255 | 255 | ao_ccss_render_rules(); |
@@ -266,23 +266,23 @@ discard block |
||
266 | 266 | $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport(); |
267 | 267 | |
268 | 268 | // Add hidden fields. |
269 | - echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>"; |
|
270 | - echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>"; |
|
271 | - echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">'; |
|
272 | - echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">'; |
|
273 | - echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">'; |
|
274 | - echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">'; |
|
275 | - echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">'; |
|
276 | - echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">'; |
|
277 | - echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">'; |
|
278 | - echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">'; |
|
279 | - echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">'; |
|
269 | + echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>"; |
|
270 | + echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>"; |
|
271 | + echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">'; |
|
272 | + echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">'; |
|
273 | + echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">'; |
|
274 | + echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="'.$ao_ccss_rlimit.'">'; |
|
275 | + echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">'; |
|
276 | + echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">'; |
|
277 | + echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">'; |
|
278 | + echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">'; |
|
279 | + echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">'; |
|
280 | 280 | } |
281 | 281 | // Render key panel unconditionally. |
282 | - ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] ); |
|
282 | + ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']); |
|
283 | 283 | ?> |
284 | 284 | <p class="submit left"> |
285 | - <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> |
|
285 | + <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /> |
|
286 | 286 | </p> |
287 | 287 | <?php |
288 | 288 | } |
@@ -300,31 +300,31 @@ discard block |
||
300 | 300 | }); |
301 | 301 | } |
302 | 302 | </script> |
303 | - <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>> |
|
304 | - <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span> |
|
305 | - <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" /> |
|
303 | + <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>> |
|
304 | + <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span> |
|
305 | + <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" /> |
|
306 | 306 | <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" /> |
307 | 307 | </form> |
308 | 308 | <div id="importdialog"></div> |
309 | 309 | </div><!-- /#autoptimize_main --> |
310 | 310 | </div><!-- /#wrap --> |
311 | 311 | <?php |
312 | - if ( ! $this->is_multisite_network_admin() ) { |
|
312 | + if (!$this->is_multisite_network_admin()) { |
|
313 | 313 | // Include debug panel if debug mode is enable. |
314 | - if ( $ao_ccss_debug ) { |
|
314 | + if ($ao_ccss_debug) { |
|
315 | 315 | ?> |
316 | 316 | <div id="debug"> |
317 | 317 | <?php |
318 | 318 | // Include debug panel. |
319 | - include( 'critcss-inc/admin_settings_debug.php' ); |
|
319 | + include('critcss-inc/admin_settings_debug.php'); |
|
320 | 320 | ?> |
321 | 321 | </div><!-- /#debug --> |
322 | 322 | <?php |
323 | 323 | } |
324 | 324 | echo '<script>'; |
325 | - include( 'critcss-inc/admin_settings_rules.js.php' ); |
|
326 | - include( 'critcss-inc/admin_settings_queue.js.php' ); |
|
327 | - include( 'critcss-inc/admin_settings_impexp.js.php' ); |
|
325 | + include('critcss-inc/admin_settings_rules.js.php'); |
|
326 | + include('critcss-inc/admin_settings_queue.js.php'); |
|
327 | + include('critcss-inc/admin_settings_impexp.js.php'); |
|
328 | 328 | echo '</script>'; |
329 | 329 | } |
330 | 330 | } |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | public static function ao_ccss_has_autorules() { |
333 | 333 | static $_has_auto_rules = null; |
334 | 334 | |
335 | - if ( null === $_has_auto_rules ) { |
|
335 | + if (null === $_has_auto_rules) { |
|
336 | 336 | global $ao_ccss_rules; |
337 | 337 | $_has_auto_rules = false; |
338 | - if ( ! empty( $ao_ccss_rules ) ) { |
|
339 | - foreach ( array( 'types', 'paths' ) as $_typat ) { |
|
340 | - foreach ( $ao_ccss_rules[ $_typat ] as $rule ) { |
|
341 | - if ( ! empty( $rule['hash'] ) ) { |
|
338 | + if (!empty($ao_ccss_rules)) { |
|
339 | + foreach (array('types', 'paths') as $_typat) { |
|
340 | + foreach ($ao_ccss_rules[$_typat] as $rule) { |
|
341 | + if (!empty($rule['hash'])) { |
|
342 | 342 | // we have at least one AUTO job, so all is fine. |
343 | 343 | $_has_auto_rules = true; |
344 | 344 | break; |
345 | 345 | } |
346 | 346 | } |
347 | - if ( $_has_auto_rules ) { |
|
347 | + if ($_has_auto_rules) { |
|
348 | 348 | break; |
349 | 349 | } |
350 | 350 | } |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | public function is_multisite_network_admin() { |
358 | 358 | static $_multisite_network_admin = null; |
359 | 359 | |
360 | - if ( null === $_multisite_network_admin ) { |
|
361 | - if ( is_multisite() && is_network_admin() ) { |
|
360 | + if (null === $_multisite_network_admin) { |
|
361 | + if (is_multisite() && is_network_admin()) { |
|
362 | 362 | $_multisite_network_admin = true; |
363 | 363 | } else { |
364 | 364 | $_multisite_network_admin = false; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Main configuration logic. |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -35,32 +35,32 @@ discard block |
||
35 | 35 | */ |
36 | 36 | private function __construct() |
37 | 37 | { |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | // Add the admin page and settings. |
40 | - if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
41 | - add_action( 'network_admin_menu', array( $this, 'addmenu' ) ); |
|
40 | + if (autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
41 | + add_action('network_admin_menu', array($this, 'addmenu')); |
|
42 | 42 | } |
43 | 43 | |
44 | - add_action( 'admin_menu', array( $this, 'addmenu' ) ); |
|
45 | - add_action( 'admin_init', array( $this, 'registersettings' ) ); |
|
44 | + add_action('admin_menu', array($this, 'addmenu')); |
|
45 | + add_action('admin_init', array($this, 'registersettings')); |
|
46 | 46 | |
47 | 47 | // Set meta info. |
48 | - if ( function_exists( 'plugin_row_meta' ) ) { |
|
48 | + if (function_exists('plugin_row_meta')) { |
|
49 | 49 | // 2.8 and higher. |
50 | - add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 ); |
|
51 | - } elseif ( function_exists( 'post_class' ) ) { |
|
50 | + add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2); |
|
51 | + } elseif (function_exists('post_class')) { |
|
52 | 52 | // 2.7 and lower. |
53 | - $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); |
|
54 | - add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) ); |
|
53 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
54 | + add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | // Clean cache? |
58 | - if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) { |
|
58 | + if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) { |
|
59 | 59 | autoptimizeCache::clearall(); |
60 | - autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 ); |
|
60 | + autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0); |
|
61 | 61 | } |
62 | 62 | |
63 | - $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
|
63 | + $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Adds the Autoptimize Toolbar to the Admin bar. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | static public function instance() |
77 | 77 | { |
78 | 78 | // Only one instance. |
79 | - if ( null === self::$instance ) { |
|
79 | + if (null === self::$instance) { |
|
80 | 80 | self::$instance = new autoptimizeConfig(); |
81 | 81 | } |
82 | 82 | |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | public function show_network_message() { |
87 | 87 | ?> |
88 | 88 | <div class="wrap"> |
89 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
89 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
90 | 90 | <?php echo $this->ao_admin_tabs(); ?> |
91 | - <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p> |
|
91 | + <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p> |
|
92 | 92 | </div> |
93 | 93 | <?php |
94 | 94 | } |
@@ -181,32 +181,32 @@ discard block |
||
181 | 181 | <div class="wrap"> |
182 | 182 | |
183 | 183 | <!-- Temporary nudge to disable aoccss power-up. --> |
184 | -<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?> |
|
184 | +<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?> |
|
185 | 185 | <div class="notice-info notice"><p> |
186 | - <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?> |
|
186 | + <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?> |
|
187 | 187 | </p></div> |
188 | 188 | <?php } ?> |
189 | 189 | |
190 | 190 | <div id="autoptimize_main"> |
191 | - <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
191 | + <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
192 | 192 | <?php echo $this->ao_admin_tabs(); ?> |
193 | 193 | |
194 | -<form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> |
|
195 | -<?php settings_fields( 'autoptimize' ); ?> |
|
194 | +<form method="post" action="<?php echo admin_url('options.php'); ?>"> |
|
195 | +<?php settings_fields('autoptimize'); ?> |
|
196 | 196 | |
197 | 197 | <ul> |
198 | 198 | |
199 | 199 | <?php |
200 | 200 | // Only show enable site configuration in network site option. |
201 | -if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
201 | +if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
202 | 202 | ?> |
203 | 203 | <li class="itemDetail multiSite"> |
204 | - <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2> |
|
204 | + <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2> |
|
205 | 205 | <table class="form-table"> |
206 | 206 | <tr valign="top"> |
207 | - <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th> |
|
208 | - <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/> |
|
209 | - <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td> |
|
207 | + <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th> |
|
208 | + <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/> |
|
209 | + <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td> |
|
210 | 210 | </tr> |
211 | 211 | </table> |
212 | 212 | </li> |
@@ -215,115 +215,115 @@ discard block |
||
215 | 215 | <?php } ?> |
216 | 216 | |
217 | 217 | <li class="itemDetail"> |
218 | -<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2> |
|
218 | +<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2> |
|
219 | 219 | <table class="form-table"> |
220 | 220 | <tr valign="top"> |
221 | -<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th> |
|
222 | -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
221 | +<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th> |
|
222 | +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td> |
|
223 | 223 | </tr> |
224 | 224 | <tr valign="top" class="js_sub"> |
225 | -<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th> |
|
226 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
227 | -<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> |
|
225 | +<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th> |
|
226 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
227 | +<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td> |
|
228 | 228 | </tr> |
229 | 229 | <tr valign="top" class="js_sub js_aggregate"> |
230 | -<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th> |
|
231 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/> |
|
232 | -<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td> |
|
230 | +<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th> |
|
231 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/> |
|
232 | +<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td> |
|
233 | 233 | </tr> |
234 | 234 | <tr valign="top" class="js_sub js_aggregate"> |
235 | -<th scope="row"><?php _e( 'Force JavaScript in <head>?', 'autoptimize' ); ?></th> |
|
236 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/> |
|
237 | -<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td> |
|
235 | +<th scope="row"><?php _e('Force JavaScript in <head>?', 'autoptimize'); ?></th> |
|
236 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/> |
|
237 | +<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td> |
|
238 | 238 | </tr> |
239 | -<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?> |
|
239 | +<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?> |
|
240 | 240 | <tr valign="top" class="js_sub js_aggregate"> |
241 | 241 | <th scope="row"> |
242 | 242 | <?php |
243 | - _e( 'Look for scripts only in <head>?', 'autoptimize' ); |
|
244 | - echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; |
|
243 | + _e('Look for scripts only in <head>?', 'autoptimize'); |
|
244 | + echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>'; |
|
245 | 245 | ?> |
246 | 246 | </th> |
247 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/> |
|
248 | -<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td> |
|
247 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/> |
|
248 | +<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td> |
|
249 | 249 | </tr> |
250 | 250 | <?php } ?> |
251 | 251 | <tr valign="top" class="js_sub"> |
252 | -<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th> |
|
253 | -<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ); ?>"/><br /> |
|
252 | +<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th> |
|
253 | +<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js'); ?>"/><br /> |
|
254 | 254 | <?php |
255 | -echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); |
|
255 | +echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize'); |
|
256 | 256 | ?> |
257 | 257 | </label></td> |
258 | 258 | </tr> |
259 | 259 | <tr valign="top" class="js_sub js_aggregate"> |
260 | -<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th> |
|
261 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/> |
|
262 | -<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td> |
|
260 | +<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th> |
|
261 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/> |
|
262 | +<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td> |
|
263 | 263 | </tr> |
264 | 264 | </table> |
265 | 265 | </li> |
266 | 266 | |
267 | 267 | <li class="itemDetail"> |
268 | -<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2> |
|
268 | +<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2> |
|
269 | 269 | <table class="form-table"> |
270 | 270 | <tr valign="top"> |
271 | -<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th> |
|
272 | -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
271 | +<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th> |
|
272 | +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td> |
|
273 | 273 | </tr> |
274 | 274 | <tr class="css_sub" valign="top"> |
275 | -<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th> |
|
276 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/> |
|
277 | -<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> |
|
275 | +<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th> |
|
276 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/> |
|
277 | +<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td> |
|
278 | 278 | </tr> |
279 | 279 | <tr valign="top" class="css_sub css_aggregate"> |
280 | -<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th> |
|
281 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
282 | -<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td> |
|
280 | +<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th> |
|
281 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/> |
|
282 | +<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td> |
|
283 | 283 | </tr> |
284 | 284 | <tr class="css_sub css_aggregate" valign="top"> |
285 | -<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th> |
|
286 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/> |
|
287 | -<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td> |
|
285 | +<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th> |
|
286 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/> |
|
287 | +<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td> |
|
288 | 288 | </tr> |
289 | -<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?> |
|
289 | +<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?> |
|
290 | 290 | <tr valign="top" class="css_sub css_aggregate"> |
291 | 291 | <th scope="row"> |
292 | 292 | <?php |
293 | -_e( 'Look for styles only in <head>?', 'autoptimize' ); |
|
294 | -echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; |
|
293 | +_e('Look for styles only in <head>?', 'autoptimize'); |
|
294 | +echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>'; |
|
295 | 295 | ?> |
296 | 296 | </th> |
297 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/> |
|
298 | -<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td> |
|
297 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/> |
|
298 | +<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td> |
|
299 | 299 | </tr> |
300 | 300 | <?php } ?> |
301 | 301 | <tr valign="top" class="css_sub"> |
302 | -<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th> |
|
303 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/> |
|
302 | +<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th> |
|
303 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/> |
|
304 | 304 | <?php |
305 | -_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' ); |
|
305 | +_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize'); |
|
306 | 306 | echo ' '; |
307 | -$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' ); |
|
307 | +$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss'); |
|
308 | 308 | // translators: links "autoptimize critical CSS" tab. |
309 | -echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' ); |
|
309 | +echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>'); |
|
310 | 310 | ?> |
311 | 311 | </label></td> |
312 | 312 | </tr> |
313 | 313 | <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline"> |
314 | 314 | <th scope="row"></th> |
315 | -<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td> |
|
315 | +<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td> |
|
316 | 316 | </tr> |
317 | 317 | <tr valign="top" class="css_sub css_aggregate"> |
318 | -<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th> |
|
319 | -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/> |
|
320 | -<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td> |
|
318 | +<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th> |
|
319 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/> |
|
320 | +<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td> |
|
321 | 321 | </tr> |
322 | 322 | <tr valign="top" class="css_sub"> |
323 | -<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th> |
|
324 | -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ); ?>"/><br /> |
|
323 | +<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th> |
|
324 | +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css'); ?>"/><br /> |
|
325 | 325 | <?php |
326 | -echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); |
|
326 | +echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize'); |
|
327 | 327 | ?> |
328 | 328 | </label></td> |
329 | 329 | </tr> |
@@ -331,55 +331,55 @@ discard block |
||
331 | 331 | </li> |
332 | 332 | |
333 | 333 | <li class="itemDetail"> |
334 | -<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2> |
|
334 | +<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2> |
|
335 | 335 | <table class="form-table"> |
336 | 336 | <tr valign="top"> |
337 | -<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th> |
|
338 | -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td> |
|
337 | +<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th> |
|
338 | +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td> |
|
339 | 339 | </tr> |
340 | 340 | <tr class="html_sub" valign="top"> |
341 | -<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th> |
|
342 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/> |
|
343 | -<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td> |
|
341 | +<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th> |
|
342 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/> |
|
343 | +<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td> |
|
344 | 344 | </tr> |
345 | 345 | </table> |
346 | 346 | </li> |
347 | 347 | |
348 | 348 | <li class="itemDetail"> |
349 | -<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2> |
|
349 | +<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2> |
|
350 | 350 | <table class="form-table"> |
351 | 351 | <tr valign="top"> |
352 | -<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th> |
|
353 | -<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br /> |
|
354 | -<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td> |
|
352 | +<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th> |
|
353 | +<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br /> |
|
354 | +<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td> |
|
355 | 355 | </tr> |
356 | 356 | </table> |
357 | 357 | </li> |
358 | 358 | |
359 | 359 | <li class="itemDetail"> |
360 | -<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2> |
|
360 | +<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2> |
|
361 | 361 | <table class="form-table" > |
362 | 362 | <tr valign="top" > |
363 | -<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th> |
|
364 | -<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td> |
|
363 | +<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th> |
|
364 | +<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td> |
|
365 | 365 | </tr> |
366 | 366 | <tr valign="top" > |
367 | -<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th> |
|
368 | -<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td> |
|
367 | +<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th> |
|
368 | +<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td> |
|
369 | 369 | </tr> |
370 | 370 | <tr valign="top" > |
371 | -<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th> |
|
371 | +<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th> |
|
372 | 372 | <td> |
373 | 373 | <?php |
374 | 374 | $ao_stat_arr = autoptimizeCache::stats(); |
375 | - if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) { |
|
376 | - $ao_cache_size = size_format( $ao_stat_arr[1], 2 ); |
|
375 | + if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) { |
|
376 | + $ao_cache_size = size_format($ao_stat_arr[1], 2); |
|
377 | 377 | $details = ''; |
378 | - if ( $ao_cache_size > 0 ) { |
|
379 | - $details = ', ~' . $ao_cache_size . ' total'; |
|
378 | + if ($ao_cache_size > 0) { |
|
379 | + $details = ', ~'.$ao_cache_size.' total'; |
|
380 | 380 | } |
381 | 381 | // translators: Kilobytes + timestamp shown. |
382 | - printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) ); |
|
382 | + printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2])); |
|
383 | 383 | } |
384 | 384 | ?> |
385 | 385 | </td> |
@@ -388,41 +388,41 @@ discard block |
||
388 | 388 | </li> |
389 | 389 | |
390 | 390 | <li class="itemDetail"> |
391 | -<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2> |
|
391 | +<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2> |
|
392 | 392 | <table class="form-table"> |
393 | 393 | <tr valign="top" > |
394 | - <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th> |
|
395 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
396 | - <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td> |
|
394 | + <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th> |
|
395 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/> |
|
396 | + <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td> |
|
397 | 397 | </tr> |
398 | 398 | <?php |
399 | 399 | $_min_excl_class = ''; |
400 | - if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) { |
|
400 | + if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) { |
|
401 | 401 | $_min_excl_class = 'hidden'; |
402 | 402 | } |
403 | 403 | ?> |
404 | 404 | <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>"> |
405 | - <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th> |
|
406 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
407 | - <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td> |
|
405 | + <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th> |
|
406 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/> |
|
407 | + <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td> |
|
408 | 408 | </tr> |
409 | 409 | <tr valign="top"> |
410 | - <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th> |
|
411 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
412 | - <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td> |
|
410 | + <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th> |
|
411 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/> |
|
412 | + <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td> |
|
413 | 413 | </tr> |
414 | 414 | <tr valign="top"> |
415 | - <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th> |
|
416 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/> |
|
417 | - <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td> |
|
415 | + <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th> |
|
416 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/> |
|
417 | + <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td> |
|
418 | 418 | </tr> |
419 | 419 | <?php |
420 | - if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) { |
|
420 | + if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) { |
|
421 | 421 | ?> |
422 | 422 | <tr valign="top" > |
423 | - <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th> |
|
424 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/> |
|
425 | - <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label> |
|
423 | + <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th> |
|
424 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/> |
|
425 | + <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label> |
|
426 | 426 | </td> |
427 | 427 | </tr> |
428 | 428 | <?php } ?> |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | </ul> |
433 | 433 | |
434 | 434 | <p class="submit"> |
435 | -<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> |
|
436 | -<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" /> |
|
435 | +<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /> |
|
436 | +<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" /> |
|
437 | 437 | </p> |
438 | 438 | |
439 | 439 | </form> |
@@ -442,46 +442,46 @@ discard block |
||
442 | 442 | <div class="autoptimize_banner hidden"> |
443 | 443 | <ul> |
444 | 444 | <?php |
445 | - if ( $this->settings_screen_do_remote_http ) { |
|
446 | - $ao_banner = get_transient( 'autoptimize_banner' ); |
|
447 | - if ( empty( $ao_banner ) ) { |
|
448 | - $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
449 | - if ( ! is_wp_error( $banner_resp ) ) { |
|
450 | - if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) { |
|
451 | - $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) ); |
|
452 | - set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS ); |
|
445 | + if ($this->settings_screen_do_remote_http) { |
|
446 | + $ao_banner = get_transient('autoptimize_banner'); |
|
447 | + if (empty($ao_banner)) { |
|
448 | + $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION); |
|
449 | + if (!is_wp_error($banner_resp)) { |
|
450 | + if ('200' == wp_remote_retrieve_response_code($banner_resp)) { |
|
451 | + $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp)); |
|
452 | + set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS); |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | } |
456 | 456 | echo $ao_banner; |
457 | 457 | } |
458 | 458 | ?> |
459 | - <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li> |
|
460 | - <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li> |
|
459 | + <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li> |
|
460 | + <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li> |
|
461 | 461 | </ul> |
462 | 462 | </div> |
463 | 463 | <div style="margin-left:10px;margin-top:-5px;"> |
464 | 464 | <h2> |
465 | - <?php _e( 'futtta about', 'autoptimize' ); ?> |
|
465 | + <?php _e('futtta about', 'autoptimize'); ?> |
|
466 | 466 | <select id="feed_dropdown" > |
467 | - <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option> |
|
468 | - <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option> |
|
469 | - <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option> |
|
467 | + <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option> |
|
468 | + <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option> |
|
469 | + <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option> |
|
470 | 470 | </select> |
471 | 471 | </h2> |
472 | 472 | <div id="futtta_feed"> |
473 | 473 | <div id="autoptimizefeed"> |
474 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?> |
|
474 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?> |
|
475 | 475 | </div> |
476 | 476 | <div id="wordpressfeed"> |
477 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?> |
|
477 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?> |
|
478 | 478 | </div> |
479 | 479 | <div id="webtechfeed"> |
480 | - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?> |
|
480 | + <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?> |
|
481 | 481 | </div> |
482 | 482 | </div> |
483 | 483 | </div> |
484 | - <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div> |
|
484 | + <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div> |
|
485 | 485 | </div> |
486 | 486 | |
487 | 487 | <script type="text/javascript"> |
@@ -630,81 +630,81 @@ discard block |
||
630 | 630 | |
631 | 631 | public function addmenu() |
632 | 632 | { |
633 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
633 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
634 | 634 | // multisite, network admin, ao network activated: add normal settings page at network level. |
635 | - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) ); |
|
636 | - } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { |
|
635 | + $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config')); |
|
636 | + } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) { |
|
637 | 637 | // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options. |
638 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) ); |
|
638 | + $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message')); |
|
639 | 639 | } else { |
640 | 640 | // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on. |
641 | - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) ); |
|
641 | + $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config')); |
|
642 | 642 | } |
643 | 643 | |
644 | - add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) ); |
|
645 | - add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) ); |
|
644 | + add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts')); |
|
645 | + add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles')); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | public function autoptimize_admin_scripts() |
649 | 649 | { |
650 | - wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
651 | - wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true ); |
|
650 | + wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true); |
|
651 | + wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | public function autoptimize_admin_styles() |
655 | 655 | { |
656 | - wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) ); |
|
657 | - wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) ); |
|
656 | + wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__)); |
|
657 | + wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__)); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | public function registersettings() { |
661 | - register_setting( 'autoptimize', 'autoptimize_html' ); |
|
662 | - register_setting( 'autoptimize', 'autoptimize_html_keepcomments' ); |
|
663 | - register_setting( 'autoptimize', 'autoptimize_enable_site_config' ); |
|
664 | - register_setting( 'autoptimize', 'autoptimize_js' ); |
|
665 | - register_setting( 'autoptimize', 'autoptimize_js_aggregate' ); |
|
666 | - register_setting( 'autoptimize', 'autoptimize_js_exclude' ); |
|
667 | - register_setting( 'autoptimize', 'autoptimize_js_trycatch' ); |
|
668 | - register_setting( 'autoptimize', 'autoptimize_js_justhead' ); |
|
669 | - register_setting( 'autoptimize', 'autoptimize_js_forcehead' ); |
|
670 | - register_setting( 'autoptimize', 'autoptimize_js_include_inline' ); |
|
671 | - register_setting( 'autoptimize', 'autoptimize_css' ); |
|
672 | - register_setting( 'autoptimize', 'autoptimize_css_aggregate' ); |
|
673 | - register_setting( 'autoptimize', 'autoptimize_css_exclude' ); |
|
674 | - register_setting( 'autoptimize', 'autoptimize_css_justhead' ); |
|
675 | - register_setting( 'autoptimize', 'autoptimize_css_datauris' ); |
|
676 | - register_setting( 'autoptimize', 'autoptimize_css_defer' ); |
|
677 | - register_setting( 'autoptimize', 'autoptimize_css_defer_inline' ); |
|
678 | - register_setting( 'autoptimize', 'autoptimize_css_inline' ); |
|
679 | - register_setting( 'autoptimize', 'autoptimize_css_include_inline' ); |
|
680 | - register_setting( 'autoptimize', 'autoptimize_cdn_url' ); |
|
681 | - register_setting( 'autoptimize', 'autoptimize_cache_clean' ); |
|
682 | - register_setting( 'autoptimize', 'autoptimize_cache_nogzip' ); |
|
683 | - register_setting( 'autoptimize', 'autoptimize_optimize_logged' ); |
|
684 | - register_setting( 'autoptimize', 'autoptimize_optimize_checkout' ); |
|
685 | - register_setting( 'autoptimize', 'autoptimize_minify_excluded' ); |
|
686 | - register_setting( 'autoptimize', 'autoptimize_cache_fallback' ); |
|
661 | + register_setting('autoptimize', 'autoptimize_html'); |
|
662 | + register_setting('autoptimize', 'autoptimize_html_keepcomments'); |
|
663 | + register_setting('autoptimize', 'autoptimize_enable_site_config'); |
|
664 | + register_setting('autoptimize', 'autoptimize_js'); |
|
665 | + register_setting('autoptimize', 'autoptimize_js_aggregate'); |
|
666 | + register_setting('autoptimize', 'autoptimize_js_exclude'); |
|
667 | + register_setting('autoptimize', 'autoptimize_js_trycatch'); |
|
668 | + register_setting('autoptimize', 'autoptimize_js_justhead'); |
|
669 | + register_setting('autoptimize', 'autoptimize_js_forcehead'); |
|
670 | + register_setting('autoptimize', 'autoptimize_js_include_inline'); |
|
671 | + register_setting('autoptimize', 'autoptimize_css'); |
|
672 | + register_setting('autoptimize', 'autoptimize_css_aggregate'); |
|
673 | + register_setting('autoptimize', 'autoptimize_css_exclude'); |
|
674 | + register_setting('autoptimize', 'autoptimize_css_justhead'); |
|
675 | + register_setting('autoptimize', 'autoptimize_css_datauris'); |
|
676 | + register_setting('autoptimize', 'autoptimize_css_defer'); |
|
677 | + register_setting('autoptimize', 'autoptimize_css_defer_inline'); |
|
678 | + register_setting('autoptimize', 'autoptimize_css_inline'); |
|
679 | + register_setting('autoptimize', 'autoptimize_css_include_inline'); |
|
680 | + register_setting('autoptimize', 'autoptimize_cdn_url'); |
|
681 | + register_setting('autoptimize', 'autoptimize_cache_clean'); |
|
682 | + register_setting('autoptimize', 'autoptimize_cache_nogzip'); |
|
683 | + register_setting('autoptimize', 'autoptimize_optimize_logged'); |
|
684 | + register_setting('autoptimize', 'autoptimize_optimize_checkout'); |
|
685 | + register_setting('autoptimize', 'autoptimize_minify_excluded'); |
|
686 | + register_setting('autoptimize', 'autoptimize_cache_fallback'); |
|
687 | 687 | } |
688 | 688 | |
689 | - public function setmeta( $links, $file = null ) |
|
689 | + public function setmeta($links, $file = null) |
|
690 | 690 | { |
691 | 691 | // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/. |
692 | 692 | // Do it only once - saves time. |
693 | 693 | static $plugin; |
694 | - if ( empty( $plugin ) ) { |
|
695 | - $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); |
|
694 | + if (empty($plugin)) { |
|
695 | + $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); |
|
696 | 696 | } |
697 | 697 | |
698 | - if ( null === $file ) { |
|
698 | + if (null === $file) { |
|
699 | 699 | // 2.7 and lower. |
700 | - $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ); |
|
701 | - array_unshift( $links, $settings_link ); |
|
700 | + $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')); |
|
701 | + array_unshift($links, $settings_link); |
|
702 | 702 | } else { |
703 | 703 | // 2.8 and higher. |
704 | 704 | // If it's us, add the link. |
705 | - if ( $file === $plugin ) { |
|
706 | - $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) ); |
|
707 | - $links = array_merge( $links, $newlink ); |
|
705 | + if ($file === $plugin) { |
|
706 | + $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'))); |
|
707 | + $links = array_merge($links, $newlink); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | 'autoptimize_imgopt_select_field_2' => '2', // quality glossy. |
781 | 781 | 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off. |
782 | 782 | 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed). |
783 | - 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. |
|
783 | + 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. |
|
784 | 784 | ); |
785 | 785 | return $defaults; |
786 | 786 | } |
@@ -792,58 +792,58 @@ discard block |
||
792 | 792 | * |
793 | 793 | * @return string |
794 | 794 | */ |
795 | - public static function get_ao_css_preload_onload( $media = 'all' ) |
|
795 | + public static function get_ao_css_preload_onload($media = 'all') |
|
796 | 796 | { |
797 | - $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" ); |
|
797 | + $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';"); |
|
798 | 798 | return $preload_onload; |
799 | 799 | } |
800 | 800 | |
801 | - public function get( $key ) |
|
801 | + public function get($key) |
|
802 | 802 | { |
803 | - if ( ! is_array( $this->config ) ) { |
|
803 | + if (!is_array($this->config)) { |
|
804 | 804 | // Default config. |
805 | 805 | $config = self::get_defaults(); |
806 | 806 | |
807 | 807 | // Override with user settings. |
808 | - foreach ( array_keys( $config ) as $name ) { |
|
809 | - $conf = autoptimizeOptionWrapper::get_option( $name ); |
|
810 | - if ( false !== $conf ) { |
|
808 | + foreach (array_keys($config) as $name) { |
|
809 | + $conf = autoptimizeOptionWrapper::get_option($name); |
|
810 | + if (false !== $conf) { |
|
811 | 811 | // It was set before! |
812 | - $config[ $name ] = $conf; |
|
812 | + $config[$name] = $conf; |
|
813 | 813 | } |
814 | 814 | } |
815 | 815 | |
816 | 816 | // Save for next call. |
817 | - $this->config = apply_filters( 'autoptimize_filter_get_config', $config ); |
|
817 | + $this->config = apply_filters('autoptimize_filter_get_config', $config); |
|
818 | 818 | } |
819 | 819 | |
820 | - if ( isset( $this->config[ $key ] ) ) { |
|
821 | - return $this->config[ $key ]; |
|
820 | + if (isset($this->config[$key])) { |
|
821 | + return $this->config[$key]; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return false; |
825 | 825 | } |
826 | 826 | |
827 | - private function get_futtta_feeds( $url ) { |
|
828 | - if ( $this->settings_screen_do_remote_http ) { |
|
829 | - $rss = fetch_feed( $url ); |
|
827 | + private function get_futtta_feeds($url) { |
|
828 | + if ($this->settings_screen_do_remote_http) { |
|
829 | + $rss = fetch_feed($url); |
|
830 | 830 | $maxitems = 0; |
831 | 831 | |
832 | - if ( ! is_wp_error( $rss ) ) { |
|
833 | - $maxitems = $rss->get_item_quantity( 7 ); |
|
834 | - $rss_items = $rss->get_items( 0, $maxitems ); |
|
832 | + if (!is_wp_error($rss)) { |
|
833 | + $maxitems = $rss->get_item_quantity(7); |
|
834 | + $rss_items = $rss->get_items(0, $maxitems); |
|
835 | 835 | } |
836 | 836 | ?> |
837 | 837 | <ul> |
838 | - <?php if ( 0 == $maxitems ) : ?> |
|
839 | - <li><?php _e( 'No items', 'autoptimize' ); ?></li> |
|
838 | + <?php if (0 == $maxitems) : ?> |
|
839 | + <li><?php _e('No items', 'autoptimize'); ?></li> |
|
840 | 840 | <?php else : ?> |
841 | - <?php foreach ( $rss_items as $item ) : ?> |
|
841 | + <?php foreach ($rss_items as $item) : ?> |
|
842 | 842 | <li> |
843 | - <a href="<?php echo esc_url( $item->get_permalink() ); ?>" |
|
843 | + <a href="<?php echo esc_url($item->get_permalink()); ?>" |
|
844 | 844 | <?php // translators: the variable contains a date. ?> |
845 | - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>"> |
|
846 | - <?php echo esc_html( $item->get_title() ); ?> |
|
845 | + title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>"> |
|
846 | + <?php echo esc_html($item->get_title()); ?> |
|
847 | 847 | </a> |
848 | 848 | </li> |
849 | 849 | <?php endforeach; ?> |
@@ -856,23 +856,23 @@ discard block |
||
856 | 856 | static function ao_admin_tabs() |
857 | 857 | { |
858 | 858 | // based on http://wordpress.stackexchange.com/a/58826 . |
859 | - $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS & HTML', 'autoptimize' ) ) ); |
|
859 | + $tabs = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS & HTML', 'autoptimize'))); |
|
860 | 860 | $tab_content = ''; |
861 | - $tabs_count = count( $tabs ); |
|
862 | - if ( $tabs_count > 1 ) { |
|
863 | - if ( isset( $_GET['page'] ) ) { |
|
861 | + $tabs_count = count($tabs); |
|
862 | + if ($tabs_count > 1) { |
|
863 | + if (isset($_GET['page'])) { |
|
864 | 864 | $current_id = $_GET['page']; |
865 | 865 | } else { |
866 | 866 | $current_id = 'autoptimize'; |
867 | 867 | } |
868 | 868 | $tab_content .= '<h2 class="nav-tab-wrapper">'; |
869 | - foreach ( $tabs as $tab_id => $tab_name ) { |
|
870 | - if ( $current_id == $tab_id ) { |
|
869 | + foreach ($tabs as $tab_id => $tab_name) { |
|
870 | + if ($current_id == $tab_id) { |
|
871 | 871 | $class = ' nav-tab-active'; |
872 | 872 | } else { |
873 | 873 | $class = ''; |
874 | 874 | } |
875 | - $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>'; |
|
875 | + $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>'; |
|
876 | 876 | } |
877 | 877 | $tab_content .= '</h2>'; |
878 | 878 | } else { |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | */ |
890 | 890 | public static function is_admin_and_not_ajax() |
891 | 891 | { |
892 | - return ( is_admin() && ! self::doing_ajax() ); |
|
892 | + return (is_admin() && !self::doing_ajax()); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -899,10 +899,10 @@ discard block |
||
899 | 899 | */ |
900 | 900 | protected static function doing_ajax() |
901 | 901 | { |
902 | - if ( function_exists( 'wp_doing_ajax' ) ) { |
|
902 | + if (function_exists('wp_doing_ajax')) { |
|
903 | 903 | return wp_doing_ajax(); |
904 | 904 | } |
905 | - return ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
905 | + return (defined('DOING_AJAX') && DOING_AJAX); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | /** |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | * @return bool |
912 | 912 | */ |
913 | 913 | public static function should_show_menu_tabs() { |
914 | - if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { |
|
914 | + if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) { |
|
915 | 915 | return true; |
916 | 916 | } else { |
917 | 917 | return false; |