Completed
Push — master ( 267ab8...da5a66 )
by frank
02:00
created
classes/autoptimizeImages.php 2 patches
Doc Comments   +13 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,6 +384,9 @@  discard block
 block discarded – undo
384 384
         }
385 385
     }
386 386
 
387
+    /**
388
+     * @return string
389
+     */
387 390
     private function get_imgopt_base_url()
388 391
     {
389 392
         static $imgopt_base_url = null;
@@ -767,6 +770,9 @@  discard block
 block discarded – undo
767 770
         return $out;
768 771
     }
769 772
 
773
+    /**
774
+     * @param string $tag
775
+     */
770 776
     public function add_lazyload( $tag, $placeholder = '' ) {
771 777
         // adds actual lazyload-attributes to an image node.
772 778
         $this->lazyload_counter++;
@@ -858,6 +864,9 @@  discard block
 block discarded – undo
858 864
         }
859 865
     }
860 866
 
867
+    /**
868
+     * @return string
869
+     */
861 870
     public function get_cdn_url() {
862 871
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
863 872
         static $cdn_url = null;
@@ -961,6 +970,9 @@  discard block
 block discarded – undo
961 970
         return $out;
962 971
     }
963 972
 
973
+    /**
974
+     * @return string
975
+     */
964 976
     public function process_bgimage( $in ) {
965 977
         if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
966 978
             $out = preg_replace_callback(
@@ -1313,7 +1325,7 @@  discard block
 block discarded – undo
1313 1325
     /**
1314 1326
      * Determines and returns the service launch status.
1315 1327
      *
1316
-     * @return bool
1328
+     * @return null|boolean
1317 1329
      */
1318 1330
     public function launch_ok()
1319 1331
     {
Please login to merge, or discard this patch.
Spacing   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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,18 +23,18 @@  discard block
 block discarded – undo
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
         $this->lazyload_counter = 0;
35 35
     }
36 36
 
37
-    public function set_options( array $options )
37
+    public function set_options(array $options)
38 38
     {
39 39
         $this->options = $options;
40 40
 
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
 
44 44
     public static function fetch_options()
45 45
     {
46
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
47
-        if ( empty( $value ) ) {
46
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
47
+        if (empty($value)) {
48 48
             // Fallback to returning defaults when no stored option exists yet.
49 49
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
50 50
         }
51 51
 
52 52
         // get service availability and add it to the options-array.
53
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
53
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
54 54
 
55
-        if ( empty( $value['availabilities'] ) ) {
56
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
55
+        if (empty($value['availabilities'])) {
56
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
57 57
         }
58 58
 
59 59
         return $value;
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
         // and does not use/ request the availablity data (which could slow things down).
67 67
         static $imgopt_active = null;
68 68
 
69
-        if ( null === $imgopt_active ) {
70
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
71
-            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'] ) {
69
+        if (null === $imgopt_active) {
70
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
71
+            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']) {
72 72
                 $imgopt_active = true;
73 73
             } else {
74 74
                 $imgopt_active = false;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public static function instance()
90 90
     {
91
-        if ( null === self::$instance ) {
91
+        if (null === self::$instance) {
92 92
             self::$instance = new self();
93 93
         }
94 94
 
@@ -97,34 +97,34 @@  discard block
 block discarded – undo
97 97
 
98 98
     public function run()
99 99
     {
100
-        if ( is_admin() ) {
101
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
102
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
100
+        if (is_admin()) {
101
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
102
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
103 103
             } else {
104
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
104
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
105 105
             }
106
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
106
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
107 107
         } else {
108
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
108
+            add_action('wp', array($this, 'run_on_frontend'));
109 109
         }
110 110
     }
111 111
 
112 112
     public function run_on_frontend() {
113
-        if ( ! $this->should_run() ) {
114
-            if ( $this->should_lazyload() ) {
113
+        if (!$this->should_run()) {
114
+            if ($this->should_lazyload()) {
115 115
                 add_filter(
116 116
                     'wp_lazy_loading_enabled',
117 117
                     '__return_false'
118 118
                 );
119 119
                 add_filter(
120 120
                     'autoptimize_html_after_minify',
121
-                    array( $this, 'filter_lazyload_images' ),
121
+                    array($this, 'filter_lazyload_images'),
122 122
                     10,
123 123
                     1
124 124
                 );
125 125
                 add_action(
126 126
                     'wp_footer',
127
-                    array( $this, 'add_lazyload_js_footer' ),
127
+                    array($this, 'add_lazyload_js_footer'),
128 128
                     10,
129 129
                     0
130 130
                 );
@@ -134,43 +134,43 @@  discard block
 block discarded – undo
134 134
 
135 135
         $active = false;
136 136
 
137
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
137
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
138 138
             add_filter(
139 139
                 'autoptimize_html_after_minify',
140
-                array( $this, 'filter_optimize_images' ),
140
+                array($this, 'filter_optimize_images'),
141 141
                 10,
142 142
                 1
143 143
             );
144 144
             $active = true;
145 145
         }
146 146
 
147
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
147
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
148 148
             add_filter(
149 149
                 'autoptimize_filter_base_replace_cdn',
150
-                array( $this, 'filter_optimize_css_images' ),
150
+                array($this, 'filter_optimize_css_images'),
151 151
                 10,
152 152
                 1
153 153
             );
154 154
             $active = true;
155 155
         }
156 156
 
157
-        if ( $active ) {
157
+        if ($active) {
158 158
             add_filter(
159 159
                 'autoptimize_extra_filter_tobepreconn',
160
-                array( $this, 'filter_preconnect_imgopt_url' ),
160
+                array($this, 'filter_preconnect_imgopt_url'),
161 161
                 10,
162 162
                 1
163 163
             );
164 164
         }
165 165
 
166
-        if ( $this->should_lazyload() ) {
166
+        if ($this->should_lazyload()) {
167 167
             add_filter(
168 168
                 'wp_lazy_loading_enabled',
169 169
                 '__return_false'
170 170
             );
171 171
             add_action(
172 172
                 'wp_footer',
173
-                array( $this, 'add_lazyload_js_footer' ),
173
+                array($this, 'add_lazyload_js_footer'),
174 174
                 10,
175 175
                 0
176 176
             );
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
     protected function should_run()
186 186
     {
187 187
         $opts              = $this->options;
188
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
189
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
188
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
189
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
190 190
 
191 191
         $do_cdn      = true;
192 192
         $_userstatus = $this->get_imgopt_provider_userstatus();
193
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
193
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
194 194
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
195 195
             $do_cdn = false;
196 196
         }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             $this->imgopt_active()
200 200
             && $do_cdn
201 201
             && $service_not_down
202
-            && ( $not_launch_status || $this->launch_ok() )
202
+            && ($not_launch_status || $this->launch_ok())
203 203
         ) {
204 204
             return true;
205 205
         }
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
     {
211 211
         static $imgopt_host = null;
212 212
 
213
-        if ( null === $imgopt_host ) {
213
+        if (null === $imgopt_host) {
214 214
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
215 215
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
216
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
217
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
216
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
217
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
218 218
             }
219
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
219
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
220 220
         }
221 221
 
222 222
         return $imgopt_host;
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
     public static function get_service_url_suffix()
233 233
     {
234
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
234
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
235 235
 
236 236
         return $suffix;
237 237
     }
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
     {
241 241
         static $quality = null;
242 242
 
243
-        if ( null === $quality ) {
243
+        if (null === $quality) {
244 244
             $q_array = $this->get_img_quality_array();
245 245
             $setting = $this->get_img_quality_setting();
246 246
             $quality = apply_filters(
247 247
                 'autoptimize_filter_imgopt_quality',
248
-                'q_' . $q_array[ $setting ]
248
+                'q_'.$q_array[$setting]
249 249
             );
250 250
         }
251 251
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         static $map = null;
258 258
 
259
-        if ( null === $map ) {
259
+        if (null === $map) {
260 260
             $map = array(
261 261
                 '1' => 'lossy',
262 262
                 '2' => 'glossy',
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
     {
276 276
         static $q = null;
277 277
 
278
-        if ( null === $q ) {
279
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
278
+        if (null === $q) {
279
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
280 280
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
281 281
             }
282 282
 
283
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
283
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
284 284
                 // default image opt. value is 2 ("glossy").
285 285
                 $q = '2';
286 286
             } else {
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
         return $q;
292 292
     }
293 293
 
294
-    public function filter_preconnect_imgopt_url( array $in )
294
+    public function filter_preconnect_imgopt_url(array $in)
295 295
     {
296
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
297
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
296
+        $url_parts = parse_url($this->get_imgopt_base_url());
297
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
298 298
 
299 299
         return $in;
300 300
     }
@@ -307,20 +307,20 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return string
309 309
      */
310
-    private function normalize_img_url( $in )
310
+    private function normalize_img_url($in)
311 311
     {
312 312
         // Only parse the site url once.
313 313
         static $parsed_site_url = null;
314
-        if ( null === $parsed_site_url ) {
315
-            $parsed_site_url = parse_url( site_url() );
314
+        if (null === $parsed_site_url) {
315
+            $parsed_site_url = parse_url(site_url());
316 316
         }
317 317
 
318 318
         // get CDN domain once.
319 319
         static $cdn_domain = null;
320
-        if ( is_null( $cdn_domain ) ) {
320
+        if (is_null($cdn_domain)) {
321 321
             $cdn_url = $this->get_cdn_url();
322
-            if ( ! empty( $cdn_url ) ) {
323
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
322
+            if (!empty($cdn_url)) {
323
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
324 324
             } else {
325 325
                 $cdn_domain = '';
326 326
             }
@@ -336,49 +336,49 @@  discard block
 block discarded – undo
336 336
          * identical string operations).
337 337
          */
338 338
         static $cache = null;
339
-        if ( null === $cache ) {
339
+        if (null === $cache) {
340 340
             $cache = array();
341 341
         }
342 342
 
343 343
         // Do the work on cache miss only.
344
-        if ( ! isset( $cache[ $in ] ) ) {
344
+        if (!isset($cache[$in])) {
345 345
             // Default to (the trimmed version of) what was given to us.
346
-            $result = trim( $in );
346
+            $result = trim($in);
347 347
 
348 348
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
349
-            if ( strpos( $result, '"' ) !== false ) {
350
-                $result = str_replace( '"', '', $result );
349
+            if (strpos($result, '"') !== false) {
350
+                $result = str_replace('"', '', $result);
351 351
             }
352 352
 
353
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
354
-                $result = $parsed_site_url['scheme'] . ':' . $result;
355
-            } elseif ( 0 === strpos( $result, '/' ) ) {
353
+            if (autoptimizeUtils::is_protocol_relative($result)) {
354
+                $result = $parsed_site_url['scheme'].':'.$result;
355
+            } elseif (0 === strpos($result, '/')) {
356 356
                 // Root-relative...
357
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
358
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
359
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
357
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
358
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
359
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
360 360
             }
361 361
 
362 362
             // filter (default off) to remove QS from image URL's to avoid eating away optimization credits.
363
-            if ( apply_filters( 'autoptimize_filter_imgopt_no_querystring', false ) && strpos( $result, '?' ) !== false ) {
364
-                $result = strtok( $result, '?' );
363
+            if (apply_filters('autoptimize_filter_imgopt_no_querystring', false) && strpos($result, '?') !== false) {
364
+                $result = strtok($result, '?');
365 365
             }
366 366
 
367
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
367
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
368 368
 
369 369
             // Store in cache.
370
-            $cache[ $in ] = $result;
370
+            $cache[$in] = $result;
371 371
         }
372 372
 
373
-        return $cache[ $in ];
373
+        return $cache[$in];
374 374
     }
375 375
 
376
-    public function filter_optimize_css_images( $in )
376
+    public function filter_optimize_css_images($in)
377 377
     {
378
-        $in = $this->normalize_img_url( $in );
378
+        $in = $this->normalize_img_url($in);
379 379
 
380
-        if ( $this->can_optimize_image( $in ) ) {
381
-            return $this->build_imgopt_url( $in, '', '' );
380
+        if ($this->can_optimize_image($in)) {
381
+            return $this->build_imgopt_url($in, '', '');
382 382
         } else {
383 383
             return $in;
384 384
         }
@@ -388,53 +388,53 @@  discard block
 block discarded – undo
388 388
     {
389 389
         static $imgopt_base_url = null;
390 390
 
391
-        if ( null === $imgopt_base_url ) {
391
+        if (null === $imgopt_base_url) {
392 392
             $imgopt_host     = $this->get_imgopt_host();
393 393
             $quality         = $this->get_img_quality_string();
394
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
395
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
396
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
394
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
395
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
396
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
397 397
         }
398 398
 
399 399
         return $imgopt_base_url;
400 400
     }
401 401
 
402
-    private function can_optimize_image( $url, $tag = '' )
402
+    private function can_optimize_image($url, $tag = '')
403 403
     {
404 404
         static $cdn_url      = null;
405 405
         static $nopti_images = null;
406 406
 
407
-        if ( null === $cdn_url ) {
407
+        if (null === $cdn_url) {
408 408
             $cdn_url = apply_filters(
409 409
                 'autoptimize_filter_base_cdnurl',
410
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
410
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
411 411
             );
412 412
         }
413 413
 
414
-        if ( null === $nopti_images ) {
415
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_text_field_6', $this->options ) ) {
414
+        if (null === $nopti_images) {
415
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_text_field_6', $this->options)) {
416 416
                 $nopti_images = $this->options['autoptimize_imgopt_text_field_6'];
417 417
             }
418
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', $nopti_images );
418
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', $nopti_images);
419 419
         }
420 420
 
421 421
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
422
-        $url        = $this->normalize_img_url( $url );
423
-        $url_parsed = parse_url( $url );
422
+        $url        = $this->normalize_img_url($url);
423
+        $url_parsed = parse_url($url);
424 424
 
425
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
425
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
426 426
             return false;
427
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
427
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
428 428
             return false;
429
-        } elseif ( strpos( $url, '.php' ) !== false ) {
429
+        } elseif (strpos($url, '.php') !== false) {
430 430
             return false;
431
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
431
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif'), '', $url_parsed['path']) === $url_parsed['path']) {
432 432
             // fixme: better check against end of string.
433 433
             return false;
434
-        } elseif ( ! empty( $nopti_images ) ) {
435
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
436
-            foreach ( $nopti_images_array as $nopti_image ) {
437
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
434
+        } elseif (!empty($nopti_images)) {
435
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
436
+            foreach ($nopti_images_array as $nopti_image) {
437
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
438 438
                     return false;
439 439
                 }
440 440
             }
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
         return true;
443 443
     }
444 444
 
445
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
445
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
446 446
     {
447 447
         // sanitize width and height.
448
-        if ( strpos( $width, '%' ) !== false ) {
448
+        if (strpos($width, '%') !== false) {
449 449
             $width = 0;
450 450
         }
451
-        if ( strpos( $height, '%' ) !== false ) {
451
+        if (strpos($height, '%') !== false) {
452 452
             $height = 0;
453 453
         }
454 454
         $width  = (int) $width;
@@ -462,46 +462,46 @@  discard block
 block discarded – undo
462 462
         );
463 463
 
464 464
         // If filter modified the url, return that.
465
-        if ( $filtered_url !== $orig_url ) {
465
+        if ($filtered_url !== $orig_url) {
466 466
             return $filtered_url;
467 467
         }
468 468
 
469
-        $orig_url        = $this->normalize_img_url( $orig_url );
469
+        $orig_url        = $this->normalize_img_url($orig_url);
470 470
         $imgopt_base_url = $this->get_imgopt_base_url();
471 471
         $imgopt_size     = '';
472 472
 
473
-        if ( $width && 0 !== $width ) {
474
-            $imgopt_size = ',w_' . $width;
473
+        if ($width && 0 !== $width) {
474
+            $imgopt_size = ',w_'.$width;
475 475
         }
476 476
 
477
-        if ( $height && 0 !== $height ) {
478
-            $imgopt_size .= ',h_' . $height;
477
+        if ($height && 0 !== $height) {
478
+            $imgopt_size .= ',h_'.$height;
479 479
         }
480 480
 
481
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
481
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
482 482
 
483 483
         return $url;
484 484
     }
485 485
 
486
-    public function replace_data_thumbs( $matches )
486
+    public function replace_data_thumbs($matches)
487 487
     {
488
-        return $this->replace_img_callback( $matches, 150, 150 );
488
+        return $this->replace_img_callback($matches, 150, 150);
489 489
     }
490 490
 
491
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
491
+    public function replace_img_callback($matches, $width = 0, $height = 0)
492 492
     {
493
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
494
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
495
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
493
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
494
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
495
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
496 496
         } else {
497 497
             return $matches[0];
498 498
         }
499 499
     }
500 500
 
501
-    public function replace_icon_callback( $matches )
501
+    public function replace_icon_callback($matches)
502 502
     {
503
-        if ( array_key_exists( '2', $matches ) ) {
504
-            $sizes  = explode( 'x', $matches[2] );
503
+        if (array_key_exists('2', $matches)) {
504
+            $sizes  = explode('x', $matches[2]);
505 505
             $width  = $sizes[0];
506 506
             $height = $sizes[1];
507 507
         } else {
@@ -510,14 +510,14 @@  discard block
 block discarded – undo
510 510
         }
511 511
 
512 512
         // make sure we're not trying to optimize a *.ico file
513
-        if ( strpos( $matches[1], '.ico' ) === false ) {
514
-            return $this->replace_img_callback( $matches, $width, $height );
513
+        if (strpos($matches[1], '.ico') === false) {
514
+            return $this->replace_img_callback($matches, $width, $height);
515 515
         } else {
516 516
             return $matches;
517 517
         }
518 518
     }
519 519
 
520
-    public function filter_optimize_images( $in )
520
+    public function filter_optimize_images($in)
521 521
     {
522 522
         /*
523 523
          * potential future functional improvements:
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
         $to_replace = array();
528 528
 
529 529
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
530
-        if ( $this->should_lazyload() ) {
530
+        if ($this->should_lazyload()) {
531 531
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
532 532
                 'SCRIPT',
533 533
                 '<script',
@@ -537,161 +537,161 @@  discard block
 block discarded – undo
537 537
         }
538 538
 
539 539
         // extract img tags.
540
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
541
-            foreach ( $matches[0] as $tag ) {
540
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
541
+            foreach ($matches[0] as $tag) {
542 542
                 $orig_tag = $tag;
543 543
                 $imgopt_w = '';
544 544
                 $imgopt_h = '';
545 545
 
546 546
                 // first do (data-)srcsets.
547
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
548
-                    foreach ( $allsrcsets as $srcset ) {
547
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
548
+                    foreach ($allsrcsets as $srcset) {
549 549
                         $srcset      = $srcset[2];
550 550
                         $orig_srcset = $srcset;
551
-                        $srcsets     = explode( ',', $srcset );
552
-                        foreach ( $srcsets as $indiv_srcset ) {
553
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
554
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
555
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
551
+                        $srcsets     = explode(',', $srcset);
552
+                        foreach ($srcsets as $indiv_srcset) {
553
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
554
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
555
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
556 556
                             }
557
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag ) ) {
558
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
559
-                                $srcset     = str_replace( $indiv_srcset_parts[0], $imgopt_url, $srcset );
557
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag)) {
558
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
559
+                                $srcset     = str_replace($indiv_srcset_parts[0], $imgopt_url, $srcset);
560 560
                             }
561 561
                         }
562
-                        $tag = str_replace( $orig_srcset, $srcset, $tag );
562
+                        $tag = str_replace($orig_srcset, $srcset, $tag);
563 563
                     }
564 564
                 }
565 565
 
566 566
                 // proceed with img src.
567 567
                 // get width and height and add to $imgopt_size.
568
-                $_get_size = $this->get_size_from_tag( $tag );
568
+                $_get_size = $this->get_size_from_tag($tag);
569 569
                 $imgopt_w  = $_get_size['width'];
570 570
                 $imgopt_h  = $_get_size['height'];
571 571
 
572 572
                 // then start replacing images src.
573
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
574
-                    foreach ( $urls as $url ) {
573
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
574
+                    foreach ($urls as $url) {
575 575
                         $full_src_orig = $url[0];
576 576
                         $url           = $url[1];
577
-                        if ( $this->can_optimize_image( $url, $full_src_orig ) ) {
578
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
579
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
580
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
577
+                        if ($this->can_optimize_image($url, $full_src_orig)) {
578
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
579
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
580
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
581 581
                         }
582 582
                     }
583 583
                 }
584 584
 
585 585
                 // do lazyload stuff.
586
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
586
+                if ($this->should_lazyload($in) && !empty($url)) {
587 587
                     // first do lpiq placeholder logic.
588
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
588
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
589 589
                         // if all img src have been replaced during srcset, we have to extract the
590 590
                         // origin url from the imgopt one to be able to set a lqip placeholder.
591
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
591
+                        $_url = substr($url, strpos($url, '/http') + 1);
592 592
                     } else {
593 593
                         $_url = $url;
594 594
                     }
595 595
 
596
-                    $_url = $this->normalize_img_url( $_url );
596
+                    $_url = $this->normalize_img_url($_url);
597 597
 
598 598
                     $placeholder = '';
599
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
599
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
600 600
                         $lqip_w = '';
601 601
                         $lqip_h = '';
602
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
603
-                            $lqip_w = ',w_' . $imgopt_w;
602
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
603
+                            $lqip_w = ',w_'.$imgopt_w;
604 604
                         }
605
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
606
-                            $lqip_h = ',h_' . $imgopt_h;
605
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
606
+                            $lqip_h = ',h_'.$imgopt_h;
607 607
                         }
608
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
608
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
609 609
                     }
610 610
                     // then call add_lazyload-function with lpiq placeholder if set.
611
-                    $tag = $this->add_lazyload( $tag, $placeholder );
611
+                    $tag = $this->add_lazyload($tag, $placeholder);
612 612
                 }
613 613
 
614 614
                 // and add tag to array for later replacement.
615
-                if ( $tag !== $orig_tag ) {
616
-                    $to_replace[ $orig_tag ] = $tag;
615
+                if ($tag !== $orig_tag) {
616
+                    $to_replace[$orig_tag] = $tag;
617 617
                 }
618 618
             }
619 619
         }
620 620
 
621 621
         // and replace all.
622
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
622
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
623 623
 
624 624
         // img thumbnails in e.g. woocommerce.
625
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
625
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
626 626
             $out = preg_replace_callback(
627 627
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
628
-                array( $this, 'replace_data_thumbs' ),
628
+                array($this, 'replace_data_thumbs'),
629 629
                 $out
630 630
             );
631 631
         }
632 632
 
633 633
         // background-image in inline style.
634
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
634
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
635 635
             $out = preg_replace_callback(
636 636
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
637
-                array( $this, 'replace_img_callback' ),
637
+                array($this, 'replace_img_callback'),
638 638
                 $out
639 639
             );
640 640
         }
641 641
 
642 642
         // act on icon links.
643
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
643
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
644 644
             $out = preg_replace_callback(
645 645
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
646
-                array( $this, 'replace_icon_callback' ),
646
+                array($this, 'replace_icon_callback'),
647 647
                 $out
648 648
             );
649 649
         }
650 650
 
651 651
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
652
-        if ( $this->should_lazyload() ) {
652
+        if ($this->should_lazyload()) {
653 653
             $out = autoptimizeBase::restore_marked_content(
654 654
                 'SCRIPT',
655 655
                 $out
656 656
             );
657 657
 
658
-            $out = $this->process_picture_tag( $out, true, true );
659
-            $out = $this->process_bgimage( $out );
658
+            $out = $this->process_picture_tag($out, true, true);
659
+            $out = $this->process_bgimage($out);
660 660
         } else {
661
-            $out = $this->process_picture_tag( $out, true, false );
661
+            $out = $this->process_picture_tag($out, true, false);
662 662
         }
663 663
 
664 664
         return $out;
665 665
     }
666 666
 
667
-    public function get_size_from_tag( $tag ) {
667
+    public function get_size_from_tag($tag) {
668 668
         // reusable function to extract widht and height from an image tag
669 669
         // enforcing a filterable maximum width and height (default 4999X4999).
670 670
         $width  = '';
671 671
         $height = '';
672 672
 
673
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
674
-            if ( strpos( $_width[2], '%' ) === false ) {
673
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
674
+            if (strpos($_width[2], '%') === false) {
675 675
                 $width = (int) $_width[2];
676 676
             }
677 677
         }
678
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
679
-            if ( strpos( $_height[2], '%' ) === false ) {
678
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
679
+            if (strpos($_height[2], '%') === false) {
680 680
                 $height = (int) $_height[2];
681 681
             }
682 682
         }
683 683
 
684 684
         // check for and enforce (filterable) max sizes.
685
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
686
-        if ( $width > $_max_width ) {
685
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
686
+        if ($width > $_max_width) {
687 687
             $_width = $_max_width;
688
-            $height = $_width / $width * $height;
688
+            $height = $_width/$width*$height;
689 689
             $width  = $_width;
690 690
         }
691
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
692
-        if ( $height > $_max_height ) {
691
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
692
+        if ($height > $_max_height) {
693 693
             $_height = $_max_height;
694
-            $width   = $_height / $height * $width;
694
+            $width   = $_height/$height*$width;
695 695
             $height  = $_height;
696 696
         }
697 697
 
@@ -710,26 +710,26 @@  discard block
 block discarded – undo
710 710
         return $self->should_lazyload();
711 711
     }
712 712
 
713
-    public function should_lazyload( $context = '' ) {
714
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
713
+    public function should_lazyload($context = '') {
714
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
715 715
             $lazyload_return = true;
716 716
         } else {
717 717
             $lazyload_return = false;
718 718
         }
719
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
719
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
720 720
 
721 721
         return $lazyload_return;
722 722
     }
723 723
 
724 724
     public function check_nolazy() {
725
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
725
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
726 726
             return true;
727 727
         } else {
728 728
             return false;
729 729
         }
730 730
     }
731 731
 
732
-    public function filter_lazyload_images( $in )
732
+    public function filter_lazyload_images($in)
733 733
     {
734 734
         // only used is image optimization is NOT active but lazyload is.
735 735
         $to_replace = array();
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
         );
744 744
 
745 745
         // extract img tags and add lazyload attribs.
746
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
747
-            foreach ( $matches[0] as $tag ) {
748
-                if ( $this->should_lazyload( $out ) ) {
749
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
746
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
747
+            foreach ($matches[0] as $tag) {
748
+                if ($this->should_lazyload($out)) {
749
+                    $to_replace[$tag] = $this->add_lazyload($tag);
750 750
                 }
751 751
             }
752
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
752
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
753 753
         }
754 754
 
755 755
         // and also lazyload picture tag.
756
-        $out = $this->process_picture_tag( $out, false, true );
756
+        $out = $this->process_picture_tag($out, false, true);
757 757
 
758 758
         // and inline style blocks with background-image.
759
-        $out = $this->process_bgimage( $out );
759
+        $out = $this->process_bgimage($out);
760 760
 
761 761
         // restore noscript tags.
762 762
         $out = autoptimizeBase::restore_marked_content(
@@ -767,85 +767,85 @@  discard block
 block discarded – undo
767 767
         return $out;
768 768
     }
769 769
 
770
-    public function add_lazyload( $tag, $placeholder = '' ) {
770
+    public function add_lazyload($tag, $placeholder = '') {
771 771
         // adds actual lazyload-attributes to an image node.
772 772
         $this->lazyload_counter++;
773
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag && $this->lazyload_counter >= apply_filters( 'autoptimize_filter_imgopt_lazyload_from_nth', 0 ) ) {
774
-            $tag = $this->maybe_fix_missing_quotes( $tag );
773
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag && $this->lazyload_counter >= apply_filters('autoptimize_filter_imgopt_lazyload_from_nth', 0)) {
774
+            $tag = $this->maybe_fix_missing_quotes($tag);
775 775
 
776 776
             // store original tag for use in noscript version.
777
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
777
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
778 778
 
779
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
779
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
780 780
 
781 781
             // insert lazyload class.
782
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
782
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
783 783
 
784
-            if ( ! $placeholder || empty( $placeholder ) ) {
784
+            if (!$placeholder || empty($placeholder)) {
785 785
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
786
-                $_get_size = $this->get_size_from_tag( $tag );
786
+                $_get_size = $this->get_size_from_tag($tag);
787 787
                 $width     = $_get_size['width'];
788 788
                 $height    = $_get_size['height'];
789
-                if ( false === $width || empty( $width ) ) {
789
+                if (false === $width || empty($width)) {
790 790
                     $width = 210; // default width for SVG placeholder.
791 791
                 }
792
-                if ( false === $height || empty( $height ) ) {
793
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
792
+                if (false === $height || empty($height)) {
793
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
794 794
                 }
795 795
 
796 796
                 // insert the actual lazyload stuff.
797 797
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
798
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
798
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
799 799
             }
800 800
 
801
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
802
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
801
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
802
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
803 803
 
804 804
             // move sizes to data-sizes unless filter says no.
805
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
806
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
805
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
806
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
807 807
             }
808 808
 
809 809
             // add the noscript-tag from earlier.
810
-            $tag = $noscript_tag . $tag;
811
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
810
+            $tag = $noscript_tag.$tag;
811
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
812 812
         }
813 813
 
814 814
         return $tag;
815 815
     }
816 816
 
817 817
     public function add_lazyload_js_footer() {
818
-        if ( false === autoptimizeMain::should_buffer() ) {
818
+        if (false === autoptimizeMain::should_buffer()) {
819 819
             return;
820 820
         }
821 821
 
822 822
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
823 823
         $noptimize_flag = '';
824
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
824
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
825 825
             $noptimize_flag = ' data-noptimize="1"';
826 826
         }
827 827
 
828
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
828
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
829 829
         $cdn_url      = $this->get_cdn_url();
830
-        if ( ! empty( $cdn_url ) ) {
831
-            $cdn_url      = rtrim( $cdn_url, '/' );
832
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
830
+        if (!empty($cdn_url)) {
831
+            $cdn_url      = rtrim($cdn_url, '/');
832
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
833 833
         }
834 834
 
835 835
         $type_js = '';
836
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
836
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
837 837
             $type_js = ' type="text/javascript"';
838 838
         }
839 839
 
840 840
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
841
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
842
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
843
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
841
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
842
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
843
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
844 844
 
845 845
         // And add webp detection and loading JS.
846
-        if ( $this->should_ngimg() ) {
846
+        if ($this->should_ngimg()) {
847 847
             // Add AVIF code, can be disabled for now to only do webp.
848
-            if ( apply_filters( 'autoptimize_filter_imgopt_do_avif', true ) ) {
848
+            if (apply_filters('autoptimize_filter_imgopt_do_avif', true)) {
849 849
                 $_ngimg_detect = 'function c_img(a,b){src="avif"==b?"data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABoAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACJtZGF0EgAKCBgADsgQEAwgMgwf8AAAWAAAAACvJ+o=":"data:image/webp;base64,UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==";var c=new Image;c.onload=function(){var d=0<c.width&&0<c.height;a(d,b)},c.onerror=function(){a(!1,b)},c.src=src}function s_img(a,b){w=window,"avif"==b?!1==a?c_img(s_img,"webp"):w.ngImg="avif":!1==a?w.ngImg=!1:w.ngImg="webp"}c_img(s_img,"avif");';
850 850
                 $_ngimg_load   = 'document.addEventListener("lazybeforeunveil",function({target:a}){window.ngImg&&["data-src","data-srcset"].forEach(function(b){attr=a.getAttribute(b),null!==attr&&-1==attr.indexOf("/client/to_")&&a.setAttribute(b,attr.replace(/\/client\//,"/client/to_"+window.ngImg+","))})});';
851 851
             } else {
@@ -853,8 +853,8 @@  discard block
 block discarded – undo
853 853
                 $_ngimg_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,'))})});";
854 854
             }
855 855
             // Keeping autoptimize_filter_imgopt_webp_js filter for now, but it is deprecated as not only for webp any more.
856
-            $_ngimg_output = apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_ngimg_detect . $_ngimg_load . '</script>' );
857
-            echo apply_filters( 'autoptimize_filter_imgopt_ngimg_js', $_ngimg_output );
856
+            $_ngimg_output = apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_ngimg_detect.$_ngimg_load.'</script>');
857
+            echo apply_filters('autoptimize_filter_imgopt_ngimg_js', $_ngimg_output);
858 858
         }
859 859
     }
860 860
 
@@ -862,10 +862,10 @@  discard block
 block discarded – undo
862 862
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
863 863
         static $cdn_url = null;
864 864
 
865
-        if ( null === $cdn_url ) {
866
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
867
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
868
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
865
+        if (null === $cdn_url) {
866
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
867
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
868
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
869 869
         }
870 870
 
871 871
         return $cdn_url;
@@ -875,47 +875,47 @@  discard block
 block discarded – undo
875 875
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
876 876
         static $exclude_lazyload_array = null;
877 877
 
878
-        if ( null === $exclude_lazyload_array ) {
878
+        if (null === $exclude_lazyload_array) {
879 879
             $options = $this->options;
880 880
 
881 881
             // set default exclusions.
882
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
882
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
883 883
 
884 884
             // add from setting.
885
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
885
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
886 886
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
887
-                if ( ! empty( $exclude_lazyload_option ) ) {
888
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
887
+                if (!empty($exclude_lazyload_option)) {
888
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
889 889
                 }
890 890
             }
891 891
 
892 892
             // and filter for developer-initiated changes.
893
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
893
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
894 894
         }
895 895
 
896 896
         return $exclude_lazyload_array;
897 897
     }
898 898
 
899
-    public function inject_classes_in_tag( $tag, $target_class ) {
900
-        if ( strpos( $tag, 'class=' ) !== false ) {
901
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
899
+    public function inject_classes_in_tag($tag, $target_class) {
900
+        if (strpos($tag, 'class=') !== false) {
901
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
902 902
         } else {
903
-            $tag = preg_replace( '/(<[a-zA-Z]*)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
903
+            $tag = preg_replace('/(<[a-zA-Z]*)\s/', '$1 class="'.trim($target_class).'" ', $tag);
904 904
         }
905 905
 
906 906
         return $tag;
907 907
     }
908 908
 
909
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
910
-        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';
909
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
910
+        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';
911 911
     }
912 912
 
913 913
     public function should_ngimg() {
914 914
         static $ngimg_return = null;
915 915
 
916
-        if ( is_null( $ngimg_return ) ) {
916
+        if (is_null($ngimg_return)) {
917 917
             // webp only works if imgopt and lazyload are also active.
918
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
918
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
919 919
                 $ngimg_return = true;
920 920
             } else {
921 921
                 $ngimg_return = false;
@@ -925,9 +925,9 @@  discard block
 block discarded – undo
925 925
         return $ngimg_return;
926 926
     }
927 927
 
928
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
928
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
929 929
         // check if "<picture" is present and if filter allows us to process <picture>.
930
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
930
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
931 931
             return $in;
932 932
         }
933 933
 
@@ -935,37 +935,37 @@  discard block
 block discarded – undo
935 935
         $to_replace_pict = array();
936 936
 
937 937
         // extract and process each picture-node.
938
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
939
-        foreach ( $_pictures as $_picture ) {
940
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
941
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
942
-                foreach ( $_sources as $_source ) {
938
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
939
+        foreach ($_pictures as $_picture) {
940
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
941
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
942
+                foreach ($_sources as $_source) {
943 943
                     $_picture_replacement = $_source[0];
944 944
 
945 945
                     // should we optimize the image?
946
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
947
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
946
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
947
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
948 948
                     }
949 949
                     // should we lazy-load?
950
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
951
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
950
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
951
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
952 952
                     }
953
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
953
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
954 954
                 }
955 955
             }
956 956
         }
957 957
 
958 958
         // and return the fully procesed $in.
959
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
959
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
960 960
 
961 961
         return $out;
962 962
     }
963 963
 
964
-    public function process_bgimage( $in ) {
965
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
964
+    public function process_bgimage($in) {
965
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
966 966
             $out = preg_replace_callback(
967 967
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
968
-                array( $this, 'lazyload_bgimg_callback' ),
968
+                array($this, 'lazyload_bgimg_callback'),
969 969
                 $in
970 970
             );
971 971
             return $out;
@@ -973,27 +973,27 @@  discard block
 block discarded – undo
973 973
         return $in;
974 974
     }
975 975
 
976
-    public function lazyload_bgimg_callback( $matches ) {
977
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
976
+    public function lazyload_bgimg_callback($matches) {
977
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
978 978
             // get placeholder & lazyload class strings.
979
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
980
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
979
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
980
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
981 981
             // replace background-image URL with SVG placeholder.
982
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
982
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
983 983
             // add data-bg attribute with real background-image URL for lazyload to pick up.
984
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
984
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
985 985
             // add lazyload class to tag.
986
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
986
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
987 987
             return $out;
988 988
         }
989 989
         return $matches[0];
990 990
     }
991 991
 
992
-    public function maybe_fix_missing_quotes( $tag_in ) {
992
+    public function maybe_fix_missing_quotes($tag_in) {
993 993
         // 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.
994
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
995
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
996
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
994
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
995
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
996
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
997 997
             return $tag_out;
998 998
         } else {
999 999
             return $tag_in;
@@ -1006,23 +1006,23 @@  discard block
 block discarded – undo
1006 1006
     public function imgopt_admin_menu()
1007 1007
     {
1008 1008
         // no acces if multisite and not network admin and no site config allowed.
1009
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1009
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1010 1010
             add_submenu_page(
1011 1011
                 null,
1012 1012
                 'autoptimize_imgopt',
1013 1013
                 'autoptimize_imgopt',
1014 1014
                 'manage_options',
1015 1015
                 'autoptimize_imgopt',
1016
-                array( $this, 'imgopt_options_page' )
1016
+                array($this, 'imgopt_options_page')
1017 1017
             );
1018 1018
         }
1019
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
1019
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
1020 1020
     }
1021 1021
 
1022
-    public function add_imgopt_tab( $in )
1022
+    public function add_imgopt_tab($in)
1023 1023
     {
1024
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1025
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
1024
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1025
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1026 1026
         }
1027 1027
 
1028 1028
         return $in;
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
     public function imgopt_options_page()
1032 1032
     {
1033 1033
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1034
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1034
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1035 1035
             $this->query_img_provider_stats();
1036 1036
         }
1037 1037
 
@@ -1043,47 +1043,47 @@  discard block
 block discarded – undo
1043 1043
         #ao_settings_form .form-table th {font-weight: normal;}
1044 1044
         #autoptimize_imgopt_descr{font-size: 120%;}
1045 1045
     </style>
1046
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1046
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1047 1047
     <div class="wrap">
1048
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1048
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1049 1049
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1050
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1050
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1051 1051
             <div class="notice-warning notice"><p>
1052 1052
             <?php
1053 1053
             // translators: "Autoptimize support forum" will appear in a "a href".
1054
-            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>' );
1054
+            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>');
1055 1055
             ?>
1056 1056
             </p></div>
1057 1057
         <?php } ?>
1058 1058
 
1059
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1059
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1060 1060
             <div class="notice-warning notice"><p>
1061
-            <?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' ); ?>
1061
+            <?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'); ?>
1062 1062
             </p></div>
1063 1063
         <?php } ?>
1064 1064
 
1065
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1065
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1066 1066
             <div class="notice-warning notice"><p>
1067 1067
             <?php
1068 1068
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1069
-            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>' );
1069
+            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>');
1070 1070
             ?>
1071 1071
             </p></div>
1072 1072
         <?php } ?>
1073
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1074
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1075
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1076
-        <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 and AVIF support included!', 'autoptimize' ); ?></span>
1073
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1074
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1075
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1076
+        <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 and AVIF support included!', 'autoptimize'); ?></span>
1077 1077
         <table class="form-table">
1078 1078
             <tr>
1079
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1079
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1080 1080
                 <td>
1081
-                    <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>
1081
+                    <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>
1082 1082
                     <?php
1083 1083
                     // show shortpixel status.
1084 1084
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1085
-                    if ( $_notice ) {
1086
-                        switch ( $_notice['status'] ) {
1085
+                    if ($_notice) {
1086
+                        switch ($_notice['status']) {
1087 1087
                             case 2:
1088 1088
                                 $_notice_color = 'green';
1089 1089
                                 break;
@@ -1098,35 +1098,35 @@  discard block
 block discarded – undo
1098 1098
                             default:
1099 1099
                                 $_notice_color = 'green';
1100 1100
                         }
1101
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1101
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1102 1102
                     } else {
1103 1103
                         // translators: link points to shortpixel.
1104
-                        $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 and AVIF 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>' );
1105
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1106
-                            $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' );
1104
+                        $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 and AVIF 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>');
1105
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1106
+                            $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');
1107 1107
                         } else {
1108 1108
                             // translators: link points to shortpixel.
1109
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1109
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1110 1110
                         }
1111
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1111
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1112 1112
                     }
1113 1113
                     // translators: link points to shortpixel FAQ.
1114
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>' );
1115
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1114
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>');
1115
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1116 1116
                     // translators: links points to shortpixel TOS & Privacy Policy.
1117
-                    $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>' );
1118
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1117
+                    $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>');
1118
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1119 1119
                     ?>
1120 1120
                 </td>
1121 1121
             </tr>
1122
-            <tr id='autoptimize_imgopt_optimization_exclusions' <?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"'; } ?>>
1123
-                <th scope="row"><?php _e( 'Optimization exclusions', 'autoptimize' ); ?></th>
1122
+            <tr id='autoptimize_imgopt_optimization_exclusions' <?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"'; } ?>>
1123
+                <th scope="row"><?php _e('Optimization exclusions', 'autoptimize'); ?></th>
1124 1124
                 <td>
1125
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_optimization_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_6]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_6'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_6'] ); } ?>'><br /><?php _e( 'Comma-separated list of image classes or filenames that should not be optimized.', 'autoptimize' ); ?></label>
1125
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_optimization_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_6]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_6'])) { echo esc_attr($options['autoptimize_imgopt_text_field_6']); } ?>'><br /><?php _e('Comma-separated list of image classes or filenames that should not be optimized.', 'autoptimize'); ?></label>
1126 1126
                 </td>
1127 1127
             </tr>
1128
-            <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"'; } ?>>
1129
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1128
+            <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"'; } ?>>
1129
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1130 1130
                 <td>
1131 1131
                     <label>
1132 1132
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1134,12 +1134,12 @@  discard block
 block discarded – undo
1134 1134
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1135 1135
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1136 1136
 
1137
-                        foreach ( $_imgopt_array as $key => $value ) {
1138
-                            echo '<option value="' . $key . '"';
1139
-                            if ( $_imgopt_val == $key ) {
1137
+                        foreach ($_imgopt_array as $key => $value) {
1138
+                            echo '<option value="'.$key.'"';
1139
+                            if ($_imgopt_val == $key) {
1140 1140
                                 echo ' selected';
1141 1141
                             }
1142
-                            echo '>' . ucfirst( $value ) . '</option>';
1142
+                            echo '>'.ucfirst($value).'</option>';
1143 1143
                         }
1144 1144
                         echo "\n";
1145 1145
                         ?>
@@ -1148,31 +1148,31 @@  discard block
 block discarded – undo
1148 1148
                     <p>
1149 1149
                         <?php
1150 1150
                             // translators: link points to shortpixel image test page.
1151
-                            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>' ) );
1151
+                            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>'));
1152 1152
                         ?>
1153 1153
                     </p>
1154 1154
                 </td>
1155 1155
             </tr>
1156
-            <tr id='autoptimize_imgopt_ngimg' <?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"'; } ?>>
1157
-                <th scope="row"><?php _e( 'Load WebP or AVIF in supported browsers?', 'autoptimize' ); ?></th>
1156
+            <tr id='autoptimize_imgopt_ngimg' <?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"'; } ?>>
1157
+                <th scope="row"><?php _e('Load WebP or AVIF in supported browsers?', 'autoptimize'); ?></th>
1158 1158
                 <td>
1159
-                    <label><input type='checkbox' id='autoptimize_imgopt_ngimg_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 or AVIF image formats to any browser that supports it (requires lazy load to be active).', 'autoptimize' ); ?></label>
1159
+                    <label><input type='checkbox' id='autoptimize_imgopt_ngimg_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 or AVIF image formats to any browser that supports it (requires lazy load to be active).', 'autoptimize'); ?></label>
1160 1160
                 </td>
1161 1161
             </tr>
1162 1162
             <tr>
1163
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1163
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1164 1164
                 <td>
1165
-                    <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>
1165
+                    <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>
1166 1166
                 </td>
1167 1167
             </tr>
1168
-            <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"'; } ?>>
1169
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1168
+            <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"'; } ?>>
1169
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1170 1170
                 <td>
1171
-                    <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>
1171
+                    <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>
1172 1172
                 </td>
1173 1173
             </tr>
1174 1174
         </table>
1175
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1175
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1176 1176
     </form>
1177 1177
     <script>
1178 1178
         jQuery(document).ready(function() {
@@ -1210,50 +1210,50 @@  discard block
 block discarded – undo
1210 1210
      * Ïmg opt status as used on dashboard.
1211 1211
      */
1212 1212
     public function get_imgopt_status_notice() {
1213
-        if ( $this->imgopt_active() ) {
1213
+        if ($this->imgopt_active()) {
1214 1214
             $_imgopt_notice  = '';
1215
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1215
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1216 1216
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1217
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1217
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1218 1218
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1219 1219
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1220 1220
 
1221
-            if ( is_array( $_stat ) ) {
1222
-                if ( 1 == $_stat['Status'] ) {
1221
+            if (is_array($_stat)) {
1222
+                if (1 == $_stat['Status']) {
1223 1223
                     // translators: "add more credits" will appear in a "a href".
1224
-                    $_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>' );
1224
+                    $_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>');
1225 1225
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1226 1226
                     // translators: "add more credits" will appear in a "a href".
1227
-                    $_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>' );
1227
+                    $_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>');
1228 1228
                     // translators: "associate your domain" will appear in a "a href".
1229
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you have enough credits/ CDN quota remaining, 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>' );
1229
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you have enough credits/ CDN quota remaining, 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>');
1230 1230
                 } elseif ( -3 == $_stat['Status'] ) {
1231 1231
                     // translators: "check the documentation here" will appear in a "a href".
1232
-                    $_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>' );
1232
+                    $_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>');
1233 1233
                 } else {
1234 1234
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1235 1235
                     // translators: "log in to check your account" will appear in a "a href".
1236
-                    $_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>' );
1236
+                    $_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>');
1237 1237
                 }
1238 1238
 
1239 1239
                 // add info on freshness + refresh link if status is not 2 (good shape).
1240
-                if ( 2 != $_stat['Status'] ) {
1241
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1240
+                if (2 != $_stat['Status']) {
1241
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1242 1242
                         'page'                => 'autoptimize_imgopt',
1243 1243
                         'refreshImgProvStats' => '1',
1244
-                    ), admin_url( 'options-general.php' ) );
1245
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1246
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1244
+                    ), admin_url('options-general.php'));
1245
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1246
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1247 1247
                     } else {
1248
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1248
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1249 1249
                     }
1250
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1250
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1251 1251
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1252
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1252
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1253 1253
                 }
1254 1254
 
1255 1255
                 // and make the full notice filterable.
1256
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1256
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1257 1257
 
1258 1258
                 return array(
1259 1259
                     'status' => $_stat['Status'],
@@ -1274,14 +1274,14 @@  discard block
 block discarded – undo
1274 1274
      * Get img provider stats (used to display notice).
1275 1275
      */
1276 1276
     public function query_img_provider_stats() {
1277
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1277
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1278 1278
             $url      = '';
1279
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1279
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1280 1280
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1281 1281
 
1282 1282
             // make sure parse_url result makes sense, keeping $url empty if not.
1283
-            if ( $domain && ! empty( $domain ) ) {
1284
-                $url = $endpoint . $domain;
1283
+            if ($domain && !empty($domain)) {
1284
+                $url = $endpoint.$domain;
1285 1285
             }
1286 1286
 
1287 1287
             $url = apply_filters(
@@ -1291,12 +1291,12 @@  discard block
 block discarded – undo
1291 1291
 
1292 1292
             // only do the remote call if $url is not empty to make sure no parse_url
1293 1293
             // weirdness results in useless calls.
1294
-            if ( ! empty( $url ) ) {
1295
-                $response = wp_remote_get( $url );
1296
-                if ( ! is_wp_error( $response ) ) {
1297
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1298
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1299
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1294
+            if (!empty($url)) {
1295
+                $response = wp_remote_get($url);
1296
+                if (!is_wp_error($response)) {
1297
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1298
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1299
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1300 1300
                     }
1301 1301
                 }
1302 1302
             }
@@ -1319,15 +1319,15 @@  discard block
 block discarded – undo
1319 1319
     {
1320 1320
         static $launch_status = null;
1321 1321
 
1322
-        if ( null === $launch_status ) {
1322
+        if (null === $launch_status) {
1323 1323
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1324
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1325
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1324
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1325
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1326 1326
             $launch_status = false;
1327
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1327
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1328 1328
                 $launch_status = true;
1329
-                if ( ! $has_launched ) {
1330
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1329
+                if (!$has_launched) {
1330
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1331 1331
                 }
1332 1332
             }
1333 1333
         }
@@ -1344,16 +1344,16 @@  discard block
 block discarded – undo
1344 1344
     public function get_imgopt_provider_userstatus() {
1345 1345
         static $_provider_userstatus = null;
1346 1346
 
1347
-        if ( is_null( $_provider_userstatus ) ) {
1348
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1349
-            if ( is_array( $_stat ) ) {
1350
-                if ( array_key_exists( 'Status', $_stat ) ) {
1347
+        if (is_null($_provider_userstatus)) {
1348
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1349
+            if (is_array($_stat)) {
1350
+                if (array_key_exists('Status', $_stat)) {
1351 1351
                     $_provider_userstatus['Status'] = $_stat['Status'];
1352 1352
                 } else {
1353 1353
                     // if no stats then we assume all is well.
1354 1354
                     $_provider_userstatus['Status'] = 2;
1355 1355
                 }
1356
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1356
+                if (array_key_exists('timestamp', $_stat)) {
1357 1357
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1358 1358
                 } else {
1359 1359
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeMain.php 1 patch
Spacing   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,101 +50,101 @@  discard block
 block discarded – undo
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' ) );
67
+        add_action('init', array($this, 'load_textdomain'));
68 68
 
69
-        if ( is_multisite() && is_admin() ) {
69
+        if (is_multisite() && is_admin()) {
70 70
             // Only if multisite and if in admin we want to check if we need to save options on network level.
71
-            add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' );
71
+            add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options');
72 72
         }
73 73
 
74 74
         // register uninstall & deactivation hooks.
75
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
76
-        register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' );
75
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
76
+        register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation');
77 77
     }
78 78
 
79 79
     public function load_textdomain()
80 80
     {
81
-        load_plugin_textdomain( 'autoptimize' );
81
+        load_plugin_textdomain('autoptimize');
82 82
     }
83 83
 
84 84
     public function setup()
85 85
     {
86 86
         // Do we gzip in php when caching or is the webserver doing it?
87
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) );
87
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip'));
88 88
 
89 89
         // These can be overridden by specifying them in wp-config.php or such.
90
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
91
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
90
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
91
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
92 92
         }
93
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
94
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
93
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
94
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
95 95
         }
96
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
97
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
96
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
97
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
98 98
         }
99 99
         // Note: trailing slash is not optional!
100
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
101
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
100
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
101
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
102 102
         }
103 103
 
104
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
104
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
105 105
 
106
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
107
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
108
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
106
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
107
+            if (function_exists('domain_mapping_siteurl')) {
108
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
109 109
             } else {
110
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
110
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
111 111
             }
112 112
         }
113
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
114
-            if ( function_exists( 'get_original_url' ) ) {
115
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
113
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
114
+            if (function_exists('get_original_url')) {
115
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
116 116
             } else {
117
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
117
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
118 118
             }
119 119
         }
120
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
121
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
120
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
121
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
122 122
                 $blog_id = get_current_blog_id();
123
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
123
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
124 124
             } else {
125
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
125
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
126 126
             }
127 127
         }
128
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
129
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
128
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
129
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
130 130
         }
131
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
132
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
131
+        if (!defined('AUTOPTIMIZE_HASH')) {
132
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
133 133
         }
134
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
135
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
134
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
135
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
136 136
         }
137 137
 
138 138
         // Multibyte-capable string replacements are available with a filter.
139 139
         // Also requires 'mbstring' extension.
140
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
141
-        if ( $with_mbstring ) {
142
-            autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) );
140
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
141
+        if ($with_mbstring) {
142
+            autoptimizeUtils::mbstring_available(\extension_loaded('mbstring'));
143 143
         } else {
144
-            autoptimizeUtils::mbstring_available( false );
144
+            autoptimizeUtils::mbstring_available(false);
145 145
         }
146 146
 
147
-        do_action( 'autoptimize_setup_done' );
147
+        do_action('autoptimize_setup_done');
148 148
     }
149 149
 
150 150
     /**
@@ -154,61 +154,61 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public function version_upgrades_check()
156 156
     {
157
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
157
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
158 158
     }
159 159
 
160 160
     public function check_cache_and_run()
161 161
     {
162
-        if ( autoptimizeCache::cacheavail() ) {
162
+        if (autoptimizeCache::cacheavail()) {
163 163
             $conf = autoptimizeConfig::instance();
164
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) {
165
-                if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) {
164
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) {
165
+                if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) {
166 166
                     // Hook into WordPress frontend.
167
-                    if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
167
+                    if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
168 168
                         add_action(
169 169
                             'init',
170
-                            array( $this, 'start_buffering' ),
170
+                            array($this, 'start_buffering'),
171 171
                             self::INIT_EARLIER_PRIORITY
172 172
                         );
173 173
                     } else {
174
-                        if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
175
-                            define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
174
+                        if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
175
+                            define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
176 176
                         }
177 177
                         add_action(
178
-                            constant( 'AUTOPTIMIZE_HOOK_INTO' ),
179
-                            array( $this, 'start_buffering' ),
178
+                            constant('AUTOPTIMIZE_HOOK_INTO'),
179
+                            array($this, 'start_buffering'),
180 180
                             self::DEFAULT_HOOK_PRIORITY
181 181
                         );
182 182
                     }
183 183
                 }
184 184
 
185 185
                 // And disable Jetpack's site accelerator if JS or CSS opt. are active.
186
-                if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) {
187
-                    add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
186
+                if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) {
187
+                    add_filter('jetpack_force_disable_site_accelerator', '__return_true');
188 188
                 }
189 189
             }
190 190
         } else {
191
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
191
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
192 192
         }
193 193
     }
194 194
 
195 195
     public function maybe_run_ao_extra()
196 196
     {
197
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
197
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
198 198
             $ao_imgopt = new autoptimizeImages();
199 199
             $ao_imgopt->run();
200 200
             $ao_extra = new autoptimizeExtra();
201 201
             $ao_extra->run();
202 202
 
203 203
             // And show the imgopt notice.
204
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
204
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
205 205
         }
206 206
     }
207 207
 
208 208
     public function maybe_run_partners_tab()
209 209
     {
210 210
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
211
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
211
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
212 212
             new autoptimizePartners();
213 213
         }
214 214
     }
@@ -216,22 +216,22 @@  discard block
 block discarded – undo
216 216
     public function maybe_run_criticalcss()
217 217
     {
218 218
         // Loads criticalcss if the power-up is not active and if the filter returns true.
219
-        if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
219
+        if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) {
220 220
             new autoptimizeCriticalCSSBase();
221 221
         }
222 222
     }
223 223
 
224 224
     public function maybe_run_notfound_fallback()
225 225
     {
226
-        if ( autoptimizeCache::do_fallback() ) {
227
-            add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) );
226
+        if (autoptimizeCache::do_fallback()) {
227
+            add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback'));
228 228
         }
229 229
     }
230 230
 
231 231
     public function hook_page_cache_purge()
232 232
     {
233 233
         // hook into a collection of page cache purge actions if filter allows.
234
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
234
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
235 235
             $page_cache_purge_actions = array(
236 236
                 'after_rocket_clean_domain', // exists.
237 237
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
                 'wpo_cache_flush', // wp-optimize.
247 247
                 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper.
248 248
             );
249
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
250
-            foreach ( $page_cache_purge_actions as $purge_action ) {
251
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
249
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
250
+            foreach ($page_cache_purge_actions as $purge_action) {
251
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
252 252
             }
253 253
         }
254 254
     }
@@ -260,38 +260,38 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function start_buffering()
262 262
     {
263
-        if ( $this->should_buffer() ) {
263
+        if ($this->should_buffer()) {
264 264
 
265 265
             // Load speedupper conditionally (true by default).
266
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
266
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
267 267
                 $ao_speedupper = new autoptimizeSpeedupper();
268 268
             }
269 269
 
270 270
             $conf = autoptimizeConfig::instance();
271 271
 
272
-            if ( $conf->get( 'autoptimize_js' ) ) {
273
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
274
-                    define( 'CONCATENATE_SCRIPTS', false );
272
+            if ($conf->get('autoptimize_js')) {
273
+                if (!defined('CONCATENATE_SCRIPTS')) {
274
+                    define('CONCATENATE_SCRIPTS', false);
275 275
                 }
276
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
277
-                    define( 'COMPRESS_SCRIPTS', false );
276
+                if (!defined('COMPRESS_SCRIPTS')) {
277
+                    define('COMPRESS_SCRIPTS', false);
278 278
                 }
279 279
             }
280 280
 
281
-            if ( $conf->get( 'autoptimize_css' ) ) {
282
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
283
-                    define( 'COMPRESS_CSS', false );
281
+            if ($conf->get('autoptimize_css')) {
282
+                if (!defined('COMPRESS_CSS')) {
283
+                    define('COMPRESS_CSS', false);
284 284
                 }
285 285
             }
286 286
 
287
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
288
-                while ( ob_get_level() > 0 ) {
287
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
288
+                while (ob_get_level() > 0) {
289 289
                     ob_end_clean();
290 290
                 }
291 291
             }
292 292
 
293 293
             // Now, start the real thing!
294
-            ob_start( array( $this, 'end_buffering' ) );
294
+            ob_start(array($this, 'end_buffering'));
295 295
         }
296 296
     }
297 297
 
@@ -302,31 +302,31 @@  discard block
 block discarded – undo
302 302
      *                          deciding once per request (for use in tests).
303 303
      * @return bool
304 304
      */
305
-    public static function should_buffer( $doing_tests = false )
305
+    public static function should_buffer($doing_tests = false)
306 306
     {
307 307
         static $do_buffering = null;
308 308
 
309 309
         // Only check once in case we're called multiple times by others but
310 310
         // still allows multiple calls when doing tests.
311
-        if ( null === $do_buffering || $doing_tests ) {
311
+        if (null === $do_buffering || $doing_tests) {
312 312
 
313 313
             $ao_noptimize = false;
314 314
 
315 315
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
316
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
316
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
317 317
                 $ao_noptimize = true;
318 318
             }
319 319
 
320 320
             // Skip checking query strings if they're disabled.
321
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
321
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
322 322
                 // Check for `ao_noptimize` (and other) keys in the query string
323 323
                 // to get non-optimized page for debugging.
324 324
                 $keys = array(
325 325
                     'ao_noptimize',
326 326
                     'ao_noptirocket',
327 327
                 );
328
-                foreach ( $keys as $key ) {
329
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
328
+                foreach ($keys as $key) {
329
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
330 330
                         $ao_noptimize = true;
331 331
                         break;
332 332
                     }
@@ -334,15 +334,15 @@  discard block
 block discarded – undo
334 334
             }
335 335
 
336 336
             // If setting says not to optimize logged in user and user is logged in...
337
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
337
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
338 338
                 $ao_noptimize = true;
339 339
             }
340 340
 
341 341
             // If setting says not to optimize cart/checkout.
342
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) {
342
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) {
343 343
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
344
-                foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
345
-                    if ( function_exists( $func ) && $func() ) {
344
+                foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
345
+                    if (function_exists($func) && $func()) {
346 346
                         $ao_noptimize = true;
347 347
                         break;
348 348
                     }
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
             }
351 351
 
352 352
             // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
353
-            if ( false === $ao_noptimize ) {
354
-                $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
355
-                foreach ( $_qs_pagebuilders as $_pagebuilder ) {
356
-                    if ( array_key_exists( $_pagebuilder, $_GET ) ) {
353
+            if (false === $ao_noptimize) {
354
+                $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor');
355
+                foreach ($_qs_pagebuilders as $_pagebuilder) {
356
+                    if (array_key_exists($_pagebuilder, $_GET)) {
357 357
                         $ao_noptimize = true;
358 358
                         break;
359 359
                     }
@@ -362,16 +362,16 @@  discard block
 block discarded – undo
362 362
 
363 363
             // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
364 364
             // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
365
-            if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
365
+            if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
366 366
                 $ao_noptimize = true;
367 367
             }
368 368
 
369 369
             // And finally allows blocking of autoptimization on your own terms regardless of above decisions.
370
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
370
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
371 371
 
372 372
             // Check for site being previewed in the Customizer (available since WP 4.0).
373 373
             $is_customize_preview = false;
374
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
374
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
375 375
                 $is_customize_preview = is_customize_preview();
376 376
             }
377 377
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
              * while the main query hasn't been ran yet. Thats why we use
383 383
              * AUTOPTIMIZE_INIT_EARLIER in tests.
384 384
              */
385
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview );
385
+            $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview);
386 386
         }
387 387
 
388 388
         return $do_buffering;
@@ -395,25 +395,25 @@  discard block
 block discarded – undo
395 395
      *
396 396
      * @return bool
397 397
      */
398
-    public function is_valid_buffer( $content )
398
+    public function is_valid_buffer($content)
399 399
     {
400 400
         // Defaults to true.
401 401
         $valid = true;
402 402
 
403
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
404
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) );
405
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 );
406
-        $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) );
403
+        $has_no_html_tag    = (false === stripos($content, '<html'));
404
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet'));
405
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0);
406
+        $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->'));
407 407
 
408
-        if ( $has_no_html_tag ) {
408
+        if ($has_no_html_tag) {
409 409
             // Can't be valid amp markup without an html tag preceding it.
410 410
             $is_amp_markup = false;
411 411
         } else {
412
-            $is_amp_markup = self::is_amp_markup( $content );
412
+            $is_amp_markup = self::is_amp_markup($content);
413 413
         }
414 414
 
415 415
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
416
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) {
416
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) {
417 417
             $valid = false;
418 418
         }
419 419
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
      *
429 429
      * @return bool
430 430
      */
431
-    public static function is_amp_markup( $content )
431
+    public static function is_amp_markup($content)
432 432
     {
433 433
         // Short-circuit if the page is already AMP from the start.
434 434
         if (
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
         }
447 447
 
448 448
         // Or else short-circuit if the AMP plugin will be processing the output to be an AMP page.
449
-        if ( function_exists( 'amp_is_request' ) ) {
449
+        if (function_exists('amp_is_request')) {
450 450
             return amp_is_request(); // For AMP plugin v2.0+.
451
-        } elseif ( function_exists( 'is_amp_endpoint' ) ) {
451
+        } elseif (function_exists('is_amp_endpoint')) {
452 452
             return is_amp_endpoint(); // For older/other AMP plugins (still supported in 2.0 as an alias).
453 453
         }
454 454
 
@@ -463,10 +463,10 @@  discard block
 block discarded – undo
463 463
      *
464 464
      * @return string
465 465
      */
466
-    public function end_buffering( $content )
466
+    public function end_buffering($content)
467 467
     {
468 468
         // Bail early without modifying anything if we can't handle the content.
469
-        if ( ! $this->is_valid_buffer( $content ) ) {
469
+        if (!$this->is_valid_buffer($content)) {
470 470
             return $content;
471 471
         }
472 472
 
@@ -474,74 +474,74 @@  discard block
 block discarded – undo
474 474
 
475 475
         // Determine what needs to be ran.
476 476
         $classes = array();
477
-        if ( $conf->get( 'autoptimize_js' ) ) {
477
+        if ($conf->get('autoptimize_js')) {
478 478
             $classes[] = 'autoptimizeScripts';
479 479
         }
480
-        if ( $conf->get( 'autoptimize_css' ) ) {
480
+        if ($conf->get('autoptimize_css')) {
481 481
             $classes[] = 'autoptimizeStyles';
482 482
         }
483
-        if ( $conf->get( 'autoptimize_html' ) ) {
483
+        if ($conf->get('autoptimize_html')) {
484 484
             $classes[] = 'autoptimizeHTML';
485 485
         }
486 486
 
487 487
         $classoptions = array(
488 488
             'autoptimizeScripts' => array(
489
-                'aggregate'           => $conf->get( 'autoptimize_js_aggregate' ),
490
-                'defer_not_aggregate' => $conf->get( 'autoptimize_js_defer_not_aggregate' ),
491
-                'justhead'            => $conf->get( 'autoptimize_js_justhead' ),
492
-                'forcehead'           => $conf->get( 'autoptimize_js_forcehead' ),
493
-                'trycatch'            => $conf->get( 'autoptimize_js_trycatch' ),
494
-                'js_exclude'          => $conf->get( 'autoptimize_js_exclude' ),
495
-                'cdn_url'             => $conf->get( 'autoptimize_cdn_url' ),
496
-                'include_inline'      => $conf->get( 'autoptimize_js_include_inline' ),
497
-                'minify_excluded'     => $conf->get( 'autoptimize_minify_excluded' ),
489
+                'aggregate'           => $conf->get('autoptimize_js_aggregate'),
490
+                'defer_not_aggregate' => $conf->get('autoptimize_js_defer_not_aggregate'),
491
+                'justhead'            => $conf->get('autoptimize_js_justhead'),
492
+                'forcehead'           => $conf->get('autoptimize_js_forcehead'),
493
+                'trycatch'            => $conf->get('autoptimize_js_trycatch'),
494
+                'js_exclude'          => $conf->get('autoptimize_js_exclude'),
495
+                'cdn_url'             => $conf->get('autoptimize_cdn_url'),
496
+                'include_inline'      => $conf->get('autoptimize_js_include_inline'),
497
+                'minify_excluded'     => $conf->get('autoptimize_minify_excluded'),
498 498
             ),
499 499
             'autoptimizeStyles'  => array(
500
-                'aggregate'       => $conf->get( 'autoptimize_css_aggregate' ),
501
-                'justhead'        => $conf->get( 'autoptimize_css_justhead' ),
502
-                'datauris'        => $conf->get( 'autoptimize_css_datauris' ),
503
-                'defer'           => $conf->get( 'autoptimize_css_defer' ),
504
-                'defer_inline'    => $conf->get( 'autoptimize_css_defer_inline' ),
505
-                'inline'          => $conf->get( 'autoptimize_css_inline' ),
506
-                'css_exclude'     => $conf->get( 'autoptimize_css_exclude' ),
507
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
508
-                'include_inline'  => $conf->get( 'autoptimize_css_include_inline' ),
509
-                'nogooglefont'    => $conf->get( 'autoptimize_css_nogooglefont' ),
510
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
500
+                'aggregate'       => $conf->get('autoptimize_css_aggregate'),
501
+                'justhead'        => $conf->get('autoptimize_css_justhead'),
502
+                'datauris'        => $conf->get('autoptimize_css_datauris'),
503
+                'defer'           => $conf->get('autoptimize_css_defer'),
504
+                'defer_inline'    => $conf->get('autoptimize_css_defer_inline'),
505
+                'inline'          => $conf->get('autoptimize_css_inline'),
506
+                'css_exclude'     => $conf->get('autoptimize_css_exclude'),
507
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
508
+                'include_inline'  => $conf->get('autoptimize_css_include_inline'),
509
+                'nogooglefont'    => $conf->get('autoptimize_css_nogooglefont'),
510
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
511 511
             ),
512 512
             'autoptimizeHTML'    => array(
513
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
513
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
514 514
             ),
515 515
         );
516 516
 
517
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
517
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
518 518
 
519 519
         // Run the classes!
520
-        foreach ( $classes as $name ) {
521
-            $instance = new $name( $content );
522
-            if ( $instance->read( $classoptions[ $name ] ) ) {
520
+        foreach ($classes as $name) {
521
+            $instance = new $name($content);
522
+            if ($instance->read($classoptions[$name])) {
523 523
                 $instance->minify();
524 524
                 $instance->cache();
525 525
                 $content = $instance->getcontent();
526 526
             }
527
-            unset( $instance );
527
+            unset($instance);
528 528
         }
529 529
 
530
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
530
+        $content = apply_filters('autoptimize_html_after_minify', $content);
531 531
 
532 532
         return $content;
533 533
     }
534 534
 
535
-    public static function autoptimize_nobuffer_optimize( $html_in ) {
535
+    public static function autoptimize_nobuffer_optimize($html_in) {
536 536
         $html_out = $html_in;
537 537
 
538
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
538
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
539 539
             $ao_speedupper = new autoptimizeSpeedupper();
540 540
         }
541 541
 
542
-        $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
543
-        if ( $self->should_buffer() ) {
544
-            $html_out = $self->end_buffering( $html_in );
542
+        $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
543
+        if ($self->should_buffer()) {
544
+            $html_out = $self->end_buffering($html_in);
545 545
         }
546 546
         return $html_out;
547 547
     }
@@ -605,45 +605,45 @@  discard block
 block discarded – undo
605 605
             'autoptimize_ccss_unloadccss',
606 606
         );
607 607
 
608
-        if ( ! is_multisite() ) {
609
-            foreach ( $delete_options as $del_opt ) {
610
-                delete_option( $del_opt );
608
+        if (!is_multisite()) {
609
+            foreach ($delete_options as $del_opt) {
610
+                delete_option($del_opt);
611 611
             }
612 612
             autoptimizeMain::remove_cronjobs();
613 613
         } else {
614 614
             global $wpdb;
615
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
615
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
616 616
             $original_blog_id = get_current_blog_id();
617
-            foreach ( $blog_ids as $blog_id ) {
618
-                switch_to_blog( $blog_id );
619
-                foreach ( $delete_options as $del_opt ) {
620
-                    delete_option( $del_opt );
617
+            foreach ($blog_ids as $blog_id) {
618
+                switch_to_blog($blog_id);
619
+                foreach ($delete_options as $del_opt) {
620
+                    delete_option($del_opt);
621 621
                 }
622 622
                 autoptimizeMain::remove_cronjobs();
623 623
             }
624
-            switch_to_blog( $original_blog_id );
624
+            switch_to_blog($original_blog_id);
625 625
         }
626 626
 
627 627
         // Remove AO CCSS cached files and directory.
628
-        $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/';
629
-        if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) {
628
+        $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/';
629
+        if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) {
630 630
             // fixme: should check for subdirs when in multisite and remove contents of those as well.
631
-            array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) );
632
-            rmdir( $ao_ccss_dir );
631
+            array_map('unlink', glob($ao_ccss_dir.'*.{css,html,json,log,zip,lock}', GLOB_BRACE));
632
+            rmdir($ao_ccss_dir);
633 633
         }
634 634
     }
635 635
 
636 636
     public static function on_deactivation()
637 637
     {
638
-        if ( is_multisite() && is_network_admin() ) {
638
+        if (is_multisite() && is_network_admin()) {
639 639
             global $wpdb;
640
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
640
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
641 641
             $original_blog_id = get_current_blog_id();
642
-            foreach ( $blog_ids as $blog_id ) {
643
-                switch_to_blog( $blog_id );
642
+            foreach ($blog_ids as $blog_id) {
643
+                switch_to_blog($blog_id);
644 644
                 autoptimizeMain::remove_cronjobs();
645 645
             }
646
-            switch_to_blog( $original_blog_id );
646
+            switch_to_blog($original_blog_id);
647 647
         } else {
648 648
             autoptimizeMain::remove_cronjobs();
649 649
         }
@@ -652,9 +652,9 @@  discard block
 block discarded – undo
652 652
 
653 653
     public static function remove_cronjobs() {
654 654
         // Remove scheduled events.
655
-        foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) {
656
-            if ( wp_get_schedule( $_event ) ) {
657
-                wp_clear_scheduled_hook( $_event );
655
+        foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) {
656
+            if (wp_get_schedule($_event)) {
657
+                wp_clear_scheduled_hook($_event);
658 658
             }
659 659
         }
660 660
     }
@@ -663,35 +663,35 @@  discard block
 block discarded – undo
663 663
     {
664 664
         echo '<div class="error"><p>';
665 665
         // Translators: %s is the cache directory location.
666
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
666
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
667 667
         echo '</p></div>';
668 668
     }
669 669
 
670 670
     public static function notice_installed()
671 671
     {
672 672
         echo '<div class="updated"><p>';
673
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
673
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
674 674
         echo '</p></div>';
675 675
     }
676 676
 
677 677
     public static function notice_updated()
678 678
     {
679 679
         echo '<div class="updated"><p>';
680
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
680
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
681 681
         echo '</p></div>';
682 682
     }
683 683
 
684 684
     public static function notice_plug_imgopt()
685 685
     {
686 686
         // Translators: the URL added points to the Autopmize Extra settings.
687
-        $_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>' );
688
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
687
+        $_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>');
688
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
689 689
         $_ao_imgopt_launch_ok        = autoptimizeImages::launch_ok_wrapper();
690 690
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
691 691
         $_ao_imgopt_active           = autoptimizeImages::imgopt_active();
692 692
 
693
-        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 ) ) {
694
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
693
+        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)) {
694
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
695 695
             echo $_ao_imgopt_plug_notice;
696 696
             echo '</p></div>';
697 697
         }
Please login to merge, or discard this patch.
classes/autoptimizeScripts.php 1 patch
Spacing   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 
@@ -206,133 +206,133 @@  discard block
 block discarded – undo
206 206
      *
207 207
      * @param array $options all options.
208 208
      */
209
-    public function read( $options )
209
+    public function read($options)
210 210
     {
211
-        $noptimize_js = apply_filters( 'autoptimize_filter_js_noptimize', false, $this->content );
212
-        if ( $noptimize_js ) {
211
+        $noptimize_js = apply_filters('autoptimize_filter_js_noptimize', false, $this->content);
212
+        if ($noptimize_js) {
213 213
             return false;
214 214
         }
215 215
 
216 216
         // only optimize known good JS?
217
-        $allowlist_js = apply_filters( 'autoptimize_filter_js_allowlist', '', $this->content );
218
-        $allowlist_js = apply_filters( 'autoptimize_filter_js_whitelist', $allowlist_js, $this->content ); // fixme: to be removed in next version.
219
-        if ( ! empty( $allowlist_js ) ) {
220
-            $this->allowlist = array_filter( array_map( 'trim', explode( ',', $allowlist_js ) ) );
217
+        $allowlist_js = apply_filters('autoptimize_filter_js_allowlist', '', $this->content);
218
+        $allowlist_js = apply_filters('autoptimize_filter_js_whitelist', $allowlist_js, $this->content); // fixme: to be removed in next version.
219
+        if (!empty($allowlist_js)) {
220
+            $this->allowlist = array_filter(array_map('trim', explode(',', $allowlist_js)));
221 221
         }
222 222
 
223 223
         // is there JS we should simply remove?
224
-        $removable_js = apply_filters( 'autoptimize_filter_js_removables', '', $this->content );
225
-        if ( ! empty( $removable_js ) ) {
226
-            $this->jsremovables = array_filter( array_map( 'trim', explode( ',', $removable_js ) ) );
224
+        $removable_js = apply_filters('autoptimize_filter_js_removables', '', $this->content);
225
+        if (!empty($removable_js)) {
226
+            $this->jsremovables = array_filter(array_map('trim', explode(',', $removable_js)));
227 227
         }
228 228
 
229 229
         // only header?
230
-        if ( apply_filters( 'autoptimize_filter_js_justhead', $options['justhead'] ) ) {
231
-            $content             = explode( '</head>', $this->content, 2 );
232
-            $this->content       = $content[0] . '</head>';
230
+        if (apply_filters('autoptimize_filter_js_justhead', $options['justhead'])) {
231
+            $content             = explode('</head>', $this->content, 2);
232
+            $this->content       = $content[0].'</head>';
233 233
             $this->restofcontent = $content[1];
234 234
         }
235 235
 
236 236
         // Determine whether we're doing JS-files aggregation or not.
237
-        if ( ! $options['aggregate'] ) {
237
+        if (!$options['aggregate']) {
238 238
             $this->aggregate = false;
239 239
         }
240 240
         // Returning true for "dontaggregate" turns off aggregation.
241
-        if ( $this->aggregate && apply_filters( 'autoptimize_filter_js_dontaggregate', false ) ) {
241
+        if ($this->aggregate && apply_filters('autoptimize_filter_js_dontaggregate', false)) {
242 242
             $this->aggregate = false;
243 243
         }
244 244
         
245 245
         // Defer when not aggregating.
246
-        if ( false === $this->aggregate && apply_filters( 'autoptimize_js_filter_defer_not_aggregate', $options['defer_not_aggregate'] ) ) {
246
+        if (false === $this->aggregate && apply_filters('autoptimize_js_filter_defer_not_aggregate', $options['defer_not_aggregate'])) {
247 247
             $this->defer_not_aggregate = true;
248 248
         }
249 249
 
250 250
         // include inline?
251
-        if ( apply_filters( 'autoptimize_js_include_inline', $options['include_inline'] ) ) {
251
+        if (apply_filters('autoptimize_js_include_inline', $options['include_inline'])) {
252 252
             $this->include_inline = true;
253 253
         }
254 254
 
255 255
         // filter to "late inject minified JS", default to true for now (it is faster).
256
-        $this->inject_min_late = apply_filters( 'autoptimize_filter_js_inject_min_late', true );
256
+        $this->inject_min_late = apply_filters('autoptimize_filter_js_inject_min_late', true);
257 257
 
258 258
         // filters to override hardcoded do(nt)move(last) array contents (array in, array out!).
259
-        $this->dontmove   = apply_filters( 'autoptimize_filter_js_dontmove', $this->dontmove );
260
-        $this->domovelast = apply_filters( 'autoptimize_filter_js_movelast', $this->domovelast );
261
-        $this->domove     = apply_filters( 'autoptimize_filter_js_domove', $this->domove );
259
+        $this->dontmove   = apply_filters('autoptimize_filter_js_dontmove', $this->dontmove);
260
+        $this->domovelast = apply_filters('autoptimize_filter_js_movelast', $this->domovelast);
261
+        $this->domove     = apply_filters('autoptimize_filter_js_domove', $this->domove);
262 262
 
263 263
         // Determine whether excluded files should be minified if not yet so.
264
-        if ( ! $options['minify_excluded'] && $options['aggregate'] ) {
264
+        if (!$options['minify_excluded'] && $options['aggregate']) {
265 265
             $this->minify_excluded = false;
266 266
         }
267
-        $this->minify_excluded = apply_filters( 'autoptimize_filter_js_minify_excluded', $this->minify_excluded, '' );
267
+        $this->minify_excluded = apply_filters('autoptimize_filter_js_minify_excluded', $this->minify_excluded, '');
268 268
 
269 269
         // get extra exclusions settings or filter.
270 270
         $exclude_js = $options['js_exclude'];
271
-        $exclude_js = apply_filters( 'autoptimize_filter_js_exclude', $exclude_js, $this->content );
272
-
273
-        if ( '' !== $exclude_js ) {
274
-            if ( is_array( $exclude_js ) ) {
275
-                $remove_keys = array_keys( $exclude_js, 'remove' );
276
-                if ( false !== $remove_keys ) {
277
-                    foreach ( $remove_keys as $remove_key ) {
278
-                        unset( $exclude_js[ $remove_key ] );
271
+        $exclude_js = apply_filters('autoptimize_filter_js_exclude', $exclude_js, $this->content);
272
+
273
+        if ('' !== $exclude_js) {
274
+            if (is_array($exclude_js)) {
275
+                $remove_keys = array_keys($exclude_js, 'remove');
276
+                if (false !== $remove_keys) {
277
+                    foreach ($remove_keys as $remove_key) {
278
+                        unset($exclude_js[$remove_key]);
279 279
                         $this->jsremovables[] = $remove_key;
280 280
                     }
281 281
                 }
282
-                $excl_js_arr = array_keys( $exclude_js );
282
+                $excl_js_arr = array_keys($exclude_js);
283 283
             } else {
284
-                $excl_js_arr = array_filter( array_map( 'trim', explode( ',', $exclude_js ) ) );
284
+                $excl_js_arr = array_filter(array_map('trim', explode(',', $exclude_js)));
285 285
             }
286
-            $this->dontmove = array_merge( $excl_js_arr, $this->dontmove );
286
+            $this->dontmove = array_merge($excl_js_arr, $this->dontmove);
287 287
         }
288 288
 
289 289
         // Should we add try-catch?
290
-        if ( $options['trycatch'] ) {
290
+        if ($options['trycatch']) {
291 291
             $this->trycatch = true;
292 292
         }
293 293
 
294 294
         // force js in head?
295
-        if ( $options['forcehead'] ) {
295
+        if ($options['forcehead']) {
296 296
             $this->forcehead = true;
297 297
         } else {
298 298
             $this->forcehead = false;
299 299
         }
300 300
 
301
-        $this->forcehead = apply_filters( 'autoptimize_filter_js_forcehead', $this->forcehead );
301
+        $this->forcehead = apply_filters('autoptimize_filter_js_forcehead', $this->forcehead);
302 302
 
303 303
         // get cdn url.
304 304
         $this->cdn_url = $options['cdn_url'];
305 305
 
306 306
         // noptimize me.
307
-        $this->content = $this->hide_noptimize( $this->content );
307
+        $this->content = $this->hide_noptimize($this->content);
308 308
 
309 309
         // Save IE hacks.
310
-        $this->content = $this->hide_iehacks( $this->content );
310
+        $this->content = $this->hide_iehacks($this->content);
311 311
 
312 312
         // comments.
313
-        $this->content = $this->hide_comments( $this->content );
313
+        $this->content = $this->hide_comments($this->content);
314 314
 
315 315
         // Get script files.
316
-        if ( preg_match_all( '#<script.*</script>#Usmi', $this->content, $matches ) ) {
317
-            foreach ( $matches[0] as $tag ) {
316
+        if (preg_match_all('#<script.*</script>#Usmi', $this->content, $matches)) {
317
+            foreach ($matches[0] as $tag) {
318 318
                 // only consider script aggregation for types allowlisted in should_aggregate-function.
319
-                $should_aggregate = $this->should_aggregate( $tag );
320
-                if ( ! $should_aggregate ) {
319
+                $should_aggregate = $this->should_aggregate($tag);
320
+                if (!$should_aggregate) {
321 321
                     $tag = '';
322 322
                     continue;
323 323
                 }
324 324
 
325
-                if ( preg_match( '#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source ) ) {
325
+                if (preg_match('#<script[^>]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) {
326 326
                     // non-inline script.
327
-                    if ( $this->isremovable( $tag, $this->jsremovables ) ) {
328
-                        $this->content = str_replace( $tag, '', $this->content );
327
+                    if ($this->isremovable($tag, $this->jsremovables)) {
328
+                        $this->content = str_replace($tag, '', $this->content);
329 329
                         continue;
330 330
                     }
331 331
 
332 332
                     $orig_tag = null;
333
-                    $url      = current( explode( '?', $source[2], 2 ) );
334
-                    $path     = $this->getpath( $url );
335
-                    if ( false !== $path && preg_match( '#\.js$#', $path ) && $this->ismergeable( $tag ) ) {
333
+                    $url      = current(explode('?', $source[2], 2));
334
+                    $path     = $this->getpath($url);
335
+                    if (false !== $path && preg_match('#\.js$#', $path) && $this->ismergeable($tag)) {
336 336
                         // ok to optimize, add to array.
337 337
                         $this->scripts[] = $path;
338 338
                     } else {
@@ -340,35 +340,35 @@  discard block
 block discarded – undo
340 340
                         $new_tag  = $tag;
341 341
 
342 342
                         // non-mergeable script (excluded or dynamic or external).
343
-                        if ( is_array( $exclude_js ) ) {
343
+                        if (is_array($exclude_js)) {
344 344
                             // should we add flags?
345
-                            foreach ( $exclude_js as $excl_tag => $excl_flags ) {
346
-                                if ( false !== strpos( $orig_tag, $excl_tag ) && in_array( $excl_flags, array( 'async', 'defer' ) ) ) {
347
-                                    $new_tag = str_replace( '<script ', '<script ' . $excl_flags . ' ', $new_tag );
345
+                            foreach ($exclude_js as $excl_tag => $excl_flags) {
346
+                                if (false !== strpos($orig_tag, $excl_tag) && in_array($excl_flags, array('async', 'defer'))) {
347
+                                    $new_tag = str_replace('<script ', '<script '.$excl_flags.' ', $new_tag);
348 348
                                 }
349 349
                             }
350 350
                         }
351 351
                         
352 352
                         // not aggregating but deferring?
353
-                        if ( $this->defer_not_aggregate && false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path && strpos( $new_tag, ' defer' ) === false ) {
354
-                            $new_tag = str_replace( '<script ', '<script defer ', $new_tag );
353
+                        if ($this->defer_not_aggregate && false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path && strpos($new_tag, ' defer') === false) {
354
+                            $new_tag = str_replace('<script ', '<script defer ', $new_tag);
355 355
                             // and remove async as async+defer=async while we explicitly want defer.
356
-                            if ( strpos( $new_tag, ' async' ) !== false && apply_filters( 'autoptimize_filter_js_defer_remove_async', true ) ) {
357
-                                $new_tag = str_replace( array( ' async', ' async="async"', " async='async'" ), '', $new_tag );
356
+                            if (strpos($new_tag, ' async') !== false && apply_filters('autoptimize_filter_js_defer_remove_async', true)) {
357
+                                $new_tag = str_replace(array(' async', ' async="async"', " async='async'"), '', $new_tag);
358 358
                             }
359 359
                         }
360 360
 
361 361
                         // Should we minify the non-aggregated script?
362 362
                         // -> if aggregate is on and exclude minify is on
363 363
                         // -> if aggregate is off and the file is not in dontmove.
364
-                        if ( $path && $this->minify_excluded ) {
365
-                            $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false );
366
-                            if ( ( false === $this->aggregate && str_replace( $this->dontmove, '', $path ) === $path ) || ( true === $this->aggregate && ( false === $consider_minified_array || str_replace( $consider_minified_array, '', $path ) === $path ) ) ) {
367
-                                $minified_url = $this->minify_single( $path );
368
-                                if ( ! empty( $minified_url ) ) {
364
+                        if ($path && $this->minify_excluded) {
365
+                            $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false);
366
+                            if ((false === $this->aggregate && str_replace($this->dontmove, '', $path) === $path) || (true === $this->aggregate && (false === $consider_minified_array || str_replace($consider_minified_array, '', $path) === $path))) {
367
+                                $minified_url = $this->minify_single($path);
368
+                                if (!empty($minified_url)) {
369 369
                                     // Replace original URL with minified URL from cache.
370
-                                    $new_tag = str_replace( $url, $minified_url, $new_tag );
371
-                                } elseif ( apply_filters( 'autoptimize_filter_ccsjs_remove_empty_minified_url', false ) ) {
370
+                                    $new_tag = str_replace($url, $minified_url, $new_tag);
371
+                                } elseif (apply_filters('autoptimize_filter_ccsjs_remove_empty_minified_url', false)) {
372 372
                                     // Remove the original script tag, because cache content is empty but only if filter
373 373
                                     // is trued because $minified_url is also false if original JS is minified already.
374 374
                                     $new_tag = '';
@@ -376,17 +376,17 @@  discard block
 block discarded – undo
376 376
                             }
377 377
                         }
378 378
 
379
-                        if ( $this->ismovable( $new_tag ) ) {
379
+                        if ($this->ismovable($new_tag)) {
380 380
                             // can be moved, flags and all.
381
-                            if ( $this->movetolast( $new_tag ) ) {
381
+                            if ($this->movetolast($new_tag)) {
382 382
                                 $this->move['last'][] = $new_tag;
383 383
                             } else {
384 384
                                 $this->move['first'][] = $new_tag;
385 385
                             }
386 386
                         } else {
387 387
                             // cannot be moved, so if flag was added re-inject altered tag immediately.
388
-                            if ( ( '' !== $new_tag && $orig_tag !== $new_tag ) || ( '' === $new_tag && apply_filters( 'autoptimize_filter_js_remove_empty_files', false ) ) ) {
389
-                                $this->content = str_replace( $orig_tag, $new_tag, $this->content );
388
+                            if (('' !== $new_tag && $orig_tag !== $new_tag) || ('' === $new_tag && apply_filters('autoptimize_filter_js_remove_empty_files', false))) {
389
+                                $this->content = str_replace($orig_tag, $new_tag, $this->content);
390 390
                                 $orig_tag      = '';
391 391
                             }
392 392
                             // and forget about the $tag (not to be touched any more).
@@ -395,23 +395,23 @@  discard block
 block discarded – undo
395 395
                     }
396 396
                 } else {
397 397
                     // Inline script.
398
-                    if ( $this->isremovable( $tag, $this->jsremovables ) ) {
399
-                        $this->content = str_replace( $tag, '', $this->content );
398
+                    if ($this->isremovable($tag, $this->jsremovables)) {
399
+                        $this->content = str_replace($tag, '', $this->content);
400 400
                         continue;
401 401
                     }
402 402
 
403 403
                     // unhide comments, as javascript may be wrapped in comment-tags for old times' sake.
404
-                    $tag = $this->restore_comments( $tag );
405
-                    if ( $this->ismergeable( $tag ) && $this->include_inline ) {
406
-                        preg_match( '#<script.*>(.*)</script>#Usmi', $tag, $code );
407
-                        $code            = preg_replace( '#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1] );
408
-                        $code            = preg_replace( '/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code );
409
-                        $this->scripts[] = 'INLINE;' . $code;
404
+                    $tag = $this->restore_comments($tag);
405
+                    if ($this->ismergeable($tag) && $this->include_inline) {
406
+                        preg_match('#<script.*>(.*)</script>#Usmi', $tag, $code);
407
+                        $code            = preg_replace('#.*<!\[CDATA\[(?:\s*\*/)?(.*)(?://|/\*)\s*?\]\]>.*#sm', '$1', $code[1]);
408
+                        $code            = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $code);
409
+                        $this->scripts[] = 'INLINE;'.$code;
410 410
                     } else {
411 411
                         // Can we move this?
412
-                        $autoptimize_js_moveable = apply_filters( 'autoptimize_js_moveable', '', $tag );
413
-                        if ( $this->ismovable( $tag ) || '' !== $autoptimize_js_moveable ) {
414
-                            if ( $this->movetolast( $tag ) || 'last' === $autoptimize_js_moveable ) {
412
+                        $autoptimize_js_moveable = apply_filters('autoptimize_js_moveable', '', $tag);
413
+                        if ($this->ismovable($tag) || '' !== $autoptimize_js_moveable) {
414
+                            if ($this->movetolast($tag) || 'last' === $autoptimize_js_moveable) {
415 415
                                 $this->move['last'][] = $tag;
416 416
                             } else {
417 417
                                 $this->move['first'][] = $tag;
@@ -422,11 +422,11 @@  discard block
 block discarded – undo
422 422
                         }
423 423
                     }
424 424
                     // Re-hide comments to be able to do the removal based on tag from $this->content.
425
-                    $tag = $this->hide_comments( $tag );
425
+                    $tag = $this->hide_comments($tag);
426 426
                 }
427 427
 
428 428
                 // Remove the original script tag.
429
-                $this->content = str_replace( $tag, '', $this->content );
429
+                $this->content = str_replace($tag, '', $this->content);
430 430
             }
431 431
 
432 432
             return true;
@@ -451,30 +451,30 @@  discard block
 block discarded – undo
451 451
      * @param string $tag Script node & child(ren).
452 452
      * @return bool
453 453
      */
454
-    public function should_aggregate( $tag )
454
+    public function should_aggregate($tag)
455 455
     {
456
-        if ( empty( $tag ) ) {
456
+        if (empty($tag)) {
457 457
             return false;
458 458
         }
459 459
 
460 460
         // We're only interested in the type attribute of the <script> tag itself, not any possible
461 461
         // inline code that might just contain the 'type=' string...
462 462
         $tag_parts = array();
463
-        preg_match( '#<(script[^>]*)>#i', $tag, $tag_parts );
463
+        preg_match('#<(script[^>]*)>#i', $tag, $tag_parts);
464 464
         $tag_without_contents = null;
465
-        if ( ! empty( $tag_parts[1] ) ) {
465
+        if (!empty($tag_parts[1])) {
466 466
             $tag_without_contents = $tag_parts[1];
467 467
         }
468 468
 
469
-        $has_type = ( strpos( $tag_without_contents, 'type' ) !== false );
469
+        $has_type = (strpos($tag_without_contents, 'type') !== false);
470 470
 
471 471
         $type_valid = false;
472
-        if ( $has_type ) {
473
-            $type_valid = (bool) preg_match( '/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents );
472
+        if ($has_type) {
473
+            $type_valid = (bool) preg_match('/type\s*=\s*[\'"]?(?:text|application)\/(?:javascript|ecmascript)[\'"]?/i', $tag_without_contents);
474 474
         }
475 475
 
476 476
         $should_aggregate = false;
477
-        if ( ! $has_type || $type_valid ) {
477
+        if (!$has_type || $type_valid) {
478 478
             $should_aggregate = true;
479 479
         }
480 480
 
@@ -486,75 +486,75 @@  discard block
 block discarded – undo
486 486
      */
487 487
     public function minify()
488 488
     {
489
-        foreach ( $this->scripts as $script ) {
490
-            if ( empty( $script ) ) {
489
+        foreach ($this->scripts as $script) {
490
+            if (empty($script)) {
491 491
                 continue;
492 492
             }
493 493
 
494 494
             // TODO/FIXME: some duplicate code here, can be reduced/simplified.
495
-            if ( preg_match( '#^INLINE;#', $script ) ) {
495
+            if (preg_match('#^INLINE;#', $script)) {
496 496
                 // Inline script.
497
-                $script = preg_replace( '#^INLINE;#', '', $script );
498
-                $script = rtrim( $script, ";\n\t\r" ) . ';';
497
+                $script = preg_replace('#^INLINE;#', '', $script);
498
+                $script = rtrim($script, ";\n\t\r").';';
499 499
                 // Add try-catch?
500
-                if ( $this->trycatch ) {
501
-                    $script = 'try{' . $script . '}catch(e){}';
500
+                if ($this->trycatch) {
501
+                    $script = 'try{'.$script.'}catch(e){}';
502 502
                 }
503
-                $tmpscript = apply_filters( 'autoptimize_js_individual_script', $script, '' );
504
-                if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscript ) ) {
503
+                $tmpscript = apply_filters('autoptimize_js_individual_script', $script, '');
504
+                if (has_filter('autoptimize_js_individual_script') && !empty($tmpscript)) {
505 505
                     $script                = $tmpscript;
506 506
                     $this->alreadyminified = true;
507 507
                 }
508
-                $this->jscode .= "\n" . $script;
508
+                $this->jscode .= "\n".$script;
509 509
             } else {
510 510
                 // External script.
511
-                if ( false !== $script && file_exists( $script ) && is_readable( $script ) ) {
512
-                    $scriptsrc = file_get_contents( $script );
513
-                    $scriptsrc = preg_replace( '/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc );
514
-                    $scriptsrc = rtrim( $scriptsrc, ";\n\t\r" ) . ';';
511
+                if (false !== $script && file_exists($script) && is_readable($script)) {
512
+                    $scriptsrc = file_get_contents($script);
513
+                    $scriptsrc = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $scriptsrc);
514
+                    $scriptsrc = rtrim($scriptsrc, ";\n\t\r").';';
515 515
                     // Add try-catch?
516
-                    if ( $this->trycatch ) {
517
-                        $scriptsrc = 'try{' . $scriptsrc . '}catch(e){}';
516
+                    if ($this->trycatch) {
517
+                        $scriptsrc = 'try{'.$scriptsrc.'}catch(e){}';
518 518
                     }
519
-                    $tmpscriptsrc = apply_filters( 'autoptimize_js_individual_script', $scriptsrc, $script );
520
-                    if ( has_filter( 'autoptimize_js_individual_script' ) && ! empty( $tmpscriptsrc ) ) {
519
+                    $tmpscriptsrc = apply_filters('autoptimize_js_individual_script', $scriptsrc, $script);
520
+                    if (has_filter('autoptimize_js_individual_script') && !empty($tmpscriptsrc)) {
521 521
                         $scriptsrc             = $tmpscriptsrc;
522 522
                         $this->alreadyminified = true;
523
-                    } elseif ( $this->can_inject_late( $script ) ) {
524
-                        $scriptsrc = self::build_injectlater_marker( $script, md5( $scriptsrc ) );
523
+                    } elseif ($this->can_inject_late($script)) {
524
+                        $scriptsrc = self::build_injectlater_marker($script, md5($scriptsrc));
525 525
                     }
526
-                    $this->jscode .= "\n" . $scriptsrc;
526
+                    $this->jscode .= "\n".$scriptsrc;
527 527
                 }
528 528
             }
529 529
         }
530 530
 
531 531
         // Check for already-minified code.
532
-        $this->md5hash = md5( $this->jscode );
533
-        $ccheck        = new autoptimizeCache( $this->md5hash, 'js' );
534
-        if ( $ccheck->check() ) {
532
+        $this->md5hash = md5($this->jscode);
533
+        $ccheck        = new autoptimizeCache($this->md5hash, 'js');
534
+        if ($ccheck->check()) {
535 535
             $this->jscode = $ccheck->retrieve();
536 536
             return true;
537 537
         }
538
-        unset( $ccheck );
538
+        unset($ccheck);
539 539
 
540 540
         // $this->jscode has all the uncompressed code now.
541
-        if ( true !== $this->alreadyminified ) {
542
-            if ( apply_filters( 'autoptimize_js_do_minify', true ) ) {
543
-                $tmp_jscode = trim( JSMin::minify( $this->jscode ) );
544
-                if ( ! empty( $tmp_jscode ) ) {
541
+        if (true !== $this->alreadyminified) {
542
+            if (apply_filters('autoptimize_js_do_minify', true)) {
543
+                $tmp_jscode = trim(JSMin::minify($this->jscode));
544
+                if (!empty($tmp_jscode)) {
545 545
                     $this->jscode = $tmp_jscode;
546
-                    unset( $tmp_jscode );
546
+                    unset($tmp_jscode);
547 547
                 }
548
-                $this->jscode = $this->inject_minified( $this->jscode );
549
-                $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode );
548
+                $this->jscode = $this->inject_minified($this->jscode);
549
+                $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode);
550 550
                 return true;
551 551
             } else {
552
-                $this->jscode = $this->inject_minified( $this->jscode );
552
+                $this->jscode = $this->inject_minified($this->jscode);
553 553
                 return false;
554 554
             }
555 555
         }
556 556
 
557
-        $this->jscode = apply_filters( 'autoptimize_js_after_minify', $this->jscode );
557
+        $this->jscode = apply_filters('autoptimize_js_after_minify', $this->jscode);
558 558
         return true;
559 559
     }
560 560
 
@@ -563,13 +563,13 @@  discard block
 block discarded – undo
563 563
      */
564 564
     public function cache()
565 565
     {
566
-        $cache = new autoptimizeCache( $this->md5hash, 'js' );
567
-        if ( ! $cache->check() ) {
566
+        $cache = new autoptimizeCache($this->md5hash, 'js');
567
+        if (!$cache->check()) {
568 568
             // Cache our code.
569
-            $cache->cache( $this->jscode, 'text/javascript' );
569
+            $cache->cache($this->jscode, 'text/javascript');
570 570
         }
571
-        $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname();
572
-        $this->url = $this->url_replace_cdn( $this->url );
571
+        $this->url = AUTOPTIMIZE_CACHE_URL.$cache->getname();
572
+        $this->url = $this->url_replace_cdn($this->url);
573 573
     }
574 574
 
575 575
     /**
@@ -578,47 +578,47 @@  discard block
 block discarded – undo
578 578
     public function getcontent()
579 579
     {
580 580
         // Restore the full content.
581
-        if ( ! empty( $this->restofcontent ) ) {
581
+        if (!empty($this->restofcontent)) {
582 582
             $this->content      .= $this->restofcontent;
583 583
             $this->restofcontent = '';
584 584
         }
585 585
 
586 586
         // Add the scripts taking forcehead/ deferred (default) into account.
587
-        if ( $this->forcehead ) {
588
-            $replace_tag = array( '</head>', 'before' );
587
+        if ($this->forcehead) {
588
+            $replace_tag = array('</head>', 'before');
589 589
             $defer       = '';
590 590
         } else {
591
-            $replace_tag = array( '</body>', 'before' );
591
+            $replace_tag = array('</body>', 'before');
592 592
             $defer       = 'defer ';
593 593
         }
594 594
 
595
-        $defer   = apply_filters( 'autoptimize_filter_js_defer', $defer );
595
+        $defer   = apply_filters('autoptimize_filter_js_defer', $defer);
596 596
         $type_js = '';
597
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
597
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
598 598
             $type_js = 'type="text/javascript" ';
599 599
         }
600 600
 
601
-        $bodyreplacementpayload = '<script ' . $type_js . $defer . 'src="' . $this->url . '"></script>';
602
-        $bodyreplacementpayload = apply_filters( 'autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload );
601
+        $bodyreplacementpayload = '<script '.$type_js.$defer.'src="'.$this->url.'"></script>';
602
+        $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload', $bodyreplacementpayload);
603 603
 
604
-        $bodyreplacement  = implode( '', $this->move['first'] );
604
+        $bodyreplacement  = implode('', $this->move['first']);
605 605
         $bodyreplacement .= $bodyreplacementpayload;
606
-        $bodyreplacement .= implode( '', $this->move['last'] );
606
+        $bodyreplacement .= implode('', $this->move['last']);
607 607
 
608
-        $replace_tag = apply_filters( 'autoptimize_filter_js_replacetag', $replace_tag );
608
+        $replace_tag = apply_filters('autoptimize_filter_js_replacetag', $replace_tag);
609 609
 
610
-        if ( strlen( $this->jscode ) > 0 ) {
611
-            $this->inject_in_html( $bodyreplacement, $replace_tag );
610
+        if (strlen($this->jscode) > 0) {
611
+            $this->inject_in_html($bodyreplacement, $replace_tag);
612 612
         }
613 613
 
614 614
         // Restore comments.
615
-        $this->content = $this->restore_comments( $this->content );
615
+        $this->content = $this->restore_comments($this->content);
616 616
 
617 617
         // Restore IE hacks.
618
-        $this->content = $this->restore_iehacks( $this->content );
618
+        $this->content = $this->restore_iehacks($this->content);
619 619
 
620 620
         // Restore noptimize.
621
-        $this->content = $this->restore_noptimize( $this->content );
621
+        $this->content = $this->restore_noptimize($this->content);
622 622
 
623 623
         // Return the modified HTML.
624 624
         return $this->content;
@@ -629,34 +629,34 @@  discard block
 block discarded – undo
629 629
      *
630 630
      * @param string $tag JS tag.
631 631
      */
632
-    private function ismergeable( $tag )
632
+    private function ismergeable($tag)
633 633
     {
634
-        if ( empty( $tag ) || ! $this->aggregate ) {
634
+        if (empty($tag) || !$this->aggregate) {
635 635
             return false;
636 636
         }
637 637
 
638
-        if ( ! empty( $this->allowlist ) ) {
639
-            foreach ( $this->allowlist as $match ) {
640
-                if ( false !== strpos( $tag, $match ) ) {
638
+        if (!empty($this->allowlist)) {
639
+            foreach ($this->allowlist as $match) {
640
+                if (false !== strpos($tag, $match)) {
641 641
                     return true;
642 642
                 }
643 643
             }
644 644
             // No match with allowlist.
645 645
             return false;
646 646
         } else {
647
-            foreach ( $this->domove as $match ) {
648
-                if ( false !== strpos( $tag, $match ) ) {
647
+            foreach ($this->domove as $match) {
648
+                if (false !== strpos($tag, $match)) {
649 649
                     // Matched something.
650 650
                     return false;
651 651
                 }
652 652
             }
653 653
 
654
-            if ( $this->movetolast( $tag ) ) {
654
+            if ($this->movetolast($tag)) {
655 655
                 return false;
656 656
             }
657 657
 
658
-            foreach ( $this->dontmove as $match ) {
659
-                if ( false !== strpos( $tag, $match ) ) {
658
+            foreach ($this->dontmove as $match) {
659
+                if (false !== strpos($tag, $match)) {
660 660
                     // Matched something.
661 661
                     return false;
662 662
                 }
@@ -672,25 +672,25 @@  discard block
 block discarded – undo
672 672
      *
673 673
      * @param string $tag tag to check for blocklist (exclusions).
674 674
      */
675
-    private function ismovable( $tag )
675
+    private function ismovable($tag)
676 676
     {
677
-        if ( empty( $tag ) || true !== $this->include_inline || apply_filters( 'autoptimize_filter_js_unmovable', true ) ) {
677
+        if (empty($tag) || true !== $this->include_inline || apply_filters('autoptimize_filter_js_unmovable', true)) {
678 678
             return false;
679 679
         }
680 680
 
681
-        foreach ( $this->domove as $match ) {
682
-            if ( false !== strpos( $tag, $match ) ) {
681
+        foreach ($this->domove as $match) {
682
+            if (false !== strpos($tag, $match)) {
683 683
                 // Matched something.
684 684
                 return true;
685 685
             }
686 686
         }
687 687
 
688
-        if ( $this->movetolast( $tag ) ) {
688
+        if ($this->movetolast($tag)) {
689 689
             return true;
690 690
         }
691 691
 
692
-        foreach ( $this->dontmove as $match ) {
693
-            if ( false !== strpos( $tag, $match ) ) {
692
+        foreach ($this->dontmove as $match) {
693
+            if (false !== strpos($tag, $match)) {
694 694
                 // Matched something.
695 695
                 return false;
696 696
             }
@@ -700,14 +700,14 @@  discard block
 block discarded – undo
700 700
         return true;
701 701
     }
702 702
 
703
-    private function movetolast( $tag )
703
+    private function movetolast($tag)
704 704
     {
705
-        if ( empty( $tag ) ) {
705
+        if (empty($tag)) {
706 706
             return false;
707 707
         }
708 708
 
709
-        foreach ( $this->domovelast as $match ) {
710
-            if ( false !== strpos( $tag, $match ) ) {
709
+        foreach ($this->domovelast as $match) {
710
+            if (false !== strpos($tag, $match)) {
711 711
                 // Matched, return true.
712 712
                 return true;
713 713
             }
@@ -727,12 +727,12 @@  discard block
 block discarded – undo
727 727
      * @param string $js_path Path to JS file.
728 728
      * @return bool
729 729
      */
730
-    private function can_inject_late( $js_path ) {
731
-        $consider_minified_array = apply_filters( 'autoptimize_filter_js_consider_minified', false );
732
-        if ( true !== $this->inject_min_late ) {
730
+    private function can_inject_late($js_path) {
731
+        $consider_minified_array = apply_filters('autoptimize_filter_js_consider_minified', false);
732
+        if (true !== $this->inject_min_late) {
733 733
             // late-inject turned off.
734 734
             return false;
735
-        } 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 ) ) {
735
+        } 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)) {
736 736
             // file not minified based on filename & filter.
737 737
             return false;
738 738
         } else {
@@ -759,35 +759,35 @@  discard block
 block discarded – undo
759 759
      *
760 760
      * @return bool|string Url pointing to the minified js file or false.
761 761
      */
762
-    public function minify_single( $filepath, $cache_miss = false )
762
+    public function minify_single($filepath, $cache_miss = false)
763 763
     {
764
-        $contents = $this->prepare_minify_single( $filepath );
764
+        $contents = $this->prepare_minify_single($filepath);
765 765
 
766
-        if ( empty( $contents ) ) {
766
+        if (empty($contents)) {
767 767
             return false;
768 768
         }
769 769
 
770 770
         // Check cache.
771
-        $hash  = 'single_' . md5( $contents );
772
-        $cache = new autoptimizeCache( $hash, 'js' );
771
+        $hash  = 'single_'.md5($contents);
772
+        $cache = new autoptimizeCache($hash, 'js');
773 773
 
774 774
         // If not in cache already, minify...
775
-        if ( ! $cache->check() || $cache_miss ) {
776
-            $contents = trim( JSMin::minify( $contents ) );
775
+        if (!$cache->check() || $cache_miss) {
776
+            $contents = trim(JSMin::minify($contents));
777 777
 
778 778
             // Check if minified cache content is empty.
779
-            if ( empty( $contents ) ) {
779
+            if (empty($contents)) {
780 780
                 return false;
781 781
             }
782 782
 
783 783
             // Filter contents of excluded minified CSS.
784
-            $contents = apply_filters( 'autoptimize_filter_js_single_after_minify', $contents );
784
+            $contents = apply_filters('autoptimize_filter_js_single_after_minify', $contents);
785 785
 
786 786
             // Store in cache.
787
-            $cache->cache( $contents, 'text/javascript' );
787
+            $cache->cache($contents, 'text/javascript');
788 788
         }
789 789
 
790
-        $url = $this->build_minify_single_url( $cache );
790
+        $url = $this->build_minify_single_url($cache);
791 791
 
792 792
         return $url;
793 793
     }
Please login to merge, or discard this patch.
classes/autoptimizeExtra.php 1 patch
Spacing   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,153 +218,153 @@  discard block
 block discarded – undo
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 240
                     // todo: support for 100..900
241
-                    $font = rawurldecode( $font );
242
-                    $font = str_replace( array( 'css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family=' ), array( 'css?', '', '', '', '', 'italic', ':italic', ',', '%7C' ), $font );
241
+                    $font = rawurldecode($font);
242
+                    $font = str_replace(array('css2?', 'ital,wght@', 'wght@', 'ital@', '0,', '1,', ':1', ';', '&family='), array('css?', '', '', '', '', 'italic', ':italic', ',', '%7C'), $font);
243 243
                 }
244
-                $font = explode( 'family=', $font );
245
-                $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array();
244
+                $font = explode('family=', $font);
245
+                $font = (isset($font[1])) ? explode('&', $font[1]) : array();
246 246
                 // Add font to $fonts[$i] but make sure not to pollute with an empty family!
247
-                $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) );
248
-                if ( ! empty( $_thisfont ) ) {
249
-                    $fonts_collection[ $i ]['fonts'] = $_thisfont;
247
+                $_thisfont = array_values(array_filter(explode('|', reset($font))));
248
+                if (!empty($_thisfont)) {
249
+                    $fonts_collection[$i]['fonts'] = $_thisfont;
250 250
                     // And add subset if any!
251
-                    $subset = ( is_array( $font ) ) ? end( $font ) : '';
252
-                    if ( false !== strpos( $subset, 'subset=' ) ) {
253
-                        $subset                            = str_replace( array( '%2C', '%2c' ), ',', $subset );
254
-                        $subset                            = explode( 'subset=', $subset );
255
-                        $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] );
251
+                    $subset = (is_array($font)) ? end($font) : '';
252
+                    if (false !== strpos($subset, 'subset=')) {
253
+                        $subset                            = str_replace(array('%2C', '%2c'), ',', $subset);
254
+                        $subset                            = explode('subset=', $subset);
255
+                        $fonts_collection[$i]['subsets'] = explode(',', $subset[1]);
256 256
                     }
257 257
                 }
258 258
                 // And remove Google Fonts.
259
-                $in = str_replace( $matches[0][ $i ], '', $in );
259
+                $in = str_replace($matches[0][$i], '', $in);
260 260
             }
261 261
             $i++;
262 262
         }
263 263
 
264 264
         $options      = $this->options;
265 265
         $fonts_markup = '';
266
-        if ( '2' === $options['autoptimize_extra_radio_field_4'] ) {
266
+        if ('2' === $options['autoptimize_extra_radio_field_4']) {
267 267
             // Remove Google Fonts.
268
-            unset( $fonts_collection );
268
+            unset($fonts_collection);
269 269
             return $in;
270
-        } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) {
270
+        } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) {
271 271
             // Aggregate & link!
272 272
             $fonts_string  = '';
273 273
             $subset_string = '';
274
-            foreach ( $fonts_collection as $font ) {
275
-                $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' );
276
-                if ( ! empty( $font['subsets'] ) ) {
277
-                    $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' );
274
+            foreach ($fonts_collection as $font) {
275
+                $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|');
276
+                if (!empty($font['subsets'])) {
277
+                    $subset_string .= ','.trim(implode(',', $font['subsets']), ',');
278 278
                 }
279 279
             }
280 280
 
281
-            if ( ! empty( $subset_string ) ) {
282
-                $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) );
283
-                $fonts_string  = $fonts_string . '&#038;subset=' . $subset_string;
281
+            if (!empty($subset_string)) {
282
+                $subset_string = str_replace(',', '%2C', ltrim($subset_string, ','));
283
+                $fonts_string  = $fonts_string.'&#038;subset='.$subset_string;
284 284
             }
285 285
 
286
-            $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) );
286
+            $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|')));
287 287
             // only add display parameter if there is none in $fonts_string (by virtue of the filter).
288
-            if ( strpos( $fonts_string, 'display=' ) === false ) {
289
-                $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&amp;display=swap' );
288
+            if (strpos($fonts_string, 'display=') === false) {
289
+                $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&amp;display=swap');
290 290
             }
291 291
 
292
-            if ( ! empty( $fonts_string ) ) {
293
-                if ( '5' === $options['autoptimize_extra_radio_field_4'] ) {
294
-                    $rel_string = 'rel="stylesheet" media="print" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"';
292
+            if (!empty($fonts_string)) {
293
+                if ('5' === $options['autoptimize_extra_radio_field_4']) {
294
+                    $rel_string = 'rel="stylesheet" media="print" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"';
295 295
                 } else {
296 296
                     $rel_string = 'rel="stylesheet"';
297 297
                 }
298
-                $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />';
298
+                $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />';
299 299
             }
300
-        } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) {
300
+        } elseif ('4' === $options['autoptimize_extra_radio_field_4']) {
301 301
             // Aggregate & load async (webfont.js impl.)!
302 302
             $fonts_array = array();
303
-            foreach ( $fonts_collection as $_fonts ) {
304
-                if ( ! empty( $_fonts['subsets'] ) ) {
305
-                    $_subset = implode( ',', $_fonts['subsets'] );
306
-                    foreach ( $_fonts['fonts'] as $key => $_one_font ) {
307
-                        $_one_font               = $_one_font . ':' . $_subset;
308
-                        $_fonts['fonts'][ $key ] = $_one_font;
303
+            foreach ($fonts_collection as $_fonts) {
304
+                if (!empty($_fonts['subsets'])) {
305
+                    $_subset = implode(',', $_fonts['subsets']);
306
+                    foreach ($_fonts['fonts'] as $key => $_one_font) {
307
+                        $_one_font               = $_one_font.':'.$_subset;
308
+                        $_fonts['fonts'][$key] = $_one_font;
309 309
                     }
310 310
                 }
311
-                $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] );
311
+                $fonts_array = array_merge($fonts_array, $_fonts['fonts']);
312 312
             }
313 313
 
314
-            $fonts_array = array_map( 'urldecode', $fonts_array );
314
+            $fonts_array = array_map('urldecode', $fonts_array);
315 315
             $fonts_array = array_map(
316
-                function( $_f ) {
317
-                    return trim( $_f, ',' );
316
+                function($_f) {
317
+                    return trim($_f, ',');
318 318
                 },
319 319
                 $fonts_array
320 320
             );
321 321
 
322 322
             // type attrib on <script not added by default.
323 323
             $type_js = '';
324
-            if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
324
+            if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
325 325
                 $type_js = 'type="text/javascript" ';
326 326
             }
327 327
 
328
-            $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>';
329
-            $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>';
330
-            $in                   = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) );
328
+            $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>';
329
+            $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>';
330
+            $in                   = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>'));
331 331
         }
332 332
 
333 333
         // Replace back in markup.
334
-        $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
335
-        $out          = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
336
-        unset( $fonts_collection );
334
+        $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link');
335
+        $out          = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point));
336
+        unset($fonts_collection);
337 337
 
338 338
         return $out;
339 339
     }
340 340
 
341
-    public function filter_preconnect( $hints, $relation_type )
341
+    public function filter_preconnect($hints, $relation_type)
342 342
     {
343 343
         $options  = $this->options;
344 344
         $preconns = array();
345 345
 
346 346
         // Get settings and store in array.
347
-        if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) {
348
-            $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) );
347
+        if (array_key_exists('autoptimize_extra_text_field_2', $options)) {
348
+            $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2'])));
349 349
         }
350
-        $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns );
350
+        $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns);
351 351
 
352 352
         // Walk array, extract domain and add to new array with crossorigin attribute.
353
-        foreach ( $preconns as $preconn ) {
353
+        foreach ($preconns as $preconn) {
354 354
             $domain = '';
355
-            $parsed = parse_url( $preconn );
356
-            if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) {
357
-                $domain = '//' . $parsed['host'];
358
-            } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) {
359
-                $domain = $parsed['scheme'] . '://' . $parsed['host'];
355
+            $parsed = parse_url($preconn);
356
+            if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) {
357
+                $domain = '//'.$parsed['host'];
358
+            } elseif (is_array($parsed) && !empty($parsed['host'])) {
359
+                $domain = $parsed['scheme'].'://'.$parsed['host'];
360 360
             }
361 361
 
362
-            if ( ! empty( $domain ) ) {
363
-                $hint = array( 'href' => $domain );
362
+            if (!empty($domain)) {
363
+                $hint = array('href' => $domain);
364 364
                 // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set
365 365
                 // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed.
366
-                $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) );
367
-                if ( in_array( $domain, $crossorigins ) ) {
366
+                $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com'));
367
+                if (in_array($domain, $crossorigins)) {
368 368
                     $hint['crossorigin'] = 'anonymous';
369 369
                 }
370 370
                 $new_hints[] = $hint;
@@ -372,21 +372,21 @@  discard block
 block discarded – undo
372 372
         }
373 373
 
374 374
         // Merge in WP's preconnect hints.
375
-        if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) {
376
-            $hints = array_merge( $hints, $new_hints );
375
+        if ('preconnect' === $relation_type && !empty($new_hints)) {
376
+            $hints = array_merge($hints, $new_hints);
377 377
         }
378 378
 
379 379
         return $hints;
380 380
     }
381 381
 
382
-    public function filter_preconnect_google_fonts( $in )
382
+    public function filter_preconnect_google_fonts($in)
383 383
     {
384
-        if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) {
384
+        if ('2' !== $this->options['autoptimize_extra_radio_field_4']) {
385 385
             // Preconnect to fonts.gstatic.com unless we remove gfonts.
386 386
             $in[] = 'https://fonts.gstatic.com';
387 387
         }
388 388
 
389
-        if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) {
389
+        if ('4' === $this->options['autoptimize_extra_radio_field_4']) {
390 390
             // Preconnect even more hosts for webfont.js!
391 391
             $in[] = 'https://ajax.googleapis.com';
392 392
             $in[] = 'https://fonts.googleapis.com';
@@ -395,76 +395,76 @@  discard block
 block discarded – undo
395 395
         return $in;
396 396
     }
397 397
 
398
-    public function filter_preload( $in ) {
398
+    public function filter_preload($in) {
399 399
         // make array from comma separated list.
400 400
         $options  = $this->options;
401 401
         $preloads = array();
402
-        if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) {
403
-            $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) );
402
+        if (array_key_exists('autoptimize_extra_text_field_7', $options)) {
403
+            $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7'])));
404 404
         }
405
-        $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads );
405
+        $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads);
406 406
 
407 407
         // immediately return if nothing to be preloaded.
408
-        if ( empty( $preloads ) ) {
408
+        if (empty($preloads)) {
409 409
             return $in;
410 410
         }
411 411
 
412 412
         // iterate through array and add preload link to tmp string.
413 413
         $preload_output = '';
414
-        foreach ( $preloads as $preload ) {
414
+        foreach ($preloads as $preload) {
415 415
             $crossorigin = '';
416 416
             $preload_as  = '';
417 417
             $mime_type   = '';
418
-            $_preload    = strtok( $preload, '?' );
418
+            $_preload    = strtok($preload, '?');
419 419
 
420
-            if ( autoptimizeUtils::str_ends_in( $_preload, '.css' ) ) {
420
+            if (autoptimizeUtils::str_ends_in($_preload, '.css')) {
421 421
                 $preload_as = 'style';
422
-            } elseif ( autoptimizeUtils::str_ends_in( $_preload, '.js' ) ) {
422
+            } elseif (autoptimizeUtils::str_ends_in($_preload, '.js')) {
423 423
                 $preload_as = 'script';
424
-            } 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' ) || autoptimizeUtils::str_ends_in( $_preload, '.otf' ) ) {
424
+            } 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') || autoptimizeUtils::str_ends_in($_preload, '.otf')) {
425 425
                 $preload_as  = 'font';
426 426
                 $crossorigin = ' crossorigin';
427
-                $mime_type   = ' type="font/' . pathinfo( $_preload, PATHINFO_EXTENSION ) . '"';
428
-                if ( ' type="font/eot"' === $mime_type ) {
427
+                $mime_type   = ' type="font/'.pathinfo($_preload, PATHINFO_EXTENSION).'"';
428
+                if (' type="font/eot"' === $mime_type) {
429 429
                     $mime_type = 'application/vnd.ms-fontobject';
430 430
                 }
431
-            } 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' ) ) {
431
+            } 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')) {
432 432
                 $preload_as = 'image';
433 433
             } else {
434 434
                 $preload_as = 'other';
435 435
             }
436 436
 
437
-            $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>';
437
+            $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>';
438 438
         }
439
-        $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output );
439
+        $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output);
440 440
 
441 441
         // add string to head (before first link node by default).
442
-        $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' );
443
-        $position       = autoptimizeUtils::strpos( $in, $preload_inject );
442
+        $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link');
443
+        $position       = autoptimizeUtils::strpos($in, $preload_inject);
444 444
 
445
-        return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) );
445
+        return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject));
446 446
     }
447 447
 
448 448
     public function admin_menu()
449 449
     {
450 450
         // no acces if multisite and not network admin and no site config allowed.
451
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
451
+        if (autoptimizeConfig::should_show_menu_tabs()) {
452 452
             add_submenu_page(
453 453
                 null,
454 454
                 'autoptimize_extra',
455 455
                 'autoptimize_extra',
456 456
                 'manage_options',
457 457
                 'autoptimize_extra',
458
-                array( $this, 'options_page' )
458
+                array($this, 'options_page')
459 459
             );
460 460
         }
461
-        register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' );
461
+        register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings');
462 462
     }
463 463
 
464
-    public function add_extra_tab( $in )
464
+    public function add_extra_tab($in)
465 465
     {
466
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
467
-            $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) );
466
+        if (autoptimizeConfig::should_show_menu_tabs()) {
467
+            $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize')));
468 468
         }
469 469
 
470 470
         return $in;
@@ -484,97 +484,97 @@  discard block
 block discarded – undo
484 484
         #ao_settings_form .form-table th {font-weight: normal;}
485 485
         #autoptimize_extra_descr{font-size: 120%;}
486 486
     </style>
487
-    <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script>
487
+    <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script>
488 488
     <div class="wrap">
489
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
489
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
490 490
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
491
-        <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?>
491
+        <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?>
492 492
             <div class="notice-warning notice"><p>
493
-            <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?>
493
+            <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?>
494 494
             </p></div>
495 495
         <?php } ?>
496 496
 
497
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
498
-        <?php settings_fields( 'autoptimize_extra_settings' ); ?>
499
-        <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2>
500
-        <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span>
497
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
498
+        <?php settings_fields('autoptimize_extra_settings'); ?>
499
+        <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2>
500
+        <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span>
501 501
         <table class="form-table">
502 502
             <tr>
503
-                <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th>
503
+                <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th>
504 504
                 <td>
505
-                    <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/>
506
-                    <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
+                    <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/>
506
+                    <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/>
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="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/>
508
+                    <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/>
509 509
                     <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?>
510
-                    <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/>
511
-                    <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
+                    <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/>
511
+                    <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/>
512 512
                 </td>
513 513
             </tr>
514 514
             <tr>
515
-                <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th>
515
+                <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th>
516 516
                 <td>
517
-                    <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>
517
+                    <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>
518 518
                 </td>
519 519
             </tr>
520 520
             <tr>
521
-                <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th>
521
+                <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th>
522 522
                 <td>
523
-                    <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>
523
+                    <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>
524 524
                 </td>
525 525
             </tr>
526 526
             <tr>
527
-                <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th>
527
+                <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th>
528 528
                 <td>
529
-                    <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>
529
+                    <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>
530 530
                 </td>
531 531
             </tr>
532 532
             <tr>
533
-                <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th>
533
+                <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th>
534 534
                 <td>
535
-                    <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>
535
+                    <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>
536 536
                 </td>
537 537
             </tr>
538 538
             <tr>
539
-                <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th>
539
+                <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th>
540 540
                 <td>
541 541
                     <?php
542
-                    if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) {
542
+                    if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) {
543 543
                         // translators: link points Async Javascript settings page.
544
-                        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>' );
544
+                        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>');
545 545
                     } else {
546 546
                         ?>
547
-                        <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'] ); } ?>'>
547
+                        <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']); } ?>'>
548 548
                         <br />
549 549
                         <?php
550
-                            _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' );
550
+                            _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');
551 551
                             // translators: %s will be replaced by a link to the "async javascript" plugin.
552
-                            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>"' );
553
-                            $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term';
554
-                            echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
552
+                            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>"');
553
+                            $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term';
554
+                            echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
555 555
                     }
556 556
                     ?>
557 557
                 </td>
558 558
             </tr>
559 559
             <tr>
560
-                <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th>
560
+                <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th>
561 561
                 <td>
562 562
                     <?php
563
-                    if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) {
564
-                        _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' );
563
+                    if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) {
564
+                        _e('Great, you have WP YouTube Lyte installed.', 'autoptimize');
565 565
                         $lyte_config_url = 'options-general.php?page=lyte_settings_page';
566
-                        echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) );
566
+                        echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize'));
567 567
                     } else {
568 568
                         // translators: %s will be replaced by a link to "wp youtube lyte" plugin.
569
-                        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>' );
570
-                        $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term';
571
-                        echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) );
569
+                        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>');
570
+                        $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term';
571
+                        echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize'));
572 572
                     }
573 573
                     ?>
574 574
                 </td>
575 575
             </tr>
576 576
         </table>
577
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
577
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
578 578
     </form>
579 579
         <?php
580 580
     }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSEnqueue.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             }
@@ -195,29 +195,29 @@  discard block
 block discarded – undo
195 195
         $page_type = false;
196 196
 
197 197
         // Iterates over the array to match a type.
198
-        foreach ( $ao_ccss_types as $type ) {
199
-            if ( is_404() ) {
198
+        foreach ($ao_ccss_types as $type) {
199
+            if (is_404()) {
200 200
                 $page_type = 'is_404';
201 201
                 break;
202
-            } elseif ( strpos( $type, 'custom_post_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
202
+            } elseif (strpos($type, 'custom_post_') !== false && (!$ao_ccss_forcepath || !is_page())) {
203 203
                 // Match custom post types and not page or page not forced to path-based.
204
-                if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
204
+                if (get_post_type(get_the_ID()) === substr($type, 12)) {
205 205
                     $page_type = $type;
206 206
                     break;
207 207
                 }
208
-            } elseif ( strpos( $type, 'template_' ) !== false && ( ! $ao_ccss_forcepath || ! is_page() ) ) {
208
+            } elseif (strpos($type, 'template_') !== false && (!$ao_ccss_forcepath || !is_page())) {
209 209
                 // Match templates if not page or if page is not forced to path-based.
210
-                if ( is_page_template( substr( $type, 9 ) ) ) {
210
+                if (is_page_template(substr($type, 9))) {
211 211
                     $page_type = $type;
212 212
                     break;
213 213
                 }
214 214
             } else {
215 215
                 // Match all other existing types
216 216
                 // but remove prefix to be able to check if the function exists & returns true.
217
-                $_type = str_replace( array( 'woo_', 'bp_', 'bbp_', 'edd_' ), '', $type );
218
-                if ( function_exists( $_type ) && call_user_func( $_type ) ) {
217
+                $_type = str_replace(array('woo_', 'bp_', 'bbp_', 'edd_'), '', $type);
218
+                if (function_exists($_type) && call_user_func($_type)) {
219 219
                     // Make sure we only return for one page, not for the "paged pages" (/page/2 ..).
220
-                    if ( ! is_page() || ! is_paged() ) {
220
+                    if (!is_page() || !is_paged()) {
221 221
                         $page_type = $type;
222 222
                         break;
223 223
                     }
@@ -229,44 +229,44 @@  discard block
 block discarded – undo
229 229
         return $page_type;
230 230
     }
231 231
 
232
-    public function ao_ccss_define_job( $path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create ) {
232
+    public function ao_ccss_define_job($path, $target, $type, $hash, $file, $jid, $jrstat, $jvstat, $create) {
233 233
         // Define a job entry to be created or updated
234 234
         // Define commom job properties.
235 235
         $path            = array();
236 236
         $path['ljid']    = $this->ao_ccss_job_id();
237 237
         $path['rtarget'] = $target;
238 238
         $path['ptype']   = $type;
239
-        $path['hashes']  = array( $hash );
239
+        $path['hashes']  = array($hash);
240 240
         $path['hash']    = $hash;
241 241
         $path['file']    = $file;
242 242
         $path['jid']     = $jid;
243 243
         $path['jqstat']  = 'NEW';
244 244
         $path['jrstat']  = $jrstat;
245 245
         $path['jvstat']  = $jvstat;
246
-        $path['jctime']  = microtime( true );
246
+        $path['jctime']  = microtime(true);
247 247
         $path['jftime']  = null;
248 248
 
249 249
         // Set operation requested.
250
-        if ( $create ) {
250
+        if ($create) {
251 251
             $operation = 'CREATED';
252 252
         } else {
253 253
             $operation = 'UPDATED';
254 254
         }
255 255
 
256 256
         // Log job creation.
257
-        autoptimizeCriticalCSSCore::ao_ccss_log( 'Job ' . $operation . ' with local job id <' . $path['ljid'] . '> for target rule <' . $target . '>', 3 );
257
+        autoptimizeCriticalCSSCore::ao_ccss_log('Job '.$operation.' with local job id <'.$path['ljid'].'> for target rule <'.$target.'>', 3);
258 258
 
259 259
         return $path;
260 260
     }
261 261
 
262
-    public function ao_ccss_job_id( $length = 6 ) {
262
+    public function ao_ccss_job_id($length = 6) {
263 263
         // Generate random strings for the local job ID
264 264
         // Based on https://stackoverflow.com/a/4356295 .
265 265
         $characters        = '0123456789abcdefghijklmnopqrstuvwxyz';
266
-        $characters_length = strlen( $characters );
266
+        $characters_length = strlen($characters);
267 267
         $random_string     = 'j-';
268
-        for ( $i = 0; $i < $length; $i++ ) {
269
-            $random_string .= $characters[ rand( 0, $characters_length - 1 ) ];
268
+        for ($i = 0; $i < $length; $i++) {
269
+            $random_string .= $characters[rand(0, $characters_length - 1)];
270 270
         }
271 271
         return $random_string;
272 272
     }
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
     public function ao_ccss_ua() {
275 275
         // Check for criticalcss.com user agent.
276 276
         $agent = '';
277
-        if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
277
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
278 278
             $agent = $_SERVER['HTTP_USER_AGENT'];
279 279
         }
280 280
 
281 281
         // Check for UA and return TRUE when criticalcss.com is the detected UA, false when not.
282
-        $rtn = strpos( $agent, AO_CCSS_URL );
283
-        if ( 0 === $rtn ) {
282
+        $rtn = strpos($agent, AO_CCSS_URL);
283
+        if (0 === $rtn) {
284 284
             $rtn = true;
285 285
         } else {
286 286
             $rtn = false;
287 287
         }
288
-        return ( $rtn );
288
+        return ($rtn);
289 289
     }
290 290
 }
Please login to merge, or discard this patch.
classes/critcss-inc/admin_settings_adv.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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']; ?>" />&nbsp;&nbsp;
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']; ?>" />&nbsp;&nbsp;
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( 'Queue processing time limit', 'autoptimize' ); ?>
62
+                            <?php _e('Queue processing time limit', 'autoptimize'); ?>
63 63
                         </th>
64 64
                         <td>
65 65
                             <input type="number" id="autoptimize_ccss_rtimelimit" name="autoptimize_ccss_rtimelimit" min="0" max="240" placeholder="0" value="<?php echo $ao_ccss_rtimelimit; ?>" />
66 66
                             <p class="notes">
67
-                                <?php _e( 'The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', 'autoptimize' ); ?>
67
+                                <?php _e('The cronned queue processing is an asynchronous process triggerd by (WordPress) cron. To avoid this process from running too long and potentially getting killed, you can set the number of seconds here, 0 means no limit.', '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>
Please login to merge, or discard this patch.
classes/autoptimizeVersionUpdatesHandler.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles version updates and should only be instantiated in autoptimize.php if/when needed.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      */
17 17
     protected $current_major_version = null;
18 18
 
19
-    public function __construct( $current_version )
19
+    public function __construct($current_version)
20 20
     {
21
-        $this->current_major_version = substr( $current_version, 0, 3 );
21
+        $this->current_major_version = substr($current_version, 0, 3);
22 22
     }
23 23
 
24 24
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $major_update = false;
31 31
 
32
-        switch ( $this->current_major_version ) {
32
+        switch ($this->current_major_version) {
33 33
             case '1.6':
34 34
                 $this->upgrade_from_1_6();
35 35
                 $major_update = true;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
                 $major_update = true;
48 48
                 // No break, intentionally, so all upgrades are ran during a single request...
49 49
             case '2.4':
50
-                if ( autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' ) == '2.4.2' ) {
50
+                if (autoptimizeOptionWrapper::get_option('autoptimize_version', 'none') == '2.4.2') {
51 51
                     $this->upgrade_from_2_4_2();
52 52
                 }
53 53
                 $this->upgrade_from_2_4();
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 // No break, intentionally, so all upgrades are ran during a single request...
60 60
         }
61 61
 
62
-        if ( true === $major_update ) {
62
+        if (true === $major_update) {
63 63
             $this->on_major_version_update();
64 64
         }
65 65
     }
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @param string $target Target version to check against (ie., the currently running one).
73 73
      */
74
-    public static function check_installed_and_update( $target )
74
+    public static function check_installed_and_update($target)
75 75
     {
76
-        $db_version = autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' );
77
-        if ( $db_version !== $target ) {
78
-            if ( 'none' === $db_version ) {
79
-                add_action( 'admin_notices', 'autoptimizeMain::notice_installed' );
76
+        $db_version = autoptimizeOptionWrapper::get_option('autoptimize_version', 'none');
77
+        if ($db_version !== $target) {
78
+            if ('none' === $db_version) {
79
+                add_action('admin_notices', 'autoptimizeMain::notice_installed');
80 80
             } else {
81
-                $updater = new self( $db_version );
81
+                $updater = new self($db_version);
82 82
                 $updater->run_needed_major_upgrades();
83 83
             }
84 84
 
85 85
             // Versions differed, upgrades happened if needed, store the new version.
86
-            autoptimizeOptionWrapper::update_option( 'autoptimize_version', $target );
86
+            autoptimizeOptionWrapper::update_option('autoptimize_version', $target);
87 87
         }
88 88
     }
89 89
 
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
     protected function on_major_version_update()
95 95
     {
96 96
         // The transients guard here prevents stale object caches from busting the cache on every request.
97
-        if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) {
98
-            set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS );
97
+        if (false == get_transient('autoptimize_stale_option_buster')) {
98
+            set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS);
99 99
             autoptimizeCache::clearall();
100
-            add_action( 'admin_notices', 'autoptimizeMain::notice_updated' );
100
+            add_action('admin_notices', 'autoptimizeMain::notice_updated');
101 101
         }
102 102
     }
103 103
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     private function upgrade_from_1_6()
108 108
     {
109 109
         // If user was on version 1.6.x, force advanced options to be shown by default.
110
-        autoptimizeOptionWrapper::update_option( 'autoptimize_show_adv', '1' );
110
+        autoptimizeOptionWrapper::update_option('autoptimize_show_adv', '1');
111 111
 
112 112
         // And remove old options.
113 113
         $to_delete_options = array(
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
             'autoptimize_cdn_img_url',
120 120
             'autoptimize_css_yui',
121 121
         );
122
-        foreach ( $to_delete_options as $del_opt ) {
123
-            delete_option( $del_opt );
122
+        foreach ($to_delete_options as $del_opt) {
123
+            delete_option($del_opt);
124 124
         }
125 125
     }
126 126
 
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
      */
132 132
     private function upgrade_from_1_7()
133 133
     {
134
-        if ( ! is_multisite() ) {
135
-            $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' );
136
-            if ( empty( $css_exclude ) ) {
134
+        if (!is_multisite()) {
135
+            $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude');
136
+            if (empty($css_exclude)) {
137 137
                 $css_exclude = 'admin-bar.min.css, dashicons.min.css';
138
-            } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
138
+            } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
139 139
                 $css_exclude .= ', dashicons.min.css';
140 140
             }
141
-            autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude );
141
+            autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude);
142 142
         } else {
143 143
             global $wpdb;
144
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
144
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
145 145
             $original_blog_id = get_current_blog_id();
146
-            foreach ( $blog_ids as $blog_id ) {
147
-                switch_to_blog( $blog_id );
148
-                $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' );
149
-                if ( empty( $css_exclude ) ) {
146
+            foreach ($blog_ids as $blog_id) {
147
+                switch_to_blog($blog_id);
148
+                $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude');
149
+                if (empty($css_exclude)) {
150 150
                     $css_exclude = 'admin-bar.min.css, dashicons.min.css';
151
-                } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
151
+                } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
152 152
                     $css_exclude .= ', dashicons.min.css';
153 153
                 }
154
-                autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude );
154
+                autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude);
155 155
             }
156
-            switch_to_blog( $original_blog_id );
156
+            switch_to_blog($original_blog_id);
157 157
         }
158 158
     }
159 159
 
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private function upgrade_from_1_9()
167 167
     {
168
-        if ( ! is_multisite() ) {
169
-            autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' );
170
-            autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' );
168
+        if (!is_multisite()) {
169
+            autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on');
170
+            autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on');
171 171
         } else {
172 172
             global $wpdb;
173
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
173
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
174 174
             $original_blog_id = get_current_blog_id();
175
-            foreach ( $blog_ids as $blog_id ) {
176
-                switch_to_blog( $blog_id );
177
-                autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' );
178
-                autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' );
175
+            foreach ($blog_ids as $blog_id) {
176
+                switch_to_blog($blog_id);
177
+                autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on');
178
+                autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on');
179 179
             }
180
-            switch_to_blog( $original_blog_id );
180
+            switch_to_blog($original_blog_id);
181 181
         }
182 182
     }
183 183
 
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
      */
189 189
     private function upgrade_from_2_2()
190 190
     {
191
-        if ( ! is_multisite() ) {
191
+        if (!is_multisite()) {
192 192
             $this->do_2_2_settings_update();
193 193
         } else {
194 194
             global $wpdb;
195
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
195
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
196 196
             $original_blog_id = get_current_blog_id();
197
-            foreach ( $blog_ids as $blog_id ) {
198
-                switch_to_blog( $blog_id );
197
+            foreach ($blog_ids as $blog_id) {
198
+                switch_to_blog($blog_id);
199 199
                 $this->do_2_2_settings_update();
200 200
             }
201
-            switch_to_blog( $original_blog_id );
201
+            switch_to_blog($original_blog_id);
202 202
         }
203 203
     }
204 204
 
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
      */
208 208
     private function do_2_2_settings_update()
209 209
     {
210
-        $nogooglefont    = autoptimizeOptionWrapper::get_option( 'autoptimize_css_nogooglefont', '' );
211
-        $ao_extrasetting = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' );
212
-        if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) {
213
-            autoptimizeOptionWrapper::update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() );
210
+        $nogooglefont    = autoptimizeOptionWrapper::get_option('autoptimize_css_nogooglefont', '');
211
+        $ao_extrasetting = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', '');
212
+        if (($nogooglefont) && (empty($ao_extrasetting))) {
213
+            autoptimizeOptionWrapper::update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options());
214 214
         }
215
-        delete_option( 'autoptimize_css_nogooglefont' );
215
+        delete_option('autoptimize_css_nogooglefont');
216 216
     }
217 217
 
218 218
     /**
@@ -224,33 +224,33 @@  discard block
 block discarded – undo
224 224
         $jobs = _get_cron_array();
225 225
 
226 226
         // Remove all ao_cachechecker cron jobs (for now).
227
-        foreach ( $jobs as $when => $job ) {
228
-            $name = key( $job );
227
+        foreach ($jobs as $when => $job) {
228
+            $name = key($job);
229 229
 
230
-            if ( false !== strpos( $name, 'ao_cachechecker' ) ) {
231
-                unset( $jobs[ $when ] );
230
+            if (false !== strpos($name, 'ao_cachechecker')) {
231
+                unset($jobs[$when]);
232 232
             }
233 233
         }
234 234
 
235 235
         // Save the data.
236
-        _set_cron_array( $jobs );
236
+        _set_cron_array($jobs);
237 237
     }
238 238
 
239 239
     /**
240 240
      * Migrate imgopt options from autoptimize_extra_settings to autoptimize_imgopt_settings
241 241
      */
242 242
     private function upgrade_from_2_4() {
243
-        $extra_settings  = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' );
244
-        $imgopt_settings = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
245
-        if ( empty( $imgopt_settings ) && ! empty( $extra_settings ) ) {
243
+        $extra_settings  = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', '');
244
+        $imgopt_settings = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
245
+        if (empty($imgopt_settings) && !empty($extra_settings)) {
246 246
             $imgopt_settings = autoptimizeConfig::get_ao_imgopt_default_options();
247
-            if ( array_key_exists( 'autoptimize_extra_checkbox_field_5', $extra_settings ) ) {
247
+            if (array_key_exists('autoptimize_extra_checkbox_field_5', $extra_settings)) {
248 248
                 $imgopt_settings['autoptimize_imgopt_checkbox_field_1'] = $extra_settings['autoptimize_extra_checkbox_field_5'];
249 249
             }
250
-            if ( array_key_exists( 'autoptimize_extra_select_field_6', $extra_settings ) ) {
250
+            if (array_key_exists('autoptimize_extra_select_field_6', $extra_settings)) {
251 251
                 $imgopt_settings['autoptimize_imgopt_select_field_2'] = $extra_settings['autoptimize_extra_select_field_6'];
252 252
             }
253
-            autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_settings', $imgopt_settings );
253
+            autoptimizeOptionWrapper::update_option('autoptimize_imgopt_settings', $imgopt_settings);
254 254
         }
255 255
     }
256 256
 
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
      * remove CCSS request limit option + update jquery exclusion to include WordPress 5.6 jquery.min.js.
259 259
      */    
260 260
     private function upgrade_from_2_7() {
261
-        delete_option( 'autoptimize_ccss_rlimit' );
262
-        $js_exclusions = get_option( 'autoptimize_js_exclude', '' );
263
-        if ( strpos( $js_exclusions, 'js/jquery/jquery.js' ) !== false && strpos( $js_exclusions, 'js/jquery/jquery.min.js' ) === false ) {
261
+        delete_option('autoptimize_ccss_rlimit');
262
+        $js_exclusions = get_option('autoptimize_js_exclude', '');
263
+        if (strpos($js_exclusions, 'js/jquery/jquery.js') !== false && strpos($js_exclusions, 'js/jquery/jquery.min.js') === false) {
264 264
             $js_exclusions .= ', js/jquery/jquery.min.js';
265
-            update_option( 'autoptimize_js_exclude', $js_exclusions );
265
+            update_option('autoptimize_js_exclude', $js_exclusions);
266 266
         }
267 267
     }
268 268
 }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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_rtimelimit' );
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_rtimelimit');
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,39 +119,39 @@  discard block
 block discarded – undo
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
122
+                if (!is_dir(AO_CCSS_DIR)) {
123
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
124 124
                 } else {
125 125
                     $mkdirresp = true;
126 126
                 }
127 127
 
128 128
                 // Make sure our index.html is there.
129
-                if ( ! is_file( AO_CCSS_DIR . 'index.html' ) ) {
130
-                    $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>' );
129
+                if (!is_file(AO_CCSS_DIR.'index.html')) {
130
+                    $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>');
131 131
                 } else {
132 132
                     $fileresp = true;
133 133
                 }
134 134
 
135 135
                 // Warn if we could not create those files.
136
-                if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
136
+                if ((!$mkdirresp) || (!$fileresp)) {
137 137
                     ?>
138 138
                     <div class="notice-error notice"><p>
139 139
                     <?php
140
-                    _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
140
+                    _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
141 141
                     ?>
142 142
                     </p></div>
143 143
                     <?php
144 144
                 }
145 145
 
146 146
                 // Check for "inline & defer CSS" being active in Autoptimize.
147
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
148
-                    if ( empty( $ao_ccss_keyst ) ) {
147
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
148
+                    if (empty($ao_ccss_keyst)) {
149 149
                         // no keystate so likely in activation-process of CCSS, let's enable "inline & defer CSS" immediately to make things easier!
150
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_css_defer', 'on' );
150
+                        autoptimizeOptionWrapper::update_option('autoptimize_css_defer', 'on');
151 151
                         ?>
152 152
                         <div class="notice-info notice"><p>
153 153
                         <?php
154
-                        _e( "The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize' );
154
+                        _e("The \"Inline and Defer CSS\" option was activated to allow critical CSS to be used.", 'autoptimize');
155 155
                         ?>
156 156
                         </p></div>
157 157
                         <?php
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                         ?>
161 161
                         <div class="notice-warning notice"><p>
162 162
                         <?php
163
-                        _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page ensure critical CSS is used on the front-end.", 'autoptimize' );
163
+                        _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page ensure critical CSS is used on the front-end.", 'autoptimize');
164 164
                         ?>
165 165
                         </p></div>
166 166
                         <?php
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
                 }
169 169
 
170 170
                 // check if WordPress cron is disabled and warn if so.
171
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
171
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
172 172
                     ?>
173 173
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
174 174
                     <?php
175
-                    _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' );
175
+                    _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');
176 176
                     ?>
177 177
                     </p></div>
178 178
                     <?php
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 
181 181
                 // warn if it looks as though the queue processing job looks isn't running
182 182
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
183
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
184
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
183
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
184
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
185 185
                     $_jobs_all_new         = true;
186
-                    $_oldest_job_timestamp = microtime( true ); // now.
186
+                    $_oldest_job_timestamp = microtime(true); // now.
187 187
                     $_jobs_too_old         = true;
188 188
 
189 189
                     // go over queue array.
190
-                    if ( empty( $ao_ccss_queue ) ) {
190
+                    if (empty($ao_ccss_queue)) {
191 191
                         // no jobs, then no warning.
192 192
                         $_jobs_all_new = false;
193 193
                     } else {
194
-                        foreach ( $ao_ccss_queue as $job ) {
195
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
194
+                        foreach ($ao_ccss_queue as $job) {
195
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
196 196
                                 // we need to catch the oldest job's timestamp.
197 197
                                 $_oldest_job_timestamp = $job['jctime'];
198 198
                             }
199 199
 
200
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
200
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
201 201
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
202 202
                                 $_jobs_all_new = false;
203 203
                                 break;
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
                     }
207 207
 
208 208
                     // is the oldest job too old (4h)?
209
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
209
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
210 210
                         $_jobs_too_old = false;
211 211
                     }
212 212
 
213
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
213
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
214 214
                         $_warn_cron            = 'on';
215 215
                         $_transient_multiplier = 1; // store for 1 hour.
216 216
                     } else {
@@ -218,35 +218,35 @@  discard block
 block discarded – undo
218 218
                         $_transient_multiplier = 4; // store for 4 hours.
219 219
                     }
220 220
                     // and set transient.
221
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
221
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
222 222
                 }
223 223
 
224
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
224
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
225 225
                     ?>
226 226
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
227 227
                     <?php
228
-                    _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' );
228
+                    _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');
229 229
                     ?>
230 230
                     </p></div>
231 231
                     <?php
232
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
232
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
233 233
                     ?>
234 234
                     <div class="notice-success notice"><p>
235 235
                     <?php
236
-                    _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' );
236
+                    _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');
237 237
                     echo ' ';
238
-                    _e( 'In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize' );
238
+                    _e('In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize');
239 239
                     ?>
240 240
                     </p></div>
241 241
                     <?php
242 242
                 }
243 243
 
244 244
                 // warn if service is down.
245
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
245
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
246 246
                     ?>
247 247
                     <div class="notice-warning notice"><p>
248 248
                     <?php
249
-                    _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' );
249
+                    _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');
250 250
                     ?>
251 251
                     </p></div>
252 252
                     <?php
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
 
255 255
                 // warn if too many rules (based on length of ao_ccss_rules option) as that might cause issues at e.g. wpengine
256 256
                 // see https://wpengine.com/support/database-optimization-best-practices/#Autoloaded_Data
257
-                $_raw_rules_length = strlen( get_option( 'autoptimize_ccss_rules', '') );
258
-                if ( $_raw_rules_length > apply_filters( 'autoptimize_ccss_rules_length_warning', 500000 ) ) {
257
+                $_raw_rules_length = strlen(get_option('autoptimize_ccss_rules', ''));
258
+                if ($_raw_rules_length > apply_filters('autoptimize_ccss_rules_length_warning', 500000)) {
259 259
                     ?>
260 260
                     <div class="notice-warning notice"><p>
261 261
                     <?php
262
-                    _e( 'It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize' );
262
+                    _e('It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize');
263 263
                     ?>
264 264
                     </p></div>
265 265
                     <?php
@@ -269,24 +269,24 @@  discard block
 block discarded – undo
269 269
                 ?>
270 270
                 <form id="settings" method="post" action="options.php">
271 271
                     <?php
272
-                    settings_fields( 'ao_ccss_options_group' );
272
+                    settings_fields('ao_ccss_options_group');
273 273
 
274 274
                     // Get API key status.
275
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
275
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
276 276
 
277
-                    if ( $this->is_multisite_network_admin() ) {
277
+                    if ($this->is_multisite_network_admin()) {
278 278
                         ?>
279 279
                         <ul id="key-panel">
280 280
                             <li class="itemDetail">
281 281
                             <?php
282 282
                                 // translators: the placesholder is for a line of code in wp-config.php.
283
-                                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>' );
283
+                                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>');
284 284
                             ?>
285 285
                             </li>
286 286
                         </ul>
287 287
                         <?php
288 288
                     } else {
289
-                        if ( 'valid' == $key['status'] ) {
289
+                        if ('valid' == $key['status']) {
290 290
                             // If key status is valid, render other panels.
291 291
                             // Render rules section.
292 292
                             ao_ccss_render_rules();
@@ -303,23 +303,23 @@  discard block
 block discarded – undo
303 303
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
304 304
 
305 305
                             // Add hidden fields.
306
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
307
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
308
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
309
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
310
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
311
-                            echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="' . $ao_ccss_rtimelimit . '">';
312
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
313
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
314
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
315
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
316
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
306
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
307
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
308
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
309
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
310
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
311
+                            echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="'.$ao_ccss_rtimelimit.'">';
312
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
313
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
314
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
315
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
316
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
317 317
                         }
318 318
                         // Render key panel unconditionally.
319
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
319
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
320 320
                         ?>
321 321
                         <p class="submit left">
322
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
322
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
323 323
                         </p>
324 324
                         <?php
325 325
                     }
@@ -337,31 +337,31 @@  discard block
 block discarded – undo
337 337
                     });
338 338
                 }
339 339
                 </script>
340
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
341
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
342
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
340
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
341
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
342
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
343 343
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
344 344
                 </form>
345 345
                 <div id="importdialog"></div>
346 346
             </div><!-- /#autoptimize_main -->
347 347
         </div><!-- /#wrap -->
348 348
         <?php
349
-        if ( ! $this->is_multisite_network_admin() ) {
349
+        if (!$this->is_multisite_network_admin()) {
350 350
             // Include debug panel if debug mode is enable.
351
-            if ( $ao_ccss_debug ) {
351
+            if ($ao_ccss_debug) {
352 352
             ?>
353 353
                 <div id="debug">
354 354
                     <?php
355 355
                     // Include debug panel.
356
-                    include( 'critcss-inc/admin_settings_debug.php' );
356
+                    include('critcss-inc/admin_settings_debug.php');
357 357
                     ?>
358 358
                 </div><!-- /#debug -->
359 359
             <?php
360 360
             }
361 361
             echo '<script>';
362
-            include( 'critcss-inc/admin_settings_rules.js.php' );
363
-            include( 'critcss-inc/admin_settings_queue.js.php' );
364
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
362
+            include('critcss-inc/admin_settings_rules.js.php');
363
+            include('critcss-inc/admin_settings_queue.js.php');
364
+            include('critcss-inc/admin_settings_impexp.js.php');
365 365
             echo '</script>';
366 366
         }
367 367
     }
@@ -369,19 +369,19 @@  discard block
 block discarded – undo
369 369
     public static function ao_ccss_has_autorules() {
370 370
         static $_has_auto_rules = null;
371 371
 
372
-        if ( null === $_has_auto_rules ) {
372
+        if (null === $_has_auto_rules) {
373 373
             global $ao_ccss_rules;
374 374
             $_has_auto_rules = false;
375
-            if ( ! empty( $ao_ccss_rules ) ) {
376
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
377
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
378
-                        if ( ! empty( $rule['hash'] ) ) {
375
+            if (!empty($ao_ccss_rules)) {
376
+                foreach (array('types', 'paths') as $_typat) {
377
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
378
+                        if (!empty($rule['hash'])) {
379 379
                             // we have at least one AUTO job, so all is fine.
380 380
                             $_has_auto_rules = true;
381 381
                             break;
382 382
                         }
383 383
                     }
384
-                    if ( $_has_auto_rules ) {
384
+                    if ($_has_auto_rules) {
385 385
                         break;
386 386
                     }
387 387
                 }
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
     public function is_multisite_network_admin() {
395 395
         static $_multisite_network_admin = null;
396 396
 
397
-        if ( null === $_multisite_network_admin ) {
398
-            if ( is_multisite() && is_network_admin() ) {
397
+        if (null === $_multisite_network_admin) {
398
+            if (is_multisite() && is_network_admin()) {
399 399
                 $_multisite_network_admin = true;
400 400
             } else {
401 401
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.
classes/autoptimizeConfig.php 1 patch
Spacing   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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,33 +35,33 @@  discard block
 block discarded – undo
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' ) );
46
-            add_action( 'admin_init', array( 'PAnD', 'init' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46
+            add_action('admin_init', array('PAnD', 'init'));
47 47
 
48 48
             // Set meta info.
49
-            if ( function_exists( 'plugin_row_meta' ) ) {
49
+            if (function_exists('plugin_row_meta')) {
50 50
                 // 2.8 and higher.
51
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52
-            } elseif ( function_exists( 'post_class' ) ) {
51
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
52
+            } elseif (function_exists('post_class')) {
53 53
                 // 2.7 and lower.
54
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
54
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
55
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
56 56
             }
57 57
 
58 58
             // Clean cache?
59
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
59
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
60 60
                 autoptimizeCache::clearall();
61
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
61
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
62 62
             }
63 63
 
64
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
64
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
65 65
         }
66 66
 
67 67
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     static public function instance()
78 78
     {
79 79
         // Only one instance.
80
-        if ( null === self::$instance ) {
80
+        if (null === self::$instance) {
81 81
             self::$instance = new autoptimizeConfig();
82 82
         }
83 83
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     public function show_network_message() {
88 88
         ?>
89 89
         <div class="wrap">
90
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
90
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
91 91
             <?php echo $this->ao_admin_tabs(); ?>
92
-            <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
+            <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>
93 93
         </div>
94 94
         <?php
95 95
     }
@@ -184,32 +184,32 @@  discard block
 block discarded – undo
184 184
 <div class="wrap">
185 185
 
186 186
 <!-- Temporary nudge to disable aoccss power-up. -->
187
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
187
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
188 188
     <div class="notice-info notice"><p>
189
-        <?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' ); ?>
189
+        <?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'); ?>
190 190
     </p></div>
191 191
 <?php } ?>
192 192
 
193 193
 <div id="autoptimize_main">
194
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
194
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
195 195
     <?php echo $this->ao_admin_tabs(); ?>
196 196
 
197
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
198
-<?php settings_fields( 'autoptimize' ); ?>
197
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
198
+<?php settings_fields('autoptimize'); ?>
199 199
 
200 200
 <ul>
201 201
 
202 202
 <?php
203 203
 // Only show enable site configuration in network site option.
204
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
204
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
205 205
 ?>
206 206
     <li class="itemDetail multiSite">
207
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
207
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
208 208
         <table class="form-table">
209 209
             <tr valign="top">
210
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
211
-                <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" ' : ''; ?>/>
212
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
210
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
211
+                <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" ' : ''; ?>/>
212
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
213 213
             </tr>
214 214
         </table>
215 215
     </li>
@@ -218,120 +218,120 @@  discard block
 block discarded – undo
218 218
 <?php } ?>    
219 219
 
220 220
 <li class="itemDetail">
221
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
221
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
222 222
 <table class="form-table">
223 223
 <tr valign="top">
224
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
225
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
224
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
225
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
226 226
 </tr>
227 227
 <tr valign="top" class="js_sub js_aggregate_master">
228
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
229
-<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" ' : ''; ?>/>
230
-<?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
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
229
+<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" ' : ''; ?>/>
230
+<?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>
231 231
 </tr>
232 232
 <tr valign="top" class="js_sub js_not_aggregate">
233
-<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
234
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
235
-<?php _e( 'When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
233
+<th scope="row"><?php _e('Do not aggregate but defer?', 'autoptimize'); ?></th>
234
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get('autoptimize_js_defer_not_aggregate') ? 'checked="checked" ' : ''; ?>/>
235
+<?php _e('When JS is not aggregated, all linked JS-files can be deferred instead, making them non-render-blocking.', 'autoptimize'); ?></label></td>
236 236
 </tr>
237 237
 <tr valign="top" class="js_sub js_aggregate">
238
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
239
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
240
-<?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>
238
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
239
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
240
+<?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>
241 241
 </tr>
242 242
 <tr valign="top" class="js_sub js_aggregate">
243
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
244
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
245
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
243
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
244
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
245
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
246 246
 </tr>
247
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
247
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
248 248
 <tr valign="top" class="js_sub js_aggregate">
249 249
 <th scope="row">
250 250
 <?php
251
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
252
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
251
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
252
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
253 253
 ?>
254 254
 </th>
255
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
256
-<?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>
255
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
256
+<?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>
257 257
 </tr>
258 258
 <?php } ?>
259 259
 <tr valign="top" class="js_sub">
260
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
261
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js' ) ); ?>"/><br />
260
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
261
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js, js/jquery/jquery.min.js')); ?>"/><br />
262 262
 <?php
263
-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' );
263
+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');
264 264
 ?>
265 265
 </label></td>
266 266
 </tr>
267 267
 <tr valign="top" class="js_sub js_aggregate">
268
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
269
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
270
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
268
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
269
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
270
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
271 271
 </tr>
272 272
 </table>
273 273
 </li>
274 274
 
275 275
 <li class="itemDetail">
276
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
276
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
277 277
 <table class="form-table">
278 278
 <tr valign="top">
279
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
280
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
279
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
280
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
281 281
 </tr>
282 282
 <tr class="css_sub" valign="top">
283
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
284
-<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" ' : ''; ?>/>
285
-<?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>
283
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
284
+<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" ' : ''; ?>/>
285
+<?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>
286 286
 </tr>
287 287
 <tr valign="top" class="css_sub css_aggregate">
288
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
289
-<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" ' : ''; ?>/>
290
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
288
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
289
+<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" ' : ''; ?>/>
290
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
291 291
 </tr>
292 292
 <tr class="css_sub css_aggregate" valign="top">
293
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
294
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
295
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
293
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
294
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
295
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
296 296
 </tr>
297
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
297
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
298 298
 <tr valign="top" class="css_sub css_aggregate">
299 299
 <th scope="row">
300 300
 <?php
301
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
302
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
301
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
302
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
303 303
 ?>
304 304
 </th>
305
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
306
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
305
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
306
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
307 307
 </tr>
308 308
 <?php } ?>
309 309
 <tr valign="top" class="css_sub">
310
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
311
-<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" ' : ''; ?>/>
310
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
311
+<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" ' : ''; ?>/>
312 312
 <?php
313
-_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' );
313
+_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');
314 314
 echo ' ';
315
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
315
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
316 316
 // translators: links "autoptimize critical CSS" tab.
317
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
317
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
318 318
 ?>
319 319
 </label></td>
320 320
 </tr>
321 321
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
322 322
 <th scope="row"></th>
323
-<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>
323
+<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>
324 324
 </tr>
325 325
 <tr valign="top" class="css_sub css_aggregate">
326
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
327
-<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" ' : ''; ?>/>
328
-<?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>
326
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
327
+<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" ' : ''; ?>/>
328
+<?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>
329 329
 </tr>
330 330
 <tr valign="top" class="css_sub">
331
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
332
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
331
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
332
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br />
333 333
 <?php
334
-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' );
334
+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');
335 335
 ?>
336 336
 </label></td>
337 337
 </tr>
@@ -339,55 +339,55 @@  discard block
 block discarded – undo
339 339
 </li>
340 340
 
341 341
 <li class="itemDetail">
342
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
342
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
343 343
 <table class="form-table">
344 344
 <tr valign="top">
345
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
346
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
345
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
346
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
347 347
 </tr>
348 348
 <tr class="html_sub" valign="top">
349
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
350
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
351
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
349
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
350
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
351
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
352 352
 </tr>
353 353
 </table>
354 354
 </li>
355 355
 
356 356
 <li class="itemDetail">
357
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
357
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
358 358
 <table class="form-table">
359 359
 <tr valign="top">
360
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
361
-<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 />
362
-<?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>
360
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
361
+<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 />
362
+<?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>
363 363
 </tr>
364 364
 </table>
365 365
 </li>
366 366
 
367 367
 <li class="itemDetail">
368
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
368
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
369 369
 <table class="form-table" >
370 370
 <tr valign="top" >
371
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
372
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
371
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
372
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
373 373
 </tr>
374 374
 <tr valign="top" >
375
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
376
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
375
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
376
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
377 377
 </tr>
378 378
 <tr valign="top" >
379
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
379
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
380 380
 <td>
381 381
     <?php
382 382
     $ao_stat_arr = autoptimizeCache::stats();
383
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
384
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
383
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
384
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
385 385
         $details       = '';
386
-        if ( $ao_cache_size > 0 ) {
387
-            $details = ', ~' . $ao_cache_size . ' total';
386
+        if ($ao_cache_size > 0) {
387
+            $details = ', ~'.$ao_cache_size.' total';
388 388
         }
389 389
         // translators: Kilobytes + timestamp shown.
390
-        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] ) );
390
+        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]));
391 391
     }
392 392
     ?>
393 393
 </td>
@@ -396,41 +396,41 @@  discard block
 block discarded – undo
396 396
 </li>
397 397
 
398 398
 <li class="itemDetail">
399
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
399
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
400 400
 <table class="form-table">
401 401
     <tr valign="top" >
402
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
403
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
404
-    <?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>
402
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
403
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
404
+    <?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>
405 405
     </tr>
406 406
     <?php
407 407
     $_min_excl_class = '';
408
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
408
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
409 409
         $_min_excl_class = 'hidden';
410 410
     }
411 411
     ?>
412 412
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
413
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
414
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
415
-        <?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>
413
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
414
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
415
+        <?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>
416 416
     </tr>
417 417
     <tr valign="top">
418
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
419
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
420
-        <?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>
418
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
419
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
420
+        <?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>
421 421
     </tr>
422 422
     <tr valign="top">
423
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
424
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
425
-    <?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>
423
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
424
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
425
+    <?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>
426 426
     </tr>
427 427
     <?php
428
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
428
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
429 429
     ?>
430 430
     <tr valign="top" >
431
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
432
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
433
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
431
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
432
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
433
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
434 434
         </td>
435 435
     </tr>
436 436
     <?php } ?>
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 </ul>
441 441
 
442 442
 <p class="submit">
443
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
444
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
443
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
444
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
445 445
 </p>
446 446
 
447 447
 </form>
@@ -450,46 +450,46 @@  discard block
 block discarded – undo
450 450
     <div class="autoptimize_banner hidden">
451 451
     <ul>
452 452
     <?php
453
-    if ( $this->settings_screen_do_remote_http ) {
454
-        $ao_banner = get_transient( 'autoptimize_banner' );
455
-        if ( empty( $ao_banner ) ) {
456
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
457
-            if ( ! is_wp_error( $banner_resp ) ) {
458
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
459
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
460
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
453
+    if ($this->settings_screen_do_remote_http) {
454
+        $ao_banner = get_transient('autoptimize_banner');
455
+        if (empty($ao_banner)) {
456
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
457
+            if (!is_wp_error($banner_resp)) {
458
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
459
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
460
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
461 461
                 }
462 462
             }
463 463
         }
464 464
         echo $ao_banner;
465 465
     }
466 466
     ?>
467
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
468
-        <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>
467
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
468
+        <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>
469 469
     </ul>
470 470
     </div>
471 471
     <div style="margin-left:10px;margin-top:-5px;">
472 472
         <h2>
473
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
473
+            <?php _e('futtta about', 'autoptimize'); ?>
474 474
             <select id="feed_dropdown" >
475
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
476
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
477
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
475
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
476
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
477
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
478 478
             </select>
479 479
         </h2>
480 480
         <div id="futtta_feed">
481 481
             <div id="autoptimizefeed">
482
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
482
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
483 483
             </div>
484 484
             <div id="wordpressfeed">
485
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
485
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
486 486
             </div>
487 487
             <div id="webtechfeed">
488
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
488
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
489 489
             </div>
490 490
         </div>
491 491
     </div>
492
-    <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>
492
+    <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>
493 493
 </div>
494 494
 
495 495
 <script type="text/javascript">
@@ -655,82 +655,82 @@  discard block
 block discarded – undo
655 655
 
656 656
     public function addmenu()
657 657
     {
658
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
658
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
659 659
             // multisite, network admin, ao network activated: add normal settings page at network level.
660
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
661
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
660
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
661
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
662 662
             // 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.
663
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
663
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
664 664
         } else {
665 665
             // 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.
666
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
666
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
667 667
         }
668 668
 
669
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
670
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
669
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
670
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
671 671
     }
672 672
 
673 673
     public function autoptimize_admin_scripts()
674 674
     {
675
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
676
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
675
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
676
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
677 677
     }
678 678
 
679 679
     public function autoptimize_admin_styles()
680 680
     {
681
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
682
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
681
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
682
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
683 683
     }
684 684
 
685 685
     public function registersettings() {
686
-        register_setting( 'autoptimize', 'autoptimize_html' );
687
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
688
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
689
-        register_setting( 'autoptimize', 'autoptimize_js' );
690
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
691
-        register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
692
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
693
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
694
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
695
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
696
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
697
-        register_setting( 'autoptimize', 'autoptimize_css' );
698
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
699
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
700
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
701
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
702
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
703
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
704
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
705
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
706
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
707
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
708
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
709
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
710
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
711
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
712
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
686
+        register_setting('autoptimize', 'autoptimize_html');
687
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
688
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
689
+        register_setting('autoptimize', 'autoptimize_js');
690
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
691
+        register_setting('autoptimize', 'autoptimize_js_defer_not_aggregate');
692
+        register_setting('autoptimize', 'autoptimize_js_exclude');
693
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
694
+        register_setting('autoptimize', 'autoptimize_js_justhead');
695
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
696
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
697
+        register_setting('autoptimize', 'autoptimize_css');
698
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
699
+        register_setting('autoptimize', 'autoptimize_css_exclude');
700
+        register_setting('autoptimize', 'autoptimize_css_justhead');
701
+        register_setting('autoptimize', 'autoptimize_css_datauris');
702
+        register_setting('autoptimize', 'autoptimize_css_defer');
703
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
704
+        register_setting('autoptimize', 'autoptimize_css_inline');
705
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
706
+        register_setting('autoptimize', 'autoptimize_cdn_url');
707
+        register_setting('autoptimize', 'autoptimize_cache_clean');
708
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
709
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
710
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
711
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
712
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
713 713
     }
714 714
 
715
-    public function setmeta( $links, $file = null )
715
+    public function setmeta($links, $file = null)
716 716
     {
717 717
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
718 718
         // Do it only once - saves time.
719 719
         static $plugin;
720
-        if ( empty( $plugin ) ) {
721
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
720
+        if (empty($plugin)) {
721
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
722 722
         }
723 723
 
724
-        if ( null === $file ) {
724
+        if (null === $file) {
725 725
             // 2.7 and lower.
726
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
727
-            array_unshift( $links, $settings_link );
726
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
727
+            array_unshift($links, $settings_link);
728 728
         } else {
729 729
             // 2.8 and higher.
730 730
             // If it's us, add the link.
731
-            if ( $file === $plugin ) {
732
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
733
-                $links   = array_merge( $links, $newlink );
731
+            if ($file === $plugin) {
732
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
733
+                $links   = array_merge($links, $newlink);
734 734
             }
735 735
         }
736 736
 
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
808 808
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
809 809
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
810
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
810
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
811 811
         );
812 812
         return $defaults;
813 813
     }
@@ -819,58 +819,58 @@  discard block
 block discarded – undo
819 819
      *
820 820
      * @return string
821 821
      */
822
-    public static function get_ao_css_preload_onload( $media = 'all' )
822
+    public static function get_ao_css_preload_onload($media = 'all')
823 823
     {
824
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
824
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
825 825
         return $preload_onload;
826 826
     }
827 827
 
828
-    public function get( $key )
828
+    public function get($key)
829 829
     {
830
-        if ( ! is_array( $this->config ) ) {
830
+        if (!is_array($this->config)) {
831 831
             // Default config.
832 832
             $config = self::get_defaults();
833 833
 
834 834
             // Override with user settings.
835
-            foreach ( array_keys( $config ) as $name ) {
836
-                $conf = autoptimizeOptionWrapper::get_option( $name );
837
-                if ( false !== $conf ) {
835
+            foreach (array_keys($config) as $name) {
836
+                $conf = autoptimizeOptionWrapper::get_option($name);
837
+                if (false !== $conf) {
838 838
                     // It was set before!
839
-                    $config[ $name ] = $conf;
839
+                    $config[$name] = $conf;
840 840
                 }
841 841
             }
842 842
 
843 843
             // Save for next call.
844
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
844
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
845 845
         }
846 846
 
847
-        if ( isset( $this->config[ $key ] ) ) {
848
-            return $this->config[ $key ];
847
+        if (isset($this->config[$key])) {
848
+            return $this->config[$key];
849 849
         }
850 850
 
851 851
         return false;
852 852
     }
853 853
 
854
-    private function get_futtta_feeds( $url ) {
855
-        if ( $this->settings_screen_do_remote_http ) {
856
-            $rss      = fetch_feed( $url );
854
+    private function get_futtta_feeds($url) {
855
+        if ($this->settings_screen_do_remote_http) {
856
+            $rss      = fetch_feed($url);
857 857
             $maxitems = 0;
858 858
 
859
-            if ( ! is_wp_error( $rss ) ) {
860
-                $maxitems  = $rss->get_item_quantity( 7 );
861
-                $rss_items = $rss->get_items( 0, $maxitems );
859
+            if (!is_wp_error($rss)) {
860
+                $maxitems  = $rss->get_item_quantity(7);
861
+                $rss_items = $rss->get_items(0, $maxitems);
862 862
             }
863 863
             ?>
864 864
             <ul>
865
-                <?php if ( 0 == $maxitems ) : ?>
866
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
865
+                <?php if (0 == $maxitems) : ?>
866
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
867 867
                 <?php else : ?>
868
-                    <?php foreach ( $rss_items as $item ) : ?>
868
+                    <?php foreach ($rss_items as $item) : ?>
869 869
                         <li>
870
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
870
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
871 871
                                 <?php // translators: the variable contains a date. ?>
872
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
873
-                                <?php echo esc_html( $item->get_title() ); ?>
872
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
873
+                                <?php echo esc_html($item->get_title()); ?>
874 874
                             </a>
875 875
                         </li>
876 876
                     <?php endforeach; ?>
@@ -883,23 +883,23 @@  discard block
 block discarded – undo
883 883
     static function ao_admin_tabs()
884 884
     {
885 885
         // based on http://wordpress.stackexchange.com/a/58826 .
886
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
886
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
887 887
         $tab_content = '';
888
-        $tabs_count  = count( $tabs );
889
-        if ( $tabs_count > 1 ) {
890
-            if ( isset( $_GET['page'] ) ) {
888
+        $tabs_count  = count($tabs);
889
+        if ($tabs_count > 1) {
890
+            if (isset($_GET['page'])) {
891 891
                 $current_id = $_GET['page'];
892 892
             } else {
893 893
                 $current_id = 'autoptimize';
894 894
             }
895 895
             $tab_content .= '<h2 class="nav-tab-wrapper">';
896
-            foreach ( $tabs as $tab_id => $tab_name ) {
897
-                if ( $current_id == $tab_id ) {
896
+            foreach ($tabs as $tab_id => $tab_name) {
897
+                if ($current_id == $tab_id) {
898 898
                     $class = ' nav-tab-active';
899 899
                 } else {
900 900
                     $class = '';
901 901
                 }
902
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
902
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
903 903
             }
904 904
             $tab_content .= '</h2>';
905 905
         } else {
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
      */
917 917
     public static function is_admin_and_not_ajax()
918 918
     {
919
-        return ( is_admin() && ! self::doing_ajax() );
919
+        return (is_admin() && !self::doing_ajax());
920 920
     }
921 921
 
922 922
     /**
@@ -926,10 +926,10 @@  discard block
 block discarded – undo
926 926
      */
927 927
     protected static function doing_ajax()
928 928
     {
929
-        if ( function_exists( 'wp_doing_ajax' ) ) {
929
+        if (function_exists('wp_doing_ajax')) {
930 930
             return wp_doing_ajax();
931 931
         }
932
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
932
+        return (defined('DOING_AJAX') && DOING_AJAX);
933 933
     }
934 934
 
935 935
     /**
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
      * @return bool
939 939
      */
940 940
     public static function should_show_menu_tabs() {
941
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
941
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
942 942
             return true;
943 943
         } else {
944 944
             return false;
Please login to merge, or discard this patch.