Completed
Push — master ( d10a3b...267ab8 )
by frank
01:54
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   +182 added lines, -182 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 ) ) {
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)) {
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,18 +814,18 @@  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 830
         }
831 831
     }
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.7.8' );
24
+define('AUTOPTIMIZE_PLUGIN_VERSION', '2.7.8');
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( '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('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.
classes/autoptimizeConfig.php 1 patch
Spacing   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Main configuration logic.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
      */
36 36
     private function __construct()
37 37
     {
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
             // Add the admin page and settings.
40
-            if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41
-                add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
40
+            if (autoptimizeOptionWrapper::is_ao_active_for_network()) {
41
+                add_action('network_admin_menu', array($this, 'addmenu'));
42 42
             }
43 43
 
44
-            add_action( 'admin_menu', array( $this, 'addmenu' ) );
45
-            add_action( 'admin_init', array( $this, 'registersettings' ) );
46
-            add_action( 'admin_init', array( 'PAnD', 'init' ) );
44
+            add_action('admin_menu', array($this, 'addmenu'));
45
+            add_action('admin_init', array($this, 'registersettings'));
46
+            add_action('admin_init', array('PAnD', 'init'));
47 47
 
48 48
             // Set meta info.
49
-            if ( function_exists( 'plugin_row_meta' ) ) {
49
+            if (function_exists('plugin_row_meta')) {
50 50
                 // 2.8 and higher.
51
-                add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52
-            } elseif ( function_exists( 'post_class' ) ) {
51
+                add_filter('plugin_row_meta', array($this, 'setmeta'), 10, 2);
52
+            } elseif (function_exists('post_class')) {
53 53
                 // 2.7 and lower.
54
-                $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55
-                add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
54
+                $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
55
+                add_filter('plugin_action_links_'.$plugin, array($this, 'setmeta'));
56 56
             }
57 57
 
58 58
             // Clean cache?
59
-            if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
59
+            if (autoptimizeOptionWrapper::get_option('autoptimize_cache_clean')) {
60 60
                 autoptimizeCache::clearall();
61
-                autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
61
+                autoptimizeOptionWrapper::update_option('autoptimize_cache_clean', 0);
62 62
             }
63 63
 
64
-            $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
64
+            $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
65 65
         }
66 66
 
67 67
         // Adds the Autoptimize Toolbar to the Admin bar.
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     static public function instance()
78 78
     {
79 79
         // Only one instance.
80
-        if ( null === self::$instance ) {
80
+        if (null === self::$instance) {
81 81
             self::$instance = new autoptimizeConfig();
82 82
         }
83 83
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     public function show_network_message() {
88 88
         ?>
89 89
         <div class="wrap">
90
-            <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
90
+            <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
91 91
             <?php echo $this->ao_admin_tabs(); ?>
92
-            <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
92
+            <p style="font-size:120%;"><?php echo apply_filters('autoptimize_filter_settingsscreen_multisite_network_message', __('Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize')); ?></p>
93 93
         </div>
94 94
         <?php
95 95
     }
@@ -182,32 +182,32 @@  discard block
 block discarded – undo
182 182
 <div class="wrap">
183 183
 
184 184
 <!-- Temporary nudge to disable aoccss power-up. -->
185
-<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
185
+<?php if (autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { ?>
186 186
     <div class="notice-info notice"><p>
187
-        <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
187
+        <?php _e('Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize'); ?>
188 188
     </p></div>
189 189
 <?php } ?>
190 190
 
191 191
 <div id="autoptimize_main">
192
-    <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
192
+    <h1 id="ao_title"><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
193 193
     <?php echo $this->ao_admin_tabs(); ?>
194 194
 
195
-<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
196
-<?php settings_fields( 'autoptimize' ); ?>
195
+<form method="post" action="<?php echo admin_url('options.php'); ?>">
196
+<?php settings_fields('autoptimize'); ?>
197 197
 
198 198
 <ul>
199 199
 
200 200
 <?php
201 201
 // Only show enable site configuration in network site option.
202
-if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
202
+if (is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
203 203
 ?>
204 204
     <li class="itemDetail multiSite">
205
-        <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
205
+        <h2 class="itemTitle"><?php _e('Multisite Options', 'autoptimize'); ?></h2>
206 206
         <table class="form-table">
207 207
             <tr valign="top">
208
-                <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
209
-                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
210
-                <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
208
+                <th scope="row"><?php _e('Enable site configuration?', 'autoptimize'); ?></th>
209
+                <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config') ? 'checked="checked" ' : ''; ?>/>
210
+                <?php _e('Enable Autoptimize configuration per site.', 'autoptimize'); ?></label></td>
211 211
             </tr>
212 212
         </table>
213 213
     </li>
@@ -216,115 +216,115 @@  discard block
 block discarded – undo
216 216
 <?php } ?>    
217 217
 
218 218
 <li class="itemDetail">
219
-<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
219
+<h2 class="itemTitle"><?php _e('JavaScript Options', 'autoptimize'); ?></h2>
220 220
 <table class="form-table">
221 221
 <tr valign="top">
222
-<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
223
-<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
222
+<th scope="row"><?php _e('Optimize JavaScript Code?', 'autoptimize'); ?></th>
223
+<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js') ? 'checked="checked" ' : ''; ?>/></td>
224 224
 </tr>
225 225
 <tr valign="top" class="js_sub">
226
-<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
227
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
228
-<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
226
+<th scope="row"><?php _e('Aggregate JS-files?', 'autoptimize'); ?></th>
227
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get('autoptimize_js_aggregate') ? 'checked="checked" ' : ''; ?>/>
228
+<?php _e('Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
229 229
 </tr>
230 230
 <tr valign="top" class="js_sub js_aggregate">
231
-<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
232
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
233
-<?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td>
231
+<th scope="row"><?php _e('Also aggregate inline JS?', 'autoptimize'); ?></th>
232
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_include_inline') ? 'checked="checked" ' : ''; ?>/>
233
+<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize'); ?></label></td>
234 234
 </tr>
235 235
 <tr valign="top" class="js_sub js_aggregate">
236
-<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
237
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
238
-<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
236
+<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?', 'autoptimize'); ?></th>
237
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_forcehead') ? 'checked="checked" ' : ''; ?>/>
238
+<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize'); ?></label></td>
239 239
 </tr>
240
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
240
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_js_justhead')) { ?>
241 241
 <tr valign="top" class="js_sub js_aggregate">
242 242
 <th scope="row">
243 243
 <?php
244
-    _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
245
-    echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
244
+    _e('Look for scripts only in &lt;head&gt;?', 'autoptimize');
245
+    echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
246 246
 ?>
247 247
 </th>
248
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
249
-<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td>
248
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_justhead') ? 'checked="checked" ' : ''; ?>/>
249
+<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize'); ?></label></td>
250 250
 </tr>
251 251
 <?php } ?>
252 252
 <tr valign="top" class="js_sub">
253
-<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
254
-<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ) ); ?>"/><br />
253
+<th scope="row"><?php _e('Exclude scripts from Autoptimize:', 'autoptimize'); ?></th>
254
+<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js')); ?>"/><br />
255 255
 <?php
256
-echo __( 'A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
256
+echo __('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated by Autoptimize.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
257 257
 ?>
258 258
 </label></td>
259 259
 </tr>
260 260
 <tr valign="top" class="js_sub js_aggregate">
261
-<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
262
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
263
-<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
261
+<th scope="row"><?php _e('Add try-catch wrapping?', 'autoptimize'); ?></th>
262
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_js_trycatch') ? 'checked="checked" ' : ''; ?>/>
263
+<?php _e('If your scripts break because of a JS-error, you might want to try this.', 'autoptimize'); ?></label></td>
264 264
 </tr>
265 265
 </table>
266 266
 </li>
267 267
 
268 268
 <li class="itemDetail">
269
-<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
269
+<h2 class="itemTitle"><?php _e('CSS Options', 'autoptimize'); ?></h2>
270 270
 <table class="form-table">
271 271
 <tr valign="top">
272
-<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
273
-<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
272
+<th scope="row"><?php _e('Optimize CSS Code?', 'autoptimize'); ?></th>
273
+<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css') ? 'checked="checked" ' : ''; ?>/></td>
274 274
 </tr>
275 275
 <tr class="css_sub" valign="top">
276
-<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
277
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
278
-<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
276
+<th scope="row"><?php _e('Aggregate CSS-files?', 'autoptimize'); ?></th>
277
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get('autoptimize_css_aggregate') ? 'checked="checked" ' : ''; ?>/>
278
+<?php _e('Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize'); ?></label></td>
279 279
 </tr>
280 280
 <tr valign="top" class="css_sub css_aggregate">
281
-<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
282
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
283
-<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
281
+<th scope="row"><?php _e('Also aggregate inline CSS?', 'autoptimize'); ?></th>
282
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_include_inline', '1') ? 'checked="checked" ' : ''; ?>/>
283
+<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize'); ?></label></td>
284 284
 </tr>
285 285
 <tr class="css_sub css_aggregate" valign="top">
286
-<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
287
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
288
-<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
286
+<th scope="row"><?php _e('Generate data: URIs for images?', 'autoptimize'); ?></th>
287
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_datauris') ? 'checked="checked" ' : ''; ?>/>
288
+<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize'); ?></label></td>
289 289
 </tr>
290
-<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
290
+<?php if (autoptimizeOptionWrapper::get_option('autoptimize_css_justhead')) { ?>
291 291
 <tr valign="top" class="css_sub css_aggregate">
292 292
 <th scope="row">
293 293
 <?php
294
-_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
295
-echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
294
+_e('Look for styles only in &lt;head&gt;?', 'autoptimize');
295
+echo ' <i>'.__('(deprecated)', 'autoptimize').'</i>';
296 296
 ?>
297 297
 </th>
298
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
299
-<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
298
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_justhead') ? 'checked="checked" ' : ''; ?>/>
299
+<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize'); ?></label></td>
300 300
 </tr>
301 301
 <?php } ?>
302 302
 <tr valign="top" class="css_sub">
303
-<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
304
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
303
+<th scope="row"><?php _e('Inline and Defer CSS?', 'autoptimize'); ?></th>
304
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer') ? 'checked="checked" ' : ''; ?>/>
305 305
 <?php
306
-_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' );
306
+_e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize');
307 307
 echo ' ';
308
-$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
308
+$critcss_settings_url = get_admin_url(null, 'options-general.php?page=ao_critcss');
309 309
 // translators: links "autoptimize critical CSS" tab.
310
-echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
310
+echo sprintf(__('This can be fully automated for different types of pages on the %s tab.', 'autoptimize'), '<a href="'.$critcss_settings_url.'">CriticalCSS</a>');
311 311
 ?>
312 312
 </label></td>
313 313
 </tr>
314 314
 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
315 315
 <th scope="row"></th>
316
-<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td>
316
+<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
317 317
 </tr>
318 318
 <tr valign="top" class="css_sub css_aggregate">
319
-<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
320
-<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
321
-<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
319
+<th scope="row"><?php _e('Inline all CSS?', 'autoptimize'); ?></th>
320
+<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_css_inline') ? 'checked="checked" ' : ''; ?>/>
321
+<?php _e('Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize'); ?></label></td>
322 322
 </tr>
323 323
 <tr valign="top" class="css_sub">
324
-<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
325
-<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
324
+<th scope="row"><?php _e('Exclude CSS from Autoptimize:', 'autoptimize'); ?></th>
325
+<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr(autoptimizeOptionWrapper::get_option('autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css')); ?>"/><br />
326 326
 <?php
327
-echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
327
+echo __('A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize').' '.__('Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize');
328 328
 ?>
329 329
 </label></td>
330 330
 </tr>
@@ -332,55 +332,55 @@  discard block
 block discarded – undo
332 332
 </li>
333 333
 
334 334
 <li class="itemDetail">
335
-<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
335
+<h2 class="itemTitle"><?php _e('HTML Options', 'autoptimize'); ?></h2>
336 336
 <table class="form-table">
337 337
 <tr valign="top">
338
-<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
339
-<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
338
+<th scope="row"><?php _e('Optimize HTML Code?', 'autoptimize'); ?></th>
339
+<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html') ? 'checked="checked" ' : ''; ?>/></td>
340 340
 </tr>
341 341
 <tr class="html_sub" valign="top">
342
-<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
343
-<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
344
-<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
342
+<th scope="row"><?php _e('Keep HTML comments?', 'autoptimize'); ?></th>
343
+<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_html_keepcomments') ? 'checked="checked" ' : ''; ?>/>
344
+<?php _e('Enable this if you want HTML comments to remain in the page.', 'autoptimize'); ?></label></td>
345 345
 </tr>
346 346
 </table>
347 347
 </li>
348 348
 
349 349
 <li class="itemDetail">
350
-<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
350
+<h2 class="itemTitle"><?php _e('CDN Options', 'autoptimize'); ?></h2>
351 351
 <table class="form-table">
352 352
 <tr valign="top">
353
-<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
354
-<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
355
-<?php _e( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize' ); ?></label></td>
353
+<th scope="row"><?php _e('CDN Base URL', 'autoptimize'); ?></th>
354
+<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', ''), array('http', 'https')); ?>" /><br />
355
+<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.', 'autoptimize'); ?></label></td>
356 356
 </tr>
357 357
 </table>
358 358
 </li>
359 359
 
360 360
 <li class="itemDetail">
361
-<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
361
+<h2 class="itemTitle"><?php _e('Cache Info', 'autoptimize'); ?></h2>
362 362
 <table class="form-table" >
363 363
 <tr valign="top" >
364
-<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
365
-<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
364
+<th scope="row"><?php _e('Cache folder', 'autoptimize'); ?></th>
365
+<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
366 366
 </tr>
367 367
 <tr valign="top" >
368
-<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
369
-<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
368
+<th scope="row"><?php _e('Can we write?', 'autoptimize'); ?></th>
369
+<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes', 'autoptimize') : __('No', 'autoptimize')); ?></td>
370 370
 </tr>
371 371
 <tr valign="top" >
372
-<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
372
+<th scope="row"><?php _e('Cached styles and scripts', 'autoptimize'); ?></th>
373 373
 <td>
374 374
     <?php
375 375
     $ao_stat_arr = autoptimizeCache::stats();
376
-    if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
377
-        $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
376
+    if (!empty($ao_stat_arr) && is_array($ao_stat_arr)) {
377
+        $ao_cache_size = size_format($ao_stat_arr[1], 2);
378 378
         $details       = '';
379
-        if ( $ao_cache_size > 0 ) {
380
-            $details = ', ~' . $ao_cache_size . ' total';
379
+        if ($ao_cache_size > 0) {
380
+            $details = ', ~'.$ao_cache_size.' total';
381 381
         }
382 382
         // translators: Kilobytes + timestamp shown.
383
-        printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
383
+        printf(__('%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize'), $ao_stat_arr[0], $ao_cache_size, date('H:i e', $ao_stat_arr[2]));
384 384
     }
385 385
     ?>
386 386
 </td>
@@ -389,41 +389,41 @@  discard block
 block discarded – undo
389 389
 </li>
390 390
 
391 391
 <li class="itemDetail">
392
-<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
392
+<h2 class="itemTitle"><?php _e('Misc Options', 'autoptimize'); ?></h2>
393 393
 <table class="form-table">
394 394
     <tr valign="top" >
395
-    <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
396
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
397
-    <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td>
395
+    <th scope="row"><?php _e('Save aggregated script/css as static files?', 'autoptimize'); ?></th>
396
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip', '1') ? 'checked="checked" ' : ''; ?>/>
397
+    <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize'); ?></label></td>
398 398
     </tr>
399 399
     <?php
400 400
     $_min_excl_class = '';
401
-    if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
401
+    if (!$conf->get('autoptimize_css_aggregate') && !$conf->get('autoptimize_js_aggregate')) {
402 402
         $_min_excl_class = 'hidden';
403 403
     }
404 404
     ?>
405 405
     <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
406
-        <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
407
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
408
-        <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td>
406
+        <th scope="row"><?php _e('Minify excluded CSS and JS files?', 'autoptimize'); ?></th>
407
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_minify_excluded', '1') ? 'checked="checked" ' : ''; ?>/>
408
+        <?php _e('When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize'); ?></label></td>
409 409
     </tr>
410 410
     <tr valign="top">
411
-        <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
412
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
413
-        <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
411
+        <th scope="row"><?php _e('Enable 404 fallbacks?', 'autoptimize'); ?></th>
412
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_cache_fallback', '1') ? 'checked="checked" ' : ''; ?>/>
413
+        <?php _e('Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize'); ?></label></td>
414 414
     </tr>
415 415
     <tr valign="top">
416
-    <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
417
-    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
418
-    <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
416
+    <th scope="row"><?php _e('Also optimize for logged in editors/ administrators?', 'autoptimize'); ?></th>
417
+    <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', '1') ? 'checked="checked" ' : ''; ?>/>
418
+    <?php _e('By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize'); ?></label></td>
419 419
     </tr>
420 420
     <?php
421
-    if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
421
+    if (function_exists('is_checkout') || function_exists('is_cart') || function_exists('edd_is_checkout') || function_exists('wpsc_is_cart') || function_exists('wpsc_is_checkout')) {
422 422
     ?>
423 423
     <tr valign="top" >
424
-        <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
425
-        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
426
-            <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
424
+        <th scope="row"><?php _e('Also optimize shop cart/ checkout?', 'autoptimize'); ?></th>
425
+        <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', '0') ? 'checked="checked" ' : ''; ?>/>
426
+            <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize'); ?></label>
427 427
         </td>
428 428
     </tr>
429 429
     <?php } ?>
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
 </ul>
434 434
 
435 435
 <p class="submit">
436
-<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
437
-<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
436
+<input type="submit" class="button-secondary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
437
+<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache', 'autoptimize'); ?>" />
438 438
 </p>
439 439
 
440 440
 </form>
@@ -443,46 +443,46 @@  discard block
 block discarded – undo
443 443
     <div class="autoptimize_banner hidden">
444 444
     <ul>
445 445
     <?php
446
-    if ( $this->settings_screen_do_remote_http ) {
447
-        $ao_banner = get_transient( 'autoptimize_banner' );
448
-        if ( empty( $ao_banner ) ) {
449
-            $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
450
-            if ( ! is_wp_error( $banner_resp ) ) {
451
-                if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
452
-                    $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
453
-                    set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
446
+    if ($this->settings_screen_do_remote_http) {
447
+        $ao_banner = get_transient('autoptimize_banner');
448
+        if (empty($ao_banner)) {
449
+            $banner_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION);
450
+            if (!is_wp_error($banner_resp)) {
451
+                if ('200' == wp_remote_retrieve_response_code($banner_resp)) {
452
+                    $ao_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
453
+                    set_transient('autoptimize_banner', $ao_banner, WEEK_IN_SECONDS);
454 454
                 }
455 455
             }
456 456
         }
457 457
         echo $ao_banner;
458 458
     }
459 459
     ?>
460
-        <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
461
-        <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
460
+        <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize'); ?></li>
461
+        <li><?php _e('Happy with Autoptimize?', 'autoptimize'); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e('Try my other plugins!', 'autoptimize'); ?></a></li>
462 462
     </ul>
463 463
     </div>
464 464
     <div style="margin-left:10px;margin-top:-5px;">
465 465
         <h2>
466
-            <?php _e( 'futtta about', 'autoptimize' ); ?>
466
+            <?php _e('futtta about', 'autoptimize'); ?>
467 467
             <select id="feed_dropdown" >
468
-                <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
469
-                <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
470
-                <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
468
+                <option value="1"><?php _e('Autoptimize', 'autoptimize'); ?></option>
469
+                <option value="2"><?php _e('WordPress', 'autoptimize'); ?></option>
470
+                <option value="3"><?php _e('Web Technology', 'autoptimize'); ?></option>
471 471
             </select>
472 472
         </h2>
473 473
         <div id="futtta_feed">
474 474
             <div id="autoptimizefeed">
475
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
475
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_autoptimize'); ?>
476 476
             </div>
477 477
             <div id="wordpressfeed">
478
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
478
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_wordpress'); ?>
479 479
             </div>
480 480
             <div id="webtechfeed">
481
-                <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
481
+                <?php $this->get_futtta_feeds('http://feeds.feedburner.com/futtta_webtech'); ?>
482 482
             </div>
483 483
         </div>
484 484
     </div>
485
-    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
485
+    <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e('Do not donate for this plugin!', 'autoptimize'); ?>"></a></div>
486 486
 </div>
487 487
 
488 488
 <script type="text/javascript">
@@ -631,81 +631,81 @@  discard block
 block discarded – undo
631 631
 
632 632
     public function addmenu()
633 633
     {
634
-        if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
634
+        if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
635 635
             // multisite, network admin, ao network activated: add normal settings page at network level.
636
-            $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
637
-        } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
636
+            $hook = add_submenu_page('settings.php', __('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_network_options', 'autoptimize', array($this, 'show_config'));
637
+        } elseif (is_multisite() && !is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
638 638
             // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options.
639
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
639
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_network_message'));
640 640
         } else {
641 641
             // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on.
642
-            $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
642
+            $hook = add_options_page(__('Autoptimize Options', 'autoptimize'), 'Autoptimize', 'manage_options', 'autoptimize', array($this, 'show_config'));
643 643
         }
644 644
 
645
-        add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
646
-        add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
645
+        add_action('admin_print_scripts-'.$hook, array($this, 'autoptimize_admin_scripts'));
646
+        add_action('admin_print_styles-'.$hook, array($this, 'autoptimize_admin_styles'));
647 647
     }
648 648
 
649 649
     public function autoptimize_admin_scripts()
650 650
     {
651
-        wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
652
-        wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
651
+        wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'), null, true);
652
+        wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'), null, true);
653 653
     }
654 654
 
655 655
     public function autoptimize_admin_styles()
656 656
     {
657
-        wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
658
-        wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
657
+        wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
658
+        wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
659 659
     }
660 660
 
661 661
     public function registersettings() {
662
-        register_setting( 'autoptimize', 'autoptimize_html' );
663
-        register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
664
-        register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
665
-        register_setting( 'autoptimize', 'autoptimize_js' );
666
-        register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
667
-        register_setting( 'autoptimize', 'autoptimize_js_exclude' );
668
-        register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
669
-        register_setting( 'autoptimize', 'autoptimize_js_justhead' );
670
-        register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
671
-        register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
672
-        register_setting( 'autoptimize', 'autoptimize_css' );
673
-        register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
674
-        register_setting( 'autoptimize', 'autoptimize_css_exclude' );
675
-        register_setting( 'autoptimize', 'autoptimize_css_justhead' );
676
-        register_setting( 'autoptimize', 'autoptimize_css_datauris' );
677
-        register_setting( 'autoptimize', 'autoptimize_css_defer' );
678
-        register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
679
-        register_setting( 'autoptimize', 'autoptimize_css_inline' );
680
-        register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
681
-        register_setting( 'autoptimize', 'autoptimize_cdn_url' );
682
-        register_setting( 'autoptimize', 'autoptimize_cache_clean' );
683
-        register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
684
-        register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
685
-        register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
686
-        register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
687
-        register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
662
+        register_setting('autoptimize', 'autoptimize_html');
663
+        register_setting('autoptimize', 'autoptimize_html_keepcomments');
664
+        register_setting('autoptimize', 'autoptimize_enable_site_config');
665
+        register_setting('autoptimize', 'autoptimize_js');
666
+        register_setting('autoptimize', 'autoptimize_js_aggregate');
667
+        register_setting('autoptimize', 'autoptimize_js_exclude');
668
+        register_setting('autoptimize', 'autoptimize_js_trycatch');
669
+        register_setting('autoptimize', 'autoptimize_js_justhead');
670
+        register_setting('autoptimize', 'autoptimize_js_forcehead');
671
+        register_setting('autoptimize', 'autoptimize_js_include_inline');
672
+        register_setting('autoptimize', 'autoptimize_css');
673
+        register_setting('autoptimize', 'autoptimize_css_aggregate');
674
+        register_setting('autoptimize', 'autoptimize_css_exclude');
675
+        register_setting('autoptimize', 'autoptimize_css_justhead');
676
+        register_setting('autoptimize', 'autoptimize_css_datauris');
677
+        register_setting('autoptimize', 'autoptimize_css_defer');
678
+        register_setting('autoptimize', 'autoptimize_css_defer_inline');
679
+        register_setting('autoptimize', 'autoptimize_css_inline');
680
+        register_setting('autoptimize', 'autoptimize_css_include_inline');
681
+        register_setting('autoptimize', 'autoptimize_cdn_url');
682
+        register_setting('autoptimize', 'autoptimize_cache_clean');
683
+        register_setting('autoptimize', 'autoptimize_cache_nogzip');
684
+        register_setting('autoptimize', 'autoptimize_optimize_logged');
685
+        register_setting('autoptimize', 'autoptimize_optimize_checkout');
686
+        register_setting('autoptimize', 'autoptimize_minify_excluded');
687
+        register_setting('autoptimize', 'autoptimize_cache_fallback');
688 688
     }
689 689
 
690
-    public function setmeta( $links, $file = null )
690
+    public function setmeta($links, $file = null)
691 691
     {
692 692
         // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
693 693
         // Do it only once - saves time.
694 694
         static $plugin;
695
-        if ( empty( $plugin ) ) {
696
-            $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
695
+        if (empty($plugin)) {
696
+            $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
697 697
         }
698 698
 
699
-        if ( null === $file ) {
699
+        if (null === $file) {
700 700
             // 2.7 and lower.
701
-            $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
702
-            array_unshift( $links, $settings_link );
701
+            $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
702
+            array_unshift($links, $settings_link);
703 703
         } else {
704 704
             // 2.8 and higher.
705 705
             // If it's us, add the link.
706
-            if ( $file === $plugin ) {
707
-                $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
708
-                $links   = array_merge( $links, $newlink );
706
+            if ($file === $plugin) {
707
+                $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')));
708
+                $links   = array_merge($links, $newlink);
709 709
             }
710 710
         }
711 711
 
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
             'autoptimize_imgopt_select_field_2'   => '2', // quality glossy.
782 782
             'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
783 783
             'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
784
-            'autoptimize_imgopt_text_field_5'     => '',  // lazy load exclusions empty.
784
+            'autoptimize_imgopt_text_field_5'     => '', // lazy load exclusions empty.
785 785
         );
786 786
         return $defaults;
787 787
     }
@@ -793,58 +793,58 @@  discard block
 block discarded – undo
793 793
      *
794 794
      * @return string
795 795
      */
796
-    public static function get_ao_css_preload_onload( $media = 'all' )
796
+    public static function get_ao_css_preload_onload($media = 'all')
797 797
     {
798
-        $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
798
+        $preload_onload = apply_filters('autoptimize_filter_css_preload_onload', "this.onload=null;this.media='".$media."';");
799 799
         return $preload_onload;
800 800
     }
801 801
 
802
-    public function get( $key )
802
+    public function get($key)
803 803
     {
804
-        if ( ! is_array( $this->config ) ) {
804
+        if (!is_array($this->config)) {
805 805
             // Default config.
806 806
             $config = self::get_defaults();
807 807
 
808 808
             // Override with user settings.
809
-            foreach ( array_keys( $config ) as $name ) {
810
-                $conf = autoptimizeOptionWrapper::get_option( $name );
811
-                if ( false !== $conf ) {
809
+            foreach (array_keys($config) as $name) {
810
+                $conf = autoptimizeOptionWrapper::get_option($name);
811
+                if (false !== $conf) {
812 812
                     // It was set before!
813
-                    $config[ $name ] = $conf;
813
+                    $config[$name] = $conf;
814 814
                 }
815 815
             }
816 816
 
817 817
             // Save for next call.
818
-            $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
818
+            $this->config = apply_filters('autoptimize_filter_get_config', $config);
819 819
         }
820 820
 
821
-        if ( isset( $this->config[ $key ] ) ) {
822
-            return $this->config[ $key ];
821
+        if (isset($this->config[$key])) {
822
+            return $this->config[$key];
823 823
         }
824 824
 
825 825
         return false;
826 826
     }
827 827
 
828
-    private function get_futtta_feeds( $url ) {
829
-        if ( $this->settings_screen_do_remote_http ) {
830
-            $rss      = fetch_feed( $url );
828
+    private function get_futtta_feeds($url) {
829
+        if ($this->settings_screen_do_remote_http) {
830
+            $rss      = fetch_feed($url);
831 831
             $maxitems = 0;
832 832
 
833
-            if ( ! is_wp_error( $rss ) ) {
834
-                $maxitems  = $rss->get_item_quantity( 7 );
835
-                $rss_items = $rss->get_items( 0, $maxitems );
833
+            if (!is_wp_error($rss)) {
834
+                $maxitems  = $rss->get_item_quantity(7);
835
+                $rss_items = $rss->get_items(0, $maxitems);
836 836
             }
837 837
             ?>
838 838
             <ul>
839
-                <?php if ( 0 == $maxitems ) : ?>
840
-                    <li><?php _e( 'No items', 'autoptimize' ); ?></li>
839
+                <?php if (0 == $maxitems) : ?>
840
+                    <li><?php _e('No items', 'autoptimize'); ?></li>
841 841
                 <?php else : ?>
842
-                    <?php foreach ( $rss_items as $item ) : ?>
842
+                    <?php foreach ($rss_items as $item) : ?>
843 843
                         <li>
844
-                            <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
844
+                            <a href="<?php echo esc_url($item->get_permalink()); ?>"
845 845
                                 <?php // translators: the variable contains a date. ?>
846
-                                title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
847
-                                <?php echo esc_html( $item->get_title() ); ?>
846
+                                title="<?php printf(__('Posted %s', 'autoptimize'), $item->get_date('j F Y | g:i a')); ?>">
847
+                                <?php echo esc_html($item->get_title()); ?>
848 848
                             </a>
849 849
                         </li>
850 850
                     <?php endforeach; ?>
@@ -857,23 +857,23 @@  discard block
 block discarded – undo
857 857
     static function ao_admin_tabs()
858 858
     {
859 859
         // based on http://wordpress.stackexchange.com/a/58826 .
860
-        $tabs        = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS  &amp; HTML', 'autoptimize' ) ) );
860
+        $tabs        = apply_filters('autoptimize_filter_settingsscreen_tabs', array('autoptimize' => __('JS, CSS  &amp; HTML', 'autoptimize')));
861 861
         $tab_content = '';
862
-        $tabs_count  = count( $tabs );
863
-        if ( $tabs_count > 1 ) {
864
-            if ( isset( $_GET['page'] ) ) {
862
+        $tabs_count  = count($tabs);
863
+        if ($tabs_count > 1) {
864
+            if (isset($_GET['page'])) {
865 865
                 $current_id = $_GET['page'];
866 866
             } else {
867 867
                 $current_id = 'autoptimize';
868 868
             }
869 869
             $tab_content .= '<h2 class="nav-tab-wrapper">';
870
-            foreach ( $tabs as $tab_id => $tab_name ) {
871
-                if ( $current_id == $tab_id ) {
870
+            foreach ($tabs as $tab_id => $tab_name) {
871
+                if ($current_id == $tab_id) {
872 872
                     $class = ' nav-tab-active';
873 873
                 } else {
874 874
                     $class = '';
875 875
                 }
876
-                $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
876
+                $tab_content .= '<a class="nav-tab'.$class.'" href="?page='.$tab_id.'">'.$tab_name.'</a>';
877 877
             }
878 878
             $tab_content .= '</h2>';
879 879
         } else {
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public static function is_admin_and_not_ajax()
892 892
     {
893
-        return ( is_admin() && ! self::doing_ajax() );
893
+        return (is_admin() && !self::doing_ajax());
894 894
     }
895 895
 
896 896
     /**
@@ -900,10 +900,10 @@  discard block
 block discarded – undo
900 900
      */
901 901
     protected static function doing_ajax()
902 902
     {
903
-        if ( function_exists( 'wp_doing_ajax' ) ) {
903
+        if (function_exists('wp_doing_ajax')) {
904 904
             return wp_doing_ajax();
905 905
         }
906
-        return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
906
+        return (defined('DOING_AJAX') && DOING_AJAX);
907 907
     }
908 908
 
909 909
     /**
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
      * @return bool
913 913
      */
914 914
     public static function should_show_menu_tabs() {
915
-        if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
915
+        if (!is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option('autoptimize_enable_site_config')) {
916 916
             return true;
917 917
         } else {
918 918
             return false;
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['rlimit']     = get_option( 'autoptimize_ccss_rlimit' );
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['rlimit']     = get_option('autoptimize_ccss_rlimit');
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_rlimit', $settings['rlimit'] );
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_rlimit', $settings['rlimit']);
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/autoptimizeCriticalCSSSettings.php 1 patch
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Critical CSS Options page.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct()
19 19
     {
20
-        $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
20
+        $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http);
21 21
         $this->run();
22 22
     }
23 23
 
24 24
     protected function enabled()
25 25
     {
26
-        return apply_filters( 'autoptimize_filter_show_criticalcss_tabs', true );
26
+        return apply_filters('autoptimize_filter_show_criticalcss_tabs', true);
27 27
     }
28 28
 
29 29
     public function run()
30 30
     {
31
-        if ( $this->enabled() ) {
32
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 );
33
-            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
31
+        if ($this->enabled()) {
32
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1);
33
+            add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
34 34
 
35
-            if ( $this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
36
-                add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) );
35
+            if ($this->is_multisite_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
36
+                add_action('network_admin_menu', array($this, 'add_critcss_admin_menu'));
37 37
             } else {
38
-                add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) );
38
+                add_action('admin_menu', array($this, 'add_critcss_admin_menu'));
39 39
             }
40 40
 
41 41
             $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax();
42 42
         }
43 43
     }
44 44
 
45
-    public function add_critcss_tabs( $in )
45
+    public function add_critcss_tabs($in)
46 46
     {
47
-        $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) );
47
+        $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize')));
48 48
 
49 49
         return $in;
50 50
     }
@@ -52,66 +52,66 @@  discard block
 block discarded – undo
52 52
     public function add_critcss_admin_menu()
53 53
     {
54 54
         // Register settings.
55
-        register_setting( 'ao_ccss_options_group', 'autoptimize_css_defer_inline' );
56
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rules' );
57
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' );
58
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' );
59
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' );
60
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' );
61
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rlimit' );
62
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' );
63
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' );
64
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' );
65
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' );
66
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_loggedin' );
67
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_forcepath' );
68
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_deferjquery' );
69
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' );
70
-        register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' );
55
+        register_setting('ao_ccss_options_group', 'autoptimize_css_defer_inline');
56
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rules');
57
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_additional');
58
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_queue');
59
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_viewport');
60
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_finclude');
61
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_rlimit');
62
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_noptimize');
63
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_debug');
64
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_key');
65
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_keyst');
66
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_loggedin');
67
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_forcepath');
68
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_deferjquery');
69
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_domain');
70
+        register_setting('ao_ccss_options_group', 'autoptimize_ccss_unloadccss');
71 71
 
72 72
         // And add submenu-page.
73
-        add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) );
73
+        add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page'));
74 74
     }
75 75
 
76
-    public function admin_assets( $hook ) {
76
+    public function admin_assets($hook) {
77 77
         // Return if plugin is not hooked.
78
-        if ( 'settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook ) {
78
+        if ('settings_page_ao_critcss' != $hook && 'admin_page_ao_critcss' != $hook) {
79 79
             return;
80 80
         }
81 81
 
82 82
         // Stylesheets to add.
83
-        wp_enqueue_style( 'wp-jquery-ui-dialog' );
84
-        wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) );
85
-        wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) );
83
+        wp_enqueue_style('wp-jquery-ui-dialog');
84
+        wp_enqueue_style('ao-tablesorter', plugins_url('critcss-inc/css/ao-tablesorter/style.css', __FILE__));
85
+        wp_enqueue_style('ao-ccss-admin-css', plugins_url('critcss-inc/css/admin_styles.css', __FILE__));
86 86
 
87 87
         // Scripts to add.
88
-        wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) );
89
-        wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true );
90
-        wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true );
91
-        wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true );
88
+        wp_enqueue_script('jquery-ui-dialog', array('jquery'));
89
+        wp_enqueue_script('md5', plugins_url('critcss-inc/js/md5.min.js', __FILE__), null, null, true);
90
+        wp_enqueue_script('tablesorter', plugins_url('critcss-inc/js/jquery.tablesorter.min.js', __FILE__), array('jquery'), null, true);
91
+        wp_enqueue_script('ao-ccss-admin-license', plugins_url('critcss-inc/js/admin_settings.js', __FILE__), array('jquery'), null, true);
92 92
     }
93 93
 
94 94
     public function ao_criticalcsssettings_page()
95 95
     {
96 96
         // these are not OO yet, simply require for now.
97
-        require_once( 'critcss-inc/admin_settings_rules.php' );
98
-        require_once( 'critcss-inc/admin_settings_queue.php' );
99
-        require_once( 'critcss-inc/admin_settings_key.php' );
100
-        require_once( 'critcss-inc/admin_settings_adv.php' );
101
-        require_once( 'critcss-inc/admin_settings_explain.php' );
97
+        require_once('critcss-inc/admin_settings_rules.php');
98
+        require_once('critcss-inc/admin_settings_queue.php');
99
+        require_once('critcss-inc/admin_settings_key.php');
100
+        require_once('critcss-inc/admin_settings_adv.php');
101
+        require_once('critcss-inc/admin_settings_explain.php');
102 102
 
103 103
         // fetch all options at once and populate them individually explicitely as globals.
104 104
         $all_options = autoptimizeCriticalCSSBase::fetch_options();
105
-        foreach ( $all_options as $_option => $_value ) {
105
+        foreach ($all_options as $_option => $_value) {
106 106
             global ${$_option};
107 107
             ${$_option} = $_value;
108 108
         }
109 109
         ?>
110
-        <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script>
110
+        <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script>
111 111
         <div class="wrap">
112 112
             <div id="autoptimize_main">
113 113
                 <div id="ao_title_and_button">
114
-                    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
114
+                    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
115 115
                 </div>
116 116
 
117 117
                 <?php
@@ -119,36 +119,36 @@  discard block
 block discarded – undo
119 119
                 echo autoptimizeConfig::ao_admin_tabs();
120 120
 
121 121
                 // Make sure dir to write ao_ccss exists and is writable.
122
-                if ( ! is_dir( AO_CCSS_DIR ) ) {
123
-                    $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine
122
+                if (!is_dir(AO_CCSS_DIR)) {
123
+                    $mkdirresp = @mkdir(AO_CCSS_DIR, 0775, true); // @codingStandardsIgnoreLine
124 124
                 } else {
125 125
                     $mkdirresp = true;
126 126
                 }
127 127
 
128 128
                 // Make sure our index.html is there.
129
-                if ( ! is_file( AO_CCSS_DIR . 'index.html' ) ) {
130
-                    $fileresp = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' );
129
+                if (!is_file(AO_CCSS_DIR.'index.html')) {
130
+                    $fileresp = file_put_contents(AO_CCSS_DIR.'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>');
131 131
                 } else {
132 132
                     $fileresp = true;
133 133
                 }
134 134
 
135 135
                 // Warn if we could not create those files.
136
-                if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) {
136
+                if ((!$mkdirresp) || (!$fileresp)) {
137 137
                     ?>
138 138
                     <div class="notice-error notice"><p>
139 139
                     <?php
140
-                    _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' );
140
+                    _e('Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize');
141 141
                     ?>
142 142
                     </p></div>
143 143
                     <?php
144 144
                 }
145 145
 
146 146
                 // Check for Autoptimize.
147
-                if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) {
147
+                if (!empty($ao_ccss_key) && !$ao_css_defer) {
148 148
                     ?>
149 149
                     <div class="notice-error notice"><p>
150 150
                     <?php
151
-                    _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' );
151
+                    _e("Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize');
152 152
                     ?>
153 153
                     </p></div>
154 154
                     <?php
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
                 }
157 157
 
158 158
                 // check if WordPress cron is disabled and warn if so.
159
-                if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) {
159
+                if (!empty($ao_ccss_key) && defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && PAnD::is_admin_notice_active('i-know-about-disable-cron-forever')) {
160 160
                     ?>
161 161
                     <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p>
162 162
                     <?php
163
-                    _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
163
+                    _e('WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
164 164
                     ?>
165 165
                     </p></div>
166 166
                     <?php
@@ -168,24 +168,24 @@  discard block
 block discarded – undo
168 168
 
169 169
                 // warn if it looks as though the queue processing job looks isn't running
170 170
                 // but store result in transient as to not to have to go through 2 arrays each and every time.
171
-                $_warn_cron = get_transient( 'ao_ccss_cronwarning' );
172
-                if ( ! empty( $ao_ccss_key ) && false === $_warn_cron ) {
171
+                $_warn_cron = get_transient('ao_ccss_cronwarning');
172
+                if (!empty($ao_ccss_key) && false === $_warn_cron) {
173 173
                     $_jobs_all_new         = true;
174
-                    $_oldest_job_timestamp = microtime( true ); // now.
174
+                    $_oldest_job_timestamp = microtime(true); // now.
175 175
                     $_jobs_too_old         = true;
176 176
 
177 177
                     // go over queue array.
178
-                    if ( empty( $ao_ccss_queue ) ) {
178
+                    if (empty($ao_ccss_queue)) {
179 179
                         // no jobs, then no warning.
180 180
                         $_jobs_all_new = false;
181 181
                     } else {
182
-                        foreach ( $ao_ccss_queue as $job ) {
183
-                            if ( $job['jctime'] < $_oldest_job_timestamp ) {
182
+                        foreach ($ao_ccss_queue as $job) {
183
+                            if ($job['jctime'] < $_oldest_job_timestamp) {
184 184
                                 // we need to catch the oldest job's timestamp.
185 185
                                 $_oldest_job_timestamp = $job['jctime'];
186 186
                             }
187 187
 
188
-                            if ( 'NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid'] ) {
188
+                            if ('NEW' !== $job['jqstat'] && 'firstrun' !== $job['ljid']) {
189 189
                                 // we have a non-"NEW" job which is not our pending firstrun job either, break the loop.
190 190
                                 $_jobs_all_new = false;
191 191
                                 break;
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
                     }
195 195
 
196 196
                     // is the oldest job too old (4h)?
197
-                    if ( $_oldest_job_timestamp > microtime( true ) - 60 * 60 * 4 ) {
197
+                    if ($_oldest_job_timestamp > microtime(true) - 60*60*4) {
198 198
                         $_jobs_too_old = false;
199 199
                     }
200 200
 
201
-                    if ( $_jobs_all_new && ! $this->ao_ccss_has_autorules() && $_jobs_too_old ) {
201
+                    if ($_jobs_all_new && !$this->ao_ccss_has_autorules() && $_jobs_too_old) {
202 202
                         $_warn_cron            = 'on';
203 203
                         $_transient_multiplier = 1; // store for 1 hour.
204 204
                     } else {
@@ -206,33 +206,33 @@  discard block
 block discarded – undo
206 206
                         $_transient_multiplier = 4; // store for 4 hours.
207 207
                     }
208 208
                     // and set transient.
209
-                    set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS );
209
+                    set_transient('ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier*HOUR_IN_SECONDS);
210 210
                 }
211 211
 
212
-                if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) {
212
+                if (!empty($ao_ccss_key) && 'on' == $_warn_cron && PAnD::is_admin_notice_active('i-know-about-cron-1')) {
213 213
                     ?>
214 214
                     <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p>
215 215
                     <?php
216
-                    _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' );
216
+                    _e('It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize');
217 217
                     ?>
218 218
                     </p></div>
219 219
                     <?php
220
-                } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) {
220
+                } elseif (!empty($ao_ccss_key) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && !$this->ao_ccss_has_autorules()) {
221 221
                     ?>
222 222
                     <div class="notice-success notice"><p>
223 223
                     <?php
224
-                    _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' );
224
+                    _e('Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize');
225 225
                     ?>
226 226
                     </p></div>
227 227
                     <?php
228 228
                 }
229 229
 
230 230
                 // warn if service is down.
231
-                if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) {
231
+                if (!empty($ao_ccss_key) && !empty($ao_ccss_servicestatus) && is_array($ao_ccss_servicestatus) && 'down' === $ao_ccss_servicestatus['critcss']['status']) {
232 232
                     ?>
233 233
                     <div class="notice-warning notice"><p>
234 234
                     <?php
235
-                    _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' );
235
+                    _e('The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize');
236 236
                     ?>
237 237
                     </p></div>
238 238
                     <?php
@@ -242,24 +242,24 @@  discard block
 block discarded – undo
242 242
                 ?>
243 243
                 <form id="settings" method="post" action="options.php">
244 244
                     <?php
245
-                    settings_fields( 'ao_ccss_options_group' );
245
+                    settings_fields('ao_ccss_options_group');
246 246
 
247 247
                     // Get API key status.
248
-                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true );
248
+                    $key = autoptimizeCriticalCSSCore::ao_ccss_key_status(true);
249 249
 
250
-                    if ( $this->is_multisite_network_admin() ) {
250
+                    if ($this->is_multisite_network_admin()) {
251 251
                         ?>
252 252
                         <ul id="key-panel">
253 253
                             <li class="itemDetail">
254 254
                             <?php
255 255
                                 // translators: the placesholder is for a line of code in wp-config.php.
256
-                                echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' );
256
+                                echo sprintf(__('<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize'), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>');
257 257
                             ?>
258 258
                             </li>
259 259
                         </ul>
260 260
                         <?php
261 261
                     } else {
262
-                        if ( 'valid' == $key['status'] ) {
262
+                        if ('valid' == $key['status']) {
263 263
                             // If key status is valid, render other panels.
264 264
                             // Render rules section.
265 265
                             ao_ccss_render_rules();
@@ -276,23 +276,23 @@  discard block
 block discarded – undo
276 276
                             $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport();
277 277
 
278 278
                             // Add hidden fields.
279
-                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>";
280
-                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>";
281
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">';
282
-                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">';
283
-                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">';
284
-                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">';
285
-                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">';
286
-                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">';
287
-                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">';
288
-                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">';
289
-                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">';
279
+                            echo "<input class='hidden' name='autoptimize_ccss_rules' value='".$ao_ccss_rules_raw."'>";
280
+                            echo "<input class='hidden' name='autoptimize_ccss_queue' value='".$ao_ccss_queue_raw."'>";
281
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="'.$viewport['w'].'">';
282
+                            echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="'.$viewport['h'].'">';
283
+                            echo '<input class="hidden" name="autoptimize_ccss_finclude" value="'.$ao_ccss_finclude.'">';
284
+                            echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="'.$ao_ccss_rlimit.'">';
285
+                            echo '<input class="hidden" name="autoptimize_ccss_debug" value="'.$ao_ccss_debug.'">';
286
+                            echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="'.$ao_ccss_noptimize.'">';
287
+                            echo '<input class="hidden" name="autoptimize_css_defer_inline" value="'.esc_attr($ao_css_defer_inline).'">';
288
+                            echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="'.$ao_ccss_loggedin.'">';
289
+                            echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="'.$ao_ccss_forcepath.'">';
290 290
                         }
291 291
                         // Render key panel unconditionally.
292
-                        ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] );
292
+                        ao_ccss_render_key($ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color']);
293 293
                         ?>
294 294
                         <p class="submit left">
295
-                            <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
295
+                            <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" />
296 296
                         </p>
297 297
                         <?php
298 298
                     }
@@ -310,31 +310,31 @@  discard block
 block discarded – undo
310 310
                     });
311 311
                 }
312 312
                 </script>
313
-                <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>>
314
-                    <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span>
315
-                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" />
313
+                <form id="importSettingsForm"<?php if ($this->is_multisite_network_admin()) { echo ' class="hidden"'; } ?>>
314
+                    <span id="exportSettings" class="button-secondary"><?php _e('Export Settings', 'autoptimize'); ?></span>
315
+                    <input class="button-secondary" id="importSettings" type="button" value="<?php _e('Import Settings', 'autoptimize'); ?>" onclick="upload();return false;" />
316 316
                     <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" />
317 317
                 </form>
318 318
                 <div id="importdialog"></div>
319 319
             </div><!-- /#autoptimize_main -->
320 320
         </div><!-- /#wrap -->
321 321
         <?php
322
-        if ( ! $this->is_multisite_network_admin() ) {
322
+        if (!$this->is_multisite_network_admin()) {
323 323
             // Include debug panel if debug mode is enable.
324
-            if ( $ao_ccss_debug ) {
324
+            if ($ao_ccss_debug) {
325 325
             ?>
326 326
                 <div id="debug">
327 327
                     <?php
328 328
                     // Include debug panel.
329
-                    include( 'critcss-inc/admin_settings_debug.php' );
329
+                    include('critcss-inc/admin_settings_debug.php');
330 330
                     ?>
331 331
                 </div><!-- /#debug -->
332 332
             <?php
333 333
             }
334 334
             echo '<script>';
335
-            include( 'critcss-inc/admin_settings_rules.js.php' );
336
-            include( 'critcss-inc/admin_settings_queue.js.php' );
337
-            include( 'critcss-inc/admin_settings_impexp.js.php' );
335
+            include('critcss-inc/admin_settings_rules.js.php');
336
+            include('critcss-inc/admin_settings_queue.js.php');
337
+            include('critcss-inc/admin_settings_impexp.js.php');
338 338
             echo '</script>';
339 339
         }
340 340
     }
@@ -342,19 +342,19 @@  discard block
 block discarded – undo
342 342
     public static function ao_ccss_has_autorules() {
343 343
         static $_has_auto_rules = null;
344 344
 
345
-        if ( null === $_has_auto_rules ) {
345
+        if (null === $_has_auto_rules) {
346 346
             global $ao_ccss_rules;
347 347
             $_has_auto_rules = false;
348
-            if ( ! empty( $ao_ccss_rules ) ) {
349
-                foreach ( array( 'types', 'paths' ) as $_typat ) {
350
-                    foreach ( $ao_ccss_rules[ $_typat ] as $rule ) {
351
-                        if ( ! empty( $rule['hash'] ) ) {
348
+            if (!empty($ao_ccss_rules)) {
349
+                foreach (array('types', 'paths') as $_typat) {
350
+                    foreach ($ao_ccss_rules[$_typat] as $rule) {
351
+                        if (!empty($rule['hash'])) {
352 352
                             // we have at least one AUTO job, so all is fine.
353 353
                             $_has_auto_rules = true;
354 354
                             break;
355 355
                         }
356 356
                     }
357
-                    if ( $_has_auto_rules ) {
357
+                    if ($_has_auto_rules) {
358 358
                         break;
359 359
                     }
360 360
                 }
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
     public function is_multisite_network_admin() {
368 368
         static $_multisite_network_admin = null;
369 369
 
370
-        if ( null === $_multisite_network_admin ) {
371
-            if ( is_multisite() && is_network_admin() ) {
370
+        if (null === $_multisite_network_admin) {
371
+            if (is_multisite() && is_network_admin()) {
372 372
                 $_multisite_network_admin = true;
373 373
             } else {
374 374
                 $_multisite_network_admin = false;
Please login to merge, or discard this patch.
classes/autoptimizeMain.php 1 patch
Spacing   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @param string $version Version.
34 34
      * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks.
35 35
      */
36
-    public function __construct( $version, $filepath )
36
+    public function __construct($version, $filepath)
37 37
     {
38 38
         $this->version  = $version;
39 39
         $this->filepath = $filepath;
@@ -50,101 +50,101 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected function add_hooks()
52 52
     {
53
-        if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) {
54
-            define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' );
53
+        if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) {
54
+            define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded');
55 55
         }
56 56
 
57
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) );
58
-        add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) );
57
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup'));
58
+        add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge'));
59 59
 
60
-        add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) );
61
-        add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) );
62
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ), 15 );
63
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ), 20 );
64
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss' ), 11 );
65
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_notfound_fallback' ), 10 );
60
+        add_action('autoptimize_setup_done', array($this, 'version_upgrades_check'));
61
+        add_action('autoptimize_setup_done', array($this, 'check_cache_and_run'));
62
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'), 15);
63
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'), 20);
64
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_criticalcss'), 11);
65
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_notfound_fallback'), 10);
66 66
 
67
-        add_action( 'init', array( $this, 'load_textdomain' ) );
67
+        add_action('init', array($this, 'load_textdomain'));
68 68
 
69
-        if ( is_multisite() && is_admin() ) {
69
+        if (is_multisite() && is_admin()) {
70 70
             // Only if multisite and if in admin we want to check if we need to save options on network level.
71
-            add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' );
71
+            add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options');
72 72
         }
73 73
 
74 74
         // register uninstall & deactivation hooks.
75
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
76
-        register_deactivation_hook( $this->filepath, 'autoptimizeMain::on_deactivation' );
75
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
76
+        register_deactivation_hook($this->filepath, 'autoptimizeMain::on_deactivation');
77 77
     }
78 78
 
79 79
     public function load_textdomain()
80 80
     {
81
-        load_plugin_textdomain( 'autoptimize' );
81
+        load_plugin_textdomain('autoptimize');
82 82
     }
83 83
 
84 84
     public function setup()
85 85
     {
86 86
         // Do we gzip in php when caching or is the webserver doing it?
87
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) );
87
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip'));
88 88
 
89 89
         // These can be overridden by specifying them in wp-config.php or such.
90
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
91
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
90
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
91
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
92 92
         }
93
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
94
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
93
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
94
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
95 95
         }
96
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
97
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
96
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
97
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
98 98
         }
99 99
         // Note: trailing slash is not optional!
100
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
101
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
100
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
101
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
102 102
         }
103 103
 
104
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
104
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
105 105
 
106
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
107
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
108
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
106
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
107
+            if (function_exists('domain_mapping_siteurl')) {
108
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
109 109
             } else {
110
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
110
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
111 111
             }
112 112
         }
113
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
114
-            if ( function_exists( 'get_original_url' ) ) {
115
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
113
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
114
+            if (function_exists('get_original_url')) {
115
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
116 116
             } else {
117
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
117
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
118 118
             }
119 119
         }
120
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
121
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
120
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
121
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
122 122
                 $blog_id = get_current_blog_id();
123
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
123
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
124 124
             } else {
125
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
125
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
126 126
             }
127 127
         }
128
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
129
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
128
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
129
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
130 130
         }
131
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
132
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
131
+        if (!defined('AUTOPTIMIZE_HASH')) {
132
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
133 133
         }
134
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
135
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
134
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
135
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
136 136
         }
137 137
 
138 138
         // Multibyte-capable string replacements are available with a filter.
139 139
         // Also requires 'mbstring' extension.
140
-        $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false );
141
-        if ( $with_mbstring ) {
142
-            autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) );
140
+        $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false);
141
+        if ($with_mbstring) {
142
+            autoptimizeUtils::mbstring_available(\extension_loaded('mbstring'));
143 143
         } else {
144
-            autoptimizeUtils::mbstring_available( false );
144
+            autoptimizeUtils::mbstring_available(false);
145 145
         }
146 146
 
147
-        do_action( 'autoptimize_setup_done' );
147
+        do_action('autoptimize_setup_done');
148 148
     }
149 149
 
150 150
     /**
@@ -154,61 +154,61 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public function version_upgrades_check()
156 156
     {
157
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
157
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
158 158
     }
159 159
 
160 160
     public function check_cache_and_run()
161 161
     {
162
-        if ( autoptimizeCache::cacheavail() ) {
162
+        if (autoptimizeCache::cacheavail()) {
163 163
             $conf = autoptimizeConfig::instance();
164
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) {
165
-                if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) {
164
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) {
165
+                if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) {
166 166
                     // Hook into WordPress frontend.
167
-                    if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
167
+                    if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
168 168
                         add_action(
169 169
                             'init',
170
-                            array( $this, 'start_buffering' ),
170
+                            array($this, 'start_buffering'),
171 171
                             self::INIT_EARLIER_PRIORITY
172 172
                         );
173 173
                     } else {
174
-                        if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
175
-                            define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
174
+                        if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
175
+                            define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
176 176
                         }
177 177
                         add_action(
178
-                            constant( 'AUTOPTIMIZE_HOOK_INTO' ),
179
-                            array( $this, 'start_buffering' ),
178
+                            constant('AUTOPTIMIZE_HOOK_INTO'),
179
+                            array($this, 'start_buffering'),
180 180
                             self::DEFAULT_HOOK_PRIORITY
181 181
                         );
182 182
                     }
183 183
                 }
184 184
 
185 185
                 // And disable Jetpack's site accelerator if JS or CSS opt. are active.
186
-                if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) {
187
-                    add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' );
186
+                if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) {
187
+                    add_filter('jetpack_force_disable_site_accelerator', '__return_true');
188 188
                 }
189 189
             }
190 190
         } else {
191
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
191
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
192 192
         }
193 193
     }
194 194
 
195 195
     public function maybe_run_ao_extra()
196 196
     {
197
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
197
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
198 198
             $ao_imgopt = new autoptimizeImages();
199 199
             $ao_imgopt->run();
200 200
             $ao_extra = new autoptimizeExtra();
201 201
             $ao_extra->run();
202 202
 
203 203
             // And show the imgopt notice.
204
-            add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' );
204
+            add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt');
205 205
         }
206 206
     }
207 207
 
208 208
     public function maybe_run_partners_tab()
209 209
     {
210 210
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
211
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
211
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
212 212
             new autoptimizePartners();
213 213
         }
214 214
     }
@@ -216,22 +216,22 @@  discard block
 block discarded – undo
216 216
     public function maybe_run_criticalcss()
217 217
     {
218 218
         // Loads criticalcss if the power-up is not active and if the filter returns true.
219
-        if ( apply_filters( 'autoptimize_filter_criticalcss_active', true ) && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
219
+        if (apply_filters('autoptimize_filter_criticalcss_active', true) && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) {
220 220
             new autoptimizeCriticalCSSBase();
221 221
         }
222 222
     }
223 223
 
224 224
     public function maybe_run_notfound_fallback()
225 225
     {
226
-        if ( autoptimizeCache::do_fallback() ) {
227
-            add_action( 'template_redirect', array( 'autoptimizeCache', 'wordpress_notfound_fallback' ) );
226
+        if (autoptimizeCache::do_fallback()) {
227
+            add_action('template_redirect', array('autoptimizeCache', 'wordpress_notfound_fallback'));
228 228
         }
229 229
     }
230 230
 
231 231
     public function hook_page_cache_purge()
232 232
     {
233 233
         // hook into a collection of page cache purge actions if filter allows.
234
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
234
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
235 235
             $page_cache_purge_actions = array(
236 236
                 'after_rocket_clean_domain', // exists.
237 237
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
                 'wpo_cache_flush', // wp-optimize.
247 247
                 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper.
248 248
             );
249
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
250
-            foreach ( $page_cache_purge_actions as $purge_action ) {
251
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
249
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
250
+            foreach ($page_cache_purge_actions as $purge_action) {
251
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
252 252
             }
253 253
         }
254 254
     }
@@ -260,38 +260,38 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function start_buffering()
262 262
     {
263
-        if ( $this->should_buffer() ) {
263
+        if ($this->should_buffer()) {
264 264
 
265 265
             // Load speedupper conditionally (true by default).
266
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
266
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
267 267
                 $ao_speedupper = new autoptimizeSpeedupper();
268 268
             }
269 269
 
270 270
             $conf = autoptimizeConfig::instance();
271 271
 
272
-            if ( $conf->get( 'autoptimize_js' ) ) {
273
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
274
-                    define( 'CONCATENATE_SCRIPTS', false );
272
+            if ($conf->get('autoptimize_js')) {
273
+                if (!defined('CONCATENATE_SCRIPTS')) {
274
+                    define('CONCATENATE_SCRIPTS', false);
275 275
                 }
276
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
277
-                    define( 'COMPRESS_SCRIPTS', false );
276
+                if (!defined('COMPRESS_SCRIPTS')) {
277
+                    define('COMPRESS_SCRIPTS', false);
278 278
                 }
279 279
             }
280 280
 
281
-            if ( $conf->get( 'autoptimize_css' ) ) {
282
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
283
-                    define( 'COMPRESS_CSS', false );
281
+            if ($conf->get('autoptimize_css')) {
282
+                if (!defined('COMPRESS_CSS')) {
283
+                    define('COMPRESS_CSS', false);
284 284
                 }
285 285
             }
286 286
 
287
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
288
-                while ( ob_get_level() > 0 ) {
287
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
288
+                while (ob_get_level() > 0) {
289 289
                     ob_end_clean();
290 290
                 }
291 291
             }
292 292
 
293 293
             // Now, start the real thing!
294
-            ob_start( array( $this, 'end_buffering' ) );
294
+            ob_start(array($this, 'end_buffering'));
295 295
         }
296 296
     }
297 297
 
@@ -302,31 +302,31 @@  discard block
 block discarded – undo
302 302
      *                          deciding once per request (for use in tests).
303 303
      * @return bool
304 304
      */
305
-    public static function should_buffer( $doing_tests = false )
305
+    public static function should_buffer($doing_tests = false)
306 306
     {
307 307
         static $do_buffering = null;
308 308
 
309 309
         // Only check once in case we're called multiple times by others but
310 310
         // still allows multiple calls when doing tests.
311
-        if ( null === $do_buffering || $doing_tests ) {
311
+        if (null === $do_buffering || $doing_tests) {
312 312
 
313 313
             $ao_noptimize = false;
314 314
 
315 315
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
316
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
316
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
317 317
                 $ao_noptimize = true;
318 318
             }
319 319
 
320 320
             // Skip checking query strings if they're disabled.
321
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
321
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
322 322
                 // Check for `ao_noptimize` (and other) keys in the query string
323 323
                 // to get non-optimized page for debugging.
324 324
                 $keys = array(
325 325
                     'ao_noptimize',
326 326
                     'ao_noptirocket',
327 327
                 );
328
-                foreach ( $keys as $key ) {
329
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
328
+                foreach ($keys as $key) {
329
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
330 330
                         $ao_noptimize = true;
331 331
                         break;
332 332
                     }
@@ -334,15 +334,15 @@  discard block
 block discarded – undo
334 334
             }
335 335
 
336 336
             // If setting says not to optimize logged in user and user is logged in...
337
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
337
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
338 338
                 $ao_noptimize = true;
339 339
             }
340 340
 
341 341
             // If setting says not to optimize cart/checkout.
342
-            if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) {
342
+            if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) {
343 343
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
344
-                foreach ( array( 'is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
345
-                    if ( function_exists( $func ) && $func() ) {
344
+                foreach (array('is_checkout', 'is_cart', 'is_account_page', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
345
+                    if (function_exists($func) && $func()) {
346 346
                         $ao_noptimize = true;
347 347
                         break;
348 348
                     }
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
             }
351 351
 
352 352
             // And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
353
-            if ( false === $ao_noptimize ) {
354
-                $_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
355
-                foreach ( $_qs_pagebuilders as $_pagebuilder ) {
356
-                    if ( array_key_exists( $_pagebuilder, $_GET ) ) {
353
+            if (false === $ao_noptimize) {
354
+                $_qs_pagebuilders = array('tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor');
355
+                foreach ($_qs_pagebuilders as $_pagebuilder) {
356
+                    if (array_key_exists($_pagebuilder, $_GET)) {
357 357
                         $ao_noptimize = true;
358 358
                         break;
359 359
                     }
@@ -362,16 +362,16 @@  discard block
 block discarded – undo
362 362
 
363 363
             // Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
364 364
             // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
365
-            if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
365
+            if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) {
366 366
                 $ao_noptimize = true;
367 367
             }
368 368
 
369 369
             // And finally allows blocking of autoptimization on your own terms regardless of above decisions.
370
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
370
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
371 371
 
372 372
             // Check for site being previewed in the Customizer (available since WP 4.0).
373 373
             $is_customize_preview = false;
374
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
374
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
375 375
                 $is_customize_preview = is_customize_preview();
376 376
             }
377 377
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
              * while the main query hasn't been ran yet. Thats why we use
383 383
              * AUTOPTIMIZE_INIT_EARLIER in tests.
384 384
              */
385
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview );
385
+            $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview);
386 386
         }
387 387
 
388 388
         return $do_buffering;
@@ -395,25 +395,25 @@  discard block
 block discarded – undo
395 395
      *
396 396
      * @return bool
397 397
      */
398
-    public function is_valid_buffer( $content )
398
+    public function is_valid_buffer($content)
399 399
     {
400 400
         // Defaults to true.
401 401
         $valid = true;
402 402
 
403
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
404
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) );
405
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 );
406
-        $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) );
403
+        $has_no_html_tag    = (false === stripos($content, '<html'));
404
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet'));
405
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0);
406
+        $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->'));
407 407
 
408
-        if ( $has_no_html_tag ) {
408
+        if ($has_no_html_tag) {
409 409
             // Can't be valid amp markup without an html tag preceding it.
410 410
             $is_amp_markup = false;
411 411
         } else {
412
-            $is_amp_markup = self::is_amp_markup( $content );
412
+            $is_amp_markup = self::is_amp_markup($content);
413 413
         }
414 414
 
415 415
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
416
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) {
416
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) {
417 417
             $valid = false;
418 418
         }
419 419
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
      *
429 429
      * @return bool
430 430
      */
431
-    public static function is_amp_markup( $content )
431
+    public static function is_amp_markup($content)
432 432
     {
433 433
         // Short-circuit if the page is already AMP from the start.
434 434
         if (
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
         }
447 447
 
448 448
         // Or else short-circuit if the AMP plugin will be processing the output to be an AMP page.
449
-        if ( function_exists( 'amp_is_request' ) ) {
449
+        if (function_exists('amp_is_request')) {
450 450
             return amp_is_request(); // For AMP plugin v2.0+.
451
-        } elseif ( function_exists( 'is_amp_endpoint' ) ) {
451
+        } elseif (function_exists('is_amp_endpoint')) {
452 452
             return is_amp_endpoint(); // For older/other AMP plugins (still supported in 2.0 as an alias).
453 453
         }
454 454
 
@@ -463,10 +463,10 @@  discard block
 block discarded – undo
463 463
      *
464 464
      * @return string
465 465
      */
466
-    public function end_buffering( $content )
466
+    public function end_buffering($content)
467 467
     {
468 468
         // Bail early without modifying anything if we can't handle the content.
469
-        if ( ! $this->is_valid_buffer( $content ) ) {
469
+        if (!$this->is_valid_buffer($content)) {
470 470
             return $content;
471 471
         }
472 472
 
@@ -474,73 +474,73 @@  discard block
 block discarded – undo
474 474
 
475 475
         // Determine what needs to be ran.
476 476
         $classes = array();
477
-        if ( $conf->get( 'autoptimize_js' ) ) {
477
+        if ($conf->get('autoptimize_js')) {
478 478
             $classes[] = 'autoptimizeScripts';
479 479
         }
480
-        if ( $conf->get( 'autoptimize_css' ) ) {
480
+        if ($conf->get('autoptimize_css')) {
481 481
             $classes[] = 'autoptimizeStyles';
482 482
         }
483
-        if ( $conf->get( 'autoptimize_html' ) ) {
483
+        if ($conf->get('autoptimize_html')) {
484 484
             $classes[] = 'autoptimizeHTML';
485 485
         }
486 486
 
487 487
         $classoptions = array(
488 488
             'autoptimizeScripts' => array(
489
-                'aggregate'       => $conf->get( 'autoptimize_js_aggregate' ),
490
-                'justhead'        => $conf->get( 'autoptimize_js_justhead' ),
491
-                'forcehead'       => $conf->get( 'autoptimize_js_forcehead' ),
492
-                'trycatch'        => $conf->get( 'autoptimize_js_trycatch' ),
493
-                'js_exclude'      => $conf->get( 'autoptimize_js_exclude' ),
494
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
495
-                'include_inline'  => $conf->get( 'autoptimize_js_include_inline' ),
496
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
489
+                'aggregate'       => $conf->get('autoptimize_js_aggregate'),
490
+                'justhead'        => $conf->get('autoptimize_js_justhead'),
491
+                'forcehead'       => $conf->get('autoptimize_js_forcehead'),
492
+                'trycatch'        => $conf->get('autoptimize_js_trycatch'),
493
+                'js_exclude'      => $conf->get('autoptimize_js_exclude'),
494
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
495
+                'include_inline'  => $conf->get('autoptimize_js_include_inline'),
496
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
497 497
             ),
498 498
             'autoptimizeStyles'  => array(
499
-                'aggregate'       => $conf->get( 'autoptimize_css_aggregate' ),
500
-                'justhead'        => $conf->get( 'autoptimize_css_justhead' ),
501
-                'datauris'        => $conf->get( 'autoptimize_css_datauris' ),
502
-                'defer'           => $conf->get( 'autoptimize_css_defer' ),
503
-                'defer_inline'    => $conf->get( 'autoptimize_css_defer_inline' ),
504
-                'inline'          => $conf->get( 'autoptimize_css_inline' ),
505
-                'css_exclude'     => $conf->get( 'autoptimize_css_exclude' ),
506
-                'cdn_url'         => $conf->get( 'autoptimize_cdn_url' ),
507
-                'include_inline'  => $conf->get( 'autoptimize_css_include_inline' ),
508
-                'nogooglefont'    => $conf->get( 'autoptimize_css_nogooglefont' ),
509
-                'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ),
499
+                'aggregate'       => $conf->get('autoptimize_css_aggregate'),
500
+                'justhead'        => $conf->get('autoptimize_css_justhead'),
501
+                'datauris'        => $conf->get('autoptimize_css_datauris'),
502
+                'defer'           => $conf->get('autoptimize_css_defer'),
503
+                'defer_inline'    => $conf->get('autoptimize_css_defer_inline'),
504
+                'inline'          => $conf->get('autoptimize_css_inline'),
505
+                'css_exclude'     => $conf->get('autoptimize_css_exclude'),
506
+                'cdn_url'         => $conf->get('autoptimize_cdn_url'),
507
+                'include_inline'  => $conf->get('autoptimize_css_include_inline'),
508
+                'nogooglefont'    => $conf->get('autoptimize_css_nogooglefont'),
509
+                'minify_excluded' => $conf->get('autoptimize_minify_excluded'),
510 510
             ),
511 511
             'autoptimizeHTML'    => array(
512
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
512
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
513 513
             ),
514 514
         );
515 515
 
516
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
516
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
517 517
 
518 518
         // Run the classes!
519
-        foreach ( $classes as $name ) {
520
-            $instance = new $name( $content );
521
-            if ( $instance->read( $classoptions[ $name ] ) ) {
519
+        foreach ($classes as $name) {
520
+            $instance = new $name($content);
521
+            if ($instance->read($classoptions[$name])) {
522 522
                 $instance->minify();
523 523
                 $instance->cache();
524 524
                 $content = $instance->getcontent();
525 525
             }
526
-            unset( $instance );
526
+            unset($instance);
527 527
         }
528 528
 
529
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
529
+        $content = apply_filters('autoptimize_html_after_minify', $content);
530 530
 
531 531
         return $content;
532 532
     }
533 533
 
534
-    public static function autoptimize_nobuffer_optimize( $html_in ) {
534
+    public static function autoptimize_nobuffer_optimize($html_in) {
535 535
         $html_out = $html_in;
536 536
 
537
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
537
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
538 538
             $ao_speedupper = new autoptimizeSpeedupper();
539 539
         }
540 540
 
541
-        $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE );
542
-        if ( $self->should_buffer() ) {
543
-            $html_out = $self->end_buffering( $html_in );
541
+        $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE);
542
+        if ($self->should_buffer()) {
543
+            $html_out = $self->end_buffering($html_in);
544 544
         }
545 545
         return $html_out;
546 546
     }
@@ -602,45 +602,45 @@  discard block
 block discarded – undo
602 602
             'autoptimize_ccss_unloadccss',
603 603
         );
604 604
 
605
-        if ( ! is_multisite() ) {
606
-            foreach ( $delete_options as $del_opt ) {
607
-                delete_option( $del_opt );
605
+        if (!is_multisite()) {
606
+            foreach ($delete_options as $del_opt) {
607
+                delete_option($del_opt);
608 608
             }
609 609
             autoptimizeMain::remove_cronjobs();
610 610
         } else {
611 611
             global $wpdb;
612
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
612
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
613 613
             $original_blog_id = get_current_blog_id();
614
-            foreach ( $blog_ids as $blog_id ) {
615
-                switch_to_blog( $blog_id );
616
-                foreach ( $delete_options as $del_opt ) {
617
-                    delete_option( $del_opt );
614
+            foreach ($blog_ids as $blog_id) {
615
+                switch_to_blog($blog_id);
616
+                foreach ($delete_options as $del_opt) {
617
+                    delete_option($del_opt);
618 618
                 }
619 619
                 autoptimizeMain::remove_cronjobs();
620 620
             }
621
-            switch_to_blog( $original_blog_id );
621
+            switch_to_blog($original_blog_id);
622 622
         }
623 623
 
624 624
         // Remove AO CCSS cached files and directory.
625
-        $ao_ccss_dir = WP_CONTENT_DIR . '/uploads/ao_ccss/';
626
-        if ( file_exists( $ao_ccss_dir ) && is_dir( $ao_ccss_dir ) ) {
625
+        $ao_ccss_dir = WP_CONTENT_DIR.'/uploads/ao_ccss/';
626
+        if (file_exists($ao_ccss_dir) && is_dir($ao_ccss_dir)) {
627 627
             // fixme: should check for subdirs when in multisite and remove contents of those as well.
628
-            array_map( 'unlink', glob( $ao_ccss_dir . '*.{css,html,json,log,zip,lock}', GLOB_BRACE ) );
629
-            rmdir( $ao_ccss_dir );
628
+            array_map('unlink', glob($ao_ccss_dir.'*.{css,html,json,log,zip,lock}', GLOB_BRACE));
629
+            rmdir($ao_ccss_dir);
630 630
         }
631 631
     }
632 632
 
633 633
     public static function on_deactivation()
634 634
     {
635
-        if ( is_multisite() && is_network_admin() ) {
635
+        if (is_multisite() && is_network_admin()) {
636 636
             global $wpdb;
637
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
637
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
638 638
             $original_blog_id = get_current_blog_id();
639
-            foreach ( $blog_ids as $blog_id ) {
640
-                switch_to_blog( $blog_id );
639
+            foreach ($blog_ids as $blog_id) {
640
+                switch_to_blog($blog_id);
641 641
                 autoptimizeMain::remove_cronjobs();
642 642
             }
643
-            switch_to_blog( $original_blog_id );
643
+            switch_to_blog($original_blog_id);
644 644
         } else {
645 645
             autoptimizeMain::remove_cronjobs();
646 646
         }
@@ -649,9 +649,9 @@  discard block
 block discarded – undo
649 649
 
650 650
     public static function remove_cronjobs() {
651 651
         // Remove scheduled events.
652
-        foreach ( array( 'ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance' ) as $_event ) {
653
-            if ( wp_get_schedule( $_event ) ) {
654
-                wp_clear_scheduled_hook( $_event );
652
+        foreach (array('ao_cachechecker', 'ao_ccss_queue', 'ao_ccss_maintenance') as $_event) {
653
+            if (wp_get_schedule($_event)) {
654
+                wp_clear_scheduled_hook($_event);
655 655
             }
656 656
         }
657 657
     }
@@ -660,35 +660,35 @@  discard block
 block discarded – undo
660 660
     {
661 661
         echo '<div class="error"><p>';
662 662
         // Translators: %s is the cache directory location.
663
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
663
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
664 664
         echo '</p></div>';
665 665
     }
666 666
 
667 667
     public static function notice_installed()
668 668
     {
669 669
         echo '<div class="updated"><p>';
670
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
670
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
671 671
         echo '</p></div>';
672 672
     }
673 673
 
674 674
     public static function notice_updated()
675 675
     {
676 676
         echo '<div class="updated"><p>';
677
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
677
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
678 678
         echo '</p></div>';
679 679
     }
680 680
 
681 681
     public static function notice_plug_imgopt()
682 682
     {
683 683
         // Translators: the URL added points to the Autopmize Extra settings.
684
-        $_ao_imgopt_plug_notice      = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' );
685
-        $_ao_imgopt_plug_notice      = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice );
684
+        $_ao_imgopt_plug_notice      = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>');
685
+        $_ao_imgopt_plug_notice      = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice);
686 686
         $_ao_imgopt_launch_ok        = autoptimizeImages::launch_ok_wrapper();
687 687
         $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123';
688 688
         $_ao_imgopt_active           = autoptimizeImages::imgopt_active();
689 689
 
690
-        if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) {
691
-            echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>';
690
+        if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) {
691
+            echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>';
692 692
             echo $_ao_imgopt_plug_notice;
693 693
             echo '</p></div>';
694 694
         }
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_rlimit']        = get_option( 'autoptimize_ccss_rlimit', '5' );
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_rlimit']        = get_option('autoptimize_ccss_rlimit', '5');
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/autoptimizeImages.php 1 patch
Spacing   +350 added lines, -350 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,17 +23,17 @@  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
     }
35 35
 
36
-    public function set_options( array $options )
36
+    public function set_options(array $options)
37 37
     {
38 38
         $this->options = $options;
39 39
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 
43 43
     public static function fetch_options()
44 44
     {
45
-        $value = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings' );
46
-        if ( empty( $value ) ) {
45
+        $value = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings');
46
+        if (empty($value)) {
47 47
             // Fallback to returning defaults when no stored option exists yet.
48 48
             $value = autoptimizeConfig::get_ao_imgopt_default_options();
49 49
         }
50 50
 
51 51
         // get service availability and add it to the options-array.
52
-        $value['availabilities'] = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
52
+        $value['availabilities'] = autoptimizeOptionWrapper::get_option('autoptimize_service_availablity');
53 53
 
54
-        if ( empty( $value['availabilities'] ) ) {
55
-            $value['availabilities'] = autoptimizeUtils::check_service_availability( true );
54
+        if (empty($value['availabilities'])) {
55
+            $value['availabilities'] = autoptimizeUtils::check_service_availability(true);
56 56
         }
57 57
 
58 58
         return $value;
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
         // and does not use/ request the availablity data (which could slow things down).
66 66
         static $imgopt_active = null;
67 67
 
68
-        if ( null === $imgopt_active ) {
69
-            $opts = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' );
70
-            if ( ! empty( $opts ) && is_array( $opts ) && array_key_exists( 'autoptimize_imgopt_checkbox_field_1', $opts ) && ! empty( $opts['autoptimize_imgopt_checkbox_field_1'] ) && '1' === $opts['autoptimize_imgopt_checkbox_field_1'] ) {
68
+        if (null === $imgopt_active) {
69
+            $opts = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', '');
70
+            if (!empty($opts) && is_array($opts) && array_key_exists('autoptimize_imgopt_checkbox_field_1', $opts) && !empty($opts['autoptimize_imgopt_checkbox_field_1']) && '1' === $opts['autoptimize_imgopt_checkbox_field_1']) {
71 71
                 $imgopt_active = true;
72 72
             } else {
73 73
                 $imgopt_active = false;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public static function instance()
89 89
     {
90
-        if ( null === self::$instance ) {
90
+        if (null === self::$instance) {
91 91
             self::$instance = new self();
92 92
         }
93 93
 
@@ -96,34 +96,34 @@  discard block
 block discarded – undo
96 96
 
97 97
     public function run()
98 98
     {
99
-        if ( is_admin() ) {
100
-            if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
101
-                add_action( 'network_admin_menu', array( $this, 'imgopt_admin_menu' ) );
99
+        if (is_admin()) {
100
+            if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) {
101
+                add_action('network_admin_menu', array($this, 'imgopt_admin_menu'));
102 102
             } else {
103
-                add_action( 'admin_menu', array( $this, 'imgopt_admin_menu' ) );
103
+                add_action('admin_menu', array($this, 'imgopt_admin_menu'));
104 104
             }
105
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_imgopt_tab' ), 9 );
105
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_imgopt_tab'), 9);
106 106
         } else {
107
-            add_action( 'wp', array( $this, 'run_on_frontend' ) );
107
+            add_action('wp', array($this, 'run_on_frontend'));
108 108
         }
109 109
     }
110 110
 
111 111
     public function run_on_frontend() {
112
-        if ( ! $this->should_run() ) {
113
-            if ( $this->should_lazyload() ) {
112
+        if (!$this->should_run()) {
113
+            if ($this->should_lazyload()) {
114 114
                 add_filter(
115 115
                     'wp_lazy_loading_enabled',
116 116
                     '__return_false'
117 117
                 );
118 118
                 add_filter(
119 119
                     'autoptimize_html_after_minify',
120
-                    array( $this, 'filter_lazyload_images' ),
120
+                    array($this, 'filter_lazyload_images'),
121 121
                     10,
122 122
                     1
123 123
                 );
124 124
                 add_action(
125 125
                     'wp_footer',
126
-                    array( $this, 'add_lazyload_js_footer' ),
126
+                    array($this, 'add_lazyload_js_footer'),
127 127
                     10,
128 128
                     0
129 129
                 );
@@ -133,43 +133,43 @@  discard block
 block discarded – undo
133 133
 
134 134
         $active = false;
135 135
 
136
-        if ( apply_filters( 'autoptimize_filter_imgopt_do', true ) ) {
136
+        if (apply_filters('autoptimize_filter_imgopt_do', true)) {
137 137
             add_filter(
138 138
                 'autoptimize_html_after_minify',
139
-                array( $this, 'filter_optimize_images' ),
139
+                array($this, 'filter_optimize_images'),
140 140
                 10,
141 141
                 1
142 142
             );
143 143
             $active = true;
144 144
         }
145 145
 
146
-        if ( apply_filters( 'autoptimize_filter_imgopt_do_css', true ) ) {
146
+        if (apply_filters('autoptimize_filter_imgopt_do_css', true)) {
147 147
             add_filter(
148 148
                 'autoptimize_filter_base_replace_cdn',
149
-                array( $this, 'filter_optimize_css_images' ),
149
+                array($this, 'filter_optimize_css_images'),
150 150
                 10,
151 151
                 1
152 152
             );
153 153
             $active = true;
154 154
         }
155 155
 
156
-        if ( $active ) {
156
+        if ($active) {
157 157
             add_filter(
158 158
                 'autoptimize_extra_filter_tobepreconn',
159
-                array( $this, 'filter_preconnect_imgopt_url' ),
159
+                array($this, 'filter_preconnect_imgopt_url'),
160 160
                 10,
161 161
                 1
162 162
             );
163 163
         }
164 164
 
165
-        if ( $this->should_lazyload() ) {
165
+        if ($this->should_lazyload()) {
166 166
             add_filter(
167 167
                 'wp_lazy_loading_enabled',
168 168
                 '__return_false'
169 169
             );
170 170
             add_action(
171 171
                 'wp_footer',
172
-                array( $this, 'add_lazyload_js_footer' ),
172
+                array($this, 'add_lazyload_js_footer'),
173 173
                 10,
174 174
                 0
175 175
             );
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
     protected function should_run()
185 185
     {
186 186
         $opts              = $this->options;
187
-        $service_not_down  = ( 'down' !== $opts['availabilities']['extra_imgopt']['status'] );
188
-        $not_launch_status = ( 'launch' !== $opts['availabilities']['extra_imgopt']['status'] );
187
+        $service_not_down  = ('down' !== $opts['availabilities']['extra_imgopt']['status']);
188
+        $not_launch_status = ('launch' !== $opts['availabilities']['extra_imgopt']['status']);
189 189
 
190 190
         $do_cdn      = true;
191 191
         $_userstatus = $this->get_imgopt_provider_userstatus();
192
-        if ( isset( $_userstatus['Status'] ) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] ) ) {
192
+        if (isset($_userstatus['Status']) && ( -2 == $_userstatus['Status'] || -3 == $_userstatus['Status'] )) {
193 193
             // don't even attempt to put images on CDN if heavily exceeded threshold or if site not reachable.
194 194
             $do_cdn = false;
195 195
         }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $this->imgopt_active()
199 199
             && $do_cdn
200 200
             && $service_not_down
201
-            && ( $not_launch_status || $this->launch_ok() )
201
+            && ($not_launch_status || $this->launch_ok())
202 202
         ) {
203 203
             return true;
204 204
         }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     {
210 210
         static $imgopt_host = null;
211 211
 
212
-        if ( null === $imgopt_host ) {
212
+        if (null === $imgopt_host) {
213 213
             $imgopt_host  = 'https://cdn.shortpixel.ai/';
214 214
             $avail_imgopt = $this->options['availabilities']['extra_imgopt'];
215
-            if ( ! empty( $avail_imgopt ) && array_key_exists( 'hosts', $avail_imgopt ) && is_array( $avail_imgopt['hosts'] ) ) {
216
-                $imgopt_host = array_rand( array_flip( $avail_imgopt['hosts'] ) );
215
+            if (!empty($avail_imgopt) && array_key_exists('hosts', $avail_imgopt) && is_array($avail_imgopt['hosts'])) {
216
+                $imgopt_host = array_rand(array_flip($avail_imgopt['hosts']));
217 217
             }
218
-            $imgopt_host = apply_filters( 'autoptimize_filter_imgopt_host', $imgopt_host );
218
+            $imgopt_host = apply_filters('autoptimize_filter_imgopt_host', $imgopt_host);
219 219
         }
220 220
 
221 221
         return $imgopt_host;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
     public static function get_service_url_suffix()
232 232
     {
233
-        $suffix = '/af/GWRGFLW109483/' . AUTOPTIMIZE_SITE_DOMAIN;
233
+        $suffix = '/af/GWRGFLW109483/'.AUTOPTIMIZE_SITE_DOMAIN;
234 234
 
235 235
         return $suffix;
236 236
     }
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
     {
240 240
         static $quality = null;
241 241
 
242
-        if ( null === $quality ) {
242
+        if (null === $quality) {
243 243
             $q_array = $this->get_img_quality_array();
244 244
             $setting = $this->get_img_quality_setting();
245 245
             $quality = apply_filters(
246 246
                 'autoptimize_filter_imgopt_quality',
247
-                'q_' . $q_array[ $setting ]
247
+                'q_'.$q_array[$setting]
248 248
             );
249 249
         }
250 250
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     {
256 256
         static $map = null;
257 257
 
258
-        if ( null === $map ) {
258
+        if (null === $map) {
259 259
             $map = array(
260 260
                 '1' => 'lossy',
261 261
                 '2' => 'glossy',
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
     {
275 275
         static $q = null;
276 276
 
277
-        if ( null === $q ) {
278
-            if ( is_array( $this->options ) && array_key_exists( 'autoptimize_imgopt_select_field_2', $this->options ) ) {
277
+        if (null === $q) {
278
+            if (is_array($this->options) && array_key_exists('autoptimize_imgopt_select_field_2', $this->options)) {
279 279
                 $setting = $this->options['autoptimize_imgopt_select_field_2'];
280 280
             }
281 281
 
282
-            if ( ! isset( $setting ) || empty( $setting ) || ( '1' !== $setting && '3' !== $setting ) ) {
282
+            if (!isset($setting) || empty($setting) || ('1' !== $setting && '3' !== $setting)) {
283 283
                 // default image opt. value is 2 ("glossy").
284 284
                 $q = '2';
285 285
             } else {
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
         return $q;
291 291
     }
292 292
 
293
-    public function filter_preconnect_imgopt_url( array $in )
293
+    public function filter_preconnect_imgopt_url(array $in)
294 294
     {
295
-        $url_parts = parse_url( $this->get_imgopt_base_url() );
296
-        $in[]      = $url_parts['scheme'] . '://' . $url_parts['host'];
295
+        $url_parts = parse_url($this->get_imgopt_base_url());
296
+        $in[]      = $url_parts['scheme'].'://'.$url_parts['host'];
297 297
 
298 298
         return $in;
299 299
     }
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
      *
307 307
      * @return string
308 308
      */
309
-    private function normalize_img_url( $in )
309
+    private function normalize_img_url($in)
310 310
     {
311 311
         // Only parse the site url once.
312 312
         static $parsed_site_url = null;
313
-        if ( null === $parsed_site_url ) {
314
-            $parsed_site_url = parse_url( site_url() );
313
+        if (null === $parsed_site_url) {
314
+            $parsed_site_url = parse_url(site_url());
315 315
         }
316 316
 
317 317
         // get CDN domain once.
318 318
         static $cdn_domain = null;
319
-        if ( is_null( $cdn_domain ) ) {
319
+        if (is_null($cdn_domain)) {
320 320
             $cdn_url = $this->get_cdn_url();
321
-            if ( ! empty( $cdn_url ) ) {
322
-                $cdn_domain = parse_url( $cdn_url, PHP_URL_HOST );
321
+            if (!empty($cdn_url)) {
322
+                $cdn_domain = parse_url($cdn_url, PHP_URL_HOST);
323 323
             } else {
324 324
                 $cdn_domain = '';
325 325
             }
@@ -335,49 +335,49 @@  discard block
 block discarded – undo
335 335
          * identical string operations).
336 336
          */
337 337
         static $cache = null;
338
-        if ( null === $cache ) {
338
+        if (null === $cache) {
339 339
             $cache = array();
340 340
         }
341 341
 
342 342
         // Do the work on cache miss only.
343
-        if ( ! isset( $cache[ $in ] ) ) {
343
+        if (!isset($cache[$in])) {
344 344
             // Default to (the trimmed version of) what was given to us.
345
-            $result = trim( $in );
345
+            $result = trim($in);
346 346
 
347 347
             // Some silly plugins wrap background images in html-encoded quotes, so remove those from the img url.
348
-            if ( strpos( $result, '&quot;' ) !== false ) {
349
-                $result = str_replace( '&quot;', '', $result );
348
+            if (strpos($result, '&quot;') !== false) {
349
+                $result = str_replace('&quot;', '', $result);
350 350
             }
351 351
 
352
-            if ( autoptimizeUtils::is_protocol_relative( $result ) ) {
353
-                $result = $parsed_site_url['scheme'] . ':' . $result;
354
-            } elseif ( 0 === strpos( $result, '/' ) ) {
352
+            if (autoptimizeUtils::is_protocol_relative($result)) {
353
+                $result = $parsed_site_url['scheme'].':'.$result;
354
+            } elseif (0 === strpos($result, '/')) {
355 355
                 // Root-relative...
356
-                $result = $parsed_site_url['scheme'] . '://' . $parsed_site_url['host'] . $result;
357
-            } elseif ( ! empty( $cdn_domain ) && strpos( $result, $cdn_domain ) !== 0 ) {
358
-                $result = str_replace( $cdn_domain, $parsed_site_url['host'], $result );
356
+                $result = $parsed_site_url['scheme'].'://'.$parsed_site_url['host'].$result;
357
+            } elseif (!empty($cdn_domain) && strpos($result, $cdn_domain) !== 0) {
358
+                $result = str_replace($cdn_domain, $parsed_site_url['host'], $result);
359 359
             }
360 360
 
361 361
             // filter (default off) to remove QS from image URL's to avoid eating away optimization credits.
362
-            if ( apply_filters( 'autoptimize_filter_imgopt_no_querystring', false ) && strpos( $result, '?' ) !== false ) {
363
-                $result = strtok( $result, '?' );
362
+            if (apply_filters('autoptimize_filter_imgopt_no_querystring', false) && strpos($result, '?') !== false) {
363
+                $result = strtok($result, '?');
364 364
             }
365 365
 
366
-            $result = apply_filters( 'autoptimize_filter_imgopt_normalized_url', $result );
366
+            $result = apply_filters('autoptimize_filter_imgopt_normalized_url', $result);
367 367
 
368 368
             // Store in cache.
369
-            $cache[ $in ] = $result;
369
+            $cache[$in] = $result;
370 370
         }
371 371
 
372
-        return $cache[ $in ];
372
+        return $cache[$in];
373 373
     }
374 374
 
375
-    public function filter_optimize_css_images( $in )
375
+    public function filter_optimize_css_images($in)
376 376
     {
377
-        $in = $this->normalize_img_url( $in );
377
+        $in = $this->normalize_img_url($in);
378 378
 
379
-        if ( $this->can_optimize_image( $in ) ) {
380
-            return $this->build_imgopt_url( $in, '', '' );
379
+        if ($this->can_optimize_image($in)) {
380
+            return $this->build_imgopt_url($in, '', '');
381 381
         } else {
382 382
             return $in;
383 383
         }
@@ -387,50 +387,50 @@  discard block
 block discarded – undo
387 387
     {
388 388
         static $imgopt_base_url = null;
389 389
 
390
-        if ( null === $imgopt_base_url ) {
390
+        if (null === $imgopt_base_url) {
391 391
             $imgopt_host     = $this->get_imgopt_host();
392 392
             $quality         = $this->get_img_quality_string();
393
-            $ret_val         = apply_filters( 'autoptimize_filter_imgopt_wait', 'ret_img' ); // values: ret_wait, ret_img, ret_json, ret_blank.
394
-            $imgopt_base_url = $imgopt_host . 'client/' . $quality . ',' . $ret_val;
395
-            $imgopt_base_url = apply_filters( 'autoptimize_filter_imgopt_base_url', $imgopt_base_url );
393
+            $ret_val         = apply_filters('autoptimize_filter_imgopt_wait', 'ret_img'); // values: ret_wait, ret_img, ret_json, ret_blank.
394
+            $imgopt_base_url = $imgopt_host.'client/'.$quality.','.$ret_val;
395
+            $imgopt_base_url = apply_filters('autoptimize_filter_imgopt_base_url', $imgopt_base_url);
396 396
         }
397 397
 
398 398
         return $imgopt_base_url;
399 399
     }
400 400
 
401
-    private function can_optimize_image( $url, $tag = '' )
401
+    private function can_optimize_image($url, $tag = '')
402 402
     {
403 403
         static $cdn_url      = null;
404 404
         static $nopti_images = null;
405 405
 
406
-        if ( null === $cdn_url ) {
406
+        if (null === $cdn_url) {
407 407
             $cdn_url = apply_filters(
408 408
                 'autoptimize_filter_base_cdnurl',
409
-                autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' )
409
+                autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '')
410 410
             );
411 411
         }
412 412
 
413
-        if ( null === $nopti_images ) {
414
-            $nopti_images = apply_filters( 'autoptimize_filter_imgopt_noptimize', '' );
413
+        if (null === $nopti_images) {
414
+            $nopti_images = apply_filters('autoptimize_filter_imgopt_noptimize', '');
415 415
         }
416 416
 
417 417
         $site_host  = AUTOPTIMIZE_SITE_DOMAIN;
418
-        $url        = $this->normalize_img_url( $url );
419
-        $url_parsed = parse_url( $url );
418
+        $url        = $this->normalize_img_url($url);
419
+        $url_parsed = parse_url($url);
420 420
 
421
-        if ( array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host && empty( $cdn_url ) ) {
421
+        if (array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host && empty($cdn_url)) {
422 422
             return false;
423
-        } elseif ( ! empty( $cdn_url ) && strpos( $url, $cdn_url ) === false && array_key_exists( 'host', $url_parsed ) && $url_parsed['host'] !== $site_host ) {
423
+        } elseif (!empty($cdn_url) && strpos($url, $cdn_url) === false && array_key_exists('host', $url_parsed) && $url_parsed['host'] !== $site_host) {
424 424
             return false;
425
-        } elseif ( strpos( $url, '.php' ) !== false ) {
425
+        } elseif (strpos($url, '.php') !== false) {
426 426
             return false;
427
-        } elseif ( str_ireplace( array( '.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif' ), '', $url_parsed['path'] ) === $url_parsed['path'] ) {
427
+        } elseif (str_ireplace(array('.png', '.gif', '.jpg', '.jpeg', '.webp', '.avif'), '', $url_parsed['path']) === $url_parsed['path']) {
428 428
             // fixme: better check against end of string.
429 429
             return false;
430
-        } elseif ( ! empty( $nopti_images ) ) {
431
-            $nopti_images_array = array_filter( array_map( 'trim', explode( ',', $nopti_images ) ) );
432
-            foreach ( $nopti_images_array as $nopti_image ) {
433
-                if ( strpos( $url, $nopti_image ) !== false || ( ( '' !== $tag && strpos( $tag, $nopti_image ) !== false ) ) ) {
430
+        } elseif (!empty($nopti_images)) {
431
+            $nopti_images_array = array_filter(array_map('trim', explode(',', $nopti_images)));
432
+            foreach ($nopti_images_array as $nopti_image) {
433
+                if (strpos($url, $nopti_image) !== false || (('' !== $tag && strpos($tag, $nopti_image) !== false))) {
434 434
                     return false;
435 435
                 }
436 436
             }
@@ -438,13 +438,13 @@  discard block
 block discarded – undo
438 438
         return true;
439 439
     }
440 440
 
441
-    private function build_imgopt_url( $orig_url, $width = 0, $height = 0 )
441
+    private function build_imgopt_url($orig_url, $width = 0, $height = 0)
442 442
     {
443 443
         // sanitize width and height.
444
-        if ( strpos( $width, '%' ) !== false ) {
444
+        if (strpos($width, '%') !== false) {
445 445
             $width = 0;
446 446
         }
447
-        if ( strpos( $height, '%' ) !== false ) {
447
+        if (strpos($height, '%') !== false) {
448 448
             $height = 0;
449 449
         }
450 450
         $width  = (int) $width;
@@ -458,56 +458,56 @@  discard block
 block discarded – undo
458 458
         );
459 459
 
460 460
         // If filter modified the url, return that.
461
-        if ( $filtered_url !== $orig_url ) {
461
+        if ($filtered_url !== $orig_url) {
462 462
             return $filtered_url;
463 463
         }
464 464
 
465
-        $orig_url        = $this->normalize_img_url( $orig_url );
465
+        $orig_url        = $this->normalize_img_url($orig_url);
466 466
         $imgopt_base_url = $this->get_imgopt_base_url();
467 467
         $imgopt_size     = '';
468 468
 
469
-        if ( $width && 0 !== $width ) {
470
-            $imgopt_size = ',w_' . $width;
469
+        if ($width && 0 !== $width) {
470
+            $imgopt_size = ',w_'.$width;
471 471
         }
472 472
 
473
-        if ( $height && 0 !== $height ) {
474
-            $imgopt_size .= ',h_' . $height;
473
+        if ($height && 0 !== $height) {
474
+            $imgopt_size .= ',h_'.$height;
475 475
         }
476 476
 
477
-        $url = $imgopt_base_url . $imgopt_size . '/' . $orig_url;
477
+        $url = $imgopt_base_url.$imgopt_size.'/'.$orig_url;
478 478
 
479 479
         return $url;
480 480
     }
481 481
 
482
-    public function replace_data_thumbs( $matches )
482
+    public function replace_data_thumbs($matches)
483 483
     {
484
-        return $this->replace_img_callback( $matches, 150, 150 );
484
+        return $this->replace_img_callback($matches, 150, 150);
485 485
     }
486 486
 
487
-    public function replace_img_callback( $matches, $width = 0, $height = 0 )
487
+    public function replace_img_callback($matches, $width = 0, $height = 0)
488 488
     {
489
-        $_normalized_img_url = $this->normalize_img_url( $matches[1] );
490
-        if ( $this->can_optimize_image( $matches[1], $matches[0] ) ) {
491
-            return str_replace( $matches[1], $this->build_imgopt_url( $_normalized_img_url, $width, $height ), $matches[0] );
489
+        $_normalized_img_url = $this->normalize_img_url($matches[1]);
490
+        if ($this->can_optimize_image($matches[1], $matches[0])) {
491
+            return str_replace($matches[1], $this->build_imgopt_url($_normalized_img_url, $width, $height), $matches[0]);
492 492
         } else {
493 493
             return $matches[0];
494 494
         }
495 495
     }
496 496
 
497
-    public function replace_icon_callback( $matches )
497
+    public function replace_icon_callback($matches)
498 498
     {
499
-        if ( array_key_exists( '2', $matches ) ) {
500
-            $sizes  = explode( 'x', $matches[2] );
499
+        if (array_key_exists('2', $matches)) {
500
+            $sizes  = explode('x', $matches[2]);
501 501
             $width  = $sizes[0];
502 502
             $height = $sizes[1];
503 503
         } else {
504 504
             $width  = 180;
505 505
             $height = 180;
506 506
         }
507
-        return $this->replace_img_callback( $matches, $width, $height );
507
+        return $this->replace_img_callback($matches, $width, $height);
508 508
     }
509 509
 
510
-    public function filter_optimize_images( $in )
510
+    public function filter_optimize_images($in)
511 511
     {
512 512
         /*
513 513
          * potential future functional improvements:
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
         $to_replace = array();
518 518
 
519 519
         // hide noscript tags to avoid nesting noscript tags (as lazyloaded images add noscript).
520
-        if ( $this->should_lazyload() ) {
520
+        if ($this->should_lazyload()) {
521 521
             $in = autoptimizeBase::replace_contents_with_marker_if_exists(
522 522
                 'SCRIPT',
523 523
                 '<script',
@@ -527,161 +527,161 @@  discard block
 block discarded – undo
527 527
         }
528 528
 
529 529
         // extract img tags.
530
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $in, $matches ) ) {
531
-            foreach ( $matches[0] as $tag ) {
530
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $in, $matches)) {
531
+            foreach ($matches[0] as $tag) {
532 532
                 $orig_tag = $tag;
533 533
                 $imgopt_w = '';
534 534
                 $imgopt_h = '';
535 535
 
536 536
                 // first do (data-)srcsets.
537
-                if ( preg_match_all( '#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER ) ) {
538
-                    foreach ( $allsrcsets as $srcset ) {
537
+                if (preg_match_all('#srcset=("|\')(.*)("|\')#Usmi', $tag, $allsrcsets, PREG_SET_ORDER)) {
538
+                    foreach ($allsrcsets as $srcset) {
539 539
                         $srcset      = $srcset[2];
540 540
                         $orig_srcset = $srcset;
541
-                        $srcsets     = explode( ',', $srcset );
542
-                        foreach ( $srcsets as $indiv_srcset ) {
543
-                            $indiv_srcset_parts = explode( ' ', trim( $indiv_srcset ) );
544
-                            if ( isset( $indiv_srcset_parts[1] ) && rtrim( $indiv_srcset_parts[1], 'w' ) !== $indiv_srcset_parts[1] ) {
545
-                                $imgopt_w = rtrim( $indiv_srcset_parts[1], 'w' );
541
+                        $srcsets     = explode(',', $srcset);
542
+                        foreach ($srcsets as $indiv_srcset) {
543
+                            $indiv_srcset_parts = explode(' ', trim($indiv_srcset));
544
+                            if (isset($indiv_srcset_parts[1]) && rtrim($indiv_srcset_parts[1], 'w') !== $indiv_srcset_parts[1]) {
545
+                                $imgopt_w = rtrim($indiv_srcset_parts[1], 'w');
546 546
                             }
547
-                            if ( $this->can_optimize_image( $indiv_srcset_parts[0], $tag ) ) {
548
-                                $imgopt_url = $this->build_imgopt_url( $indiv_srcset_parts[0], $imgopt_w, '' );
549
-                                $srcset     = str_replace( $indiv_srcset_parts[0], $imgopt_url, $srcset );
547
+                            if ($this->can_optimize_image($indiv_srcset_parts[0], $tag)) {
548
+                                $imgopt_url = $this->build_imgopt_url($indiv_srcset_parts[0], $imgopt_w, '');
549
+                                $srcset     = str_replace($indiv_srcset_parts[0], $imgopt_url, $srcset);
550 550
                             }
551 551
                         }
552
-                        $tag = str_replace( $orig_srcset, $srcset, $tag );
552
+                        $tag = str_replace($orig_srcset, $srcset, $tag);
553 553
                     }
554 554
                 }
555 555
 
556 556
                 // proceed with img src.
557 557
                 // get width and height and add to $imgopt_size.
558
-                $_get_size = $this->get_size_from_tag( $tag );
558
+                $_get_size = $this->get_size_from_tag($tag);
559 559
                 $imgopt_w  = $_get_size['width'];
560 560
                 $imgopt_h  = $_get_size['height'];
561 561
 
562 562
                 // then start replacing images src.
563
-                if ( preg_match_all( '#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER ) ) {
564
-                    foreach ( $urls as $url ) {
563
+                if (preg_match_all('#src=(?:"|\')(?!data)(.*)(?:"|\')#Usmi', $tag, $urls, PREG_SET_ORDER)) {
564
+                    foreach ($urls as $url) {
565 565
                         $full_src_orig = $url[0];
566 566
                         $url           = $url[1];
567
-                        if ( $this->can_optimize_image( $url, $full_src_orig ) ) {
568
-                            $imgopt_url      = $this->build_imgopt_url( $url, $imgopt_w, $imgopt_h );
569
-                            $full_imgopt_src = str_replace( $url, $imgopt_url, $full_src_orig );
570
-                            $tag             = str_replace( $full_src_orig, $full_imgopt_src, $tag );
567
+                        if ($this->can_optimize_image($url, $full_src_orig)) {
568
+                            $imgopt_url      = $this->build_imgopt_url($url, $imgopt_w, $imgopt_h);
569
+                            $full_imgopt_src = str_replace($url, $imgopt_url, $full_src_orig);
570
+                            $tag             = str_replace($full_src_orig, $full_imgopt_src, $tag);
571 571
                         }
572 572
                     }
573 573
                 }
574 574
 
575 575
                 // do lazyload stuff.
576
-                if ( $this->should_lazyload( $in ) && ! empty( $url ) ) {
576
+                if ($this->should_lazyload($in) && !empty($url)) {
577 577
                     // first do lpiq placeholder logic.
578
-                    if ( strpos( $url, $this->get_imgopt_host() ) === 0 ) {
578
+                    if (strpos($url, $this->get_imgopt_host()) === 0) {
579 579
                         // if all img src have been replaced during srcset, we have to extract the
580 580
                         // origin url from the imgopt one to be able to set a lqip placeholder.
581
-                        $_url = substr( $url, strpos( $url, '/http' ) + 1 );
581
+                        $_url = substr($url, strpos($url, '/http') + 1);
582 582
                     } else {
583 583
                         $_url = $url;
584 584
                     }
585 585
 
586
-                    $_url = $this->normalize_img_url( $_url );
586
+                    $_url = $this->normalize_img_url($_url);
587 587
 
588 588
                     $placeholder = '';
589
-                    if ( $this->can_optimize_image( $_url, $tag ) && apply_filters( 'autoptimize_filter_imgopt_lazyload_dolqip', true ) ) {
589
+                    if ($this->can_optimize_image($_url, $tag) && apply_filters('autoptimize_filter_imgopt_lazyload_dolqip', true)) {
590 590
                         $lqip_w = '';
591 591
                         $lqip_h = '';
592
-                        if ( isset( $imgopt_w ) && ! empty( $imgopt_w ) ) {
593
-                            $lqip_w = ',w_' . $imgopt_w;
592
+                        if (isset($imgopt_w) && !empty($imgopt_w)) {
593
+                            $lqip_w = ',w_'.$imgopt_w;
594 594
                         }
595
-                        if ( isset( $imgopt_h ) && ! empty( $imgopt_h ) ) {
596
-                            $lqip_h = ',h_' . $imgopt_h;
595
+                        if (isset($imgopt_h) && !empty($imgopt_h)) {
596
+                            $lqip_h = ',h_'.$imgopt_h;
597 597
                         }
598
-                        $placeholder = $this->get_imgopt_host() . 'client/q_lqip,ret_wait' . $lqip_w . $lqip_h . '/' . $_url;
598
+                        $placeholder = $this->get_imgopt_host().'client/q_lqip,ret_wait'.$lqip_w.$lqip_h.'/'.$_url;
599 599
                     }
600 600
                     // then call add_lazyload-function with lpiq placeholder if set.
601
-                    $tag = $this->add_lazyload( $tag, $placeholder );
601
+                    $tag = $this->add_lazyload($tag, $placeholder);
602 602
                 }
603 603
 
604 604
                 // and add tag to array for later replacement.
605
-                if ( $tag !== $orig_tag ) {
606
-                    $to_replace[ $orig_tag ] = $tag;
605
+                if ($tag !== $orig_tag) {
606
+                    $to_replace[$orig_tag] = $tag;
607 607
                 }
608 608
             }
609 609
         }
610 610
 
611 611
         // and replace all.
612
-        $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $in );
612
+        $out = str_replace(array_keys($to_replace), array_values($to_replace), $in);
613 613
 
614 614
         // img thumbnails in e.g. woocommerce.
615
-        if ( strpos( $out, 'data-thumb' ) !== false && apply_filters( 'autoptimize_filter_imgopt_datathumbs', true ) ) {
615
+        if (strpos($out, 'data-thumb') !== false && apply_filters('autoptimize_filter_imgopt_datathumbs', true)) {
616 616
             $out = preg_replace_callback(
617 617
                 '/\<div(?:[^>]?)\sdata-thumb\=(?:\"|\')(.+?)(?:\"|\')(?:[^>]*)?\>/s',
618
-                array( $this, 'replace_data_thumbs' ),
618
+                array($this, 'replace_data_thumbs'),
619 619
                 $out
620 620
             );
621 621
         }
622 622
 
623 623
         // background-image in inline style.
624
-        if ( strpos( $out, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_backgroundimages', true ) ) {
624
+        if (strpos($out, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_backgroundimages', true)) {
625 625
             $out = preg_replace_callback(
626 626
                 '/style=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)/',
627
-                array( $this, 'replace_img_callback' ),
627
+                array($this, 'replace_img_callback'),
628 628
                 $out
629 629
             );
630 630
         }
631 631
 
632 632
         // act on icon links.
633
-        if ( ( strpos( $out, '<link rel="icon"' ) !== false || ( strpos( $out, "<link rel='icon'" ) !== false ) ) && apply_filters( 'autoptimize_filter_imgopt_linkicon', true ) ) {
633
+        if ((strpos($out, '<link rel="icon"') !== false || (strpos($out, "<link rel='icon'") !== false)) && apply_filters('autoptimize_filter_imgopt_linkicon', true)) {
634 634
             $out = preg_replace_callback(
635 635
                 '/<link\srel=(?:"|\')(?:apple-touch-)?icon(?:"|\').*\shref=(?:"|\')(.*)(?:"|\')(?:\ssizes=(?:"|\')(\d*x\d*)(?:"|\'))?\s\/>/Um',
636
-                array( $this, 'replace_icon_callback' ),
636
+                array($this, 'replace_icon_callback'),
637 637
                 $out
638 638
             );
639 639
         }
640 640
 
641 641
         // lazyload: restore noscript tags + lazyload picture source tags and bgimage.
642
-        if ( $this->should_lazyload() ) {
642
+        if ($this->should_lazyload()) {
643 643
             $out = autoptimizeBase::restore_marked_content(
644 644
                 'SCRIPT',
645 645
                 $out
646 646
             );
647 647
 
648
-            $out = $this->process_picture_tag( $out, true, true );
649
-            $out = $this->process_bgimage( $out );
648
+            $out = $this->process_picture_tag($out, true, true);
649
+            $out = $this->process_bgimage($out);
650 650
         } else {
651
-            $out = $this->process_picture_tag( $out, true, false );
651
+            $out = $this->process_picture_tag($out, true, false);
652 652
         }
653 653
 
654 654
         return $out;
655 655
     }
656 656
 
657
-    public function get_size_from_tag( $tag ) {
657
+    public function get_size_from_tag($tag) {
658 658
         // reusable function to extract widht and height from an image tag
659 659
         // enforcing a filterable maximum width and height (default 4999X4999).
660 660
         $width  = '';
661 661
         $height = '';
662 662
 
663
-        if ( preg_match( '#width=("|\')(.*)("|\')#Usmi', $tag, $_width ) ) {
664
-            if ( strpos( $_width[2], '%' ) === false ) {
663
+        if (preg_match('#width=("|\')(.*)("|\')#Usmi', $tag, $_width)) {
664
+            if (strpos($_width[2], '%') === false) {
665 665
                 $width = (int) $_width[2];
666 666
             }
667 667
         }
668
-        if ( preg_match( '#height=("|\')(.*)("|\')#Usmi', $tag, $_height ) ) {
669
-            if ( strpos( $_height[2], '%' ) === false ) {
668
+        if (preg_match('#height=("|\')(.*)("|\')#Usmi', $tag, $_height)) {
669
+            if (strpos($_height[2], '%') === false) {
670 670
                 $height = (int) $_height[2];
671 671
             }
672 672
         }
673 673
 
674 674
         // check for and enforce (filterable) max sizes.
675
-        $_max_width = apply_filters( 'autoptimize_filter_imgopt_max_width', 4999 );
676
-        if ( $width > $_max_width ) {
675
+        $_max_width = apply_filters('autoptimize_filter_imgopt_max_width', 4999);
676
+        if ($width > $_max_width) {
677 677
             $_width = $_max_width;
678
-            $height = $_width / $width * $height;
678
+            $height = $_width/$width*$height;
679 679
             $width  = $_width;
680 680
         }
681
-        $_max_height = apply_filters( 'autoptimize_filter_imgopt_max_height', 4999 );
682
-        if ( $height > $_max_height ) {
681
+        $_max_height = apply_filters('autoptimize_filter_imgopt_max_height', 4999);
682
+        if ($height > $_max_height) {
683 683
             $_height = $_max_height;
684
-            $width   = $_height / $height * $width;
684
+            $width   = $_height/$height*$width;
685 685
             $height  = $_height;
686 686
         }
687 687
 
@@ -700,26 +700,26 @@  discard block
 block discarded – undo
700 700
         return $self->should_lazyload();
701 701
     }
702 702
 
703
-    public function should_lazyload( $context = '' ) {
704
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && false === $this->check_nolazy() ) {
703
+    public function should_lazyload($context = '') {
704
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_3']) && false === $this->check_nolazy()) {
705 705
             $lazyload_return = true;
706 706
         } else {
707 707
             $lazyload_return = false;
708 708
         }
709
-        $lazyload_return = apply_filters( 'autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context );
709
+        $lazyload_return = apply_filters('autoptimize_filter_imgopt_should_lazyload', $lazyload_return, $context);
710 710
 
711 711
         return $lazyload_return;
712 712
     }
713 713
 
714 714
     public function check_nolazy() {
715
-        if ( array_key_exists( 'ao_nolazy', $_GET ) && '1' === $_GET['ao_nolazy'] ) {
715
+        if (array_key_exists('ao_nolazy', $_GET) && '1' === $_GET['ao_nolazy']) {
716 716
             return true;
717 717
         } else {
718 718
             return false;
719 719
         }
720 720
     }
721 721
 
722
-    public function filter_lazyload_images( $in )
722
+    public function filter_lazyload_images($in)
723 723
     {
724 724
         // only used is image optimization is NOT active but lazyload is.
725 725
         $to_replace = array();
@@ -733,20 +733,20 @@  discard block
 block discarded – undo
733 733
         );
734 734
 
735 735
         // extract img tags and add lazyload attribs.
736
-        if ( preg_match_all( '#<img[^>]*src[^>]*>#Usmi', $out, $matches ) ) {
737
-            foreach ( $matches[0] as $tag ) {
738
-                if ( $this->should_lazyload( $out ) ) {
739
-                    $to_replace[ $tag ] = $this->add_lazyload( $tag );
736
+        if (preg_match_all('#<img[^>]*src[^>]*>#Usmi', $out, $matches)) {
737
+            foreach ($matches[0] as $tag) {
738
+                if ($this->should_lazyload($out)) {
739
+                    $to_replace[$tag] = $this->add_lazyload($tag);
740 740
                 }
741 741
             }
742
-            $out = str_replace( array_keys( $to_replace ), array_values( $to_replace ), $out );
742
+            $out = str_replace(array_keys($to_replace), array_values($to_replace), $out);
743 743
         }
744 744
 
745 745
         // and also lazyload picture tag.
746
-        $out = $this->process_picture_tag( $out, false, true );
746
+        $out = $this->process_picture_tag($out, false, true);
747 747
 
748 748
         // and inline style blocks with background-image.
749
-        $out = $this->process_bgimage( $out );
749
+        $out = $this->process_bgimage($out);
750 750
 
751 751
         // restore noscript tags.
752 752
         $out = autoptimizeBase::restore_marked_content(
@@ -757,84 +757,84 @@  discard block
 block discarded – undo
757 757
         return $out;
758 758
     }
759 759
 
760
-    public function add_lazyload( $tag, $placeholder = '' ) {
760
+    public function add_lazyload($tag, $placeholder = '') {
761 761
         // adds actual lazyload-attributes to an image node.
762
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $tag ) === $tag ) {
763
-            $tag = $this->maybe_fix_missing_quotes( $tag );
762
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $tag) === $tag) {
763
+            $tag = $this->maybe_fix_missing_quotes($tag);
764 764
 
765 765
             // store original tag for use in noscript version.
766
-            $noscript_tag = '<noscript>' . autoptimizeUtils::remove_id_from_node( $tag ) . '</noscript>';
766
+            $noscript_tag = '<noscript>'.autoptimizeUtils::remove_id_from_node($tag).'</noscript>';
767 767
 
768
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
768
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
769 769
 
770 770
             // insert lazyload class.
771
-            $tag = $this->inject_classes_in_tag( $tag, "$lazyload_class " );
771
+            $tag = $this->inject_classes_in_tag($tag, "$lazyload_class ");
772 772
 
773
-            if ( ! $placeholder || empty( $placeholder ) ) {
773
+            if (!$placeholder || empty($placeholder)) {
774 774
                 // get image width & heigth for placeholder fun (and to prevent content reflow).
775
-                $_get_size = $this->get_size_from_tag( $tag );
775
+                $_get_size = $this->get_size_from_tag($tag);
776 776
                 $width     = $_get_size['width'];
777 777
                 $height    = $_get_size['height'];
778
-                if ( false === $width || empty( $width ) ) {
778
+                if (false === $width || empty($width)) {
779 779
                     $width = 210; // default width for SVG placeholder.
780 780
                 }
781
-                if ( false === $height || empty( $height ) ) {
782
-                    $height = $width / 3 * 2; // if no height, base it on width using the 3/2 aspect ratio.
781
+                if (false === $height || empty($height)) {
782
+                    $height = $width/3*2; // if no height, base it on width using the 3/2 aspect ratio.
783 783
                 }
784 784
 
785 785
                 // insert the actual lazyload stuff.
786 786
                 // see https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/ for great read on why we're using empty svg's.
787
-                $placeholder = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( $width, $height ) );
787
+                $placeholder = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder($width, $height));
788 788
             }
789 789
 
790
-            $tag = preg_replace( '/(\s)src=/', ' src=\'' . $placeholder . '\' data-src=', $tag );
791
-            $tag = preg_replace( '/(\s)srcset=/', ' data-srcset=', $tag );
790
+            $tag = preg_replace('/(\s)src=/', ' src=\''.$placeholder.'\' data-src=', $tag);
791
+            $tag = preg_replace('/(\s)srcset=/', ' data-srcset=', $tag);
792 792
 
793 793
             // move sizes to data-sizes unless filter says no.
794
-            if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_move_sizes', true ) ) {
795
-                $tag = str_replace( ' sizes=', ' data-sizes=', $tag );
794
+            if (apply_filters('autoptimize_filter_imgopt_lazyload_move_sizes', true)) {
795
+                $tag = str_replace(' sizes=', ' data-sizes=', $tag);
796 796
             }
797 797
 
798 798
             // add the noscript-tag from earlier.
799
-            $tag = $noscript_tag . $tag;
800
-            $tag = apply_filters( 'autoptimize_filter_imgopt_lazyloaded_img', $tag );
799
+            $tag = $noscript_tag.$tag;
800
+            $tag = apply_filters('autoptimize_filter_imgopt_lazyloaded_img', $tag);
801 801
         }
802 802
 
803 803
         return $tag;
804 804
     }
805 805
 
806 806
     public function add_lazyload_js_footer() {
807
-        if ( false === autoptimizeMain::should_buffer() ) {
807
+        if (false === autoptimizeMain::should_buffer()) {
808 808
             return;
809 809
         }
810 810
 
811 811
         // The JS will by default be excluded form autoptimization but this can be changed with a filter.
812 812
         $noptimize_flag = '';
813
-        if ( apply_filters( 'autoptimize_filter_imgopt_lazyload_js_noptimize', true ) ) {
813
+        if (apply_filters('autoptimize_filter_imgopt_lazyload_js_noptimize', true)) {
814 814
             $noptimize_flag = ' data-noptimize="1"';
815 815
         }
816 816
 
817
-        $lazysizes_js = plugins_url( 'external/js/lazysizes.min.js?ao_version=' . AUTOPTIMIZE_PLUGIN_VERSION, __FILE__ );
817
+        $lazysizes_js = plugins_url('external/js/lazysizes.min.js?ao_version='.AUTOPTIMIZE_PLUGIN_VERSION, __FILE__);
818 818
         $cdn_url      = $this->get_cdn_url();
819
-        if ( ! empty( $cdn_url ) ) {
820
-            $cdn_url      = rtrim( $cdn_url, '/' );
821
-            $lazysizes_js = str_replace( AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js );
819
+        if (!empty($cdn_url)) {
820
+            $cdn_url      = rtrim($cdn_url, '/');
821
+            $lazysizes_js = str_replace(AUTOPTIMIZE_WP_SITE_URL, $cdn_url, $lazysizes_js);
822 822
         }
823 823
 
824 824
         $type_js = '';
825
-        if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) {
825
+        if (apply_filters('autoptimize_filter_cssjs_addtype', false)) {
826 826
             $type_js = ' type="text/javascript"';
827 827
         }
828 828
 
829 829
         // Adds lazyload CSS & JS to footer, using echo because wp_enqueue_script seems not to support pushing attributes (async).
830
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>' );
831
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_jsconfig', '<script' . $type_js . $noptimize_flag . '>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>' );
832
-        echo apply_filters( 'autoptimize_filter_imgopt_lazyload_js', '<script async' . $type_js . $noptimize_flag . ' src=\'' . $lazysizes_js . '\'></script>' );
830
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_cssoutput', '<noscript><style>.lazyload{display:none;}</style></noscript>');
831
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_jsconfig', '<script'.$type_js.$noptimize_flag.'>window.lazySizesConfig=window.lazySizesConfig||{};window.lazySizesConfig.loadMode=1;</script>');
832
+        echo apply_filters('autoptimize_filter_imgopt_lazyload_js', '<script async'.$type_js.$noptimize_flag.' src=\''.$lazysizes_js.'\'></script>');
833 833
 
834 834
         // And add webp detection and loading JS.
835
-        if ( $this->should_ngimg() ) {
835
+        if ($this->should_ngimg()) {
836 836
             // Add AVIF code, can be disabled for now to only do webp.
837
-            if ( apply_filters( 'autoptimize_filter_imgopt_do_avif', true ) ) {
837
+            if (apply_filters('autoptimize_filter_imgopt_do_avif', true)) {
838 838
                 $_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");';
839 839
                 $_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+","))})});';
840 840
             } else {
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
                 $_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,'))})});";
843 843
             }
844 844
             // Keeping autoptimize_filter_imgopt_webp_js filter for now, but it is deprecated as not only for webp any more.
845
-            $_ngimg_output = apply_filters( 'autoptimize_filter_imgopt_webp_js', '<script' . $type_js . $noptimize_flag . '>' . $_ngimg_detect . $_ngimg_load . '</script>' );
846
-            echo apply_filters( 'autoptimize_filter_imgopt_ngimg_js', $_ngimg_output );
845
+            $_ngimg_output = apply_filters('autoptimize_filter_imgopt_webp_js', '<script'.$type_js.$noptimize_flag.'>'.$_ngimg_detect.$_ngimg_load.'</script>');
846
+            echo apply_filters('autoptimize_filter_imgopt_ngimg_js', $_ngimg_output);
847 847
         }
848 848
     }
849 849
 
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
         // getting CDN url here to avoid having to make bigger changes to autoptimizeBase.
852 852
         static $cdn_url = null;
853 853
 
854
-        if ( null === $cdn_url ) {
855
-            $cdn_url = autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' );
856
-            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $cdn_url );
857
-            $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
854
+        if (null === $cdn_url) {
855
+            $cdn_url = autoptimizeOptionWrapper::get_option('autoptimize_cdn_url', '');
856
+            $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($cdn_url);
857
+            $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
858 858
         }
859 859
 
860 860
         return $cdn_url;
@@ -864,47 +864,47 @@  discard block
 block discarded – undo
864 864
         // returns array of strings that if found in an <img tag will stop the img from being lazy-loaded.
865 865
         static $exclude_lazyload_array = null;
866 866
 
867
-        if ( null === $exclude_lazyload_array ) {
867
+        if (null === $exclude_lazyload_array) {
868 868
             $options = $this->options;
869 869
 
870 870
             // set default exclusions.
871
-            $exclude_lazyload_array = array( 'skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"' );
871
+            $exclude_lazyload_array = array('skip-lazy', 'data-no-lazy', 'notlazy', 'data-src', 'data-srcset', 'data:image/', 'data-lazyload', 'rev-slidebg', 'loading="eager"');
872 872
 
873 873
             // add from setting.
874
-            if ( array_key_exists( 'autoptimize_imgopt_text_field_5', $options ) ) {
874
+            if (array_key_exists('autoptimize_imgopt_text_field_5', $options)) {
875 875
                 $exclude_lazyload_option = $options['autoptimize_imgopt_text_field_5'];
876
-                if ( ! empty( $exclude_lazyload_option ) ) {
877
-                    $exclude_lazyload_array = array_merge( $exclude_lazyload_array, array_filter( array_map( 'trim', explode( ',', $options['autoptimize_imgopt_text_field_5'] ) ) ) );
876
+                if (!empty($exclude_lazyload_option)) {
877
+                    $exclude_lazyload_array = array_merge($exclude_lazyload_array, array_filter(array_map('trim', explode(',', $options['autoptimize_imgopt_text_field_5']))));
878 878
                 }
879 879
             }
880 880
 
881 881
             // and filter for developer-initiated changes.
882
-            $exclude_lazyload_array = apply_filters( 'autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array );
882
+            $exclude_lazyload_array = apply_filters('autoptimize_filter_imgopt_lazyload_exclude_array', $exclude_lazyload_array);
883 883
         }
884 884
 
885 885
         return $exclude_lazyload_array;
886 886
     }
887 887
 
888
-    public function inject_classes_in_tag( $tag, $target_class ) {
889
-        if ( strpos( $tag, 'class=' ) !== false ) {
890
-            $tag = preg_replace( '/(\sclass\s?=\s?("|\'))/', '$1' . $target_class, $tag );
888
+    public function inject_classes_in_tag($tag, $target_class) {
889
+        if (strpos($tag, 'class=') !== false) {
890
+            $tag = preg_replace('/(\sclass\s?=\s?("|\'))/', '$1'.$target_class, $tag);
891 891
         } else {
892
-            $tag = preg_replace( '/(<img)\s/', '$1 class="' . trim( $target_class ) . '" ', $tag );
892
+            $tag = preg_replace('/(<img)\s/', '$1 class="'.trim($target_class).'" ', $tag);
893 893
         }
894 894
 
895 895
         return $tag;
896 896
     }
897 897
 
898
-    public function get_default_lazyload_placeholder( $imgopt_w, $imgopt_h ) {
899
-        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';
898
+    public function get_default_lazyload_placeholder($imgopt_w, $imgopt_h) {
899
+        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';
900 900
     }
901 901
 
902 902
     public function should_ngimg() {
903 903
         static $ngimg_return = null;
904 904
 
905
-        if ( is_null( $ngimg_return ) ) {
905
+        if (is_null($ngimg_return)) {
906 906
             // webp only works if imgopt and lazyload are also active.
907
-            if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_4'] ) && ! empty( $this->options['autoptimize_imgopt_checkbox_field_3'] ) && $this->imgopt_active() ) {
907
+            if (!empty($this->options['autoptimize_imgopt_checkbox_field_4']) && !empty($this->options['autoptimize_imgopt_checkbox_field_3']) && $this->imgopt_active()) {
908 908
                 $ngimg_return = true;
909 909
             } else {
910 910
                 $ngimg_return = false;
@@ -914,9 +914,9 @@  discard block
 block discarded – undo
914 914
         return $ngimg_return;
915 915
     }
916 916
 
917
-    public function process_picture_tag( $in, $imgopt = false, $lazy = false ) {
917
+    public function process_picture_tag($in, $imgopt = false, $lazy = false) {
918 918
         // check if "<picture" is present and if filter allows us to process <picture>.
919
-        if ( strpos( $in, '<picture' ) === false || apply_filters( 'autoptimize_filter_imgopt_dopicture', true ) === false ) {
919
+        if (strpos($in, '<picture') === false || apply_filters('autoptimize_filter_imgopt_dopicture', true) === false) {
920 920
             return $in;
921 921
         }
922 922
 
@@ -924,37 +924,37 @@  discard block
 block discarded – undo
924 924
         $to_replace_pict = array();
925 925
 
926 926
         // extract and process each picture-node.
927
-        preg_match_all( '#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER );
928
-        foreach ( $_pictures as $_picture ) {
929
-            $_picture = $this->maybe_fix_missing_quotes( $_picture );
930
-            if ( strpos( $_picture[0], '<source ' ) !== false && preg_match_all( '#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER ) !== false ) {
931
-                foreach ( $_sources as $_source ) {
927
+        preg_match_all('#<picture.*</picture>#Usmi', $in, $_pictures, PREG_SET_ORDER);
928
+        foreach ($_pictures as $_picture) {
929
+            $_picture = $this->maybe_fix_missing_quotes($_picture);
930
+            if (strpos($_picture[0], '<source ') !== false && preg_match_all('#<source .*srcset=(?:"|\')(?!data)(.*)(?:"|\').*>#Usmi', $_picture[0], $_sources, PREG_SET_ORDER) !== false) {
931
+                foreach ($_sources as $_source) {
932 932
                     $_picture_replacement = $_source[0];
933 933
 
934 934
                     // should we optimize the image?
935
-                    if ( $imgopt && $this->can_optimize_image( $_source[1], $_picture[0] ) ) {
936
-                        $_picture_replacement = str_replace( $_source[1], $this->build_imgopt_url( $_source[1] ), $_picture_replacement );
935
+                    if ($imgopt && $this->can_optimize_image($_source[1], $_picture[0])) {
936
+                        $_picture_replacement = str_replace($_source[1], $this->build_imgopt_url($_source[1]), $_picture_replacement);
937 937
                     }
938 938
                     // should we lazy-load?
939
-                    if ( $lazy && $this->should_lazyload() && str_ireplace( $_exclusions, '', $_picture_replacement ) === $_picture_replacement ) {
940
-                        $_picture_replacement = str_replace( ' srcset=', ' data-srcset=', $_picture_replacement );
939
+                    if ($lazy && $this->should_lazyload() && str_ireplace($_exclusions, '', $_picture_replacement) === $_picture_replacement) {
940
+                        $_picture_replacement = str_replace(' srcset=', ' data-srcset=', $_picture_replacement);
941 941
                     }
942
-                    $to_replace_pict[ $_source[0] ] = $_picture_replacement;
942
+                    $to_replace_pict[$_source[0]] = $_picture_replacement;
943 943
                 }
944 944
             }
945 945
         }
946 946
 
947 947
         // and return the fully procesed $in.
948
-        $out = str_replace( array_keys( $to_replace_pict ), array_values( $to_replace_pict ), $in );
948
+        $out = str_replace(array_keys($to_replace_pict), array_values($to_replace_pict), $in);
949 949
 
950 950
         return $out;
951 951
     }
952 952
 
953
-    public function process_bgimage( $in ) {
954
-        if ( strpos( $in, 'background-image:' ) !== false && apply_filters( 'autoptimize_filter_imgopt_lazyload_backgroundimages', true ) ) {
953
+    public function process_bgimage($in) {
954
+        if (strpos($in, 'background-image:') !== false && apply_filters('autoptimize_filter_imgopt_lazyload_backgroundimages', true)) {
955 955
             $out = preg_replace_callback(
956 956
                 '/(<(?:article|aside|body|div|footer|header|p|section|table)[^>]*)\sstyle=(?:"|\')[^<>]*?background-image:\s?url\((?:"|\')?([^"\')]*)(?:"|\')?\)[^>]*/',
957
-                array( $this, 'lazyload_bgimg_callback' ),
957
+                array($this, 'lazyload_bgimg_callback'),
958 958
                 $in
959 959
             );
960 960
             return $out;
@@ -962,27 +962,27 @@  discard block
 block discarded – undo
962 962
         return $in;
963 963
     }
964 964
 
965
-    public function lazyload_bgimg_callback( $matches ) {
966
-        if ( str_ireplace( $this->get_lazyload_exclusions(), '', $matches[0] ) === $matches[0] ) {
965
+    public function lazyload_bgimg_callback($matches) {
966
+        if (str_ireplace($this->get_lazyload_exclusions(), '', $matches[0]) === $matches[0]) {
967 967
             // get placeholder & lazyload class strings.
968
-            $placeholder    = apply_filters( 'autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder( 500, 300 ) );
969
-            $lazyload_class = apply_filters( 'autoptimize_filter_imgopt_lazyload_class', 'lazyload' );
968
+            $placeholder    = apply_filters('autoptimize_filter_imgopt_lazyload_placeholder', $this->get_default_lazyload_placeholder(500, 300));
969
+            $lazyload_class = apply_filters('autoptimize_filter_imgopt_lazyload_class', 'lazyload');
970 970
             // replace background-image URL with SVG placeholder.
971
-            $out = str_replace( $matches[2], $placeholder, $matches[0] );
971
+            $out = str_replace($matches[2], $placeholder, $matches[0]);
972 972
             // add data-bg attribute with real background-image URL for lazyload to pick up.
973
-            $out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '&quot;' ), '', $matches[2] ) ) . '"', $out );
973
+            $out = str_replace($matches[1], $matches[1].' data-bg="'.trim(str_replace(array("\r\n", '&quot;'), '', $matches[2])).'"', $out);
974 974
             // add lazyload class to tag.
975
-            $out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
975
+            $out = $this->inject_classes_in_tag($out, "$lazyload_class ");
976 976
             return $out;
977 977
         }
978 978
         return $matches[0];
979 979
     }
980 980
 
981
-    public function maybe_fix_missing_quotes( $tag_in ) {
981
+    public function maybe_fix_missing_quotes($tag_in) {
982 982
         // 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.
983
-        if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) && class_exists( 'Minify_HTML' ) && apply_filters( 'autoptimize_filter_imgopt_fixquotes', true ) ) {
984
-            $tag_out = preg_replace( '/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in );
985
-            $tag_out = preg_replace( '/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out );
983
+        if (file_exists(WP_PLUGIN_DIR.'/w3-total-cache/w3-total-cache.php') && class_exists('Minify_HTML') && apply_filters('autoptimize_filter_imgopt_fixquotes', true)) {
984
+            $tag_out = preg_replace('/class\s?=([^("|\')]*)(\s|>)/U', 'class=\'$1\'$2', $tag_in);
985
+            $tag_out = preg_replace('/\s(width|height)=(?:"|\')?([^\s"\'>]*)(?:"|\')?/', ' $1=\'$2\'', $tag_out);
986 986
             return $tag_out;
987 987
         } else {
988 988
             return $tag_in;
@@ -995,23 +995,23 @@  discard block
 block discarded – undo
995 995
     public function imgopt_admin_menu()
996 996
     {
997 997
         // no acces if multisite and not network admin and no site config allowed.
998
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
998
+        if (autoptimizeConfig::should_show_menu_tabs()) {
999 999
             add_submenu_page(
1000 1000
                 null,
1001 1001
                 'autoptimize_imgopt',
1002 1002
                 'autoptimize_imgopt',
1003 1003
                 'manage_options',
1004 1004
                 'autoptimize_imgopt',
1005
-                array( $this, 'imgopt_options_page' )
1005
+                array($this, 'imgopt_options_page')
1006 1006
             );
1007 1007
         }
1008
-        register_setting( 'autoptimize_imgopt_settings', 'autoptimize_imgopt_settings' );
1008
+        register_setting('autoptimize_imgopt_settings', 'autoptimize_imgopt_settings');
1009 1009
     }
1010 1010
 
1011
-    public function add_imgopt_tab( $in )
1011
+    public function add_imgopt_tab($in)
1012 1012
     {
1013
-        if ( autoptimizeConfig::should_show_menu_tabs() ) {
1014
-            $in = array_merge( $in, array( 'autoptimize_imgopt' => __( 'Images', 'autoptimize' ) ) );
1013
+        if (autoptimizeConfig::should_show_menu_tabs()) {
1014
+            $in = array_merge($in, array('autoptimize_imgopt' => __('Images', 'autoptimize')));
1015 1015
         }
1016 1016
 
1017 1017
         return $in;
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
     public function imgopt_options_page()
1021 1021
     {
1022 1022
         // Check querystring for "refreshCacheChecker" and call cachechecker if so.
1023
-        if ( array_key_exists( 'refreshImgProvStats', $_GET ) && 1 == $_GET['refreshImgProvStats'] ) {
1023
+        if (array_key_exists('refreshImgProvStats', $_GET) && 1 == $_GET['refreshImgProvStats']) {
1024 1024
             $this->query_img_provider_stats();
1025 1025
         }
1026 1026
 
@@ -1032,47 +1032,47 @@  discard block
 block discarded – undo
1032 1032
         #ao_settings_form .form-table th {font-weight: normal;}
1033 1033
         #autoptimize_imgopt_descr{font-size: 120%;}
1034 1034
     </style>
1035
-    <script>document.title = "Autoptimize: <?php _e( 'Images', 'autoptimize' ); ?> " + document.title;</script>
1035
+    <script>document.title = "Autoptimize: <?php _e('Images', 'autoptimize'); ?> " + document.title;</script>
1036 1036
     <div class="wrap">
1037
-    <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
1037
+    <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
1038 1038
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
1039
-        <?php if ( 'down' === $options['availabilities']['extra_imgopt']['status'] ) { ?>
1039
+        <?php if ('down' === $options['availabilities']['extra_imgopt']['status']) { ?>
1040 1040
             <div class="notice-warning notice"><p>
1041 1041
             <?php
1042 1042
             // translators: "Autoptimize support forum" will appear in a "a href".
1043
-            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>' );
1043
+            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>');
1044 1044
             ?>
1045 1045
             </p></div>
1046 1046
         <?php } ?>
1047 1047
 
1048
-        <?php if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] && ! autoptimizeImages::instance()->launch_ok() ) { ?>
1048
+        <?php if ('launch' === $options['availabilities']['extra_imgopt']['status'] && !autoptimizeImages::instance()->launch_ok()) { ?>
1049 1049
             <div class="notice-warning notice"><p>
1050
-            <?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' ); ?>
1050
+            <?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'); ?>
1051 1051
             </p></div>
1052 1052
         <?php } ?>
1053 1053
 
1054
-        <?php if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() ) ) { ?>
1054
+        <?php if (class_exists('Jetpack') && method_exists('Jetpack', 'get_active_modules') && in_array('photon', Jetpack::get_active_modules())) { ?>
1055 1055
             <div class="notice-warning notice"><p>
1056 1056
             <?php
1057 1057
             // translators: "disable  Jetpack's site accelerator for images" will appear in a "a href" linking to the jetpack settings page.
1058
-            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>' );
1058
+            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>');
1059 1059
             ?>
1060 1060
             </p></div>
1061 1061
         <?php } ?>
1062
-    <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'>
1063
-        <?php settings_fields( 'autoptimize_imgopt_settings' ); ?>
1064
-        <h2><?php _e( 'Image optimization', 'autoptimize' ); ?></h2>
1065
-        <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>
1062
+    <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'>
1063
+        <?php settings_fields('autoptimize_imgopt_settings'); ?>
1064
+        <h2><?php _e('Image optimization', 'autoptimize'); ?></h2>
1065
+        <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>
1066 1066
         <table class="form-table">
1067 1067
             <tr>
1068
-                <th scope="row"><?php _e( 'Optimize Images', 'autoptimize' ); ?></th>
1068
+                <th scope="row"><?php _e('Optimize Images', 'autoptimize'); ?></th>
1069 1069
                 <td>
1070
-                    <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>
1070
+                    <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>
1071 1071
                     <?php
1072 1072
                     // show shortpixel status.
1073 1073
                     $_notice = autoptimizeImages::instance()->get_imgopt_status_notice();
1074
-                    if ( $_notice ) {
1075
-                        switch ( $_notice['status'] ) {
1074
+                    if ($_notice) {
1075
+                        switch ($_notice['status']) {
1076 1076
                             case 2:
1077 1077
                                 $_notice_color = 'green';
1078 1078
                                 break;
@@ -1087,29 +1087,29 @@  discard block
 block discarded – undo
1087 1087
                             default:
1088 1088
                                 $_notice_color = 'green';
1089 1089
                         }
1090
-                        echo apply_filters( 'autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:' . $_notice_color . ';">' . __( 'Shortpixel status: ', 'autoptimize' ) . '</span></strong>' . $_notice['notice'] . '</p>' );
1090
+                        echo apply_filters('autoptimize_filter_imgopt_settings_status', '<p><strong><span style="color:'.$_notice_color.';">'.__('Shortpixel status: ', 'autoptimize').'</span></strong>'.$_notice['notice'].'</p>');
1091 1091
                     } else {
1092 1092
                         // translators: link points to shortpixel.
1093
-                        $upsell_msg_1 = '<p>' . sprintf( __( 'Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP and AVIF image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1094
-                        if ( 'launch' === $options['availabilities']['extra_imgopt']['status'] ) {
1095
-                            $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' );
1093
+                        $upsell_msg_1 = '<p>'.sprintf(__('Get more Google love and improve your website\'s loading speed by having your publicly available images optimized on the fly (also in the "next-gen" WebP and AVIF image format) by %1$sShortPixel%2$s and then cached and served fast from Shortpixel\'s global CDN.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1094
+                        if ('launch' === $options['availabilities']['extra_imgopt']['status']) {
1095
+                            $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');
1096 1096
                         } else {
1097 1097
                             // translators: link points to shortpixel.
1098
-                            $upsell_msg_2 = sprintf( __( '%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize' ), '<a href="https://shortpixel.com/aospai' . $sp_url_suffix . '" target="_blank">', '</a>' );
1098
+                            $upsell_msg_2 = sprintf(__('%1$sSign-up now%2$s to receive extra traffic or image optimization credits for free. You\'ll also receive +50&percnt; more CDN traffic or image optimization credits regardless for any future plan that you\'ll choose to purchase.', 'autoptimize'), '<a href="https://shortpixel.com/aospai'.$sp_url_suffix.'" target="_blank">', '</a>');
1099 1099
                         }
1100
-                        echo apply_filters( 'autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1 . ' ' . $upsell_msg_2 . '</p>' );
1100
+                        echo apply_filters('autoptimize_imgopt_imgopt_settings_copy', $upsell_msg_1.' '.$upsell_msg_2.'</p>');
1101 1101
                     }
1102 1102
                     // translators: link points to shortpixel FAQ.
1103
-                    $faqcopy = sprintf( __( '<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize' ), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>' );
1104
-                    $faqcopy = $faqcopy . ' ' . __( 'Only works for sites/ images that are publicly available.', 'autoptimize' );
1103
+                    $faqcopy = sprintf(__('<strong>Questions</strong>? Have a look at the %1$sShortPixel FAQ%2$s!', 'autoptimize'), '<strong><a href="https://help.shortpixel.com/category/405-autoptimize" target="_blank">', '</strong></a>');
1104
+                    $faqcopy = $faqcopy.' '.__('Only works for sites/ images that are publicly available.', 'autoptimize');
1105 1105
                     // translators: links points to shortpixel TOS & Privacy Policy.
1106
-                    $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>' );
1107
-                    echo apply_filters( 'autoptimize_imgopt_imgopt_settings_tos', '<p>' . $faqcopy . ' ' . $toscopy . '</p>' );
1106
+                    $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>');
1107
+                    echo apply_filters('autoptimize_imgopt_imgopt_settings_tos', '<p>'.$faqcopy.' '.$toscopy.'</p>');
1108 1108
                     ?>
1109 1109
                 </td>
1110 1110
             </tr>
1111
-            <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"'; } ?>>
1112
-                <th scope="row"><?php _e( 'Image Optimization quality', 'autoptimize' ); ?></th>
1111
+            <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"'; } ?>>
1112
+                <th scope="row"><?php _e('Image Optimization quality', 'autoptimize'); ?></th>
1113 1113
                 <td>
1114 1114
                     <label>
1115 1115
                     <select name='autoptimize_imgopt_settings[autoptimize_imgopt_select_field_2]'>
@@ -1117,12 +1117,12 @@  discard block
 block discarded – undo
1117 1117
                         $_imgopt_array = autoptimizeImages::instance()->get_img_quality_array();
1118 1118
                         $_imgopt_val   = autoptimizeImages::instance()->get_img_quality_setting();
1119 1119
 
1120
-                        foreach ( $_imgopt_array as $key => $value ) {
1121
-                            echo '<option value="' . $key . '"';
1122
-                            if ( $_imgopt_val == $key ) {
1120
+                        foreach ($_imgopt_array as $key => $value) {
1121
+                            echo '<option value="'.$key.'"';
1122
+                            if ($_imgopt_val == $key) {
1123 1123
                                 echo ' selected';
1124 1124
                             }
1125
-                            echo '>' . ucfirst( $value ) . '</option>';
1125
+                            echo '>'.ucfirst($value).'</option>';
1126 1126
                         }
1127 1127
                         echo "\n";
1128 1128
                         ?>
@@ -1131,31 +1131,31 @@  discard block
 block discarded – undo
1131 1131
                     <p>
1132 1132
                         <?php
1133 1133
                             // translators: link points to shortpixel image test page.
1134
-                            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>' ) );
1134
+                            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>'));
1135 1135
                         ?>
1136 1136
                     </p>
1137 1137
                 </td>
1138 1138
             </tr>
1139
-            <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"'; } ?>>
1140
-                <th scope="row"><?php _e( 'Load WebP or AVIF in supported browsers?', 'autoptimize' ); ?></th>
1139
+            <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"'; } ?>>
1140
+                <th scope="row"><?php _e('Load WebP or AVIF in supported browsers?', 'autoptimize'); ?></th>
1141 1141
                 <td>
1142
-                    <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>
1142
+                    <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>
1143 1143
                 </td>
1144 1144
             </tr>
1145 1145
             <tr>
1146
-                <th scope="row"><?php _e( 'Lazy-load images?', 'autoptimize' ); ?></th>
1146
+                <th scope="row"><?php _e('Lazy-load images?', 'autoptimize'); ?></th>
1147 1147
                 <td>
1148
-                    <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>
1148
+                    <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>
1149 1149
                 </td>
1150 1150
             </tr>
1151
-            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if ( ! array_key_exists( 'autoptimize_imgopt_checkbox_field_3', $options ) || ( isset( $options['autoptimize_imgopt_checkbox_field_3'] ) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'] ) ) { echo 'class="hidden"'; } ?>>
1152
-                <th scope="row"><?php _e( 'Lazy-load exclusions', 'autoptimize' ); ?></th>
1151
+            <tr id='autoptimize_imgopt_lazyload_exclusions' <?php if (!array_key_exists('autoptimize_imgopt_checkbox_field_3', $options) || (isset($options['autoptimize_imgopt_checkbox_field_3']) && '1' !== $options['autoptimize_imgopt_checkbox_field_3'])) { echo 'class="hidden"'; } ?>>
1152
+                <th scope="row"><?php _e('Lazy-load exclusions', 'autoptimize'); ?></th>
1153 1153
                 <td>
1154
-                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if ( ! empty( $options['autoptimize_imgopt_text_field_5'] ) ) { echo esc_attr( $options['autoptimize_imgopt_text_field_5'] ); } ?>'><br /><?php _e( 'Comma-separated list of to be excluded image classes or filenames.', 'autoptimize' ); ?></label>
1154
+                    <label><input type='text' style='width:80%' id='autoptimize_imgopt_lazyload_exclusions' name='autoptimize_imgopt_settings[autoptimize_imgopt_text_field_5]' value='<?php if (!empty($options['autoptimize_imgopt_text_field_5'])) { echo esc_attr($options['autoptimize_imgopt_text_field_5']); } ?>'><br /><?php _e('Comma-separated list of to be excluded image classes or filenames.', 'autoptimize'); ?></label>
1155 1155
                 </td>
1156 1156
             </tr>
1157 1157
         </table>
1158
-        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p>
1158
+        <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p>
1159 1159
     </form>
1160 1160
     <script>
1161 1161
         jQuery(document).ready(function() {
@@ -1191,50 +1191,50 @@  discard block
 block discarded – undo
1191 1191
      * Ïmg opt status as used on dashboard.
1192 1192
      */
1193 1193
     public function get_imgopt_status_notice() {
1194
-        if ( $this->imgopt_active() ) {
1194
+        if ($this->imgopt_active()) {
1195 1195
             $_imgopt_notice  = '';
1196
-            $_stat           = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1196
+            $_stat           = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1197 1197
             $_site_host      = AUTOPTIMIZE_SITE_DOMAIN;
1198
-            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/' . $_site_host;
1198
+            $_imgopt_upsell  = 'https://shortpixel.com/aospai/af/GWRGFLW109483/'.$_site_host;
1199 1199
             $_imgopt_assoc   = 'https://shortpixel.helpscoutdocs.com/article/94-how-to-associate-a-domain-to-my-account';
1200 1200
             $_imgopt_unreach = 'https://shortpixel.helpscoutdocs.com/article/148-why-are-my-images-redirected-from-cdn-shortpixel-ai';
1201 1201
 
1202
-            if ( is_array( $_stat ) ) {
1203
-                if ( 1 == $_stat['Status'] ) {
1202
+            if (is_array($_stat)) {
1203
+                if (1 == $_stat['Status']) {
1204 1204
                     // translators: "add more credits" will appear in a "a href".
1205
-                    $_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>' );
1205
+                    $_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>');
1206 1206
                 } elseif ( -1 == $_stat['Status'] || -2 == $_stat['Status'] ) {
1207 1207
                     // translators: "add more credits" will appear in a "a href".
1208
-                    $_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>' );
1208
+                    $_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>');
1209 1209
                     // translators: "associate your domain" will appear in a "a href".
1210
-                    $_imgopt_notice = $_imgopt_notice . ' ' . sprintf( __( 'If you have enough credits/ CDN quota remaining, then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize' ), '<a rel="noopener noreferrer" href="' . $_imgopt_assoc . '" target="_blank">', '</a>' );
1210
+                    $_imgopt_notice = $_imgopt_notice.' '.sprintf(__('If you have enough credits/ CDN quota remaining, then you may need to %1$sassociate your domain%2$s to your Shortpixel account.', 'autoptimize'), '<a rel="noopener noreferrer" href="'.$_imgopt_assoc.'" target="_blank">', '</a>');
1211 1211
                 } elseif ( -3 == $_stat['Status'] ) {
1212 1212
                     // translators: "check the documentation here" will appear in a "a href".
1213
-                    $_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>' );
1213
+                    $_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>');
1214 1214
                 } else {
1215 1215
                     $_imgopt_upsell = 'https://shortpixel.com/g/af/GWRGFLW109483';
1216 1216
                     // translators: "log in to check your account" will appear in a "a href".
1217
-                    $_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>' );
1217
+                    $_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>');
1218 1218
                 }
1219 1219
 
1220 1220
                 // add info on freshness + refresh link if status is not 2 (good shape).
1221
-                if ( 2 != $_stat['Status'] ) {
1222
-                    $_imgopt_stats_refresh_url = add_query_arg( array(
1221
+                if (2 != $_stat['Status']) {
1222
+                    $_imgopt_stats_refresh_url = add_query_arg(array(
1223 1223
                         'page'                => 'autoptimize_imgopt',
1224 1224
                         'refreshImgProvStats' => '1',
1225
-                    ), admin_url( 'options-general.php' ) );
1226
-                    if ( $_stat && array_key_exists( 'timestamp', $_stat ) && ! empty( $_stat['timestamp'] ) ) {
1227
-                        $_imgopt_stats_last_run = __( 'based on status at ', 'autoptimize' ) . date_i18n( autoptimizeOptionWrapper::get_option( 'time_format' ), $_stat['timestamp'] );
1225
+                    ), admin_url('options-general.php'));
1226
+                    if ($_stat && array_key_exists('timestamp', $_stat) && !empty($_stat['timestamp'])) {
1227
+                        $_imgopt_stats_last_run = __('based on status at ', 'autoptimize').date_i18n(autoptimizeOptionWrapper::get_option('time_format'), $_stat['timestamp']);
1228 1228
                     } else {
1229
-                        $_imgopt_stats_last_run = __( 'based on previously fetched data', 'autoptimize' );
1229
+                        $_imgopt_stats_last_run = __('based on previously fetched data', 'autoptimize');
1230 1230
                     }
1231
-                    $_imgopt_notice .= ' (' . $_imgopt_stats_last_run . ', ';
1231
+                    $_imgopt_notice .= ' ('.$_imgopt_stats_last_run.', ';
1232 1232
                     // translators: "here to refresh" links to the Autoptimize Extra page and forces a refresh of the img opt stats.
1233
-                    $_imgopt_notice .= sprintf( __( 'click %1$shere to refresh%2$s', 'autoptimize' ), '<a href="' . $_imgopt_stats_refresh_url . '">', '</a>).' );
1233
+                    $_imgopt_notice .= sprintf(__('click %1$shere to refresh%2$s', 'autoptimize'), '<a href="'.$_imgopt_stats_refresh_url.'">', '</a>).');
1234 1234
                 }
1235 1235
 
1236 1236
                 // and make the full notice filterable.
1237
-                $_imgopt_notice = apply_filters( 'autoptimize_filter_imgopt_notice', $_imgopt_notice );
1237
+                $_imgopt_notice = apply_filters('autoptimize_filter_imgopt_notice', $_imgopt_notice);
1238 1238
 
1239 1239
                 return array(
1240 1240
                     'status' => $_stat['Status'],
@@ -1255,14 +1255,14 @@  discard block
 block discarded – undo
1255 1255
      * Get img provider stats (used to display notice).
1256 1256
      */
1257 1257
     public function query_img_provider_stats() {
1258
-        if ( ! empty( $this->options['autoptimize_imgopt_checkbox_field_1'] ) ) {
1258
+        if (!empty($this->options['autoptimize_imgopt_checkbox_field_1'])) {
1259 1259
             $url      = '';
1260
-            $endpoint = $this->get_imgopt_host() . 'read-domain/';
1260
+            $endpoint = $this->get_imgopt_host().'read-domain/';
1261 1261
             $domain   = AUTOPTIMIZE_SITE_DOMAIN;
1262 1262
 
1263 1263
             // make sure parse_url result makes sense, keeping $url empty if not.
1264
-            if ( $domain && ! empty( $domain ) ) {
1265
-                $url = $endpoint . $domain;
1264
+            if ($domain && !empty($domain)) {
1265
+                $url = $endpoint.$domain;
1266 1266
             }
1267 1267
 
1268 1268
             $url = apply_filters(
@@ -1272,12 +1272,12 @@  discard block
 block discarded – undo
1272 1272
 
1273 1273
             // only do the remote call if $url is not empty to make sure no parse_url
1274 1274
             // weirdness results in useless calls.
1275
-            if ( ! empty( $url ) ) {
1276
-                $response = wp_remote_get( $url );
1277
-                if ( ! is_wp_error( $response ) ) {
1278
-                    if ( '200' == wp_remote_retrieve_response_code( $response ) ) {
1279
-                        $stats = json_decode( wp_remote_retrieve_body( $response ), true );
1280
-                        autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_provider_stat', $stats );
1275
+            if (!empty($url)) {
1276
+                $response = wp_remote_get($url);
1277
+                if (!is_wp_error($response)) {
1278
+                    if ('200' == wp_remote_retrieve_response_code($response)) {
1279
+                        $stats = json_decode(wp_remote_retrieve_body($response), true);
1280
+                        autoptimizeOptionWrapper::update_option('autoptimize_imgopt_provider_stat', $stats);
1281 1281
                     }
1282 1282
                 }
1283 1283
             }
@@ -1300,15 +1300,15 @@  discard block
 block discarded – undo
1300 1300
     {
1301 1301
         static $launch_status = null;
1302 1302
 
1303
-        if ( null === $launch_status ) {
1303
+        if (null === $launch_status) {
1304 1304
             $avail_imgopt  = $this->options['availabilities']['extra_imgopt'];
1305
-            $magic_number  = intval( substr( md5( parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ), 0, 3 ), 16 );
1306
-            $has_launched  = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_launched', '' );
1305
+            $magic_number  = intval(substr(md5(parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)), 0, 3), 16);
1306
+            $has_launched  = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_launched', '');
1307 1307
             $launch_status = false;
1308
-            if ( $has_launched || ( is_array( $avail_imgopt ) && array_key_exists( 'launch-threshold', $avail_imgopt ) && $magic_number < $avail_imgopt['launch-threshold'] ) ) {
1308
+            if ($has_launched || (is_array($avail_imgopt) && array_key_exists('launch-threshold', $avail_imgopt) && $magic_number < $avail_imgopt['launch-threshold'])) {
1309 1309
                 $launch_status = true;
1310
-                if ( ! $has_launched ) {
1311
-                    autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_launched', 'on' );
1310
+                if (!$has_launched) {
1311
+                    autoptimizeOptionWrapper::update_option('autoptimize_imgopt_launched', 'on');
1312 1312
                 }
1313 1313
             }
1314 1314
         }
@@ -1325,16 +1325,16 @@  discard block
 block discarded – undo
1325 1325
     public function get_imgopt_provider_userstatus() {
1326 1326
         static $_provider_userstatus = null;
1327 1327
 
1328
-        if ( is_null( $_provider_userstatus ) ) {
1329
-            $_stat = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_provider_stat', '' );
1330
-            if ( is_array( $_stat ) ) {
1331
-                if ( array_key_exists( 'Status', $_stat ) ) {
1328
+        if (is_null($_provider_userstatus)) {
1329
+            $_stat = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_provider_stat', '');
1330
+            if (is_array($_stat)) {
1331
+                if (array_key_exists('Status', $_stat)) {
1332 1332
                     $_provider_userstatus['Status'] = $_stat['Status'];
1333 1333
                 } else {
1334 1334
                     // if no stats then we assume all is well.
1335 1335
                     $_provider_userstatus['Status'] = 2;
1336 1336
                 }
1337
-                if ( array_key_exists( 'timestamp', $_stat ) ) {
1337
+                if (array_key_exists('timestamp', $_stat)) {
1338 1338
                     $_provider_userstatus['timestamp'] = $_stat['timestamp'];
1339 1339
                 } else {
1340 1340
                     // if no timestamp then we return "".
Please login to merge, or discard this patch.