Completed
Push — master ( 471c26...e80620 )
by frank
01:49
created
classes/autoptimizeCache.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @param string $data Data to cache.
92 92
      * @param string $mime Mimetype.
93 93
      *
94
-     * @return void
94
+     * @return boolean|null
95 95
      */
96 96
     public function cache( $data, $mime )
97 97
     {
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
      * size = total filesize (in bytes) of found files
490 490
      * timestamp = unix timestamp when the scan was last performed/finished.
491 491
      *
492
-     * @return array
492
+     * @return integer[]
493 493
      */
494 494
     protected static function stats_scan()
495 495
     {
Please login to merge, or discard this patch.
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles disk-cache-related operations.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
      * @param string $md5 Hash.
39 39
      * @param string $ext Extension.
40 40
      */
41
-    public function __construct( $md5, $ext = 'php' )
41
+    public function __construct($md5, $ext = 'php')
42 42
     {
43 43
         $_min_ext = '';
44
-        if ( apply_filters( 'autoptimize_filter_cache_url_add_min_ext', false ) ) {
44
+        if (apply_filters('autoptimize_filter_cache_url_add_min_ext', false)) {
45 45
             $_min_ext = '.min';
46 46
         }
47 47
 
48 48
         $this->cachedir = AUTOPTIMIZE_CACHE_DIR;
49 49
         $this->nogzip   = AUTOPTIMIZE_CACHE_NOGZIP;
50
-        if ( ! $this->nogzip ) {
51
-            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.php';
50
+        if (!$this->nogzip) {
51
+            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.php';
52 52
         } else {
53
-            if ( in_array( $ext, array( 'js', 'css' ) ) ) {
54
-                $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
53
+            if (in_array($ext, array('js', 'css'))) {
54
+                $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
55 55
             } else {
56
-                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . $_min_ext . '.' . $ext;
56
+                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.$_min_ext.'.'.$ext;
57 57
             }
58 58
         }
59 59
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function check()
67 67
     {
68
-        return file_exists( $this->cachedir . $this->filename );
68
+        return file_exists($this->cachedir.$this->filename);
69 69
     }
70 70
 
71 71
     /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function retrieve()
77 77
     {
78
-        if ( $this->check() ) {
79
-            if ( false == $this->nogzip ) {
80
-                return file_get_contents( $this->cachedir . $this->filename . '.none' );
78
+        if ($this->check()) {
79
+            if (false == $this->nogzip) {
80
+                return file_get_contents($this->cachedir.$this->filename.'.none');
81 81
             } else {
82
-                return file_get_contents( $this->cachedir . $this->filename );
82
+                return file_get_contents($this->cachedir.$this->filename);
83 83
             }
84 84
         }
85 85
         return false;
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return void
95 95
      */
96
-    public function cache( $data, $mime )
96
+    public function cache($data, $mime)
97 97
     {
98 98
         // readonly FS explicitly OK'ed by developer, so just pretend all is OK.
99
-        if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
99
+        if (defined('AUTOPTIMIZE_CACHE_READONLY')) {
100 100
             return true;
101 101
         }
102 102
 
@@ -104,44 +104,44 @@  discard block
 block discarded – undo
104 104
         //
105 105
         // to be activated for users that experience these ugly errors;
106 106
         // PHP Warning: file_put_contents failed to open stream: No such file or directory.
107
-        if ( apply_filters( 'autoptimize_filter_cache_checkdirs_on_write', false ) ) {
107
+        if (apply_filters('autoptimize_filter_cache_checkdirs_on_write', false)) {
108 108
             $this->check_and_create_dirs();
109 109
         }
110 110
 
111
-        if ( false === $this->nogzip ) {
111
+        if (false === $this->nogzip) {
112 112
             // We handle gzipping ourselves.
113 113
             $file    = 'default.php';
114
-            $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file );
115
-            $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode );
114
+            $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file);
115
+            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode);
116 116
 
117
-            file_put_contents( $this->cachedir . $this->filename, $phpcode );
118
-            file_put_contents( $this->cachedir . $this->filename . '.none', $data );
117
+            file_put_contents($this->cachedir.$this->filename, $phpcode);
118
+            file_put_contents($this->cachedir.$this->filename.'.none', $data);
119 119
         } else {
120 120
             // Write code to cache without doing anything else.
121
-            file_put_contents( $this->cachedir . $this->filename, $data );
121
+            file_put_contents($this->cachedir.$this->filename, $data);
122 122
 
123 123
             // save fallback .js or .css file if filter true (to be false by default) but not if snippet or single.
124
-            if ( self::do_fallback() && strpos( $this->filename, '_snippet_' ) === false && strpos( $this->filename, '_single_' ) === false ) {
125
-                $_extension     = pathinfo( $this->filename, PATHINFO_EXTENSION );
126
-                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX . 'fallback.' . $_extension;
127
-                if ( ( 'css' === $_extension || 'js' === $_extension ) && ! file_exists( $this->cachedir . $_extension . '/' . $_fallback_file ) ) {
128
-                    file_put_contents( $this->cachedir . $_extension . '/' . $_fallback_file, $data );
124
+            if (self::do_fallback() && strpos($this->filename, '_snippet_') === false && strpos($this->filename, '_single_') === false) {
125
+                $_extension     = pathinfo($this->filename, PATHINFO_EXTENSION);
126
+                $_fallback_file = AUTOPTIMIZE_CACHEFILE_PREFIX.'fallback.'.$_extension;
127
+                if (('css' === $_extension || 'js' === $_extension) && !file_exists($this->cachedir.$_extension.'/'.$_fallback_file)) {
128
+                    file_put_contents($this->cachedir.$_extension.'/'.$_fallback_file, $data);
129 129
                 }
130 130
             }
131 131
 
132
-            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) {
132
+            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) {
133 133
                 // Create an additional cached gzip file.
134
-                file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) );
134
+                file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP));
135 135
                 // If PHP Brotli extension is installed, create an additional cached Brotli file.
136
-                if ( function_exists( 'brotli_compress' ) ) {
137
-                    file_put_contents( $this->cachedir . $this->filename . '.br', brotli_compress( $data, 11, BROTLI_GENERIC ) );
136
+                if (function_exists('brotli_compress')) {
137
+                    file_put_contents($this->cachedir.$this->filename.'.br', brotli_compress($data, 11, BROTLI_GENERIC));
138 138
                 }
139 139
             }
140 140
         }
141 141
 
142 142
         // Provide 3rd party action hook for every cache file that is created.
143 143
         // This hook can for example be used to inject a copy of the created cache file to a other domain.
144
-        do_action( 'autoptimize_action_cache_file_created', $this->cachedir . $this->filename );
144
+        do_action('autoptimize_action_cache_file_created', $this->cachedir.$this->filename);
145 145
     }
146 146
 
147 147
     /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         // The original idea here was to provide 3rd party code a hook so that
157 157
         // it can "listen" to all the complete autoptimized-urls that the page
158 158
         // will emit... Or something to that effect I think?
159
-        apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename );
159
+        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename);
160 160
 
161 161
         return $this->filename;
162 162
     }
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
      * @param string $file Filename.
170 170
      * @return bool
171 171
      */
172
-    protected static function is_valid_cache_file( $dir, $file )
172
+    protected static function is_valid_cache_file($dir, $file)
173 173
     {
174
-        if ( '.' !== $file && '..' !== $file &&
175
-            false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) &&
176
-            is_file( $dir . $file ) ) {
174
+        if ('.' !== $file && '..' !== $file &&
175
+            false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) &&
176
+            is_file($dir.$file)) {
177 177
 
178 178
             // It's a valid file!
179 179
             return true;
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
     protected static function clear_cache_classic()
192 192
     {
193 193
         $contents = self::get_cache_contents();
194
-        foreach ( $contents as $name => $files ) {
195
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
196
-            foreach ( $files as $file ) {
197
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
198
-                    @unlink( $dir . $file ); // @codingStandardsIgnoreLine
194
+        foreach ($contents as $name => $files) {
195
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
196
+            foreach ($files as $file) {
197
+                if (self::is_valid_cache_file($dir, $file)) {
198
+                    @unlink($dir.$file); // @codingStandardsIgnoreLine
199 199
                 }
200 200
             }
201 201
         }
202 202
 
203
-        @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine
203
+        @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine
204 204
     }
205 205
 
206 206
     /**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return bool
213 213
      */
214
-    protected static function rmdir( $pathname )
214
+    protected static function rmdir($pathname)
215 215
     {
216
-        $files = self::get_dir_contents( $pathname );
217
-        foreach ( $files as $file ) {
218
-            $path = $pathname . '/' . $file;
219
-            if ( is_dir( $path ) ) {
220
-                self::rmdir( $path );
216
+        $files = self::get_dir_contents($pathname);
217
+        foreach ($files as $file) {
218
+            $path = $pathname.'/'.$file;
219
+            if (is_dir($path)) {
220
+                self::rmdir($path);
221 221
             } else {
222
-                unlink( $path );
222
+                unlink($path);
223 223
             }
224 224
         }
225 225
 
226
-        return rmdir( $pathname );
226
+        return rmdir($pathname);
227 227
     }
228 228
 
229 229
     /**
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
         $new_name = self::get_unique_name();
245 245
 
246 246
         // Makes sure the new pathname is on the same level...
247
-        $new_pathname = dirname( $dir ) . '/' . $new_name;
248
-        $renamed      = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine
247
+        $new_pathname = dirname($dir).'/'.$new_name;
248
+        $renamed      = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine
249 249
 
250 250
         // When renamed, re-create the default cache directory back so it's
251 251
         // available again...
252
-        if ( $renamed ) {
252
+        if ($renamed) {
253 253
             $ok = self::cacheavail();
254 254
         }
255 255
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public static function advanced_cache_clear_enabled()
265 265
     {
266
-        return apply_filters( 'autoptimize_filter_cache_clear_advanced', false );
266
+        return apply_filters('autoptimize_filter_cache_clear_advanced', false);
267 267
     }
268 268
 
269 269
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     protected static function get_unique_name()
275 275
     {
276 276
         $prefix   = self::get_advanced_cache_clear_prefix();
277
-        $new_name = uniqid( $prefix, true );
277
+        $new_name = uniqid($prefix, true);
278 278
 
279 279
         return $new_name;
280 280
     }
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
     protected static function get_advanced_cache_clear_prefix()
288 288
     {
289 289
         $pathname = self::get_pathname_base();
290
-        $basename = basename( $pathname );
291
-        $prefix   = $basename . '-artifact-';
290
+        $basename = basename($pathname);
291
+        $prefix   = $basename.'-artifact-';
292 292
 
293 293
         return $prefix;
294 294
     }
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
      *
302 302
      * @return array
303 303
      */
304
-    protected static function get_dir_contents( $pathname )
304
+    protected static function get_dir_contents($pathname)
305 305
     {
306
-        return array_slice( scandir( $pathname ), 2 );
306
+        return array_slice(scandir($pathname), 2);
307 307
     }
308 308
 
309 309
     /**
@@ -316,24 +316,24 @@  discard block
 block discarded – undo
316 316
     public static function delete_advanced_cache_clear_artifacts()
317 317
     {
318 318
         // Don't go through these motions (called from the cachechecker) if advanced cache clear isn't even active.
319
-        if ( ! self::advanced_cache_clear_enabled() ) {
319
+        if (!self::advanced_cache_clear_enabled()) {
320 320
             return false;
321 321
         }
322 322
 
323 323
         $dir    = self::get_pathname_base();
324 324
         $prefix = self::get_advanced_cache_clear_prefix();
325
-        $parent = dirname( $dir );
325
+        $parent = dirname($dir);
326 326
         $ok     = false;
327 327
 
328 328
         // Returns the list of files without '.' and '..' elements.
329
-        $files = self::get_dir_contents( $parent );
330
-        if ( is_array( $files ) && ! empty( $files ) ) {
331
-            foreach ( $files as $file ) {
332
-                $path     = $parent . '/' . $file;
333
-                $prefixed = ( false !== strpos( $path, $prefix ) );
329
+        $files = self::get_dir_contents($parent);
330
+        if (is_array($files) && !empty($files)) {
331
+            foreach ($files as $file) {
332
+                $path     = $parent.'/'.$file;
333
+                $prefixed = (false !== strpos($path, $prefix));
334 334
                 // Removing only our own (prefixed) directories...
335
-                if ( is_dir( $path ) && $prefixed ) {
336
-                    $ok = self::rmdir( $path );
335
+                if (is_dir($path) && $prefixed) {
336
+                    $ok = self::rmdir($path);
337 337
                 }
338 338
             }
339 339
         }
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
     {
354 354
         $pathname = self::get_pathname_base();
355 355
 
356
-        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
356
+        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
357 357
             $blog_id   = get_current_blog_id();
358
-            $pathname .= $blog_id . '/';
358
+            $pathname .= $blog_id.'/';
359 359
         }
360 360
 
361 361
         return $pathname;
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     protected static function get_pathname_base()
370 370
     {
371
-        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
371
+        $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR;
372 372
 
373 373
         return $pathname;
374 374
     }
@@ -380,46 +380,46 @@  discard block
 block discarded – undo
380 380
      *
381 381
      * @return bool
382 382
      */
383
-    public static function clearall( $propagate = true )
383
+    public static function clearall($propagate = true)
384 384
     {
385
-        if ( ! self::cacheavail() ) {
385
+        if (!self::cacheavail()) {
386 386
             return false;
387 387
         }
388 388
 
389 389
         // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
390
-        if ( self::advanced_cache_clear_enabled() ) {
390
+        if (self::advanced_cache_clear_enabled()) {
391 391
             self::clear_cache_via_rename();
392 392
         } else {
393 393
             self::clear_cache_classic();
394 394
         }
395 395
 
396 396
         // Remove 404 handler if required.
397
-        if ( self::do_fallback() ) {
398
-            $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . 'autoptimize_404_handler.php';
399
-            @unlink( $_fallback_php ); // @codingStandardsIgnoreLine
397
+        if (self::do_fallback()) {
398
+            $_fallback_php = trailingslashit(WP_CONTENT_DIR).'autoptimize_404_handler.php';
399
+            @unlink($_fallback_php); // @codingStandardsIgnoreLine
400 400
         }
401 401
 
402 402
         // Remove the transient so it gets regenerated...
403
-        delete_transient( 'autoptimize_stats' );
403
+        delete_transient('autoptimize_stats');
404 404
 
405 405
         // Cache was just purged, clear page cache and allow others to hook into our purging...
406
-        if ( true === $propagate ) {
407
-            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) {
406
+        if (true === $propagate) {
407
+            if (!function_exists('autoptimize_do_cachepurged_action')) {
408 408
                 function autoptimize_do_cachepurged_action() {
409
-                    do_action( 'autoptimize_action_cachepurged' );
409
+                    do_action('autoptimize_action_cachepurged');
410 410
                 }
411 411
             }
412
-            add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 );
413
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 );
412
+            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11);
413
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0);
414 414
         }
415 415
 
416 416
         // Warm cache (part of speedupper)!
417
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) && false == get_transient( 'autoptimize_cache_warmer_protector' ) ) {
418
-            set_transient( 'autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60 * 10 );
419
-            $url   = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 );
420
-            $url   = apply_filters( 'autoptimize_filter_cache_warmer_url', $url );
421
-            $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine
422
-            unset( $cache );
417
+        if (apply_filters('autoptimize_filter_speedupper', true) && false == get_transient('autoptimize_cache_warmer_protector')) {
418
+            set_transient('autoptimize_cache_warmer_protector', 'I shall not warm cache for another 10 minutes.', 60*10);
419
+            $url   = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000);
420
+            $url   = apply_filters('autoptimize_filter_cache_warmer_url', $url);
421
+            $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine
422
+            unset($cache);
423 423
         }
424 424
 
425 425
         return true;
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
      */
435 435
     public static function clearall_actionless()
436 436
     {
437
-        return self::clearall( false );
437
+        return self::clearall(false);
438 438
     }
439 439
 
440 440
     /**
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
     {
447 447
         $contents = array();
448 448
 
449
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
450
-            $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir );
449
+        foreach (array('', 'js', 'css') as $dir) {
450
+            $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir);
451 451
         }
452 452
 
453 453
         return $contents;
@@ -460,21 +460,21 @@  discard block
 block discarded – undo
460 460
      */
461 461
     public static function stats()
462 462
     {
463
-        $stats = get_transient( 'autoptimize_stats' );
463
+        $stats = get_transient('autoptimize_stats');
464 464
 
465 465
         // If no transient, do the actual scan!
466
-        if ( ! is_array( $stats ) ) {
467
-            if ( ! self::cacheavail() ) {
466
+        if (!is_array($stats)) {
467
+            if (!self::cacheavail()) {
468 468
                 return 0;
469 469
             }
470 470
             $stats = self::stats_scan();
471 471
             $count = $stats[0];
472
-            if ( $count > 100 ) {
472
+            if ($count > 100) {
473 473
                 // Store results in transient.
474 474
                 set_transient(
475 475
                     'autoptimize_stats',
476 476
                     $stats,
477
-                    apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS )
477
+                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS)
478 478
                 );
479 479
             }
480 480
         }
@@ -497,30 +497,30 @@  discard block
 block discarded – undo
497 497
         $size  = 0;
498 498
 
499 499
         // Scan everything in our cache directories.
500
-        foreach ( self::get_cache_contents() as $name => $files ) {
501
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
502
-            foreach ( $files as $file ) {
503
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
504
-                    if ( AUTOPTIMIZE_CACHE_NOGZIP &&
500
+        foreach (self::get_cache_contents() as $name => $files) {
501
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
502
+            foreach ($files as $file) {
503
+                if (self::is_valid_cache_file($dir, $file)) {
504
+                    if (AUTOPTIMIZE_CACHE_NOGZIP &&
505 505
                         (
506
-                            false !== strpos( $file, '.js' ) ||
507
-                            false !== strpos( $file, '.css' ) ||
508
-                            false !== strpos( $file, '.img' ) ||
509
-                            false !== strpos( $file, '.txt' )
506
+                            false !== strpos($file, '.js') ||
507
+                            false !== strpos($file, '.css') ||
508
+                            false !== strpos($file, '.img') ||
509
+                            false !== strpos($file, '.txt')
510 510
                         )
511 511
                     ) {
512 512
                         // Web server is gzipping, we count .js|.css|.img|.txt files.
513 513
                         $count++;
514
-                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) {
514
+                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) {
515 515
                         // We are gzipping ourselves via php, counting only .none files.
516 516
                         $count++;
517 517
                     }
518
-                    $size += filesize( $dir . $file );
518
+                    $size += filesize($dir.$file);
519 519
                 }
520 520
             }
521 521
         }
522 522
 
523
-        $stats = array( $count, $size, time() );
523
+        $stats = array($count, $size, time());
524 524
 
525 525
         return $stats;
526 526
     }
@@ -535,26 +535,26 @@  discard block
 block discarded – undo
535 535
     public static function cacheavail()
536 536
     {
537 537
         // readonly FS explicitly OK'ed by dev, let's assume the cache dirs are there!
538
-        if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
538
+        if (defined('AUTOPTIMIZE_CACHE_READONLY')) {
539 539
             return true;
540 540
         }
541 541
 
542
-        if ( false === autoptimizeCache::check_and_create_dirs() ) {
542
+        if (false === autoptimizeCache::check_and_create_dirs()) {
543 543
             return false;
544 544
         }
545 545
 
546 546
         // Using .htaccess inside our cache folder to overrule wp-super-cache.
547
-        $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
548
-        if ( ! is_file( $htaccess ) ) {
547
+        $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess';
548
+        if (!is_file($htaccess)) {
549 549
             /**
550 550
              * Create `wp-content/AO_htaccess_tmpl` file with
551 551
              * whatever htaccess rules you might need
552 552
              * if you want to override default AO htaccess
553 553
              */
554
-            $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl';
555
-            if ( is_file( $htaccess_tmpl ) ) {
556
-                $content = file_get_contents( $htaccess_tmpl );
557
-            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) {
554
+            $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl';
555
+            if (is_file($htaccess_tmpl)) {
556
+                $content = file_get_contents($htaccess_tmpl);
557
+            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) {
558 558
                 $content = '<IfModule mod_expires.c>
559 559
         ExpiresActive On
560 560
         ExpiresByType text/css A30672000
@@ -608,13 +608,13 @@  discard block
 block discarded – undo
608 608
 </IfModule>';
609 609
             }
610 610
 
611
-            if ( self::do_fallback() === true ) {
612
-                $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
611
+            if (self::do_fallback() === true) {
612
+                $content .= "\nErrorDocument 404 ".trailingslashit(parse_url(content_url(), PHP_URL_PATH)).'autoptimize_404_handler.php';
613 613
             }
614
-            @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
614
+            @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine
615 615
         }
616 616
 
617
-        if ( self::do_fallback() ) {
617
+        if (self::do_fallback()) {
618 618
             self::check_fallback_php();
619 619
         }
620 620
 
@@ -629,17 +629,17 @@  discard block
 block discarded – undo
629 629
      */
630 630
     public static function check_fallback_php() {
631 631
         $_fallback_filename = 'autoptimize_404_handler.php';
632
-        $_fallback_php      = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename;
632
+        $_fallback_php      = trailingslashit(WP_CONTENT_DIR).$_fallback_filename;
633 633
         $_fallback_status   = true;
634 634
 
635
-        if ( ! file_exists( $_fallback_php ) && is_writable( WP_CONTENT_DIR ) ) {
636
-            $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
637
-            $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
638
-            $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
639
-            if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
640
-                $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
635
+        if (!file_exists($_fallback_php) && is_writable(WP_CONTENT_DIR)) {
636
+            $_fallback_php_contents = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$_fallback_filename);
637
+            $_fallback_php_contents = str_replace('<?php exit;', '<?php', $_fallback_php_contents);
638
+            $_fallback_php_contents = str_replace('<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents);
639
+            if (apply_filters('autoptimize_filter_cache_fallback_log_errors', false)) {
640
+                $_fallback_php_contents = str_replace('// error_log', 'error_log', $_fallback_php_contents);
641 641
             }
642
-            $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
642
+            $_fallback_status = file_put_contents($_fallback_php, $_fallback_php_contents);
643 643
         }
644 644
 
645 645
         return $_fallback_status;
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
     public static function do_fallback() {
657 657
         static $_do_fallback = null;
658 658
 
659
-        if ( null === $_do_fallback ) {
660
-            $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) );
659
+        if (null === $_do_fallback) {
660
+            $_do_fallback = (bool) apply_filters('autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1'));
661 661
         }
662 662
 
663 663
         return $_do_fallback;
@@ -669,31 +669,31 @@  discard block
 block discarded – undo
669 669
      * and 410'ing ("Gone") if fallback not available.
670 670
      */
671 671
     public static function wordpress_notfound_fallback() {
672
-        $original_request = strtok( $_SERVER['REQUEST_URI'], '?' );
673
-        if ( strpos( $original_request, wp_basename( WP_CONTENT_DIR ) . AUTOPTIMIZE_CACHE_CHILD_DIR ) !== false && is_404() ) {
672
+        $original_request = strtok($_SERVER['REQUEST_URI'], '?');
673
+        if (strpos($original_request, wp_basename(WP_CONTENT_DIR).AUTOPTIMIZE_CACHE_CHILD_DIR) !== false && is_404()) {
674 674
             // make sure this is not considered a 404.
675 675
             global $wp_query;
676 676
             $wp_query->is_404 = false;
677 677
 
678 678
             // set fallback path.
679
-            $js_or_css     = pathinfo( $original_request, PATHINFO_EXTENSION );
680
-            $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
679
+            $js_or_css     = pathinfo($original_request, PATHINFO_EXTENSION);
680
+            $fallback_path = AUTOPTIMIZE_CACHE_DIR.$js_or_css.'/autoptimize_fallback.'.$js_or_css;
681 681
 
682 682
             // prepare for Shakeeb's Unused CSS files to be 404-handled as well.
683
-            if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
684
-                $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request  );
683
+            if (strpos($original_request, 'uucss/uucss-') !== false) {
684
+                $original_request = preg_replace('/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request);
685 685
             }
686 686
 
687 687
             // set fallback URL.
688
-            $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
688
+            $fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request);
689 689
 
690 690
             // redirect to fallback if possible.
691
-            if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) {
691
+            if ($original_request !== $fallback_target && file_exists($fallback_path)) {
692 692
                 // redirect to fallback.
693
-                wp_redirect( $fallback_target, 302 );
693
+                wp_redirect($fallback_target, 302);
694 694
             } else {
695 695
                 // return HTTP 410 (gone) reponse.
696
-                status_header( 410 );
696
+                status_header(410);
697 697
             }
698 698
         }
699 699
     }
@@ -705,13 +705,13 @@  discard block
 block discarded – undo
705 705
      * @return bool
706 706
      */
707 707
     public static function check_and_create_dirs() {
708
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
708
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
709 709
             // We didn't set a cache.
710 710
             return false;
711 711
         }
712 712
 
713
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
714
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
713
+        foreach (array('', 'js', 'css') as $dir) {
714
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
715 715
                 return false;
716 716
             }
717 717
         }
@@ -726,25 +726,25 @@  discard block
 block discarded – undo
726 726
      *
727 727
      * @return bool
728 728
      */
729
-    protected static function check_cache_dir( $dir )
729
+    protected static function check_cache_dir($dir)
730 730
     {
731 731
         // Try creating the dir if it doesn't exist.
732
-        if ( ! file_exists( $dir ) ) {
733
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
734
-            if ( ! file_exists( $dir ) ) {
732
+        if (!file_exists($dir)) {
733
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
734
+            if (!file_exists($dir)) {
735 735
                 return false;
736 736
             }
737 737
         }
738 738
 
739 739
         // If we still cannot write, bail.
740
-        if ( ! is_writable( $dir ) ) {
740
+        if (!is_writable($dir)) {
741 741
             return false;
742 742
         }
743 743
 
744 744
         // Create an index.html in there to avoid prying eyes!
745
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
746
-        if ( ! is_file( $idx_file ) ) {
747
-            @file_put_contents( $idx_file, '<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>' ); // @codingStandardsIgnoreLine
745
+        $idx_file = rtrim($dir, '/\\').'/index.html';
746
+        if (!is_file($idx_file)) {
747
+            @file_put_contents($idx_file, '<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>'); // @codingStandardsIgnoreLine
748 748
         }
749 749
 
750 750
         return true;
@@ -758,54 +758,54 @@  discard block
 block discarded – undo
758 758
     // @codingStandardsIgnoreStart
759 759
     public static function flushPageCache()
760 760
     {
761
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
762
-            if ( is_multisite() ) {
761
+        if (function_exists('wp_cache_clear_cache')) {
762
+            if (is_multisite()) {
763 763
                 $blog_id = get_current_blog_id();
764
-                wp_cache_clear_cache( $blog_id );
764
+                wp_cache_clear_cache($blog_id);
765 765
             } else {
766 766
                 wp_cache_clear_cache();
767 767
             }
768
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
769
-            do_action( 'cachify_flush_cache' );
770
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
768
+        } elseif (has_action('cachify_flush_cache')) {
769
+            do_action('cachify_flush_cache');
770
+        } elseif (function_exists('w3tc_pgcache_flush')) {
771 771
             w3tc_pgcache_flush();
772
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
772
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
773 773
             wp_fast_cache_bulk_delete_all();
774
-        } elseif ( function_exists( 'rapidcache_clear_cache' ) ) {
774
+        } elseif (function_exists('rapidcache_clear_cache')) {
775 775
             rapidcache_clear_cache();
776
-        } elseif ( class_exists( 'Swift_Performance_Cache' ) ) {
776
+        } elseif (class_exists('Swift_Performance_Cache')) {
777 777
             Swift_Performance_Cache::clear_all_cache();
778
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
778
+        } elseif (class_exists('WpFastestCache')) {
779 779
             $wpfc = new WpFastestCache();
780 780
             $wpfc->deleteCache();
781
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
781
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
782 782
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
783
-        } elseif ( class_exists( 'zencache' ) ) {
783
+        } elseif (class_exists('zencache')) {
784 784
             zencache::clear();
785
-        } elseif ( class_exists( 'comet_cache' ) ) {
785
+        } elseif (class_exists('comet_cache')) {
786 786
             comet_cache::clear();
787
-        } elseif ( class_exists( 'WpeCommon' ) ) {
787
+        } elseif (class_exists('WpeCommon')) {
788 788
             // WPEngine cache purge/flush methods to call by default
789 789
             $wpe_methods = array(
790 790
                 'purge_varnish_cache',
791 791
             );
792 792
 
793 793
             // More agressive clear/flush/purge behind a filter
794
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
795
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
794
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
795
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
796 796
             }
797 797
 
798 798
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
799
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
799
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
800 800
 
801
-            foreach ( $wpe_methods as $wpe_method ) {
802
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
801
+            foreach ($wpe_methods as $wpe_method) {
802
+                if (method_exists('WpeCommon', $wpe_method)) {
803 803
                     WpeCommon::$wpe_method();
804 804
                 }
805 805
             }
806
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
806
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
807 807
             sg_cachepress_purge_cache();
808
-        } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
808
+        } elseif (array_key_exists('KINSTA_CACHE_ZONE', $_SERVER)) {
809 809
             $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
810 810
             $_kinsta_response        = wp_remote_get(
811 811
                 $_kinsta_clear_cache_url,
@@ -814,20 +814,20 @@  discard block
 block discarded – undo
814 814
                     'timeout' => 5,
815 815
                     )
816 816
             );
817
-        } elseif ( defined('NGINX_HELPER_BASENAME') ) {
818
-            do_action( 'rt_nginx_helper_purge_all' );
819
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
817
+        } elseif (defined('NGINX_HELPER_BASENAME')) {
818
+            do_action('rt_nginx_helper_purge_all');
819
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
820 820
             // fallback for WP-Super-Cache
821 821
             global $cache_path;
822
-            if ( is_multisite() ) {
822
+            if (is_multisite()) {
823 823
                 $blog_id = get_current_blog_id();
824
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
825
-                prune_super_cache( $cache_path . 'blogs/', true );
824
+                prune_super_cache(get_supercache_dir($blog_id), true);
825
+                prune_super_cache($cache_path.'blogs/', true);
826 826
             } else {
827
-                prune_super_cache( $cache_path . 'supercache/', true );
828
-                prune_super_cache( $cache_path, true );
827
+                prune_super_cache($cache_path.'supercache/', true);
828
+                prune_super_cache($cache_path, true);
829 829
             }
830
-        } elseif ( class_exists( 'NginxCache' ) ) {
830
+        } elseif (class_exists('NginxCache')) {
831 831
             $nginx_cache = new NginxCache();
832 832
             $nginx_cache->purge_zone_once();
833 833
         }
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/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/autoptimizeCriticalCSSBase.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS base file (initializes all ccss files).
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -19,35 +19,35 @@  discard block
 block discarded – undo
19 19
     public function __construct()
20 20
     {
21 21
         // define constant, but only once.
22
-        if ( ! defined( 'AO_CCSS_DIR' ) ) {
22
+        if (!defined('AO_CCSS_DIR')) {
23 23
             // Define a constant with the directory to store critical CSS in.
24
-            if ( is_multisite() ) {
24
+            if (is_multisite()) {
25 25
                 $blog_id = get_current_blog_id();
26
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' . $blog_id . '/' );
26
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/'.$blog_id.'/');
27 27
             } else {
28
-                define( 'AO_CCSS_DIR', WP_CONTENT_DIR . '/uploads/ao_ccss/' );
28
+                define('AO_CCSS_DIR', WP_CONTENT_DIR.'/uploads/ao_ccss/');
29 29
             }
30 30
         }
31
-        if ( ! defined( 'AO_CCSS_VER' ) ) {
31
+        if (!defined('AO_CCSS_VER')) {
32 32
             // Define plugin version.
33
-            define( 'AO_CCSS_VER', 'AO_' . AUTOPTIMIZE_PLUGIN_VERSION );
33
+            define('AO_CCSS_VER', 'AO_'.AUTOPTIMIZE_PLUGIN_VERSION);
34 34
 
35 35
             // Define constants for criticalcss.com base path and API endpoints.
36 36
             // fixme: AO_CCSS_URL should be read from the autoptimize availability json stored as option.
37
-            define( 'AO_CCSS_URL', 'https://criticalcss.com' );
38
-            define( 'AO_CCSS_API', AO_CCSS_URL . '/api/premium/' );
39
-            define( 'AO_CCSS_SLEEP', 10 );
37
+            define('AO_CCSS_URL', 'https://criticalcss.com');
38
+            define('AO_CCSS_API', AO_CCSS_URL.'/api/premium/');
39
+            define('AO_CCSS_SLEEP', 10);
40 40
         }
41 41
 
42 42
         // Define support files locations, in case they are not already defined.
43
-        if ( ! defined( 'AO_CCSS_LOCK' ) ) {
44
-            define( 'AO_CCSS_LOCK', AO_CCSS_DIR . 'queue.lock' );
43
+        if (!defined('AO_CCSS_LOCK')) {
44
+            define('AO_CCSS_LOCK', AO_CCSS_DIR.'queue.lock');
45 45
         }
46
-        if ( ! defined( 'AO_CCSS_LOG' ) ) {
47
-            define( 'AO_CCSS_LOG', AO_CCSS_DIR . 'queuelog.html' );
46
+        if (!defined('AO_CCSS_LOG')) {
47
+            define('AO_CCSS_LOG', AO_CCSS_DIR.'queuelog.html');
48 48
         }
49
-        if ( ! defined( 'AO_CCSS_DEBUG' ) ) {
50
-            define( 'AO_CCSS_DEBUG', AO_CCSS_DIR . 'queue.json' );
49
+        if (!defined('AO_CCSS_DEBUG')) {
50
+            define('AO_CCSS_DEBUG', AO_CCSS_DIR.'queue.json');
51 51
         }
52 52
 
53 53
         $this->filepath = __FILE__;
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
     {
61 61
         // get all options.
62 62
         $all_options = $this->fetch_options();
63
-        foreach ( $all_options as $option => $value ) {
63
+        foreach ($all_options as $option => $value) {
64 64
             ${$option} = $value;
65 65
         }
66 66
 
67 67
         // make sure the 10 minutes cron schedule is added.
68
-        add_filter( 'cron_schedules', array( $this, 'ao_ccss_interval' ) );
68
+        add_filter('cron_schedules', array($this, 'ao_ccss_interval'));
69 69
 
70 70
         // check if we need to upgrade.
71 71
         $this->check_upgrade();
72 72
 
73 73
         // make sure ao_ccss_queue is scheduled OK if an API key is set.
74
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
75
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
74
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
75
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
76 76
         }
77 77
     }
78 78
 
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
         // Required libs, core is always needed.
81 81
         $criticalcss_core = new autoptimizeCriticalCSSCore();
82 82
 
83
-        if ( defined( 'WP_CLI' ) || defined( 'DOING_CRON' ) || is_admin() ) {
83
+        if (defined('WP_CLI') || defined('DOING_CRON') || is_admin()) {
84 84
             // TODO: also include if overridden somehow to force queue processing to be executed?
85 85
             $criticalcss_cron = new autoptimizeCriticalCSSCron();
86 86
         }
87 87
 
88
-        if ( is_admin() ) {
88
+        if (is_admin()) {
89 89
             $criticalcss_settings = new autoptimizeCriticalCSSSettings();
90 90
         } else {
91 91
             // enqueuing only done when not wp-admin.
@@ -96,51 +96,51 @@  discard block
 block discarded – undo
96 96
     public static function fetch_options() {
97 97
         static $autoptimize_ccss_options = null;
98 98
 
99
-        if ( null === $autoptimize_ccss_options ) {
99
+        if (null === $autoptimize_ccss_options) {
100 100
             // not cached yet, fetching from WordPress options.
101
-            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' );
102
-            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' );
103
-            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option( 'autoptimize_ccss_rules', false );
104
-            $autoptimize_ccss_options['ao_ccss_additional']    = get_option( 'autoptimize_ccss_additional' );
105
-            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option( 'autoptimize_ccss_queue', false );
106
-            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option( 'autoptimize_ccss_viewport', false );
107
-            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option( 'autoptimize_ccss_finclude', false );
108
-            $autoptimize_ccss_options['ao_ccss_rtimelimit']    = get_option( 'autoptimize_ccss_rtimelimit', '30' );
109
-            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option( 'autoptimize_ccss_noptimize', false );
110
-            $autoptimize_ccss_options['ao_ccss_debug']         = get_option( 'autoptimize_ccss_debug', false );
111
-            $autoptimize_ccss_options['ao_ccss_key']           = get_option( 'autoptimize_ccss_key' );
112
-            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option( 'autoptimize_ccss_keyst' );
113
-            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option( 'autoptimize_ccss_loggedin', '1' );
114
-            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option( 'autoptimize_ccss_forcepath', '1' );
115
-            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' );
116
-            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option( 'autoptimize_ccss_deferjquery', false );
117
-            $autoptimize_ccss_options['ao_ccss_domain']        = get_option( 'autoptimize_ccss_domain' );
118
-            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option( 'autoptimize_ccss_unloadccss', false );
119
-
120
-            if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) {
121
-                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] );
122
-            } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) {
101
+            $autoptimize_ccss_options['ao_css_defer']          = autoptimizeOptionWrapper::get_option('autoptimize_css_defer');
102
+            $autoptimize_ccss_options['ao_css_defer_inline']   = autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline');
103
+            $autoptimize_ccss_options['ao_ccss_rules_raw']     = get_option('autoptimize_ccss_rules', false);
104
+            $autoptimize_ccss_options['ao_ccss_additional']    = get_option('autoptimize_ccss_additional');
105
+            $autoptimize_ccss_options['ao_ccss_queue_raw']     = get_option('autoptimize_ccss_queue', false);
106
+            $autoptimize_ccss_options['ao_ccss_viewport']      = get_option('autoptimize_ccss_viewport', false);
107
+            $autoptimize_ccss_options['ao_ccss_finclude']      = get_option('autoptimize_ccss_finclude', false);
108
+            $autoptimize_ccss_options['ao_ccss_rtimelimit']    = get_option('autoptimize_ccss_rtimelimit', '30');
109
+            $autoptimize_ccss_options['ao_ccss_noptimize']     = get_option('autoptimize_ccss_noptimize', false);
110
+            $autoptimize_ccss_options['ao_ccss_debug']         = get_option('autoptimize_ccss_debug', false);
111
+            $autoptimize_ccss_options['ao_ccss_key']           = get_option('autoptimize_ccss_key');
112
+            $autoptimize_ccss_options['ao_ccss_keyst']         = get_option('autoptimize_ccss_keyst');
113
+            $autoptimize_ccss_options['ao_ccss_loggedin']      = get_option('autoptimize_ccss_loggedin', '1');
114
+            $autoptimize_ccss_options['ao_ccss_forcepath']     = get_option('autoptimize_ccss_forcepath', '1');
115
+            $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option('autoptimize_service_availablity');
116
+            $autoptimize_ccss_options['ao_ccss_deferjquery']   = get_option('autoptimize_ccss_deferjquery', false);
117
+            $autoptimize_ccss_options['ao_ccss_domain']        = get_option('autoptimize_ccss_domain');
118
+            $autoptimize_ccss_options['ao_ccss_unloadccss']    = get_option('autoptimize_ccss_unloadccss', false);
119
+
120
+            if (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') === false && strpos($autoptimize_ccss_options['ao_ccss_domain'], 'uggc') === 0) {
121
+                $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13($autoptimize_ccss_options['ao_ccss_domain']);
122
+            } elseif (strpos($autoptimize_ccss_options['ao_ccss_domain'], 'http') !== false) {
123 123
                 // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain).
124
-                update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) );
124
+                update_option('autoptimize_ccss_domain', str_rot13($autoptimize_ccss_options['ao_ccss_domain']));
125 125
             }
126 126
 
127 127
             // Setup the rules array.
128
-            if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) {
128
+            if (empty($autoptimize_ccss_options['ao_ccss_rules_raw'])) {
129 129
                 $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array();
130 130
                 $autoptimize_ccss_options['ao_ccss_rules']['types'] = array();
131 131
             } else {
132
-                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true );
132
+                $autoptimize_ccss_options['ao_ccss_rules'] = json_decode($autoptimize_ccss_options['ao_ccss_rules_raw'], true);
133 133
             }
134 134
 
135 135
             // Setup the queue array.
136
-            if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) {
136
+            if (empty($autoptimize_ccss_options['ao_ccss_queue_raw'])) {
137 137
                 $autoptimize_ccss_options['ao_ccss_queue'] = array();
138 138
             } else {
139
-                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true );
139
+                $autoptimize_ccss_options['ao_ccss_queue'] = json_decode($autoptimize_ccss_options['ao_ccss_queue_raw'], true);
140 140
             }
141 141
 
142 142
             // Override API key if constant is defined.
143
-            if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) {
143
+            if (defined('AUTOPTIMIZE_CRITICALCSS_API_KEY')) {
144 144
                 $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY;
145 145
             }
146 146
         }
@@ -152,49 +152,49 @@  discard block
 block discarded – undo
152 152
         global $ao_ccss_key;
153 153
 
154 154
         // Create the cache directory if it doesn't exist already.
155
-        if ( ! file_exists( AO_CCSS_DIR ) ) {
156
-            mkdir( AO_CCSS_DIR, 0755, true );
155
+        if (!file_exists(AO_CCSS_DIR)) {
156
+            mkdir(AO_CCSS_DIR, 0755, true);
157 157
         }
158 158
 
159 159
         // Create a scheduled event for the queue.
160
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) {
161
-            wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' );
160
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_queue')) {
161
+            wp_schedule_event(time(), apply_filters('ao_ccss_queue_schedule', 'ao_ccss'), 'ao_ccss_queue');
162 162
         }
163 163
 
164 164
         // Create a scheduled event for log maintenance.
165
-        if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) {
166
-            wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' );
165
+        if (isset($ao_ccss_key) && !empty($ao_ccss_key) && !wp_next_scheduled('ao_ccss_maintenance')) {
166
+            wp_schedule_event(time(), 'twicedaily', 'ao_ccss_maintenance');
167 167
         }
168 168
     }
169 169
 
170 170
     public function check_upgrade() {
171
-        $db_version = get_option( 'autoptimize_ccss_version', '' );
172
-        if ( AO_CCSS_VER !== $db_version ) {
171
+        $db_version = get_option('autoptimize_ccss_version', '');
172
+        if (AO_CCSS_VER !== $db_version) {
173 173
             // check schedules & re-schedule if needed.
174 174
             $this->on_upgrade();
175 175
             // and update db_version.
176
-            update_option( 'autoptimize_ccss_version', AO_CCSS_VER );
176
+            update_option('autoptimize_ccss_version', AO_CCSS_VER);
177 177
         }
178 178
     }
179 179
 
180
-    public function ao_ccss_interval( $schedules ) {
180
+    public function ao_ccss_interval($schedules) {
181 181
         // Let interval be configurable.
182
-        if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) {
182
+        if (!defined('AO_CCSS_DEBUG_INTERVAL')) {
183 183
             $intsec = 600;
184 184
         } else {
185 185
             $intsec = AO_CCSS_DEBUG_INTERVAL;
186
-            if ( $intsec >= 120 ) {
187
-                $inttxt = $intsec / 60 . ' minutes';
186
+            if ($intsec >= 120) {
187
+                $inttxt = $intsec/60.' minutes';
188 188
             } else {
189
-                $inttxt = $intsec . ' second(s)';
189
+                $inttxt = $intsec.' second(s)';
190 190
             }
191
-            autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 );
191
+            autoptimizeCriticalCSSCore::ao_ccss_log('Using custom WP-Cron interval of '.$inttxt, 3);
192 192
         }
193 193
 
194 194
         // Attach interval to schedule.
195 195
         $schedules['ao_ccss'] = array(
196 196
             'interval' => $intsec,
197
-            'display'  => __( 'Autoptimize CriticalCSS' ),
197
+            'display'  => __('Autoptimize CriticalCSS'),
198 198
         );
199 199
         return $schedules;
200 200
     }
Please login to merge, or discard this patch.
classes/autoptimizeCriticalCSSSettingsAjax.php 1 patch
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS settings AJAX logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,7 +12,7 @@  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
         }
@@ -21,47 +21,47 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function run() {
23 23
         // add filters.
24
-        add_action( 'wp_ajax_fetch_critcss', array( $this, 'critcss_fetch_callback' ) );
25
-        add_action( 'wp_ajax_save_critcss', array( $this, 'critcss_save_callback' ) );
26
-        add_action( 'wp_ajax_rm_critcss', array( $this, 'critcss_rm_callback' ) );
27
-        add_action( 'wp_ajax_rm_critcss_all', array( $this, 'critcss_rm_all_callback' ) );
28
-        add_action( 'wp_ajax_ao_ccss_export', array( $this, 'ao_ccss_export_callback' ) );
29
-        add_action( 'wp_ajax_ao_ccss_import', array( $this, 'ao_ccss_import_callback' ) );
24
+        add_action('wp_ajax_fetch_critcss', array($this, 'critcss_fetch_callback'));
25
+        add_action('wp_ajax_save_critcss', array($this, 'critcss_save_callback'));
26
+        add_action('wp_ajax_rm_critcss', array($this, 'critcss_rm_callback'));
27
+        add_action('wp_ajax_rm_critcss_all', array($this, 'critcss_rm_all_callback'));
28
+        add_action('wp_ajax_ao_ccss_export', array($this, 'ao_ccss_export_callback'));
29
+        add_action('wp_ajax_ao_ccss_import', array($this, 'ao_ccss_import_callback'));
30 30
     }
31 31
 
32 32
     public function critcss_fetch_callback() {
33 33
         // Ajax handler to obtain a critical CSS file from the filesystem.
34 34
         // Check referer.
35
-        check_ajax_referer( 'fetch_critcss_nonce', 'critcss_fetch_nonce' );
35
+        check_ajax_referer('fetch_critcss_nonce', 'critcss_fetch_nonce');
36 36
 
37 37
         // Initialize error flag.
38 38
         $error = true;
39 39
 
40 40
         // Allow no content for MANUAL rules (as they may not exist just yet).
41
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
41
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
42 42
             $content = '';
43 43
             $error   = false;
44
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
44
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
45 45
             // Or check user permissios and filename.
46 46
             // Set file path and obtain its content.
47
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
48
-            if ( file_exists( $critcssfile ) ) {
49
-                $content = file_get_contents( $critcssfile );
47
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
48
+            if (file_exists($critcssfile)) {
49
+                $content = file_get_contents($critcssfile);
50 50
                 $error   = false;
51 51
             }
52 52
         }
53 53
 
54 54
         // Prepare response.
55
-        if ( $error ) {
55
+        if ($error) {
56 56
             $response['code']   = '500';
57
-            $response['string'] = 'Error reading file ' . $critcssfile . '.';
57
+            $response['string'] = 'Error reading file '.$critcssfile.'.';
58 58
         } else {
59 59
             $response['code']   = '200';
60 60
             $response['string'] = $content;
61 61
         }
62 62
 
63 63
         // Dispatch respose.
64
-        echo json_encode( $response );
64
+        echo json_encode($response);
65 65
 
66 66
         // Close ajax request.
67 67
         wp_die();
@@ -74,22 +74,22 @@  discard block
 block discarded – undo
74 74
 
75 75
         // Ajax handler to write a critical CSS to the filesystem
76 76
         // Check referer.
77
-        check_ajax_referer( 'save_critcss_nonce', 'critcss_save_nonce' );
77
+        check_ajax_referer('save_critcss_nonce', 'critcss_save_nonce');
78 78
 
79 79
         // Allow empty contents for MANUAL rules (as they are fetched later).
80
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
80
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
81 81
             $critcssfile = false;
82 82
             $status      = true;
83
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
83
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
84 84
             // Or check user permissios and filename
85 85
             // Set critical CSS content.
86
-            $critcsscontents = stripslashes( $_POST['critcsscontents'] );
86
+            $critcsscontents = stripslashes($_POST['critcsscontents']);
87 87
 
88 88
             // If there is content and it's valid, write the file.
89
-            if ( $critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents( $critcsscontents ) ) {
89
+            if ($critcsscontents && autoptimizeCriticalCSSCore::ao_ccss_check_contents($critcsscontents)) {
90 90
                 // Set file path and status.
91
-                $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
92
-                $status      = file_put_contents( $critcssfile, $critcsscontents, LOCK_EX );
91
+                $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
92
+                $status      = file_put_contents($critcssfile, $critcsscontents, LOCK_EX);
93 93
                 // Or set as error.
94 94
             } else {
95 95
                 $error = true;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
         }
101 101
 
102 102
         // Prepare response.
103
-        if ( ! $status || $error ) {
103
+        if (!$status || $error) {
104 104
             $response['code']   = '500';
105
-            $response['string'] = 'Error saving file ' . $critcssfile . '.';
105
+            $response['string'] = 'Error saving file '.$critcssfile.'.';
106 106
         } else {
107 107
             $response['code'] = '200';
108
-            if ( $critcssfile ) {
109
-                $response['string'] = 'File ' . $critcssfile . ' saved.';
108
+            if ($critcssfile) {
109
+                $response['string'] = 'File '.$critcssfile.' saved.';
110 110
             } else {
111 111
                 $response['string'] = 'Empty content do not need to be saved.';
112 112
             }
113 113
         }
114 114
 
115 115
         // Dispatch respose.
116
-        echo json_encode( $response );
116
+        echo json_encode($response);
117 117
 
118 118
         // Close ajax request.
119 119
         wp_die();
@@ -123,40 +123,40 @@  discard block
 block discarded – undo
123 123
     public function critcss_rm_callback() {
124 124
         // Ajax handler to delete a critical CSS from the filesystem
125 125
         // Check referer.
126
-        check_ajax_referer( 'rm_critcss_nonce', 'critcss_rm_nonce' );
126
+        check_ajax_referer('rm_critcss_nonce', 'critcss_rm_nonce');
127 127
 
128 128
         // Initialize error and status flags.
129 129
         $error  = true;
130 130
         $status = false;
131 131
 
132 132
         // Allow no file for MANUAL rules (as they may not exist just yet).
133
-        if ( current_user_can( 'manage_options' ) && empty( $_POST['critcssfile'] ) ) {
133
+        if (current_user_can('manage_options') && empty($_POST['critcssfile'])) {
134 134
             $error = false;
135
-        } elseif ( current_user_can( 'manage_options' ) && $this->critcss_check_filename( $_POST['critcssfile'] ) ) {
135
+        } elseif (current_user_can('manage_options') && $this->critcss_check_filename($_POST['critcssfile'])) {
136 136
             // Or check user permissios and filename
137 137
             // Set file path and delete it.
138
-            $critcssfile = AO_CCSS_DIR . strip_tags( $_POST['critcssfile'] );
139
-            if ( file_exists( $critcssfile ) ) {
140
-                $status = unlink( $critcssfile );
138
+            $critcssfile = AO_CCSS_DIR.strip_tags($_POST['critcssfile']);
139
+            if (file_exists($critcssfile)) {
140
+                $status = unlink($critcssfile);
141 141
                 $error  = false;
142 142
             }
143 143
         }
144 144
 
145 145
         // Prepare response.
146
-        if ( $error ) {
146
+        if ($error) {
147 147
             $response['code']   = '500';
148
-            $response['string'] = 'Error removing file ' . $critcssfile . '.';
148
+            $response['string'] = 'Error removing file '.$critcssfile.'.';
149 149
         } else {
150 150
             $response['code'] = '200';
151
-            if ( $status ) {
152
-                $response['string'] = 'File ' . $critcssfile . ' removed.';
151
+            if ($status) {
152
+                $response['string'] = 'File '.$critcssfile.' removed.';
153 153
             } else {
154 154
                 $response['string'] = 'No file to be removed.';
155 155
             }
156 156
         }
157 157
 
158 158
         // Dispatch respose.
159
-        echo json_encode( $response );
159
+        echo json_encode($response);
160 160
 
161 161
         // Close ajax request.
162 162
         wp_die();
@@ -165,28 +165,28 @@  discard block
 block discarded – undo
165 165
     public function critcss_rm_all_callback() {
166 166
         // Ajax handler to delete a critical CSS from the filesystem
167 167
         // Check referer.
168
-        check_ajax_referer( 'rm_critcss_all_nonce', 'critcss_rm_all_nonce' );
168
+        check_ajax_referer('rm_critcss_all_nonce', 'critcss_rm_all_nonce');
169 169
 
170 170
         // Initialize error and status flags.
171 171
         $error  = true;
172 172
         $status = false;
173 173
 
174 174
         // Remove all ccss files on filesystem.
175
-        if ( current_user_can( 'manage_options' ) ) {
176
-            if ( file_exists( AO_CCSS_DIR ) && is_dir( AO_CCSS_DIR ) ) {
177
-                array_map( 'unlink', glob( AO_CCSS_DIR . 'ccss_*.css', GLOB_BRACE ) );
175
+        if (current_user_can('manage_options')) {
176
+            if (file_exists(AO_CCSS_DIR) && is_dir(AO_CCSS_DIR)) {
177
+                array_map('unlink', glob(AO_CCSS_DIR.'ccss_*.css', GLOB_BRACE));
178 178
                 $error  = false;
179 179
                 $status = true;
180 180
             }
181 181
         }
182 182
 
183 183
         // Prepare response.
184
-        if ( $error ) {
184
+        if ($error) {
185 185
             $response['code']   = '500';
186 186
             $response['string'] = 'Error removing all critical CSS files.';
187 187
         } else {
188 188
             $response['code'] = '200';
189
-            if ( $status ) {
189
+            if ($status) {
190 190
                 $response['string'] = 'Critical CSS Files removed.';
191 191
             } else {
192 192
                 $response['string'] = 'No file removed.';
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Dispatch respose.
197
-        echo json_encode( $response );
197
+        echo json_encode($response);
198 198
 
199 199
         // Close ajax request.
200 200
         wp_die();
@@ -203,70 +203,70 @@  discard block
 block discarded – undo
203 203
     public function ao_ccss_export_callback() {
204 204
         // Ajax handler export settings
205 205
         // Check referer.
206
-        check_ajax_referer( 'ao_ccss_export_nonce', 'ao_ccss_export_nonce' );
206
+        check_ajax_referer('ao_ccss_export_nonce', 'ao_ccss_export_nonce');
207 207
 
208
-        if ( ! class_exists( 'ZipArchive' ) ) {
208
+        if (!class_exists('ZipArchive')) {
209 209
             $response['code'] = '500';
210 210
             $response['msg']  = 'PHP ZipArchive not present, cannot create zipfile';
211
-            echo json_encode( $response );
211
+            echo json_encode($response);
212 212
             wp_die();
213 213
         }
214 214
 
215 215
         // Init array, get options and prepare the raw object.
216 216
         $settings               = array();
217
-        $settings['rules']      = get_option( 'autoptimize_ccss_rules' );
218
-        $settings['additional'] = get_option( 'autoptimize_ccss_additional' );
219
-        $settings['viewport']   = get_option( 'autoptimize_ccss_viewport' );
220
-        $settings['finclude']   = get_option( 'autoptimize_ccss_finclude' );
221
-        $settings['rtimelimit'] = get_option( 'autoptimize_ccss_rtimelimit' );
222
-        $settings['noptimize']  = get_option( 'autoptimize_ccss_noptimize' );
223
-        $settings['debug']      = get_option( 'autoptimize_ccss_debug' );
224
-        $settings['key']        = get_option( 'autoptimize_ccss_key' );
217
+        $settings['rules']      = get_option('autoptimize_ccss_rules');
218
+        $settings['additional'] = get_option('autoptimize_ccss_additional');
219
+        $settings['viewport']   = get_option('autoptimize_ccss_viewport');
220
+        $settings['finclude']   = get_option('autoptimize_ccss_finclude');
221
+        $settings['rtimelimit'] = get_option('autoptimize_ccss_rtimelimit');
222
+        $settings['noptimize']  = get_option('autoptimize_ccss_noptimize');
223
+        $settings['debug']      = get_option('autoptimize_ccss_debug');
224
+        $settings['key']        = get_option('autoptimize_ccss_key');
225 225
 
226 226
         // Initialize error flag.
227 227
         $error = true;
228 228
 
229 229
         // Check user permissions.
230
-        if ( current_user_can( 'manage_options' ) ) {
230
+        if (current_user_can('manage_options')) {
231 231
             // Prepare settings file path and content.
232
-            $exportfile = AO_CCSS_DIR . 'settings.json';
233
-            $contents   = json_encode( $settings );
234
-            $status     = file_put_contents( $exportfile, $contents, LOCK_EX );
232
+            $exportfile = AO_CCSS_DIR.'settings.json';
233
+            $contents   = json_encode($settings);
234
+            $status     = file_put_contents($exportfile, $contents, LOCK_EX);
235 235
             $error      = false;
236 236
         }
237 237
 
238 238
         // Prepare archive.
239
-        $zipfile = AO_CCSS_DIR . date( 'Ymd-H\hi' ) . '_ao_ccss_settings.zip';
240
-        $file    = pathinfo( $zipfile, PATHINFO_BASENAME );
239
+        $zipfile = AO_CCSS_DIR.date('Ymd-H\hi').'_ao_ccss_settings.zip';
240
+        $file    = pathinfo($zipfile, PATHINFO_BASENAME);
241 241
         $zip     = new ZipArchive();
242
-        $ret     = $zip->open( $zipfile, ZipArchive::CREATE );
243
-        if ( true !== $ret ) {
242
+        $ret     = $zip->open($zipfile, ZipArchive::CREATE);
243
+        if (true !== $ret) {
244 244
             $error = true;
245 245
         } else {
246
-            $zip->addFile( AO_CCSS_DIR . 'settings.json', 'settings.json' );
247
-            if ( file_exists( AO_CCSS_DIR . 'queue.json' ) ) {
248
-                $zip->addFile( AO_CCSS_DIR . 'queue.json', 'queue.json' );
246
+            $zip->addFile(AO_CCSS_DIR.'settings.json', 'settings.json');
247
+            if (file_exists(AO_CCSS_DIR.'queue.json')) {
248
+                $zip->addFile(AO_CCSS_DIR.'queue.json', 'queue.json');
249 249
             }
250 250
             $options = array(
251 251
                 'add_path'        => './',
252 252
                 'remove_all_path' => true,
253 253
             );
254
-            $zip->addGlob( AO_CCSS_DIR . '*.css', 0, $options );
254
+            $zip->addGlob(AO_CCSS_DIR.'*.css', 0, $options);
255 255
             $zip->close();
256 256
         }
257 257
 
258 258
         // Prepare response.
259
-        if ( ! $status || $error ) {
259
+        if (!$status || $error) {
260 260
             $response['code'] = '500';
261
-            $response['msg']  = 'Error saving file ' . $file . ', code: ' . $ret;
261
+            $response['msg']  = 'Error saving file '.$file.', code: '.$ret;
262 262
         } else {
263 263
             $response['code'] = '200';
264
-            $response['msg']  = 'File ' . $file . ' saved.';
264
+            $response['msg']  = 'File '.$file.' saved.';
265 265
             $response['file'] = $file;
266 266
         }
267 267
 
268 268
         // Dispatch respose.
269
-        echo json_encode( $response );
269
+        echo json_encode($response);
270 270
 
271 271
         // Close ajax request.
272 272
         wp_die();
@@ -275,30 +275,30 @@  discard block
 block discarded – undo
275 275
     public function ao_ccss_import_callback() {
276 276
         // Ajax handler import settings
277 277
         // Check referer.
278
-        check_ajax_referer( 'ao_ccss_import_nonce', 'ao_ccss_import_nonce' );
278
+        check_ajax_referer('ao_ccss_import_nonce', 'ao_ccss_import_nonce');
279 279
 
280 280
         // Initialize error flag.
281 281
         $error = false;
282 282
 
283 283
         // Process an uploaded file with no errors.
284
-        if ( current_user_can( 'manage_options' ) && ! $_FILES['file']['error'] && $_FILES['file']['size'] < 500001 && strpos( $_FILES['file']['name'], '.zip' ) === strlen( $_FILES['file']['name'] ) - 4 ) {
284
+        if (current_user_can('manage_options') && !$_FILES['file']['error'] && $_FILES['file']['size'] < 500001 && strpos($_FILES['file']['name'], '.zip') === strlen($_FILES['file']['name']) - 4) {
285 285
             // create tmp dir with hard guess name in AO_CCSS_DIR.
286
-            $_secret_dir     = wp_hash( uniqid( md5( AUTOPTIMIZE_CACHE_URL ), true ) );
287
-            $_import_tmp_dir = trailingslashit( AO_CCSS_DIR . $_secret_dir );
288
-            mkdir( $_import_tmp_dir );
286
+            $_secret_dir     = wp_hash(uniqid(md5(AUTOPTIMIZE_CACHE_URL), true));
287
+            $_import_tmp_dir = trailingslashit(AO_CCSS_DIR.$_secret_dir);
288
+            mkdir($_import_tmp_dir);
289 289
 
290 290
             // Save file to that tmp directory but give it our own name to prevent directory traversal risks when using original name.
291
-            $zipfile = $_import_tmp_dir . uniqid( 'import_settings-', true ) . '.zip';
292
-            move_uploaded_file( $_FILES['file']['tmp_name'], $zipfile );
291
+            $zipfile = $_import_tmp_dir.uniqid('import_settings-', true).'.zip';
292
+            move_uploaded_file($_FILES['file']['tmp_name'], $zipfile);
293 293
 
294 294
             // Extract archive in the tmp directory.
295 295
             $zip = new ZipArchive;
296
-            if ( $zip->open( $zipfile ) === true ) {
296
+            if ($zip->open($zipfile) === true) {
297 297
                 // loop through all files in the zipfile.
298 298
                 for ($i = 0; $i < $zip->numFiles; $i++) {
299 299
                     // but only extract known good files.
300
-                    if ( preg_match('/^settings\.json$|^ccss_[a-z0-9]{32}\.css$/', $zip->getNameIndex( $i ) ) > 0 ) {
301
-                        $zip->extractTo( AO_CCSS_DIR, $zip->getNameIndex( $i ) );
300
+                    if (preg_match('/^settings\.json$|^ccss_[a-z0-9]{32}\.css$/', $zip->getNameIndex($i)) > 0) {
301
+                        $zip->extractTo(AO_CCSS_DIR, $zip->getNameIndex($i));
302 302
                     }
303 303
                 }
304 304
                 $zip->close();
@@ -307,26 +307,26 @@  discard block
 block discarded – undo
307 307
             }
308 308
             
309 309
             // and remove temp. dir with all contents (the import-zipfile).
310
-            $this->rrmdir( $_import_tmp_dir );
310
+            $this->rrmdir($_import_tmp_dir);
311 311
 
312
-            if ( ! $error ) {
312
+            if (!$error) {
313 313
                 // Archive extraction ok, continue importing settings from AO_CCSS_DIR.
314 314
                 // Settings file.
315
-                $importfile = AO_CCSS_DIR . 'settings.json';
315
+                $importfile = AO_CCSS_DIR.'settings.json';
316 316
 
317
-                if ( file_exists( $importfile ) ) {
317
+                if (file_exists($importfile)) {
318 318
                     // Get settings and turn them into an object.
319
-                    $settings = json_decode( file_get_contents( $importfile ), true );
319
+                    $settings = json_decode(file_get_contents($importfile), true);
320 320
 
321 321
                     // Update options.
322
-                    update_option( 'autoptimize_ccss_rules', $settings['rules'] );
323
-                    update_option( 'autoptimize_ccss_additional', $settings['additional'] );
324
-                    update_option( 'autoptimize_ccss_viewport', $settings['viewport'] );
325
-                    update_option( 'autoptimize_ccss_finclude', $settings['finclude'] );
326
-                    update_option( 'autoptimize_ccss_rtimelimit', $settings['rtimelimit'] );
327
-                    update_option( 'autoptimize_ccss_noptimize', $settings['noptimize'] );
328
-                    update_option( 'autoptimize_ccss_debug', $settings['debug'] );
329
-                    update_option( 'autoptimize_ccss_key', $settings['key'] );
322
+                    update_option('autoptimize_ccss_rules', $settings['rules']);
323
+                    update_option('autoptimize_ccss_additional', $settings['additional']);
324
+                    update_option('autoptimize_ccss_viewport', $settings['viewport']);
325
+                    update_option('autoptimize_ccss_finclude', $settings['finclude']);
326
+                    update_option('autoptimize_ccss_rtimelimit', $settings['rtimelimit']);
327
+                    update_option('autoptimize_ccss_noptimize', $settings['noptimize']);
328
+                    update_option('autoptimize_ccss_debug', $settings['debug']);
329
+                    update_option('autoptimize_ccss_key', $settings['key']);
330 330
                 } else {
331 331
                     // Settings file doesn't exist, update error flag.
332 332
                     $error = 'settings file does not exist';
@@ -337,28 +337,28 @@  discard block
 block discarded – undo
337 337
         }
338 338
 
339 339
         // Prepare response.
340
-        if ( $error ) {
340
+        if ($error) {
341 341
             $response['code'] = '500';
342
-            $response['msg']  = 'Error importing settings: ' . $error;
342
+            $response['msg']  = 'Error importing settings: '.$error;
343 343
         } else {
344 344
             $response['code'] = '200';
345 345
             $response['msg']  = 'Settings imported successfully';
346 346
         }
347 347
 
348 348
         // Dispatch respose.
349
-        echo json_encode( $response );
349
+        echo json_encode($response);
350 350
 
351 351
         // Close ajax request.
352 352
         wp_die();
353 353
     }
354 354
 
355
-    public function critcss_check_filename( $filename ) {
355
+    public function critcss_check_filename($filename) {
356 356
         // Try to avoid directory traversal when reading/writing/deleting critical CSS files.
357
-        if ( strpos( $filename, 'ccss_' ) !== 0 ) {
357
+        if (strpos($filename, 'ccss_') !== 0) {
358 358
             return false;
359
-        } elseif ( substr( $filename, -4, 4 ) !== '.css' ) {
359
+        } elseif (substr($filename, -4, 4) !== '.css') {
360 360
             return false;
361
-        } elseif ( sanitize_file_name( $filename ) !== $filename ) {
361
+        } elseif (sanitize_file_name($filename) !== $filename) {
362 362
             // Use WordPress core's sanitize_file_name to see if anything fishy is going on.
363 363
             return false;
364 364
         } else {
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
         }
367 367
     }
368 368
     
369
-    public function rrmdir( $path ) {
369
+    public function rrmdir($path) {
370 370
         // recursively remove a directory as found on
371 371
         // https://andy-carter.com/blog/recursively-remove-a-directory-in-php.
372
-        $files = glob($path . '/*');
373
-        foreach ( $files as $file ) {
374
-            is_dir( $file ) ? $this->rrmdir( $file ) : unlink( $file );
372
+        $files = glob($path.'/*');
373
+        foreach ($files as $file) {
374
+            is_dir($file) ? $this->rrmdir($file) : unlink($file);
375 375
         }
376
-        rmdir( $path );
376
+        rmdir($path);
377 377
 
378 378
         return;
379 379
     }
Please login to merge, or discard this patch.
classes/autoptimizeImages.php 2 patches
Doc Comments   +10 added lines, -1 removed lines patch added patch discarded remove patch
@@ -382,6 +382,9 @@  discard block
 block discarded – undo
382 382
         }
383 383
     }
384 384
 
385
+    /**
386
+     * @return string
387
+     */
385 388
     private function get_imgopt_base_url()
386 389
     {
387 390
         static $imgopt_base_url = null;
@@ -873,6 +876,9 @@  discard block
 block discarded – undo
873 876
         }
874 877
     }
875 878
 
879
+    /**
880
+     * @return string
881
+     */
876 882
     public function get_cdn_url() {
877 883
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
878 884
         static $cdn_url = null;
@@ -976,6 +982,9 @@  discard block
 block discarded – undo
976 982
         return $out;
977 983
     }
978 984
 
985
+    /**
986
+     * @return string
987
+     */
979 988
     public function process_bgimage( $in ) {
980 989
         if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
981 990
             $out = preg_replace_callback(
@@ -1345,7 +1354,7 @@  discard block
 block discarded – undo
1345 1354
     /**
1346 1355
      * Determines and returns the service launch status.
1347 1356
      *
1348
-     * @return bool
1357
+     * @return null|boolean
1349 1358
      */
1350 1359
     public function launch_ok()
1351 1360
     {
Please login to merge, or discard this patch.
Spacing   +369 added lines, -369 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/SPZURYE109483/' . AUTOPTIMIZE_SITE_DOMAIN;
234
+        $suffix = '/af/SPZURYE109483/'.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,47 +336,47 @@  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
-            $result = $this->fix_silly_bgimg_quotes( $result );
349
+            $result = $this->fix_silly_bgimg_quotes($result);
350 350
 
351
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
352
-                $result = $parsed_site_url['scheme'] . ':' . $result;
353
-            } elseif ( 0 === strpos( $result, '/' ) ) {
351
+            if (autoptimizeUtils::is_protocol_relative($result)) {
352
+                $result = $parsed_site_url['scheme'].':'.$result;
353
+            } elseif (0 === strpos($result, '/')) {
354 354
                 // Root-relative...
355
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
356
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
357
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
355
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
356
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
357
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
358 358
             }
359 359
 
360 360
             // filter (default off) to remove QS from image URL's to avoid eating away optimization credits.
361
-            if ( apply_filters( 'autoptimize_filter_imgopt_no_querystring', false ) && strpos( $result, '?' ) !== false ) {
362
-                $result = strtok( $result, '?' );
361
+            if (apply_filters('autoptimize_filter_imgopt_no_querystring', false) && strpos($result, '?') !== false) {
362
+                $result = strtok($result, '?');
363 363
             }
364 364
 
365
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
365
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
366 366
 
367 367
             // Store in cache.
368
-            $cache[ $in ] = $result;
368
+            $cache[$in] = $result;
369 369
         }
370 370
 
371
-        return $cache[ $in ];
371
+        return $cache[$in];
372 372
     }
373 373
 
374
-    public function filter_optimize_css_images( $in )
374
+    public function filter_optimize_css_images($in)
375 375
     {
376
-        $in = $this->normalize_img_url( $in );
376
+        $in = $this->normalize_img_url($in);
377 377
 
378
-        if ( $this->can_optimize_image( $in ) ) {
379
-            return $this->build_imgopt_url( $in, '', '' );
378
+        if ($this->can_optimize_image($in)) {
379
+            return $this->build_imgopt_url($in, '', '');
380 380
         } else {
381 381
             return $in;
382 382
         }
@@ -386,53 +386,53 @@  discard block
 block discarded – undo
386 386
     {
387 387
         static $imgopt_base_url = null;
388 388
 
389
-        if ( null === $imgopt_base_url ) {
389
+        if (null === $imgopt_base_url) {
390 390
             $imgopt_host     = $this->get_imgopt_host();
391 391
             $quality         = $this->get_img_quality_string();
392
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
393
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
394
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
392
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
393
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
394
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
395 395
         }
396 396
 
397 397
         return $imgopt_base_url;
398 398
     }
399 399
 
400
-    private function can_optimize_image( $url, $tag = '', $testing = false )
400
+    private function can_optimize_image($url, $tag = '', $testing = false)
401 401
     {
402 402
         static $cdn_url      = null;
403 403
         static $nopti_images = null;
404 404
 
405
-        if ( null === $cdn_url ) {
405
+        if (null === $cdn_url) {
406 406
             $cdn_url = apply_filters(
407 407
                 'autoptimize_filter_base_cdnurl',
408
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
408
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
409 409
             );
410 410
         }
411 411
 
412
-        if ( null === $nopti_images || $testing ) {
413
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_text_field_6', $this->options ) ) {
412
+        if (null === $nopti_images || $testing) {
413
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_text_field_6', $this->options)) {
414 414
                 $nopti_images = $this->options['autoptimize_imgopt_text_field_6'];
415 415
             }
416
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', $nopti_images );
416
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', $nopti_images);
417 417
         }
418 418
 
419 419
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
420
-        $url        = $this->normalize_img_url( $url );
421
-        $url_parsed = parse_url( $url );
420
+        $url        = $this->normalize_img_url($url);
421
+        $url_parsed = parse_url($url);
422 422
 
423
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
423
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
424 424
             return false;
425
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
425
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
426 426
             return false;
427
-        } elseif ( strpos( $url, '.php' ) !== false ) {
427
+        } elseif (strpos($url, '.php') !== false) {
428 428
             return false;
429
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
429
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif'), '', $url_parsed['path']) === $url_parsed['path']) {
430 430
             // fixme: better check against end of string.
431 431
             return false;
432
-        } elseif ( ! empty( $nopti_images ) ) {
433
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
434
-            foreach ( $nopti_images_array as $nopti_image ) {
435
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
432
+        } elseif (!empty($nopti_images)) {
433
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
434
+            foreach ($nopti_images_array as $nopti_image) {
435
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
436 436
                     return false;
437 437
                 }
438 438
             }
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
         return true;
441 441
     }
442 442
 
443
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
443
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
444 444
     {
445 445
         // sanitize width and height.
446
-        if ( strpos( $width, '%' ) !== false ) {
446
+        if (strpos($width, '%') !== false) {
447 447
             $width = 0;
448 448
         }
449
-        if ( strpos( $height, '%' ) !== false ) {
449
+        if (strpos($height, '%') !== false) {
450 450
             $height = 0;
451 451
         }
452 452
         $width  = (int) $width;
@@ -460,52 +460,52 @@  discard block
 block discarded – undo
460 460
         );
461 461
 
462 462
         // If filter modified the url, return that.
463
-        if ( $filtered_url !== $orig_url ) {
463
+        if ($filtered_url !== $orig_url) {
464 464
             return $filtered_url;
465 465
         }
466 466
 
467
-        $normalized_url = $this->normalize_img_url( $orig_url );
467
+        $normalized_url = $this->normalize_img_url($orig_url);
468 468
 
469 469
         // if the URL is ascii we check if we have a real URL with filter_var (which only works on ascii url's) and if not a real URL we return the original one.
470
-        if ( apply_filters( 'autoptimize_filter_imgopt_check_normalized_url', true ) && ! preg_match( '/[^\x20-\x7e]/', $normalized_url ) && false === filter_var( $normalized_url, FILTER_VALIDATE_URL ) ) {
470
+        if (apply_filters('autoptimize_filter_imgopt_check_normalized_url', true) && !preg_match('/[^\x20-\x7e]/', $normalized_url) && false === filter_var($normalized_url, FILTER_VALIDATE_URL)) {
471 471
             return $orig_url;
472 472
         }
473 473
 
474 474
         $imgopt_base_url = $this->get_imgopt_base_url();
475 475
         $imgopt_size     = '';
476 476
 
477
-        if ( $width && 0 !== $width ) {
478
-            $imgopt_size = ',w_' . $width;
477
+        if ($width && 0 !== $width) {
478
+            $imgopt_size = ',w_'.$width;
479 479
         }
480 480
 
481
-        if ( $height && 0 !== $height ) {
482
-            $imgopt_size .= ',h_' . $height;
481
+        if ($height && 0 !== $height) {
482
+            $imgopt_size .= ',h_'.$height;
483 483
         }
484 484
 
485
-        $url = $imgopt_base_url . $imgopt_size . '/' . $normalized_url;
485
+        $url = $imgopt_base_url.$imgopt_size.'/'.$normalized_url;
486 486
 
487 487
         return $url;
488 488
     }
489 489
 
490
-    public function replace_data_thumbs( $matches )
490
+    public function replace_data_thumbs($matches)
491 491
     {
492
-        return $this->replace_img_callback( $matches, 150, 150 );
492
+        return $this->replace_img_callback($matches, 150, 150);
493 493
     }
494 494
 
495
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
495
+    public function replace_img_callback($matches, $width = 0, $height = 0)
496 496
     {
497
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
498
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
499
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
497
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
498
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
499
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
500 500
         } else {
501 501
             return $matches[0];
502 502
         }
503 503
     }
504 504
 
505
-    public function replace_icon_callback( $matches )
505
+    public function replace_icon_callback($matches)
506 506
     {
507
-        if ( array_key_exists( '2', $matches ) ) {
508
-            $sizes  = explode( 'x', $matches[2] );
507
+        if (array_key_exists('2', $matches)) {
508
+            $sizes  = explode('x', $matches[2]);
509 509
             $width  = $sizes[0];
510 510
             $height = $sizes[1];
511 511
         } else {
@@ -514,14 +514,14 @@  discard block
 block discarded – undo
514 514
         }
515 515
 
516 516
         // make sure we're not trying to optimize a *.ico file
517
-        if ( strpos( $matches[1], '.ico' ) === false ) {
518
-            return $this->replace_img_callback( $matches, $width, $height );
517
+        if (strpos($matches[1], '.ico') === false) {
518
+            return $this->replace_img_callback($matches, $width, $height);
519 519
         } else {
520 520
             return $matches[0];
521 521
         }
522 522
     }
523 523
 
524
-    public function filter_optimize_images( $in, $testing = false )
524
+    public function filter_optimize_images($in, $testing = false)
525 525
     {
526 526
         /*
527 527
          * potential future functional improvements:
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         $to_replace = array();
532 532
 
533 533
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
534
-        if ( $this->should_lazyload() ) {
534
+        if ($this->should_lazyload()) {
535 535
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
536 536
                 'SCRIPT',
537 537
                 '<script',
@@ -541,165 +541,165 @@  discard block
 block discarded – undo
541 541
         }
542 542
 
543 543
         // extract img tags.
544
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
545
-            foreach ( $matches[0] as $tag ) {
546
-                $tag = apply_filters( 'autoptimize_filter_imgopt_tag_preopt' , $tag );
544
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
545
+            foreach ($matches[0] as $tag) {
546
+                $tag = apply_filters('autoptimize_filter_imgopt_tag_preopt', $tag);
547 547
 
548 548
                 $orig_tag = $tag;
549 549
                 $imgopt_w = '';
550 550
                 $imgopt_h = '';
551 551
 
552 552
                 // first do (data-)srcsets.
553
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
554
-                    foreach ( $allsrcsets as $srcset ) {
553
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
554
+                    foreach ($allsrcsets as $srcset) {
555 555
                         $srcset      = $srcset[2];
556 556
                         $orig_srcset = $srcset;
557
-                        $srcsets     = explode( ',', $srcset );
558
-                        foreach ( $srcsets as $indiv_srcset ) {
559
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
560
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
561
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
557
+                        $srcsets     = explode(',', $srcset);
558
+                        foreach ($srcsets as $indiv_srcset) {
559
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
560
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
561
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
562 562
                             }
563
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag, $testing ) ) {
564
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
565
-                                $srcset     = str_replace( $indiv_srcset_parts[0], $imgopt_url, $srcset );
563
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag, $testing)) {
564
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
565
+                                $srcset     = str_replace($indiv_srcset_parts[0], $imgopt_url, $srcset);
566 566
                             }
567 567
                         }
568
-                        $tag = str_replace( $orig_srcset, $srcset, $tag );
568
+                        $tag = str_replace($orig_srcset, $srcset, $tag);
569 569
                     }
570 570
                 }
571 571
 
572 572
                 // proceed with img src.
573 573
                 // get width and height and add to $imgopt_size.
574
-                $_get_size = $this->get_size_from_tag( $tag );
574
+                $_get_size = $this->get_size_from_tag($tag);
575 575
                 $imgopt_w  = $_get_size['width'];
576 576
                 $imgopt_h  = $_get_size['height'];
577 577
 
578 578
                 // then start replacing images src.
579
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
580
-                    foreach ( $urls as $url ) {
579
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
580
+                    foreach ($urls as $url) {
581 581
                         $full_src_orig = $url[0];
582 582
                         $url           = $url[1];
583
-                        if ( $this->can_optimize_image( $url, $tag, $testing ) ) {
584
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
585
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
586
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
583
+                        if ($this->can_optimize_image($url, $tag, $testing)) {
584
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
585
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
586
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
587 587
                         }
588 588
                     }
589 589
                 }
590 590
 
591 591
                 // do lazyload stuff.
592
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
592
+                if ($this->should_lazyload($in) && !empty($url)) {
593 593
                     // first do lpiq placeholder logic.
594
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
594
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
595 595
                         // if all img src have been replaced during srcset, we have to extract the
596 596
                         // origin url from the imgopt one to be able to set a lqip placeholder.
597
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
597
+                        $_url = substr($url, strpos($url, '/http') + 1);
598 598
                     } else {
599 599
                         $_url = $url;
600 600
                     }
601 601
 
602
-                    $_url = $this->normalize_img_url( $_url );
602
+                    $_url = $this->normalize_img_url($_url);
603 603
 
604 604
                     $placeholder = '';
605
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true, $_url ) ) {
605
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true, $_url)) {
606 606
                         $lqip_w = '';
607 607
                         $lqip_h = '';
608
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
609
-                            $lqip_w = ',w_' . $imgopt_w;
608
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
609
+                            $lqip_w = ',w_'.$imgopt_w;
610 610
                         }
611
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
612
-                            $lqip_h = ',h_' . $imgopt_h;
611
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
612
+                            $lqip_h = ',h_'.$imgopt_h;
613 613
                         }
614
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
614
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
615 615
                     }
616 616
                     // then call add_lazyload-function with lpiq placeholder if set.
617
-                    $tag = $this->add_lazyload( $tag, $placeholder );
617
+                    $tag = $this->add_lazyload($tag, $placeholder);
618 618
                 }
619 619
 
620
-                $tag = apply_filters( 'autoptimize_filter_imgopt_tag_postopt' , $tag );
620
+                $tag = apply_filters('autoptimize_filter_imgopt_tag_postopt', $tag);
621 621
 
622 622
                 // and add tag to array for later replacement.
623
-                if ( $tag !== $orig_tag ) {
624
-                    $to_replace[ $orig_tag ] = $tag;
623
+                if ($tag !== $orig_tag) {
624
+                    $to_replace[$orig_tag] = $tag;
625 625
                 }
626 626
             }
627 627
         }
628 628
 
629 629
         // and replace all.
630
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
630
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
631 631
 
632 632
         // img thumbnails in e.g. woocommerce.
633
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
633
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
634 634
             $out = preg_replace_callback(
635 635
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
636
-                array( $this, 'replace_data_thumbs' ),
636
+                array($this, 'replace_data_thumbs'),
637 637
                 $out
638 638
             );
639 639
         }
640 640
 
641 641
         // background-image in inline style.
642
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
642
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
643 643
             $out = preg_replace_callback(
644 644
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
645
-                array( $this, 'replace_img_callback' ),
645
+                array($this, 'replace_img_callback'),
646 646
                 $out
647 647
             );
648 648
         }
649 649
 
650 650
         // act on icon links.
651
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
651
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
652 652
             $out = preg_replace_callback(
653 653
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
654
-                array( $this, 'replace_icon_callback' ),
654
+                array($this, 'replace_icon_callback'),
655 655
                 $out
656 656
             );
657 657
         }
658 658
 
659 659
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
660
-        if ( $this->should_lazyload() ) {
660
+        if ($this->should_lazyload()) {
661 661
             $out = autoptimizeBase::restore_marked_content(
662 662
                 'SCRIPT',
663 663
                 $out
664 664
             );
665 665
 
666
-            $out = $this->process_picture_tag( $out, true, true );
667
-            $out = $this->process_bgimage( $out );
666
+            $out = $this->process_picture_tag($out, true, true);
667
+            $out = $this->process_bgimage($out);
668 668
         } else {
669
-            $out = $this->process_picture_tag( $out, true, false );
669
+            $out = $this->process_picture_tag($out, true, false);
670 670
         }
671 671
 
672 672
         return $out;
673 673
     }
674 674
 
675
-    public function get_size_from_tag( $tag ) {
675
+    public function get_size_from_tag($tag) {
676 676
         // reusable function to extract widht and height from an image tag
677 677
         // enforcing a filterable maximum width and height (default 4999X4999).
678 678
         $width  = '';
679 679
         $height = '';
680 680
 
681
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
682
-            if ( strpos( $_width[2], '%' ) === false ) {
681
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
682
+            if (strpos($_width[2], '%') === false) {
683 683
                 $width = (int) $_width[2];
684 684
             }
685 685
         }
686
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
687
-            if ( strpos( $_height[2], '%' ) === false ) {
686
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
687
+            if (strpos($_height[2], '%') === false) {
688 688
                 $height = (int) $_height[2];
689 689
             }
690 690
         }
691 691
 
692 692
         // check for and enforce (filterable) max sizes.
693
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
694
-        if ( $width > $_max_width ) {
693
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
694
+        if ($width > $_max_width) {
695 695
             $_width = $_max_width;
696
-            $height = $_width / $width * $height;
696
+            $height = $_width/$width*$height;
697 697
             $width  = $_width;
698 698
         }
699
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
700
-        if ( $height > $_max_height ) {
699
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
700
+        if ($height > $_max_height) {
701 701
             $_height = $_max_height;
702
-            $width   = $_height / $height * $width;
702
+            $width   = $_height/$height*$width;
703 703
             $height  = $_height;
704 704
         }
705 705
 
@@ -718,26 +718,26 @@  discard block
 block discarded – undo
718 718
         return $self->should_lazyload();
719 719
     }
720 720
 
721
-    public function should_lazyload( $context = '' ) {
722
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
721
+    public function should_lazyload($context = '') {
722
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
723 723
             $lazyload_return = true;
724 724
         } else {
725 725
             $lazyload_return = false;
726 726
         }
727
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
727
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
728 728
 
729 729
         return $lazyload_return;
730 730
     }
731 731
 
732 732
     public function check_nolazy() {
733
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
733
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
734 734
             return true;
735 735
         } else {
736 736
             return false;
737 737
         }
738 738
     }
739 739
 
740
-    public function filter_lazyload_images( $in )
740
+    public function filter_lazyload_images($in)
741 741
     {
742 742
         // only used is image optimization is NOT active but lazyload is.
743 743
         $to_replace = array();
@@ -751,20 +751,20 @@  discard block
 block discarded – undo
751 751
         );
752 752
 
753 753
         // extract img tags and add lazyload attribs.
754
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
755
-            foreach ( $matches[0] as $tag ) {
756
-                if ( $this->should_lazyload( $out ) ) {
757
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
754
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
755
+            foreach ($matches[0] as $tag) {
756
+                if ($this->should_lazyload($out)) {
757
+                    $to_replace[$tag] = $this->add_lazyload($tag);
758 758
                 }
759 759
             }
760
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
760
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
761 761
         }
762 762
 
763 763
         // and also lazyload picture tag.
764
-        $out = $this->process_picture_tag( $out, false, true );
764
+        $out = $this->process_picture_tag($out, false, true);
765 765
 
766 766
         // and inline style blocks with background-image.
767
-        $out = $this->process_bgimage( $out );
767
+        $out = $this->process_bgimage($out);
768 768
 
769 769
         // restore noscript tags.
770 770
         $out = autoptimizeBase::restore_marked_content(
@@ -775,92 +775,92 @@  discard block
 block discarded – undo
775 775
         return $out;
776 776
     }
777 777
 
778
-    public function add_lazyload( $tag, $placeholder = '' ) {
778
+    public function add_lazyload($tag, $placeholder = '') {
779 779
         // adds actual lazyload-attributes to an image node.
780 780
         $this->lazyload_counter++;
781 781
 
782 782
         $_lazyload_from_nth = '';
783
-        if ( array_key_exists( 'autoptimize_imgopt_number_field_7', $this->options ) ) {
783
+        if (array_key_exists('autoptimize_imgopt_number_field_7', $this->options)) {
784 784
             $_lazyload_from_nth = $this->options['autoptimize_imgopt_number_field_7'];
785 785
         }
786
-        $_lazyload_from_nth = apply_filters( 'autoptimize_filter_imgopt_lazyload_from_nth', $_lazyload_from_nth );
786
+        $_lazyload_from_nth = apply_filters('autoptimize_filter_imgopt_lazyload_from_nth', $_lazyload_from_nth);
787 787
 
788
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag && $this->lazyload_counter >= $_lazyload_from_nth ) {
789
-            $tag = $this->maybe_fix_missing_quotes( $tag );
788
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag && $this->lazyload_counter >= $_lazyload_from_nth) {
789
+            $tag = $this->maybe_fix_missing_quotes($tag);
790 790
 
791 791
             // store original tag for use in noscript version.
792
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
792
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
793 793
 
794
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
794
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
795 795
 
796 796
             // insert lazyload class.
797
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
797
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
798 798
 
799
-            if ( ! $placeholder || empty( $placeholder ) ) {
799
+            if (!$placeholder || empty($placeholder)) {
800 800
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
801
-                $_get_size = $this->get_size_from_tag( $tag );
801
+                $_get_size = $this->get_size_from_tag($tag);
802 802
                 $width     = $_get_size['width'];
803 803
                 $height    = $_get_size['height'];
804
-                if ( false === $width || empty( $width ) ) {
804
+                if (false === $width || empty($width)) {
805 805
                     $width = 210; // default width for SVG placeholder.
806 806
                 }
807
-                if ( false === $height || empty( $height ) ) {
808
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
807
+                if (false === $height || empty($height)) {
808
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
809 809
                 }
810 810
 
811 811
                 // insert the actual lazyload stuff.
812 812
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
813
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
813
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
814 814
             }
815 815
 
816
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
817
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
816
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
817
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
818 818
 
819 819
             // move sizes to data-sizes unless filter says no.
820
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
821
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
820
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
821
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
822 822
             }
823 823
 
824 824
             // add the noscript-tag from earlier.
825
-            $tag = $noscript_tag . $tag;
826
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
825
+            $tag = $noscript_tag.$tag;
826
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
827 827
         }
828 828
 
829 829
         return $tag;
830 830
     }
831 831
 
832 832
     public function add_lazyload_js_footer() {
833
-        if ( false === autoptimizeMain::should_buffer() ) {
833
+        if (false === autoptimizeMain::should_buffer()) {
834 834
             return;
835 835
         }
836 836
 
837 837
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
838 838
         $noptimize_flag = '';
839
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
839
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
840 840
             $noptimize_flag = ' data-noptimize="1"';
841 841
         }
842 842
 
843
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
843
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
844 844
         $cdn_url      = $this->get_cdn_url();
845
-        if ( ! empty( $cdn_url ) ) {
846
-            $cdn_url      = rtrim( $cdn_url, '/' );
847
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
845
+        if (!empty($cdn_url)) {
846
+            $cdn_url      = rtrim($cdn_url, '/');
847
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
848 848
         }
849 849
 
850 850
         $type_js = '';
851
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
851
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
852 852
             $type_js = ' type="text/javascript"';
853 853
         }
854 854
 
855 855
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
856
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
857
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
858
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
856
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
857
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
858
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
859 859
 
860 860
         // And add webp detection and loading JS.
861
-        if ( $this->should_ngimg() ) {
861
+        if ($this->should_ngimg()) {
862 862
             // Add AVIF code, can be disabled for now to only do webp.
863
-            if ( apply_filters( 'autoptimize_filter_imgopt_do_avif', true ) ) {
863
+            if (apply_filters('autoptimize_filter_imgopt_do_avif', true)) {
864 864
                 $_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");';
865 865
                 $_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+","))})});';
866 866
             } else {
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
                 $_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,'))})});";
869 869
             }
870 870
             // Keeping autoptimize_filter_imgopt_webp_js filter for now, but it is deprecated as not only for webp any more.
871
-            $_ngimg_output = apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_ngimg_detect . $_ngimg_load . '</script>' );
872
-            echo apply_filters( 'autoptimize_filter_imgopt_ngimg_js', $_ngimg_output );
871
+            $_ngimg_output = apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_ngimg_detect.$_ngimg_load.'</script>');
872
+            echo apply_filters('autoptimize_filter_imgopt_ngimg_js', $_ngimg_output);
873 873
         }
874 874
     }
875 875
 
@@ -877,10 +877,10 @@  discard block
 block discarded – undo
877 877
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
878 878
         static $cdn_url = null;
879 879
 
880
-        if ( null === $cdn_url ) {
881
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
882
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
883
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
880
+        if (null === $cdn_url) {
881
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
882
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
883
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
884 884
         }
885 885
 
886 886
         return $cdn_url;
@@ -890,47 +890,47 @@  discard block
 block discarded – undo
890 890
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
891 891
         static $exclude_lazyload_array = null;
892 892
 
893
-        if ( null === $exclude_lazyload_array ) {
893
+        if (null === $exclude_lazyload_array) {
894 894
             $options = $this->options;
895 895
 
896 896
             // set default exclusions.
897
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
897
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
898 898
 
899 899
             // add from setting.
900
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
900
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
901 901
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
902
-                if ( ! empty( $exclude_lazyload_option ) ) {
903
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
902
+                if (!empty($exclude_lazyload_option)) {
903
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
904 904
                 }
905 905
             }
906 906
 
907 907
             // and filter for developer-initiated changes.
908
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
908
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
909 909
         }
910 910
 
911 911
         return $exclude_lazyload_array;
912 912
     }
913 913
 
914
-    public function inject_classes_in_tag( $tag, $target_class ) {
915
-        if ( strpos( $tag, 'class=' ) !== false ) {
916
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
914
+    public function inject_classes_in_tag($tag, $target_class) {
915
+        if (strpos($tag, 'class=') !== false) {
916
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
917 917
         } else {
918
-            $tag = preg_replace( '/(<[a-zA-Z]*)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
918
+            $tag = preg_replace('/(<[a-zA-Z]*)\s/', '$1 class="'.trim($target_class).'" ', $tag);
919 919
         }
920 920
 
921 921
         return $tag;
922 922
     }
923 923
 
924
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
925
-        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';
924
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
925
+        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';
926 926
     }
927 927
 
928 928
     public function should_ngimg() {
929 929
         static $ngimg_return = null;
930 930
 
931
-        if ( is_null( $ngimg_return ) ) {
931
+        if (is_null($ngimg_return)) {
932 932
             // webp only works if imgopt and lazyload are also active.
933
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
933
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
934 934
                 $ngimg_return = true;
935 935
             } else {
936 936
                 $ngimg_return = false;
@@ -940,9 +940,9 @@  discard block
 block discarded – undo
940 940
         return $ngimg_return;
941 941
     }
942 942
 
943
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
943
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
944 944
         // check if "<picture" is present and if filter allows us to process <picture>.
945
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
945
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
946 946
             return $in;
947 947
         }
948 948
 
@@ -950,37 +950,37 @@  discard block
 block discarded – undo
950 950
         $to_replace_pict = array();
951 951
 
952 952
         // extract and process each picture-node.
953
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
954
-        foreach ( $_pictures as $_picture ) {
955
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
956
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
957
-                foreach ( $_sources as $_source ) {
953
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
954
+        foreach ($_pictures as $_picture) {
955
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
956
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
957
+                foreach ($_sources as $_source) {
958 958
                     $_picture_replacement = $_source[0];
959 959
 
960 960
                     // should we optimize the image?
961
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
962
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
961
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
962
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
963 963
                     }
964 964
                     // should we lazy-load?
965
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
966
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
965
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
966
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
967 967
                     }
968
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
968
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
969 969
                 }
970 970
             }
971 971
         }
972 972
 
973 973
         // and return the fully procesed $in.
974
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
974
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
975 975
 
976 976
         return $out;
977 977
     }
978 978
 
979
-    public function process_bgimage( $in ) {
980
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
979
+    public function process_bgimage($in) {
980
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
981 981
             $out = preg_replace_callback(
982 982
                 '/(<(?:article|aside|body|div|footer|header|p|section|span|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
983
-                array( $this, 'lazyload_bgimg_callback' ),
983
+                array($this, 'lazyload_bgimg_callback'),
984 984
                 $in
985 985
             );
986 986
             return $out;
@@ -988,34 +988,34 @@  discard block
 block discarded – undo
988 988
         return $in;
989 989
     }
990 990
 
991
-    public function lazyload_bgimg_callback( $matches ) {
992
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
991
+    public function lazyload_bgimg_callback($matches) {
992
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
993 993
             // get placeholder & lazyload class strings.
994
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
995
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
994
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
995
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
996 996
             // replace background-image URL with SVG placeholder.
997
-            $out = str_replace( 'url(' . $matches[2], 'url(' . $placeholder, $matches[0] );
997
+            $out = str_replace('url('.$matches[2], 'url('.$placeholder, $matches[0]);
998 998
             // sanitize bgimg src for quote sillyness.
999
-            $bgimg_src = $this->fix_silly_bgimg_quotes( $matches[2] );
999
+            $bgimg_src = $this->fix_silly_bgimg_quotes($matches[2]);
1000 1000
             // add data-bg attribute with real background-image URL for lazyload to pick up.
1001
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . $bgimg_src . '"', $out );
1001
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.$bgimg_src.'"', $out);
1002 1002
             // and finally add lazyload class to tag.
1003
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
1003
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
1004 1004
             return $out;
1005 1005
         }
1006 1006
         return $matches[0];
1007 1007
     }
1008 1008
     
1009
-    public function fix_silly_bgimg_quotes( $tag_in ) {
1009
+    public function fix_silly_bgimg_quotes($tag_in) {
1010 1010
         // some themes/ pagebuilders wrap backgroundimages in HTML-encoded quotes (or linebreaks) which breaks imgopt/ lazyloading, this removes them.
1011
-        return trim( str_replace( array( "\r\n", '&quot;', '&#034;', '&apos;', '&#039;' ), '', $tag_in ) );
1011
+        return trim(str_replace(array("\r\n", '&quot;', '&#034;', '&apos;', '&#039;'), '', $tag_in));
1012 1012
     }
1013 1013
 
1014
-    public function maybe_fix_missing_quotes( $tag_in ) {
1014
+    public function maybe_fix_missing_quotes($tag_in) {
1015 1015
         // 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.
1016
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
1017
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
1018
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
1016
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
1017
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
1018
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
1019 1019
             return $tag_out;
1020 1020
         } else {
1021 1021
             return $tag_in;
@@ -1028,23 +1028,23 @@  discard block
 block discarded – undo
1028 1028
     public function imgopt_admin_menu()
1029 1029
     {
1030 1030
         // no acces if multisite and not network admin and no site config allowed.
1031
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1031
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1032 1032
             add_submenu_page(
1033 1033
                 null,
1034 1034
                 'autoptimize_imgopt',
1035 1035
                 'autoptimize_imgopt',
1036 1036
                 'manage_options',
1037 1037
                 'autoptimize_imgopt',
1038
-                array( $this, 'imgopt_options_page' )
1038
+                array($this, 'imgopt_options_page')
1039 1039
             );
1040 1040
         }
1041
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
1041
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
1042 1042
     }
1043 1043
 
1044
-    public function add_imgopt_tab( $in )
1044
+    public function add_imgopt_tab($in)
1045 1045
     {
1046
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1047
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
1046
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1047
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1048 1048
         }
1049 1049
 
1050 1050
         return $in;
@@ -1053,8 +1053,8 @@  discard block
 block discarded – undo
1053 1053
     public function imgopt_options_page()
1054 1054
     {
1055 1055
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1056
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1057
-            $this->query_img_provider_stats( true );
1056
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1057
+            $this->query_img_provider_stats(true);
1058 1058
         }
1059 1059
 
1060 1060
         $options       = $this->fetch_options();
@@ -1065,47 +1065,47 @@  discard block
 block discarded – undo
1065 1065
         #ao_settings_form .form-table th {font-weight: normal;}
1066 1066
         #autoptimize_imgopt_descr{font-size: 120%;}
1067 1067
     </style>
1068
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1068
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1069 1069
     <div class="wrap">
1070
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1070
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1071 1071
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1072
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1072
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1073 1073
             <div class="notice-warning notice"><p>
1074 1074
             <?php
1075 1075
             // translators: "Autoptimize support forum" will appear in a "a href".
1076
-            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>' );
1076
+            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>');
1077 1077
             ?>
1078 1078
             </p></div>
1079 1079
         <?php } ?>
1080 1080
 
1081
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1081
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1082 1082
             <div class="notice-warning notice"><p>
1083
-            <?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' ); ?>
1083
+            <?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'); ?>
1084 1084
             </p></div>
1085 1085
         <?php } ?>
1086 1086
 
1087
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1087
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1088 1088
             <div class="notice-warning notice"><p>
1089 1089
             <?php
1090 1090
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1091
-            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>' );
1091
+            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>');
1092 1092
             ?>
1093 1093
             </p></div>
1094 1094
         <?php } ?>
1095
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1096
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1097
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1098
-        <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>
1095
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1096
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1097
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1098
+        <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>
1099 1099
         <table class="form-table">
1100 1100
             <tr>
1101
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1101
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1102 1102
                 <td>
1103
-                    <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>
1103
+                    <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>
1104 1104
                     <?php
1105 1105
                     // show shortpixel status.
1106 1106
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1107
-                    if ( $_notice ) {
1108
-                        switch ( $_notice['status'] ) {
1107
+                    if ($_notice) {
1108
+                        switch ($_notice['status']) {
1109 1109
                             case 2:
1110 1110
                                 $_notice_color = 'green';
1111 1111
                                 break;
@@ -1120,35 +1120,35 @@  discard block
 block discarded – undo
1120 1120
                             default:
1121 1121
                                 $_notice_color = 'green';
1122 1122
                         }
1123
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1123
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1124 1124
                     } else {
1125 1125
                         // translators: link points to shortpixel.
1126
-                        $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love by speeding up your website. Start serving on-the-fly optimized images (also in the "next-gen" <strong>WebP</strong> and <strong>AVIF</strong> image formats) by %1$sShortPixel%2$s. The optimized images are cached and served from %3$sShortPixel\'s global CDN%2$s.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>', '<a href="https://help.shortpixel.com/article/62-where-does-the-cdn-has-pops" target="_blank">' );
1127
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1128
-                            $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' );
1126
+                        $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love by speeding up your website. Start serving on-the-fly optimized images (also in the "next-gen" <strong>WebP</strong> and <strong>AVIF</strong> image formats) by %1$sShortPixel%2$s. The optimized images are cached and served from %3$sShortPixel\'s global CDN%2$s.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>', '<a href="https://help.shortpixel.com/article/62-where-does-the-cdn-has-pops" target="_blank">');
1127
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1128
+                            $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');
1129 1129
                         } else {
1130 1130
                             // translators: link points to shortpixel.
1131
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive x2 more CDN traffic or image optimization credits for free! This offer also applies to any future plan that you\'ll choose to purchase.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1131
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive x2 more CDN traffic or image optimization credits for free! This offer also applies to any future plan that you\'ll choose to purchase.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1132 1132
                         }
1133
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1133
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1134 1134
                     }
1135 1135
                     // translators: link points to shortpixel FAQ.
1136
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sAutoptimize + ShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>' );
1137
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for websites and images that are publicly available.', 'autoptimize' );
1136
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sAutoptimize + ShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>');
1137
+                    $faqcopy = $faqcopy.' '.__('Only works for websites and images that are publicly available.', 'autoptimize');
1138 1138
                     // translators: links points to shortpixel TOS & Privacy Policy.
1139
-                    $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>' );
1140
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1139
+                    $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>');
1140
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1141 1141
                     ?>
1142 1142
                 </td>
1143 1143
             </tr>
1144
-            <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"'; } ?>>
1145
-                <th scope="row"><?php _e( 'Optimization exclusions', 'autoptimize' ); ?></th>
1144
+            <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"'; } ?>>
1145
+                <th scope="row"><?php _e('Optimization exclusions', 'autoptimize'); ?></th>
1146 1146
                 <td>
1147
-                    <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>
1147
+                    <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>
1148 1148
                 </td>
1149 1149
             </tr>
1150
-            <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"'; } ?>>
1151
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1150
+            <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"'; } ?>>
1151
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1152 1152
                 <td>
1153 1153
                     <label>
1154 1154
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1156,12 +1156,12 @@  discard block
 block discarded – undo
1156 1156
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1157 1157
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1158 1158
 
1159
-                        foreach ( $_imgopt_array as $key => $value ) {
1160
-                            echo '<option value="' . $key . '"';
1161
-                            if ( $_imgopt_val == $key ) {
1159
+                        foreach ($_imgopt_array as $key => $value) {
1160
+                            echo '<option value="'.$key.'"';
1161
+                            if ($_imgopt_val == $key) {
1162 1162
                                 echo ' selected';
1163 1163
                             }
1164
-                            echo '>' . ucfirst( $value ) . '</option>';
1164
+                            echo '>'.ucfirst($value).'</option>';
1165 1165
                         }
1166 1166
                         echo "\n";
1167 1167
                         ?>
@@ -1170,37 +1170,37 @@  discard block
 block discarded – undo
1170 1170
                     <p>
1171 1171
                         <?php
1172 1172
                             // translators: link points to shortpixel image test page.
1173
-                            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>' ) );
1173
+                            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>'));
1174 1174
                         ?>
1175 1175
                     </p>
1176 1176
                 </td>
1177 1177
             </tr>
1178
-            <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"'; } ?>>
1179
-                <th scope="row"><?php _e( 'Load WebP or AVIF in supported browsers?', 'autoptimize' ); ?></th>
1178
+            <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"'; } ?>>
1179
+                <th scope="row"><?php _e('Load WebP or AVIF in supported browsers?', 'autoptimize'); ?></th>
1180 1180
                 <td>
1181
-                    <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>
1181
+                    <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>
1182 1182
                 </td>
1183 1183
             </tr>
1184 1184
             <tr>
1185
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1185
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1186 1186
                 <td>
1187
-                    <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>
1187
+                    <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>
1188 1188
                 </td>
1189 1189
             </tr>
1190
-            <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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1191
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1190
+            <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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1191
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1192 1192
                 <td>
1193
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions_text' 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>
1193
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions_text' 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>
1194 1194
                 </td>
1195 1195
             </tr>
1196
-            <tr id='autoptimize_imgopt_lazyload_from_nth_image' <?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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1197
-                <th scope="row"><?php _e( 'Lazy-load from nth image', 'autoptimize' ); ?></th>
1196
+            <tr id='autoptimize_imgopt_lazyload_from_nth_image' <?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="autoptimize_lazyload_child hidden"'; } else { echo 'class="autoptimize_lazyload_child"'; } ?>>
1197
+                <th scope="row"><?php _e('Lazy-load from nth image', 'autoptimize'); ?></th>
1198 1198
                 <td>
1199
-                    <label><input type='number' min='0' max='50' style='width:80%' id='autoptimize_imgopt_lazyload_from_nth_image_number' name='autoptimize_imgopt_settings[autoptimize_imgopt_number_field_7]' value='<?php if ( ! empty( $options['autoptimize_imgopt_number_field_7'] ) ) { echo esc_attr( $options['autoptimize_imgopt_number_field_7'] ); } else { echo '0'; } ?>'><br /><?php _e( 'Don\'t lazyload the first X images, \'0\' lazyloads all.', 'autoptimize' ); ?></label>
1199
+                    <label><input type='number' min='0' max='50' style='width:80%' id='autoptimize_imgopt_lazyload_from_nth_image_number' name='autoptimize_imgopt_settings[autoptimize_imgopt_number_field_7]' value='<?php if (!empty($options['autoptimize_imgopt_number_field_7'])) { echo esc_attr($options['autoptimize_imgopt_number_field_7']); } else { echo '0'; } ?>'><br /><?php _e('Don\'t lazyload the first X images, \'0\' lazyloads all.', 'autoptimize'); ?></label>
1200 1200
                 </td>
1201 1201
             </tr>
1202 1202
         </table>
1203
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1203
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1204 1204
     </form>
1205 1205
     <script>
1206 1206
         jQuery(document).ready(function() {
@@ -1238,50 +1238,50 @@  discard block
 block discarded – undo
1238 1238
      * Ïmg opt status as used on dashboard.
1239 1239
      */
1240 1240
     public function get_imgopt_status_notice() {
1241
-        if ( $this->imgopt_active() ) {
1241
+        if ($this->imgopt_active()) {
1242 1242
             $_imgopt_notice  = '';
1243
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1243
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1244 1244
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1245
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/SPZURYE109483/' . $_site_host;
1245
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/SPZURYE109483/'.$_site_host;
1246 1246
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1247 1247
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1248 1248
 
1249
-            if ( is_array( $_stat ) ) {
1250
-                if ( 1 == $_stat['Status'] ) {
1249
+            if (is_array($_stat)) {
1250
+                if (1 == $_stat['Status']) {
1251 1251
                     // translators: "add more credits" will appear in a "a href".
1252
-                    $_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>' );
1252
+                    $_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>');
1253 1253
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1254 1254
                     // translators: "add more credits" will appear in a "a href".
1255
-                    $_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>' );
1255
+                    $_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>');
1256 1256
                     // translators: "associate your domain" will appear in a "a href".
1257
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you have enough 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>' );
1257
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you have enough 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>');
1258 1258
                 } elseif ( -3 == $_stat['Status'] ) {
1259 1259
                     // translators: "check the documentation here" will appear in a "a href".
1260
-                    $_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>' );
1260
+                    $_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>');
1261 1261
                 } else {
1262 1262
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/SPZURYE109483';
1263 1263
                     // translators: "log in to check your account" will appear in a "a href".
1264
-                    $_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>' );
1264
+                    $_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>');
1265 1265
                 }
1266 1266
 
1267 1267
                 // add info on freshness + refresh link if status is not 2 (good shape).
1268
-                if ( 2 != $_stat['Status'] ) {
1269
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1268
+                if (2 != $_stat['Status']) {
1269
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1270 1270
                         'page'                => 'autoptimize_imgopt',
1271 1271
                         'refreshImgProvStats' => '1',
1272
-                    ), admin_url( 'options-general.php' ) );
1273
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1274
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1272
+                    ), admin_url('options-general.php'));
1273
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1274
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1275 1275
                     } else {
1276
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1276
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1277 1277
                     }
1278
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1278
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1279 1279
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1280
-                    $_imgopt_notice .= sprintf( __( 'you can click %1$shere to refresh your quota status%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1280
+                    $_imgopt_notice .= sprintf(__('you can click %1$shere to refresh your quota status%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1281 1281
                 }
1282 1282
 
1283 1283
                 // and make the full notice filterable.
1284
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1284
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1285 1285
 
1286 1286
                 return array(
1287 1287
                     'status' => $_stat['Status'],
@@ -1301,18 +1301,18 @@  discard block
 block discarded – undo
1301 1301
     /**
1302 1302
      * Get img provider stats (used to display notice).
1303 1303
      */
1304
-    public function query_img_provider_stats( $_refresh = false ) {
1305
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1304
+    public function query_img_provider_stats($_refresh = false) {
1305
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1306 1306
             $url      = '';
1307 1307
             $stat_dom = 'https://no-cdn.shortpixel.ai/';
1308
-            $endpoint = $stat_dom . 'read-domain/';
1308
+            $endpoint = $stat_dom.'read-domain/';
1309 1309
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1310 1310
 
1311 1311
             // make sure parse_url result makes sense, keeping $url empty if not.
1312
-            if ( $domain && ! empty( $domain ) ) {
1313
-                $url = $endpoint . $domain;
1314
-                if ( true === $_refresh ) {
1315
-                    $url = $url . '/refresh';
1312
+            if ($domain && !empty($domain)) {
1313
+                $url = $endpoint.$domain;
1314
+                if (true === $_refresh) {
1315
+                    $url = $url.'/refresh';
1316 1316
                 }
1317 1317
             }
1318 1318
 
@@ -1323,12 +1323,12 @@  discard block
 block discarded – undo
1323 1323
 
1324 1324
             // only do the remote call if $url is not empty to make sure no parse_url
1325 1325
             // weirdness results in useless calls.
1326
-            if ( ! empty( $url ) ) {
1327
-                $response = wp_remote_get( $url );
1328
-                if ( ! is_wp_error( $response ) ) {
1329
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1330
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1331
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1326
+            if (!empty($url)) {
1327
+                $response = wp_remote_get($url);
1328
+                if (!is_wp_error($response)) {
1329
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1330
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1331
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1332 1332
                     }
1333 1333
                 }
1334 1334
             }
@@ -1351,15 +1351,15 @@  discard block
 block discarded – undo
1351 1351
     {
1352 1352
         static $launch_status = null;
1353 1353
 
1354
-        if ( null === $launch_status ) {
1354
+        if (null === $launch_status) {
1355 1355
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1356
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1357
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1356
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1357
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1358 1358
             $launch_status = false;
1359
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1359
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1360 1360
                 $launch_status = true;
1361
-                if ( ! $has_launched ) {
1362
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1361
+                if (!$has_launched) {
1362
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1363 1363
                 }
1364 1364
             }
1365 1365
         }
@@ -1376,16 +1376,16 @@  discard block
 block discarded – undo
1376 1376
     public function get_imgopt_provider_userstatus() {
1377 1377
         static $_provider_userstatus = null;
1378 1378
 
1379
-        if ( is_null( $_provider_userstatus ) ) {
1380
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1381
-            if ( is_array( $_stat ) ) {
1382
-                if ( array_key_exists( 'Status', $_stat ) ) {
1379
+        if (is_null($_provider_userstatus)) {
1380
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1381
+            if (is_array($_stat)) {
1382
+                if (array_key_exists('Status', $_stat)) {
1383 1383
                     $_provider_userstatus['Status'] = $_stat['Status'];
1384 1384
                 } else {
1385 1385
                     // if no stats then we assume all is well.
1386 1386
                     $_provider_userstatus['Status'] = 2;
1387 1387
                 }
1388
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1388
+                if (array_key_exists('timestamp', $_stat)) {
1389 1389
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1390 1390
                 } else {
1391 1391
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.
classes/autoptimizeHTML.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles minifying HTML markup.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
         '<!--/noindex-->',
35 35
     );
36 36
 
37
-    public function read( $options )
37
+    public function read($options)
38 38
     {
39 39
         // Remove the HTML comments?
40 40
         $this->keepcomments = (bool) $options['keepcomments'];
41 41
 
42 42
         // Filter to force xhtml.
43
-        $this->forcexhtml = (bool) apply_filters( 'autoptimize_filter_html_forcexhtml', false );
43
+        $this->forcexhtml = (bool) apply_filters('autoptimize_filter_html_forcexhtml', false);
44 44
 
45 45
         // Filterable strings to be excluded from HTML minification.
46
-        $exclude = apply_filters( 'autoptimize_filter_html_exclude', '' );
47
-        if ( '' !== $exclude ) {
48
-            $exclude_arr   = array_filter( array_map( 'trim', explode( ',', $exclude ) ) );
49
-            $this->exclude = array_merge( $exclude_arr, $this->exclude );
46
+        $exclude = apply_filters('autoptimize_filter_html_exclude', '');
47
+        if ('' !== $exclude) {
48
+            $exclude_arr   = array_filter(array_map('trim', explode(',', $exclude)));
49
+            $this->exclude = array_merge($exclude_arr, $this->exclude);
50 50
         }
51 51
 
52 52
         // Nothing else for HTML!
@@ -60,49 +60,49 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function minify()
62 62
     {
63
-        $noptimize = apply_filters( 'autoptimize_filter_html_noptimize', false, $this->content );
64
-        if ( $noptimize ) {
63
+        $noptimize = apply_filters('autoptimize_filter_html_noptimize', false, $this->content);
64
+        if ($noptimize) {
65 65
             return false;
66 66
         }
67 67
 
68 68
         // Wrap the to-be-excluded strings in noptimize tags.
69
-        foreach ( $this->exclude as $str ) {
70
-            if ( false !== strpos( $this->content, $str ) ) {
71
-                $replacement   = '<!--noptimize-->' . $str . '<!--/noptimize-->';
72
-                $this->content = str_replace( $str, $replacement, $this->content );
69
+        foreach ($this->exclude as $str) {
70
+            if (false !== strpos($this->content, $str)) {
71
+                $replacement   = '<!--noptimize-->'.$str.'<!--/noptimize-->';
72
+                $this->content = str_replace($str, $replacement, $this->content);
73 73
             }
74 74
         }
75 75
 
76 76
         // Noptimize.
77
-        $this->content = $this->hide_noptimize( $this->content );
77
+        $this->content = $this->hide_noptimize($this->content);
78 78
 
79 79
         // Preparing options for Minify_HTML.
80
-        $options = array( 'keepComments' => $this->keepcomments );
81
-        if ( $this->forcexhtml ) {
80
+        $options = array('keepComments' => $this->keepcomments);
81
+        if ($this->forcexhtml) {
82 82
             $options['xhtml'] = true;
83 83
         }
84 84
 
85
-        $tmp_content = AO_Minify_HTML::minify( $this->content, $options );
86
-        if ( ! empty( $tmp_content ) ) {
85
+        $tmp_content = AO_Minify_HTML::minify($this->content, $options);
86
+        if (!empty($tmp_content)) {
87 87
             $this->content = $tmp_content;
88
-            unset( $tmp_content );
88
+            unset($tmp_content);
89 89
         }
90 90
 
91 91
         // Restore noptimize.
92
-        $this->content = $this->restore_noptimize( $this->content );
92
+        $this->content = $this->restore_noptimize($this->content);
93 93
 
94 94
         // Remove the noptimize-wrapper from around the excluded strings.
95
-        foreach ( $this->exclude as $str ) {
96
-            $replacement = '<!--noptimize-->' . $str . '<!--/noptimize-->';
97
-            if ( false !== strpos( $this->content, $replacement ) ) {
98
-                $this->content = str_replace( $replacement, $str, $this->content );
95
+        foreach ($this->exclude as $str) {
96
+            $replacement = '<!--noptimize-->'.$str.'<!--/noptimize-->';
97
+            if (false !== strpos($this->content, $replacement)) {
98
+                $this->content = str_replace($replacement, $str, $this->content);
99 99
             }
100 100
         }
101 101
 
102 102
         // Revslider data attribs somehow suffer from HTML optimization, this fixes that!
103
-        if ( class_exists( 'RevSlider' ) && apply_filters( 'autoptimize_filter_html_dataattrib_cleanup', false ) ) {
104
-            $this->content = preg_replace( '#\n(data-.*$)\n#Um', ' $1 ', $this->content );
105
-            $this->content = preg_replace( '#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content );
103
+        if (class_exists('RevSlider') && apply_filters('autoptimize_filter_html_dataattrib_cleanup', false)) {
104
+            $this->content = preg_replace('#\n(data-.*$)\n#Um', ' $1 ', $this->content);
105
+            $this->content = preg_replace('#<[^>]*(=\"[^"\'<>\s]*\")(\w)#', '$1 $2', $this->content);
106 106
         }
107 107
 
108 108
         return true;
Please login to merge, or discard this patch.
classes/external/php/ao-minify-html.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     {
74 74
         $this->_html = str_replace("\r\n", "\n", trim($html));
75 75
         if (isset($options['xhtml'])) {
76
-            $this->_isXhtml = (bool)$options['xhtml'];
76
+            $this->_isXhtml = (bool) $options['xhtml'];
77 77
         }
78 78
         if (isset($options['cssMinifier'])) {
79 79
             $this->_cssMinifier = $options['cssMinifier'];
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
99 99
         }
100 100
 
101
-        $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
101
+        $this->_replacementHash = 'MINIFYHTML'.md5($_SERVER['REQUEST_TIME']);
102 102
         $this->_placeholders = array();
103 103
 
104 104
         // replace SCRIPTs (and minify) with placeholders
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             ,$this->_html);
115 115
 
116 116
         // remove HTML comments (not containing IE conditional comments).
117
-        if  ($this->_keepComments == false) {
117
+        if ($this->_keepComments == false) {
118 118
             $this->_html = preg_replace_callback(
119 119
                 '/<!--([\\s\\S]*?)-->/'
120 120
                 ,array($this, '_commentCB')
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         //$this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);
160 160
 
161 161
         // reverse order while preserving keys to ensure the last replacement is done first, etc ...
162
-        $this->_placeholders = array_reverse( $this->_placeholders, true );
162
+        $this->_placeholders = array_reverse($this->_placeholders, true);
163 163
 
164 164
         // fill placeholders
165 165
         $this->_html = str_replace(
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
     protected function _reservePlace($content)
181 181
     {
182
-        $placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
182
+        $placeholder = '%'.$this->_replacementHash.count($this->_placeholders).'%';
183 183
         $this->_placeholders[$placeholder] = $content;
184 184
         return $placeholder;
185 185
     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 
194 194
     protected function _outsideTagCB($m)
195 195
     {
196
-        return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
196
+        return '>'.preg_replace('/^\\s+|\\s+$/', ' ', $m[1]).'<';
197 197
     }
198 198
 
199 199
     protected function _removePreCB($m)
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     protected function _removeCdata($str)
266 266
     {
267 267
         return (false !== strpos($str, '<![CDATA['))
268
-            ? str_replace(array('/* <![CDATA[ */','/* ]]> */','/*<![CDATA[*/','/*]]>*/','<![CDATA[', ']]>'), '', $str)
268
+            ? str_replace(array('/* <![CDATA[ */', '/* ]]> */', '/*<![CDATA[*/', '/*]]>*/', '<![CDATA[', ']]>'), '', $str)
269 269
             : $str;
270 270
     }
271 271
 
Please login to merge, or discard this patch.
autoptimize.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,66 +17,66 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 
20
-if ( ! defined( 'ABSPATH' ) ) {
20
+if (!defined('ABSPATH')) {
21 21
     exit;
22 22
 }
23 23
 
24
-define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.8.3' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.8.3');
25 25
 
26 26
 // plugin_dir_path() returns the trailing slash!
27
-define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
28
-define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ );
27
+define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__));
28
+define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__);
29 29
 
30 30
 // Bail early if attempting to run on non-supported php versions.
31
-if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
31
+if (version_compare(PHP_VERSION, '5.6', '<')) {
32 32
     function autoptimize_incompatible_admin_notice() {
33
-        echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>';
34
-        if ( isset( $_GET['activate'] ) ) {
35
-            unset( $_GET['activate'] );
33
+        echo '<div class="error"><p>'.__('Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize').'</p></div>';
34
+        if (isset($_GET['activate'])) {
35
+            unset($_GET['activate']);
36 36
         }
37 37
     }
38 38
     function autoptimize_deactivate_self() {
39
-        deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) );
39
+        deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE));
40 40
     }
41
-    add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' );
42
-    add_action( 'admin_init', 'autoptimize_deactivate_self' );
41
+    add_action('admin_notices', 'autoptimize_incompatible_admin_notice');
42
+    add_action('admin_init', 'autoptimize_deactivate_self');
43 43
     return;
44 44
 }
45 45
 
46
-function autoptimize_autoload( $class_name ) {
47
-    if ( in_array( $class_name, array( 'AO_Minify_HTML', 'JSMin' ) ) ) {
48
-        $file     = strtolower( $class_name );
49
-        $file     = str_replace( '_', '-', $file );
50
-        $path     = dirname( __FILE__ ) . '/classes/external/php/';
51
-        $filepath = $path . $file . '.php';
52
-    } elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) {
53
-        $file     = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name );
54
-        $path     = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/';
55
-        $filepath = $path . $file . '.php';
56
-    } elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) {
46
+function autoptimize_autoload($class_name) {
47
+    if (in_array($class_name, array('AO_Minify_HTML', 'JSMin'))) {
48
+        $file     = strtolower($class_name);
49
+        $file     = str_replace('_', '-', $file);
50
+        $path     = dirname(__FILE__).'/classes/external/php/';
51
+        $filepath = $path.$file.'.php';
52
+    } elseif (false !== strpos($class_name, 'Autoptimize\\tubalmartin\\CssMin')) {
53
+        $file     = str_replace('Autoptimize\\tubalmartin\\CssMin\\', '', $class_name);
54
+        $path     = dirname(__FILE__).'/classes/external/php/yui-php-cssmin-bundled/';
55
+        $filepath = $path.$file.'.php';
56
+    } elseif ('autoptimize' === substr($class_name, 0, 11)) {
57 57
         // One of our "old" classes.
58 58
         $file     = $class_name;
59
-        $path     = dirname( __FILE__ ) . '/classes/';
60
-        $filepath = $path . $file . '.php';
61
-    } elseif ( 'PAnD' === $class_name ) {
59
+        $path     = dirname(__FILE__).'/classes/';
60
+        $filepath = $path.$file.'.php';
61
+    } elseif ('PAnD' === $class_name) {
62 62
         $file     = 'persist-admin-notices-dismissal';
63
-        $path     = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/';
64
-        $filepath = $path . $file . '.php';
63
+        $path     = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/';
64
+        $filepath = $path.$file.'.php';
65 65
     }
66 66
 
67 67
     // If we didn't match one of our rules, bail!
68
-    if ( ! isset( $filepath ) ) {
68
+    if (!isset($filepath)) {
69 69
         return;
70 70
     }
71 71
 
72 72
     require $filepath;
73 73
 }
74 74
 
75
-spl_autoload_register( 'autoptimize_autoload' );
75
+spl_autoload_register('autoptimize_autoload');
76 76
 
77 77
 // Load WP CLI command(s) on demand.
78
-if ( defined( 'WP_CLI' ) && WP_CLI ) {
79
-    require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php';
78
+if (defined('WP_CLI') && WP_CLI) {
79
+    require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php';
80 80
 }
81 81
 
82 82
 /**
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 function autoptimize() {
88 88
     static $plugin = null;
89 89
 
90
-    if ( null === $plugin ) {
91
-        $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
90
+    if (null === $plugin) {
91
+        $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
92 92
     }
93 93
 
94 94
     return $plugin;
Please login to merge, or discard this patch.