Completed
Push — master ( 8e7dca...6ec0d0 )
by frank
01:41
created
classes/autoptimizeCLI.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
  * WP-CLI commands for Autoptimize.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
10 10
 // This is a WP-CLI command, so bail if it's not available.
11
-if ( ! defined( 'WP_CLI' ) ) {
11
+if (!defined('WP_CLI')) {
12 12
     return;
13 13
 }
14 14
 
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
      *
25 25
      * @return void
26 26
      */
27
-    public function clear( $args, $args_assoc ) {
28
-        WP_CLI::line( esc_html__( 'Flushing the cache...', 'autoptimize' ) );
27
+    public function clear($args, $args_assoc) {
28
+        WP_CLI::line(esc_html__('Flushing the cache...', 'autoptimize'));
29 29
         autoptimizeCache::clearall();
30
-        WP_CLI::success( esc_html__( 'Cache flushed.', 'autoptimize' ) );
30
+        WP_CLI::success(esc_html__('Cache flushed.', 'autoptimize'));
31 31
     }
32 32
 }
33 33
 
34
-WP_CLI::add_command( 'autoptimize', 'autoptimizeCLI' );
34
+WP_CLI::add_command('autoptimize', 'autoptimizeCLI');
Please login to merge, or discard this patch.
classes/autoptimizeCache.php 1 patch
Spacing   +134 added lines, -134 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,17 +38,17 @@  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
         $this->cachedir = AUTOPTIMIZE_CACHE_DIR;
44 44
         $this->nogzip   = AUTOPTIMIZE_CACHE_NOGZIP;
45
-        if ( ! $this->nogzip ) {
46
-            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.php';
45
+        if (!$this->nogzip) {
46
+            $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.php';
47 47
         } else {
48
-            if ( in_array( $ext, array( 'js', 'css' ) ) ) {
49
-                $this->filename = $ext . '/' . AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.' . $ext;
48
+            if (in_array($ext, array('js', 'css'))) {
49
+                $this->filename = $ext.'/'.AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.'.$ext;
50 50
             } else {
51
-                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX . $md5 . '.' . $ext;
51
+                $this->filename = AUTOPTIMIZE_CACHEFILE_PREFIX.$md5.'.'.$ext;
52 52
             }
53 53
         }
54 54
     }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function check()
62 62
     {
63
-        return file_exists( $this->cachedir . $this->filename );
63
+        return file_exists($this->cachedir.$this->filename);
64 64
     }
65 65
 
66 66
     /**
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public function retrieve()
72 72
     {
73
-        if ( $this->check() ) {
74
-            if ( false == $this->nogzip ) {
75
-                return file_get_contents( $this->cachedir . $this->filename . '.none' );
73
+        if ($this->check()) {
74
+            if (false == $this->nogzip) {
75
+                return file_get_contents($this->cachedir.$this->filename.'.none');
76 76
             } else {
77
-                return file_get_contents( $this->cachedir . $this->filename );
77
+                return file_get_contents($this->cachedir.$this->filename);
78 78
             }
79 79
         }
80 80
         return false;
@@ -88,22 +88,22 @@  discard block
 block discarded – undo
88 88
      *
89 89
      * @return void
90 90
      */
91
-    public function cache( $data, $mime )
91
+    public function cache($data, $mime)
92 92
     {
93
-        if ( false === $this->nogzip ) {
93
+        if (false === $this->nogzip) {
94 94
             // We handle gzipping ourselves.
95 95
             $file    = 'default.php';
96
-            $phpcode = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $file );
97
-            $phpcode = str_replace( array( '%%CONTENT%%', 'exit;' ), array( $mime, '' ), $phpcode );
96
+            $phpcode = file_get_contents(AUTOPTIMIZE_PLUGIN_DIR.'config/'.$file);
97
+            $phpcode = str_replace(array('%%CONTENT%%', 'exit;'), array($mime, ''), $phpcode);
98 98
 
99
-            file_put_contents( $this->cachedir . $this->filename, $phpcode );
100
-            file_put_contents( $this->cachedir . $this->filename . '.none', $data );
99
+            file_put_contents($this->cachedir.$this->filename, $phpcode);
100
+            file_put_contents($this->cachedir.$this->filename.'.none', $data);
101 101
         } else {
102 102
             // Write code to cache without doing anything else.
103
-            file_put_contents( $this->cachedir . $this->filename, $data );
104
-            if ( apply_filters( 'autoptimize_filter_cache_create_static_gzip', false ) ) {
103
+            file_put_contents($this->cachedir.$this->filename, $data);
104
+            if (apply_filters('autoptimize_filter_cache_create_static_gzip', false)) {
105 105
                 // Create an additional cached gzip file.
106
-                file_put_contents( $this->cachedir . $this->filename . '.gz', gzencode( $data, 9, FORCE_GZIP ) );
106
+                file_put_contents($this->cachedir.$this->filename.'.gz', gzencode($data, 9, FORCE_GZIP));
107 107
             }
108 108
         }
109 109
     }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         // The original idea here was to provide 3rd party code a hook so that
121 121
         // it can "listen" to all the complete autoptimized-urls that the page
122 122
         // will emit... Or something to that effect I think?
123
-        apply_filters( 'autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL . $this->filename );
123
+        apply_filters('autoptimize_filter_cache_getname', AUTOPTIMIZE_CACHE_URL.$this->filename);
124 124
 
125 125
         return $this->filename;
126 126
     }
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
      * @param string $file Filename.
134 134
      * @return bool
135 135
      */
136
-    protected static function is_valid_cache_file( $dir, $file )
136
+    protected static function is_valid_cache_file($dir, $file)
137 137
     {
138
-        if ( '.' !== $file && '..' !== $file &&
139
-            false !== strpos( $file, AUTOPTIMIZE_CACHEFILE_PREFIX ) &&
140
-            is_file( $dir . $file ) ) {
138
+        if ('.' !== $file && '..' !== $file &&
139
+            false !== strpos($file, AUTOPTIMIZE_CACHEFILE_PREFIX) &&
140
+            is_file($dir.$file)) {
141 141
 
142 142
             // It's a valid file!
143 143
             return true;
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
     protected static function clear_cache_classic()
156 156
     {
157 157
         $contents = self::get_cache_contents();
158
-        foreach ( $contents as $name => $files ) {
159
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
160
-            foreach ( $files as $file ) {
161
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
162
-                    @unlink( $dir . $file ); // @codingStandardsIgnoreLine
158
+        foreach ($contents as $name => $files) {
159
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
160
+            foreach ($files as $file) {
161
+                if (self::is_valid_cache_file($dir, $file)) {
162
+                    @unlink($dir.$file); // @codingStandardsIgnoreLine
163 163
                 }
164 164
             }
165 165
         }
166 166
 
167
-        @unlink( AUTOPTIMIZE_CACHE_DIR . '/.htaccess' ); // @codingStandardsIgnoreLine
167
+        @unlink(AUTOPTIMIZE_CACHE_DIR.'/.htaccess'); // @codingStandardsIgnoreLine
168 168
     }
169 169
 
170 170
     /**
@@ -175,19 +175,19 @@  discard block
 block discarded – undo
175 175
      *
176 176
      * @return bool
177 177
      */
178
-    protected static function rmdir( $pathname )
178
+    protected static function rmdir($pathname)
179 179
     {
180
-        $files = self::get_dir_contents( $pathname );
181
-        foreach ( $files as $file ) {
182
-            $path = $pathname . '/' . $file;
183
-            if ( is_dir( $path ) ) {
184
-                self::rmdir( $path );
180
+        $files = self::get_dir_contents($pathname);
181
+        foreach ($files as $file) {
182
+            $path = $pathname.'/'.$file;
183
+            if (is_dir($path)) {
184
+                self::rmdir($path);
185 185
             } else {
186
-                unlink( $path );
186
+                unlink($path);
187 187
             }
188 188
         }
189 189
 
190
-        return rmdir( $pathname );
190
+        return rmdir($pathname);
191 191
     }
192 192
 
193 193
     /**
@@ -204,12 +204,12 @@  discard block
 block discarded – undo
204 204
         $new_name = self::get_unique_name();
205 205
 
206 206
         // Makes sure the new pathname is on the same level...
207
-        $new_pathname = dirname( $dir ) . '/' . $new_name;
208
-        $renamed      = @rename( $dir, $new_pathname ); // @codingStandardsIgnoreLine
207
+        $new_pathname = dirname($dir).'/'.$new_name;
208
+        $renamed      = @rename($dir, $new_pathname); // @codingStandardsIgnoreLine
209 209
 
210 210
         // When renamed, re-create the default cache directory back so it's
211 211
         // available again...
212
-        if ( $renamed ) {
212
+        if ($renamed) {
213 213
             $ok = self::cacheavail();
214 214
         }
215 215
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      */
224 224
     public static function advanced_cache_clear_enabled()
225 225
     {
226
-        return apply_filters( 'autoptimize_filter_cache_clear_advanced', false );
226
+        return apply_filters('autoptimize_filter_cache_clear_advanced', false);
227 227
     }
228 228
 
229 229
     /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
     protected static function get_unique_name()
235 235
     {
236 236
         $prefix   = self::get_advanced_cache_clear_prefix();
237
-        $new_name = uniqid( $prefix, true );
237
+        $new_name = uniqid($prefix, true);
238 238
 
239 239
         return $new_name;
240 240
     }
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
     protected static function get_advanced_cache_clear_prefix()
248 248
     {
249 249
         $pathname = self::get_pathname_base();
250
-        $basename = basename( $pathname );
251
-        $prefix   = $basename . '-';
250
+        $basename = basename($pathname);
251
+        $prefix   = $basename.'-';
252 252
 
253 253
         return $prefix;
254 254
     }
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
      *
262 262
      * @return array
263 263
      */
264
-    protected static function get_dir_contents( $pathname )
264
+    protected static function get_dir_contents($pathname)
265 265
     {
266
-        return array_slice( scandir( $pathname ), 2 );
266
+        return array_slice(scandir($pathname), 2);
267 267
     }
268 268
 
269 269
     /**
@@ -277,17 +277,17 @@  discard block
 block discarded – undo
277 277
     {
278 278
         $dir    = self::get_pathname_base();
279 279
         $prefix = self::get_advanced_cache_clear_prefix();
280
-        $parent = dirname( $dir );
280
+        $parent = dirname($dir);
281 281
         $ok     = false;
282 282
 
283 283
         // Returns the list of files without '.' and '..' elements.
284
-        $files = self::get_dir_contents( $parent );
285
-        foreach ( $files as $file ) {
286
-            $path     = $parent . '/' . $file;
287
-            $prefixed = ( false !== strpos( $path, $prefix ) );
284
+        $files = self::get_dir_contents($parent);
285
+        foreach ($files as $file) {
286
+            $path     = $parent.'/'.$file;
287
+            $prefixed = (false !== strpos($path, $prefix));
288 288
             // Removing only our own (prefixed) directories...
289
-            if ( is_dir( $path ) && $prefixed ) {
290
-                $ok = self::rmdir( $path );
289
+            if (is_dir($path) && $prefixed) {
290
+                $ok = self::rmdir($path);
291 291
             }
292 292
         }
293 293
 
@@ -306,9 +306,9 @@  discard block
 block discarded – undo
306 306
     {
307 307
         $pathname = self::get_pathname_base();
308 308
 
309
-        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
309
+        if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
310 310
             $blog_id   = get_current_blog_id();
311
-            $pathname .= $blog_id . '/';
311
+            $pathname .= $blog_id.'/';
312 312
         }
313 313
 
314 314
         return $pathname;
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      */
322 322
     protected static function get_pathname_base()
323 323
     {
324
-        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
324
+        $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR;
325 325
 
326 326
         return $pathname;
327 327
     }
@@ -333,38 +333,38 @@  discard block
 block discarded – undo
333 333
      *
334 334
      * @return bool
335 335
      */
336
-    public static function clearall( $propagate = true )
336
+    public static function clearall($propagate = true)
337 337
     {
338
-        if ( ! self::cacheavail() ) {
338
+        if (!self::cacheavail()) {
339 339
             return false;
340 340
         }
341 341
 
342 342
         // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
343
-        if ( self::advanced_cache_clear_enabled() ) {
343
+        if (self::advanced_cache_clear_enabled()) {
344 344
             self::clear_cache_via_rename();
345 345
         } else {
346 346
             self::clear_cache_classic();
347 347
         }
348 348
 
349 349
         // Remove the transient so it gets regenerated...
350
-        delete_transient( 'autoptimize_stats' );
350
+        delete_transient('autoptimize_stats');
351 351
 
352 352
         // Cache was just purged, clear page cache and allow others to hook into our purging...
353
-        if ( true === $propagate ) {
354
-            if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) {
353
+        if (true === $propagate) {
354
+            if (!function_exists('autoptimize_do_cachepurged_action')) {
355 355
                 function autoptimize_do_cachepurged_action() {
356
-                    do_action( 'autoptimize_action_cachepurged' );
356
+                    do_action('autoptimize_action_cachepurged');
357 357
                 }
358 358
             }
359
-            add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 );
360
-            add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 );
359
+            add_action('shutdown', 'autoptimize_do_cachepurged_action', 11);
360
+            add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0);
361 361
         }
362 362
 
363 363
         // Warm cache (part of speedupper)!
364
-        if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
365
-            $url   = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 );
366
-            $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine
367
-            unset( $cache );
364
+        if (apply_filters('autoptimize_filter_speedupper', true)) {
365
+            $url   = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000);
366
+            $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine
367
+            unset($cache);
368 368
         }
369 369
 
370 370
         return true;
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
      */
380 380
     public static function clearall_actionless()
381 381
     {
382
-        return self::clearall( false );
382
+        return self::clearall(false);
383 383
     }
384 384
 
385 385
     /**
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
     {
392 392
         $contents = array();
393 393
 
394
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
395
-            $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir );
394
+        foreach (array('', 'js', 'css') as $dir) {
395
+            $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir);
396 396
         }
397 397
 
398 398
         return $contents;
@@ -405,21 +405,21 @@  discard block
 block discarded – undo
405 405
      */
406 406
     public static function stats()
407 407
     {
408
-        $stats = get_transient( 'autoptimize_stats' );
408
+        $stats = get_transient('autoptimize_stats');
409 409
 
410 410
         // If no transient, do the actual scan!
411
-        if ( ! is_array( $stats ) ) {
412
-            if ( ! self::cacheavail() ) {
411
+        if (!is_array($stats)) {
412
+            if (!self::cacheavail()) {
413 413
                 return 0;
414 414
             }
415 415
             $stats = self::stats_scan();
416 416
             $count = $stats[0];
417
-            if ( $count > 100 ) {
417
+            if ($count > 100) {
418 418
                 // Store results in transient.
419 419
                 set_transient(
420 420
                     'autoptimize_stats',
421 421
                     $stats,
422
-                    apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS )
422
+                    apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS)
423 423
                 );
424 424
             }
425 425
         }
@@ -442,30 +442,30 @@  discard block
 block discarded – undo
442 442
         $size  = 0;
443 443
 
444 444
         // Scan everything in our cache directories.
445
-        foreach ( self::get_cache_contents() as $name => $files ) {
446
-            $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/';
447
-            foreach ( $files as $file ) {
448
-                if ( self::is_valid_cache_file( $dir, $file ) ) {
449
-                    if ( AUTOPTIMIZE_CACHE_NOGZIP &&
445
+        foreach (self::get_cache_contents() as $name => $files) {
446
+            $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/';
447
+            foreach ($files as $file) {
448
+                if (self::is_valid_cache_file($dir, $file)) {
449
+                    if (AUTOPTIMIZE_CACHE_NOGZIP &&
450 450
                         (
451
-                            false !== strpos( $file, '.js' ) ||
452
-                            false !== strpos( $file, '.css' ) ||
453
-                            false !== strpos( $file, '.img' ) ||
454
-                            false !== strpos( $file, '.txt' )
451
+                            false !== strpos($file, '.js') ||
452
+                            false !== strpos($file, '.css') ||
453
+                            false !== strpos($file, '.img') ||
454
+                            false !== strpos($file, '.txt')
455 455
                         )
456 456
                     ) {
457 457
                         // Web server is gzipping, we count .js|.css|.img|.txt files.
458 458
                         $count++;
459
-                    } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) {
459
+                    } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) {
460 460
                         // We are gzipping ourselves via php, counting only .none files.
461 461
                         $count++;
462 462
                     }
463
-                    $size += filesize( $dir . $file );
463
+                    $size += filesize($dir.$file);
464 464
                 }
465 465
             }
466 466
         }
467 467
 
468
-        $stats = array( $count, $size, time() );
468
+        $stats = array($count, $size, time());
469 469
 
470 470
         return $stats;
471 471
     }
@@ -479,29 +479,29 @@  discard block
 block discarded – undo
479 479
      */
480 480
     public static function cacheavail()
481 481
     {
482
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
482
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
483 483
             // We didn't set a cache.
484 484
             return false;
485 485
         }
486 486
 
487
-        foreach ( array( '', 'js', 'css' ) as $dir ) {
488
-            if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) {
487
+        foreach (array('', 'js', 'css') as $dir) {
488
+            if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) {
489 489
                 return false;
490 490
             }
491 491
         }
492 492
 
493 493
         // Using .htaccess inside our cache folder to overrule wp-super-cache.
494
-        $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess';
495
-        if ( ! is_file( $htaccess ) ) {
494
+        $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess';
495
+        if (!is_file($htaccess)) {
496 496
             /**
497 497
              * Create `wp-content/AO_htaccess_tmpl` file with
498 498
              * whatever htaccess rules you might need
499 499
              * if you want to override default AO htaccess
500 500
              */
501
-            $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl';
502
-            if ( is_file( $htaccess_tmpl ) ) {
503
-                $content = file_get_contents( $htaccess_tmpl );
504
-            } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) {
501
+            $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl';
502
+            if (is_file($htaccess_tmpl)) {
503
+                $content = file_get_contents($htaccess_tmpl);
504
+            } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) {
505 505
                 $content = '<IfModule mod_expires.c>
506 506
         ExpiresActive On
507 507
         ExpiresByType text/css A30672000
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
     </Files>
555 555
 </IfModule>';
556 556
             }
557
-            @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
557
+            @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine
558 558
         }
559 559
 
560 560
         // All OK!
@@ -569,25 +569,25 @@  discard block
 block discarded – undo
569 569
      *
570 570
      * @return bool
571 571
      */
572
-    protected static function check_cache_dir( $dir )
572
+    protected static function check_cache_dir($dir)
573 573
     {
574 574
         // Try creating the dir if it doesn't exist.
575
-        if ( ! file_exists( $dir ) ) {
576
-            @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine
577
-            if ( ! file_exists( $dir ) ) {
575
+        if (!file_exists($dir)) {
576
+            @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine
577
+            if (!file_exists($dir)) {
578 578
                 return false;
579 579
             }
580 580
         }
581 581
 
582 582
         // If we still cannot write, bail.
583
-        if ( ! is_writable( $dir ) ) {
583
+        if (!is_writable($dir)) {
584 584
             return false;
585 585
         }
586 586
 
587 587
         // Create an index.html in there to avoid prying eyes!
588
-        $idx_file = rtrim( $dir, '/\\' ) . '/index.html';
589
-        if ( ! is_file( $idx_file ) ) {
590
-            @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
588
+        $idx_file = rtrim($dir, '/\\').'/index.html';
589
+        if (!is_file($idx_file)) {
590
+            @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
591 591
         }
592 592
 
593 593
         return true;
@@ -601,59 +601,59 @@  discard block
 block discarded – undo
601 601
     // @codingStandardsIgnoreStart
602 602
     public static function flushPageCache()
603 603
     {
604
-        if ( function_exists( 'wp_cache_clear_cache' ) ) {
605
-            if ( is_multisite() ) {
604
+        if (function_exists('wp_cache_clear_cache')) {
605
+            if (is_multisite()) {
606 606
                 $blog_id = get_current_blog_id();
607
-                wp_cache_clear_cache( $blog_id );
607
+                wp_cache_clear_cache($blog_id);
608 608
             } else {
609 609
                 wp_cache_clear_cache();
610 610
             }
611
-        } elseif ( has_action( 'cachify_flush_cache' ) ) {
612
-            do_action( 'cachify_flush_cache' );
613
-        } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
611
+        } elseif (has_action('cachify_flush_cache')) {
612
+            do_action('cachify_flush_cache');
613
+        } elseif (function_exists('w3tc_pgcache_flush')) {
614 614
             w3tc_pgcache_flush();
615
-        } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
615
+        } elseif (function_exists('wp_fast_cache_bulk_delete_all')) {
616 616
             wp_fast_cache_bulk_delete_all();
617
-        } elseif ( class_exists( 'WpFastestCache' ) ) {
617
+        } elseif (class_exists('WpFastestCache')) {
618 618
             $wpfc = new WpFastestCache();
619 619
             $wpfc->deleteCache();
620
-        } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
620
+        } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) {
621 621
             c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
622
-        } elseif ( class_exists( 'zencache' ) ) {
622
+        } elseif (class_exists('zencache')) {
623 623
             zencache::clear();
624
-        } elseif ( class_exists( 'comet_cache' ) ) {
624
+        } elseif (class_exists('comet_cache')) {
625 625
             comet_cache::clear();
626
-        } elseif ( class_exists( 'WpeCommon' ) ) {
626
+        } elseif (class_exists('WpeCommon')) {
627 627
             // WPEngine cache purge/flush methods to call by default
628 628
             $wpe_methods = array(
629 629
                 'purge_varnish_cache',
630 630
             );
631 631
 
632 632
             // More agressive clear/flush/purge behind a filter
633
-            if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) {
634
-                $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) );
633
+            if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) {
634
+                $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache'));
635 635
             }
636 636
 
637 637
             // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing)
638
-            $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods );
638
+            $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods);
639 639
 
640
-            foreach ( $wpe_methods as $wpe_method ) {
641
-                if ( method_exists( 'WpeCommon', $wpe_method ) ) {
640
+            foreach ($wpe_methods as $wpe_method) {
641
+                if (method_exists('WpeCommon', $wpe_method)) {
642 642
                     WpeCommon::$wpe_method();
643 643
                 }
644 644
             }
645
-        } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
645
+        } elseif (function_exists('sg_cachepress_purge_cache')) {
646 646
             sg_cachepress_purge_cache();
647
-        } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
647
+        } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) {
648 648
             // fallback for WP-Super-Cache
649 649
             global $cache_path;
650
-            if ( is_multisite() ) {
650
+            if (is_multisite()) {
651 651
                 $blog_id = get_current_blog_id();
652
-                prune_super_cache( get_supercache_dir( $blog_id ), true );
653
-                prune_super_cache( $cache_path . 'blogs/', true );
652
+                prune_super_cache(get_supercache_dir($blog_id), true);
653
+                prune_super_cache($cache_path.'blogs/', true);
654 654
             } else {
655
-                prune_super_cache( $cache_path . 'supercache/', true );
656
-                prune_super_cache( $cache_path, true );
655
+                prune_super_cache($cache_path.'supercache/', true);
656
+                prune_super_cache($cache_path, true);
657 657
             }
658 658
         }
659 659
     }
Please login to merge, or discard this patch.
classes/autoptimizePartners.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * addons and/or affiliate services.
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -17,64 +17,64 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function run()
19 19
     {
20
-        if ( $this->enabled() ) {
21
-            add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 );
20
+        if ($this->enabled()) {
21
+            add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_partner_tabs'), 10, 1);
22 22
         }
23
-        add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
23
+        add_action('admin_menu', array($this, 'add_admin_menu'));
24 24
     }
25 25
 
26 26
     protected function enabled()
27 27
     {
28
-        return apply_filters( 'autoptimize_filter_show_partner_tabs', true );
28
+        return apply_filters('autoptimize_filter_show_partner_tabs', true);
29 29
     }
30 30
 
31
-    public function add_partner_tabs( $in )
31
+    public function add_partner_tabs($in)
32 32
     {
33
-        $in = array_merge( $in, array(
34
-            'ao_partners' => __( 'Optimize More!', 'autoptimize' ),
35
-        ) );
33
+        $in = array_merge($in, array(
34
+            'ao_partners' => __('Optimize More!', 'autoptimize'),
35
+        ));
36 36
 
37 37
         return $in;
38 38
     }
39 39
 
40 40
     public function add_admin_menu()
41 41
     {
42
-        if ( $this->enabled() ) {
43
-            add_submenu_page( null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array( $this, 'ao_partners_page' ) );
42
+        if ($this->enabled()) {
43
+            add_submenu_page(null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array($this, 'ao_partners_page'));
44 44
         }
45 45
     }
46 46
 
47 47
     protected function get_ao_partner_feed_markup()
48 48
     {
49
-        $no_feed_text = __( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize' );
49
+        $no_feed_text = __('Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize');
50 50
         $output       = '';
51
-        if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
52
-            $rss      = fetch_feed( 'http://feeds.feedburner.com/OptimizingMattersDownloads' );
51
+        if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) {
52
+            $rss      = fetch_feed('http://feeds.feedburner.com/OptimizingMattersDownloads');
53 53
             $maxitems = 0;
54 54
 
55
-            if ( ! is_wp_error( $rss ) ) {
56
-                $maxitems  = $rss->get_item_quantity( 20 );
57
-                $rss_items = $rss->get_items( 0, $maxitems );
55
+            if (!is_wp_error($rss)) {
56
+                $maxitems  = $rss->get_item_quantity(20);
57
+                $rss_items = $rss->get_items(0, $maxitems);
58 58
             }
59 59
 
60
-            if ( 0 == $maxitems ) {
60
+            if (0 == $maxitems) {
61 61
                 $output .= $no_feed_text;
62 62
             } else {
63 63
                 $output .= '<ul>';
64
-                foreach ( $rss_items as $item ) {
65
-                    $item_url  = esc_url( $item->get_permalink() );
64
+                foreach ($rss_items as $item) {
65
+                    $item_url  = esc_url($item->get_permalink());
66 66
                     $enclosure = $item->get_enclosure();
67 67
 
68 68
                     $output .= '<li class="itemDetail">';
69
-                    $output .= '<h3 class="itemTitle"><a href="' . $item_url . '" target="_blank">' . esc_html( $item->get_title() ) . '</a></h3>';
69
+                    $output .= '<h3 class="itemTitle"><a href="'.$item_url.'" target="_blank">'.esc_html($item->get_title()).'</a></h3>';
70 70
 
71
-                    if ( $enclosure && ( false !== strpos( $enclosure->get_type(), 'image' ) ) ) {
72
-                        $img_url = esc_url( $enclosure->get_link() );
73
-                        $output .= '<div class="itemImage"><a href="' . $item_url . '" target="_blank"><img src="' . $img_url . '"></a></div>';
71
+                    if ($enclosure && (false !== strpos($enclosure->get_type(), 'image'))) {
72
+                        $img_url = esc_url($enclosure->get_link());
73
+                        $output .= '<div class="itemImage"><a href="'.$item_url.'" target="_blank"><img src="'.$img_url.'"></a></div>';
74 74
                     }
75 75
 
76
-                    $output .= '<div class="itemDescription">' . wp_kses_post( $item->get_description() ) . '</div>';
77
-                    $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="' . $item_url . '" target="_blank">' . __( 'More info', 'autoptimize' ) . '</a></div></div>';
76
+                    $output .= '<div class="itemDescription">'.wp_kses_post($item->get_description()).'</div>';
77
+                    $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="'.$item_url.'" target="_blank">'.__('More info', 'autoptimize').'</a></div></div>';
78 78
                     $output .= '</li>';
79 79
                 }
80 80
                 $output .= '</ul>';
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
     }
134 134
     </style>
135 135
     <div class="wrap">
136
-        <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
136
+        <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1>
137 137
         <?php echo autoptimizeConfig::ao_admin_tabs(); ?>
138
-        <?php echo '<h2>' . __( "These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize' ) . '</h2>'; ?>
138
+        <?php echo '<h2>'.__("These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize').'</h2>'; ?>
139 139
         <div>
140 140
             <?php echo $this->get_ao_partner_feed_markup(); ?>
141 141
         </div>
Please login to merge, or discard this patch.
classes/autoptimizeMain.php 1 patch
Spacing   +136 added lines, -136 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,84 +50,84 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected function add_hooks()
52 52
     {
53
-        add_action( 'plugins_loaded', array( $this, 'setup' ) );
53
+        add_action('plugins_loaded', array($this, 'setup'));
54 54
 
55
-        add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) );
56
-        add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) );
57
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) );
58
-        add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) );
55
+        add_action('autoptimize_setup_done', array($this, 'version_upgrades_check'));
56
+        add_action('autoptimize_setup_done', array($this, 'check_cache_and_run'));
57
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra'));
58
+        add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab'));
59 59
 
60
-        add_action( 'init', array( $this, 'load_textdomain' ) );
61
-        add_action( 'plugins_loaded', array( $this, 'hook_page_cache_purge' ) );
62
-        add_action( 'admin_init', array( 'PAnD', 'init' ) );
60
+        add_action('init', array($this, 'load_textdomain'));
61
+        add_action('plugins_loaded', array($this, 'hook_page_cache_purge'));
62
+        add_action('admin_init', array('PAnD', 'init'));
63 63
 
64
-        register_activation_hook( $this->filepath, array( $this, 'on_activate' ) );
64
+        register_activation_hook($this->filepath, array($this, 'on_activate'));
65 65
     }
66 66
 
67 67
     public function on_activate()
68 68
     {
69
-        register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' );
69
+        register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall');
70 70
     }
71 71
 
72 72
     public function load_textdomain()
73 73
     {
74
-        load_plugin_textdomain( 'autoptimize' );
74
+        load_plugin_textdomain('autoptimize');
75 75
     }
76 76
 
77 77
     public function setup()
78 78
     {
79 79
         // Do we gzip in php when caching or is the webserver doing it?
80
-        define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option( 'autoptimize_cache_nogzip' ) );
80
+        define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip'));
81 81
 
82 82
         // These can be overridden by specifying them in wp-config.php or such.
83
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) {
84
-            define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) );
83
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) {
84
+            define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR));
85 85
         }
86
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) {
87
-            define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' );
86
+        if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) {
87
+            define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/');
88 88
         }
89
-        if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) {
90
-            define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' );
89
+        if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) {
90
+            define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_');
91 91
         }
92 92
         // Note: trailing slash is not optional!
93
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) {
94
-            define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() );
93
+        if (!defined('AUTOPTIMIZE_CACHE_DIR')) {
94
+            define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname());
95 95
         }
96 96
 
97
-        define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) );
97
+        define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME)));
98 98
 
99
-        if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) {
100
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
101
-                define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) );
99
+        if (!defined('AUTOPTIMIZE_WP_SITE_URL')) {
100
+            if (function_exists('domain_mapping_siteurl')) {
101
+                define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id()));
102 102
             } else {
103
-                define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() );
103
+                define('AUTOPTIMIZE_WP_SITE_URL', site_url());
104 104
             }
105 105
         }
106
-        if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) {
107
-            if ( function_exists( 'domain_mapping_siteurl' ) ) {
108
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) );
106
+        if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) {
107
+            if (function_exists('domain_mapping_siteurl')) {
108
+                define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url()));
109 109
             } else {
110
-                define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() );
110
+                define('AUTOPTIMIZE_WP_CONTENT_URL', content_url());
111 111
             }
112 112
         }
113
-        if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) {
114
-            if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
113
+        if (!defined('AUTOPTIMIZE_CACHE_URL')) {
114
+            if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) {
115 115
                 $blog_id = get_current_blog_id();
116
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' );
116
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/');
117 117
             } else {
118
-                define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR );
118
+                define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
119 119
             }
120 120
         }
121
-        if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) {
122
-            define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) );
121
+        if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) {
122
+            define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL));
123 123
         }
124
-        if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) {
125
-            define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) );
124
+        if (!defined('AUTOPTIMIZE_HASH')) {
125
+            define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL));
126 126
         }
127
-        if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) {
128
-            define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) );
127
+        if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) {
128
+            define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST));
129 129
         }
130
-        do_action( 'autoptimize_setup_done' );
130
+        do_action('autoptimize_setup_done');
131 131
     }
132 132
 
133 133
     /**
@@ -137,40 +137,40 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public function version_upgrades_check()
139 139
     {
140
-        autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version );
140
+        autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version);
141 141
     }
142 142
 
143 143
     public function check_cache_and_run()
144 144
     {
145
-        if ( autoptimizeCache::cacheavail() ) {
145
+        if (autoptimizeCache::cacheavail()) {
146 146
             $conf = autoptimizeConfig::instance();
147
-            if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) {
147
+            if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) {
148 148
                 // Hook into WordPress frontend.
149
-                if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) {
149
+                if (defined('AUTOPTIMIZE_INIT_EARLIER')) {
150 150
                     add_action(
151 151
                         'init',
152
-                        array( $this, 'start_buffering' ),
152
+                        array($this, 'start_buffering'),
153 153
                         self::INIT_EARLIER_PRIORITY
154 154
                     );
155 155
                 } else {
156
-                    if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) {
157
-                        define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' );
156
+                    if (!defined('AUTOPTIMIZE_HOOK_INTO')) {
157
+                        define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect');
158 158
                     }
159 159
                     add_action(
160
-                        constant( 'AUTOPTIMIZE_HOOK_INTO' ),
161
-                        array( $this, 'start_buffering' ),
160
+                        constant('AUTOPTIMIZE_HOOK_INTO'),
161
+                        array($this, 'start_buffering'),
162 162
                         self::DEFAULT_HOOK_PRIORITY
163 163
                     );
164 164
                 }
165 165
             }
166 166
         } else {
167
-            add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' );
167
+            add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable');
168 168
         }
169 169
     }
170 170
 
171 171
     public function maybe_run_ao_extra()
172 172
     {
173
-        if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) {
173
+        if (apply_filters('autoptimize_filter_extra_activate', true)) {
174 174
             $ao_extra = new autoptimizeExtra();
175 175
             $ao_extra->run();
176 176
         }
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     public function maybe_run_partners_tab()
180 180
     {
181 181
         // Loads partners tab code if in admin (and not in admin-ajax.php)!
182
-        if ( autoptimizeConfig::is_admin_and_not_ajax() ) {
182
+        if (autoptimizeConfig::is_admin_and_not_ajax()) {
183 183
             new autoptimizePartners();
184 184
         }
185 185
     }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function hook_page_cache_purge()
188 188
     {
189 189
         // hook into a collection of page cache purge actions if filter allows.
190
-        if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) {
190
+        if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) {
191 191
             $page_cache_purge_actions = array(
192 192
                 'after_rocket_clean_domain', // exists.
193 193
                 'hyper_cache_purged', // Stefano confirmed this will be added.
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
                 'wpfc_delete_cache', // Emre confirmed this will be added this.
200 200
                 'swift_performance_after_clear_all_cache', // swift perf. yeah!
201 201
             );
202
-            $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions );
203
-            foreach ( $page_cache_purge_actions as $purge_action ) {
204
-                add_action( $purge_action, 'autoptimizeCache::clearall_actionless' );
202
+            $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions);
203
+            foreach ($page_cache_purge_actions as $purge_action) {
204
+                add_action($purge_action, 'autoptimizeCache::clearall_actionless');
205 205
             }
206 206
         }
207 207
     }
@@ -213,38 +213,38 @@  discard block
 block discarded – undo
213 213
      */
214 214
     public function start_buffering()
215 215
     {
216
-        if ( $this->should_buffer() ) {
216
+        if ($this->should_buffer()) {
217 217
 
218 218
             // Load speedupper conditionally (true by default).
219
-            if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) {
219
+            if (apply_filters('autoptimize_filter_speedupper', true)) {
220 220
                 $ao_speedupper = new autoptimizeSpeedupper();
221 221
             }
222 222
 
223 223
             $conf = autoptimizeConfig::instance();
224 224
 
225
-            if ( $conf->get( 'autoptimize_js' ) ) {
226
-                if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) {
227
-                    define( 'CONCATENATE_SCRIPTS', false );
225
+            if ($conf->get('autoptimize_js')) {
226
+                if (!defined('CONCATENATE_SCRIPTS')) {
227
+                    define('CONCATENATE_SCRIPTS', false);
228 228
                 }
229
-                if ( ! defined( 'COMPRESS_SCRIPTS' ) ) {
230
-                    define( 'COMPRESS_SCRIPTS', false );
229
+                if (!defined('COMPRESS_SCRIPTS')) {
230
+                    define('COMPRESS_SCRIPTS', false);
231 231
                 }
232 232
             }
233 233
 
234
-            if ( $conf->get( 'autoptimize_css' ) ) {
235
-                if ( ! defined( 'COMPRESS_CSS' ) ) {
236
-                    define( 'COMPRESS_CSS', false );
234
+            if ($conf->get('autoptimize_css')) {
235
+                if (!defined('COMPRESS_CSS')) {
236
+                    define('COMPRESS_CSS', false);
237 237
                 }
238 238
             }
239 239
 
240
-            if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) {
241
-                while ( ob_get_level() > 0 ) {
240
+            if (apply_filters('autoptimize_filter_obkiller', false)) {
241
+                while (ob_get_level() > 0) {
242 242
                     ob_end_clean();
243 243
                 }
244 244
             }
245 245
 
246 246
             // Now, start the real thing!
247
-            ob_start( array( $this, 'end_buffering' ) );
247
+            ob_start(array($this, 'end_buffering'));
248 248
         }
249 249
     }
250 250
 
@@ -255,31 +255,31 @@  discard block
 block discarded – undo
255 255
      *                          deciding once per request (for use in tests).
256 256
      * @return bool
257 257
      */
258
-    public function should_buffer( $doing_tests = false )
258
+    public function should_buffer($doing_tests = false)
259 259
     {
260 260
         static $do_buffering = null;
261 261
 
262 262
         // Only check once in case we're called multiple times by others but
263 263
         // still allows multiple calls when doing tests.
264
-        if ( null === $do_buffering || $doing_tests ) {
264
+        if (null === $do_buffering || $doing_tests) {
265 265
 
266 266
             $ao_noptimize = false;
267 267
 
268 268
             // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS.
269
-            if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) {
269
+            if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) {
270 270
                 $ao_noptimize = true;
271 271
             }
272 272
 
273 273
             // Skip checking query strings if they're disabled.
274
-            if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) {
274
+            if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) {
275 275
                 // Check for `ao_noptimize` (and other) keys in the query string
276 276
                 // to get non-optimized page for debugging.
277 277
                 $keys = array(
278 278
                     'ao_noptimize',
279 279
                     'ao_noptirocket',
280 280
                 );
281
-                foreach ( $keys as $key ) {
282
-                    if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) {
281
+                foreach ($keys as $key) {
282
+                    if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) {
283 283
                         $ao_noptimize = true;
284 284
                         break;
285 285
                     }
@@ -287,15 +287,15 @@  discard block
 block discarded – undo
287 287
             }
288 288
 
289 289
             // If setting says not to optimize logged in user and user is logged in...
290
-            if ( 'on' !== get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
290
+            if ('on' !== get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) {
291 291
                 $ao_noptimize = true;
292 292
             }
293 293
 
294 294
             // If setting says not to optimize cart/checkout.
295
-            if ( 'on' !== get_option( 'autoptimize_optimize_checkout', 'on' ) ) {
295
+            if ('on' !== get_option('autoptimize_optimize_checkout', 'on')) {
296 296
                 // Checking for woocommerce, easy digital downloads and wp ecommerce...
297
-                foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) {
298
-                    if ( function_exists( $func ) && $func() ) {
297
+                foreach (array('is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) {
298
+                    if (function_exists($func) && $func()) {
299 299
                         $ao_noptimize = true;
300 300
                         break;
301 301
                     }
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
             }
304 304
 
305 305
             // Allows blocking of autoptimization on your own terms regardless of above decisions.
306
-            $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );
306
+            $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize);
307 307
 
308 308
             // Check for site being previewed in the Customizer (available since WP 4.0).
309 309
             $is_customize_preview = false;
310
-            if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
310
+            if (function_exists('is_customize_preview') && is_customize_preview()) {
311 311
                 $is_customize_preview = is_customize_preview();
312 312
             }
313 313
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
              * while the main query hasn't been ran yet. Thats why we use
319 319
              * AUTOPTIMIZE_INIT_EARLIER in tests.
320 320
              */
321
-            $do_buffering = ( ! is_admin() && ! is_feed() && ! $ao_noptimize && ! $is_customize_preview );
321
+            $do_buffering = (!is_admin() && !is_feed() && !$ao_noptimize && !$is_customize_preview);
322 322
         }
323 323
 
324 324
         return $do_buffering;
@@ -331,24 +331,24 @@  discard block
 block discarded – undo
331 331
      *
332 332
      * @return bool
333 333
      */
334
-    public function is_valid_buffer( $content )
334
+    public function is_valid_buffer($content)
335 335
     {
336 336
         // Defaults to true.
337 337
         $valid = true;
338 338
 
339
-        $has_no_html_tag    = ( false === stripos( $content, '<html' ) );
340
-        $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) );
341
-        $has_html5_doctype  = ( preg_match( '/^<!DOCTYPE.+html>/i', $content ) > 0 );
339
+        $has_no_html_tag    = (false === stripos($content, '<html'));
340
+        $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet'));
341
+        $has_html5_doctype  = (preg_match('/^<!DOCTYPE.+html>/i', $content) > 0);
342 342
 
343
-        if ( $has_no_html_tag ) {
343
+        if ($has_no_html_tag) {
344 344
             // Can't be valid amp markup without an html tag preceding it.
345 345
             $is_amp_markup = false;
346 346
         } else {
347
-            $is_amp_markup = self::is_amp_markup( $content );
347
+            $is_amp_markup = self::is_amp_markup($content);
348 348
         }
349 349
 
350 350
         // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it.
351
-        if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet ) {
351
+        if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet) {
352 352
             $valid = false;
353 353
         }
354 354
 
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
      *
364 364
      * @return bool
365 365
      */
366
-    public static function is_amp_markup( $content )
366
+    public static function is_amp_markup($content)
367 367
     {
368
-        $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content );
368
+        $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content);
369 369
 
370 370
         return (bool) $is_amp_markup;
371 371
     }
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
      *
379 379
      * @return string
380 380
      */
381
-    public function end_buffering( $content )
381
+    public function end_buffering($content)
382 382
     {
383 383
         // Bail early without modifying anything if we can't handle the content.
384
-        if ( ! $this->is_valid_buffer( $content ) ) {
384
+        if (!$this->is_valid_buffer($content)) {
385 385
             return $content;
386 386
         }
387 387
 
@@ -389,57 +389,57 @@  discard block
 block discarded – undo
389 389
 
390 390
         // Determine what needs to be ran.
391 391
         $classes = array();
392
-        if ( $conf->get( 'autoptimize_js' ) ) {
392
+        if ($conf->get('autoptimize_js')) {
393 393
             $classes[] = 'autoptimizeScripts';
394 394
         }
395
-        if ( $conf->get( 'autoptimize_css' ) ) {
395
+        if ($conf->get('autoptimize_css')) {
396 396
             $classes[] = 'autoptimizeStyles';
397 397
         }
398
-        if ( $conf->get( 'autoptimize_html' ) ) {
398
+        if ($conf->get('autoptimize_html')) {
399 399
             $classes[] = 'autoptimizeHTML';
400 400
         }
401 401
 
402 402
         $classoptions = array(
403 403
             'autoptimizeScripts' => array(
404
-                'aggregate'      => $conf->get( 'autoptimize_js_aggregate' ),
405
-                'justhead'       => $conf->get( 'autoptimize_js_justhead' ),
406
-                'forcehead'      => $conf->get( 'autoptimize_js_forcehead' ),
407
-                'trycatch'       => $conf->get( 'autoptimize_js_trycatch' ),
408
-                'js_exclude'     => $conf->get( 'autoptimize_js_exclude' ),
409
-                'cdn_url'        => $conf->get( 'autoptimize_cdn_url' ),
410
-                'include_inline' => $conf->get( 'autoptimize_js_include_inline' ),
404
+                'aggregate'      => $conf->get('autoptimize_js_aggregate'),
405
+                'justhead'       => $conf->get('autoptimize_js_justhead'),
406
+                'forcehead'      => $conf->get('autoptimize_js_forcehead'),
407
+                'trycatch'       => $conf->get('autoptimize_js_trycatch'),
408
+                'js_exclude'     => $conf->get('autoptimize_js_exclude'),
409
+                'cdn_url'        => $conf->get('autoptimize_cdn_url'),
410
+                'include_inline' => $conf->get('autoptimize_js_include_inline'),
411 411
             ),
412 412
             'autoptimizeStyles'  => array(
413
-                'aggregate'      => $conf->get( 'autoptimize_css_aggregate' ),
414
-                'justhead'       => $conf->get( 'autoptimize_css_justhead' ),
415
-                'datauris'       => $conf->get( 'autoptimize_css_datauris' ),
416
-                'defer'          => $conf->get( 'autoptimize_css_defer' ),
417
-                'defer_inline'   => $conf->get( 'autoptimize_css_defer_inline' ),
418
-                'inline'         => $conf->get( 'autoptimize_css_inline' ),
419
-                'css_exclude'    => $conf->get( 'autoptimize_css_exclude' ),
420
-                'cdn_url'        => $conf->get( 'autoptimize_cdn_url' ),
421
-                'include_inline' => $conf->get( 'autoptimize_css_include_inline' ),
422
-                'nogooglefont'   => $conf->get( 'autoptimize_css_nogooglefont' ),
413
+                'aggregate'      => $conf->get('autoptimize_css_aggregate'),
414
+                'justhead'       => $conf->get('autoptimize_css_justhead'),
415
+                'datauris'       => $conf->get('autoptimize_css_datauris'),
416
+                'defer'          => $conf->get('autoptimize_css_defer'),
417
+                'defer_inline'   => $conf->get('autoptimize_css_defer_inline'),
418
+                'inline'         => $conf->get('autoptimize_css_inline'),
419
+                'css_exclude'    => $conf->get('autoptimize_css_exclude'),
420
+                'cdn_url'        => $conf->get('autoptimize_cdn_url'),
421
+                'include_inline' => $conf->get('autoptimize_css_include_inline'),
422
+                'nogooglefont'   => $conf->get('autoptimize_css_nogooglefont'),
423 423
             ),
424 424
             'autoptimizeHTML'    => array(
425
-                'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ),
425
+                'keepcomments' => $conf->get('autoptimize_html_keepcomments'),
426 426
             ),
427 427
         );
428 428
 
429
-        $content = apply_filters( 'autoptimize_filter_html_before_minify', $content );
429
+        $content = apply_filters('autoptimize_filter_html_before_minify', $content);
430 430
 
431 431
         // Run the classes!
432
-        foreach ( $classes as $name ) {
433
-            $instance = new $name( $content );
434
-            if ( $instance->read( $classoptions[ $name ] ) ) {
432
+        foreach ($classes as $name) {
433
+            $instance = new $name($content);
434
+            if ($instance->read($classoptions[$name])) {
435 435
                 $instance->minify();
436 436
                 $instance->cache();
437 437
                 $content = $instance->getcontent();
438 438
             }
439
-            unset( $instance );
439
+            unset($instance);
440 440
         }
441 441
 
442
-        $content = apply_filters( 'autoptimize_html_after_minify', $content );
442
+        $content = apply_filters('autoptimize_html_after_minify', $content);
443 443
 
444 444
         return $content;
445 445
     }
@@ -481,25 +481,25 @@  discard block
 block discarded – undo
481 481
             'autoptimize_imgopt_launched',
482 482
         );
483 483
 
484
-        if ( ! is_multisite() ) {
485
-            foreach ( $delete_options as $del_opt ) {
486
-                delete_option( $del_opt );
484
+        if (!is_multisite()) {
485
+            foreach ($delete_options as $del_opt) {
486
+                delete_option($del_opt);
487 487
             }
488 488
         } else {
489 489
             global $wpdb;
490
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
490
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
491 491
             $original_blog_id = get_current_blog_id();
492
-            foreach ( $blog_ids as $blog_id ) {
493
-                switch_to_blog( $blog_id );
494
-                foreach ( $delete_options as $del_opt ) {
495
-                    delete_option( $del_opt );
492
+            foreach ($blog_ids as $blog_id) {
493
+                switch_to_blog($blog_id);
494
+                foreach ($delete_options as $del_opt) {
495
+                    delete_option($del_opt);
496 496
                 }
497 497
             }
498
-            switch_to_blog( $original_blog_id );
498
+            switch_to_blog($original_blog_id);
499 499
         }
500 500
 
501
-        if ( wp_get_schedule( 'ao_cachechecker' ) ) {
502
-            wp_clear_scheduled_hook( 'ao_cachechecker' );
501
+        if (wp_get_schedule('ao_cachechecker')) {
502
+            wp_clear_scheduled_hook('ao_cachechecker');
503 503
         }
504 504
     }
505 505
 
@@ -507,21 +507,21 @@  discard block
 block discarded – undo
507 507
     {
508 508
         echo '<div class="error"><p>';
509 509
         // Translators: %s is the cache directory location.
510
-        printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR );
510
+        printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR);
511 511
         echo '</p></div>';
512 512
     }
513 513
 
514 514
     public static function notice_installed()
515 515
     {
516 516
         echo '<div class="updated"><p>';
517
-        _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' );
517
+        _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize');
518 518
         echo '</p></div>';
519 519
     }
520 520
 
521 521
     public static function notice_updated()
522 522
     {
523 523
         echo '<div class="updated"><p>';
524
-        _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' );
524
+        _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize');
525 525
         echo '</p></div>';
526 526
     }
527 527
 
Please login to merge, or discard this patch.
classes/autoptimizeCSSmin.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Thin wrapper around css minifiers to avoid rewriting a bunch of existing code.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @param bool $raise_limits Whether to raise memory limits or not. Default true.
23 23
      */
24
-    public function __construct( $raise_limits = true )
24
+    public function __construct($raise_limits = true)
25 25
     {
26
-        $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier( $raise_limits );
26
+        $this->minifier = new Autoptimize\tubalmartin\CssMin\Minifier($raise_limits);
27 27
     }
28 28
 
29 29
     /**
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @return string
36 36
      */
37
-    public function run( $css )
37
+    public function run($css)
38 38
     {
39
-        $result = $this->minifier->run( $css );
39
+        $result = $this->minifier->run($css);
40 40
 
41 41
         return $result;
42 42
     }
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @return string
50 50
      */
51
-    public static function minify( $css )
51
+    public static function minify($css)
52 52
     {
53 53
         $minifier = new self();
54 54
 
55
-        return $minifier->run( $css );
55
+        return $minifier->run($css);
56 56
     }
57 57
 }
Please login to merge, or discard this patch.
classes/autoptimizeVersionUpdatesHandler.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles version updates and should only be instantiated in autoptimize.php if/when needed.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      */
17 17
     protected $current_major_version = null;
18 18
 
19
-    public function __construct( $current_version )
19
+    public function __construct($current_version)
20 20
     {
21
-        $this->current_major_version = substr( $current_version, 0, 3 );
21
+        $this->current_major_version = substr($current_version, 0, 3);
22 22
     }
23 23
 
24 24
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $major_update = false;
31 31
 
32
-        switch ( $this->current_major_version ) {
32
+        switch ($this->current_major_version) {
33 33
             case '1.6':
34 34
                 $this->upgrade_from_1_6();
35 35
                 $major_update = true;
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
                 // No break, intentionally, so all upgrades are ran during a single request...
49 49
         }
50 50
 
51
-        if ( true === $major_update ) {
51
+        if (true === $major_update) {
52 52
             $this->on_major_version_update();
53 53
         }
54 54
     }
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @param string $target Target version to check against (ie., the currently running one).
62 62
      */
63
-    public static function check_installed_and_update( $target )
63
+    public static function check_installed_and_update($target)
64 64
     {
65
-        $db_version = get_option( 'autoptimize_version', 'none' );
66
-        if ( $db_version !== $target ) {
67
-            if ( 'none' === $db_version ) {
68
-                add_action( 'admin_notices', 'autoptimizeMain::notice_installed' );
65
+        $db_version = get_option('autoptimize_version', 'none');
66
+        if ($db_version !== $target) {
67
+            if ('none' === $db_version) {
68
+                add_action('admin_notices', 'autoptimizeMain::notice_installed');
69 69
             } else {
70
-                $updater = new self( $db_version );
70
+                $updater = new self($db_version);
71 71
                 $updater->run_needed_major_upgrades();
72 72
             }
73 73
 
74 74
             // Versions differed, upgrades happened if needed, store the new version.
75
-            update_option( 'autoptimize_version', $target );
75
+            update_option('autoptimize_version', $target);
76 76
         }
77 77
     }
78 78
 
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
     protected function on_major_version_update()
84 84
     {
85 85
         // The transients guard here prevents stale object caches from busting the cache on every request.
86
-        if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) {
87
-            set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS );
86
+        if (false == get_transient('autoptimize_stale_option_buster')) {
87
+            set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS);
88 88
             autoptimizeCache::clearall();
89
-            add_action( 'admin_notices', 'autoptimizeMain::notice_updated' );
89
+            add_action('admin_notices', 'autoptimizeMain::notice_updated');
90 90
         }
91 91
     }
92 92
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     private function upgrade_from_1_6()
97 97
     {
98 98
         // If user was on version 1.6.x, force advanced options to be shown by default.
99
-        update_option( 'autoptimize_show_adv', '1' );
99
+        update_option('autoptimize_show_adv', '1');
100 100
 
101 101
         // And remove old options.
102 102
         $to_delete_options = array(
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
             'autoptimize_cdn_img_url',
109 109
             'autoptimize_css_yui',
110 110
         );
111
-        foreach ( $to_delete_options as $del_opt ) {
112
-            delete_option( $del_opt );
111
+        foreach ($to_delete_options as $del_opt) {
112
+            delete_option($del_opt);
113 113
         }
114 114
     }
115 115
 
@@ -120,29 +120,29 @@  discard block
 block discarded – undo
120 120
      */
121 121
     private function upgrade_from_1_7()
122 122
     {
123
-        if ( ! is_multisite() ) {
124
-            $css_exclude = get_option( 'autoptimize_css_exclude' );
125
-            if ( empty( $css_exclude ) ) {
123
+        if (!is_multisite()) {
124
+            $css_exclude = get_option('autoptimize_css_exclude');
125
+            if (empty($css_exclude)) {
126 126
                 $css_exclude = 'admin-bar.min.css, dashicons.min.css';
127
-            } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
127
+            } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
128 128
                 $css_exclude .= ', dashicons.min.css';
129 129
             }
130
-            update_option( 'autoptimize_css_exclude', $css_exclude );
130
+            update_option('autoptimize_css_exclude', $css_exclude);
131 131
         } else {
132 132
             global $wpdb;
133
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
133
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
134 134
             $original_blog_id = get_current_blog_id();
135
-            foreach ( $blog_ids as $blog_id ) {
136
-                switch_to_blog( $blog_id );
137
-                $css_exclude = get_option( 'autoptimize_css_exclude' );
138
-                if ( empty( $css_exclude ) ) {
135
+            foreach ($blog_ids as $blog_id) {
136
+                switch_to_blog($blog_id);
137
+                $css_exclude = get_option('autoptimize_css_exclude');
138
+                if (empty($css_exclude)) {
139 139
                     $css_exclude = 'admin-bar.min.css, dashicons.min.css';
140
-                } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) {
140
+                } elseif (false === strpos($css_exclude, 'dashicons.min.css')) {
141 141
                     $css_exclude .= ', dashicons.min.css';
142 142
                 }
143
-                update_option( 'autoptimize_css_exclude', $css_exclude );
143
+                update_option('autoptimize_css_exclude', $css_exclude);
144 144
             }
145
-            switch_to_blog( $original_blog_id );
145
+            switch_to_blog($original_blog_id);
146 146
         }
147 147
     }
148 148
 
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
      */
155 155
     private function upgrade_from_1_9()
156 156
     {
157
-        if ( ! is_multisite() ) {
158
-            update_option( 'autoptimize_css_include_inline', 'on' );
159
-            update_option( 'autoptimize_js_include_inline', 'on' );
157
+        if (!is_multisite()) {
158
+            update_option('autoptimize_css_include_inline', 'on');
159
+            update_option('autoptimize_js_include_inline', 'on');
160 160
         } else {
161 161
             global $wpdb;
162
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
162
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
163 163
             $original_blog_id = get_current_blog_id();
164
-            foreach ( $blog_ids as $blog_id ) {
165
-                switch_to_blog( $blog_id );
166
-                update_option( 'autoptimize_css_include_inline', 'on' );
167
-                update_option( 'autoptimize_js_include_inline', 'on' );
164
+            foreach ($blog_ids as $blog_id) {
165
+                switch_to_blog($blog_id);
166
+                update_option('autoptimize_css_include_inline', 'on');
167
+                update_option('autoptimize_js_include_inline', 'on');
168 168
             }
169
-            switch_to_blog( $original_blog_id );
169
+            switch_to_blog($original_blog_id);
170 170
         }
171 171
     }
172 172
 
@@ -177,17 +177,17 @@  discard block
 block discarded – undo
177 177
      */
178 178
     private function upgrade_from_2_2()
179 179
     {
180
-        if ( ! is_multisite() ) {
180
+        if (!is_multisite()) {
181 181
             $this->do_2_2_settings_update();
182 182
         } else {
183 183
             global $wpdb;
184
-            $blog_ids         = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
184
+            $blog_ids         = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
185 185
             $original_blog_id = get_current_blog_id();
186
-            foreach ( $blog_ids as $blog_id ) {
187
-                switch_to_blog( $blog_id );
186
+            foreach ($blog_ids as $blog_id) {
187
+                switch_to_blog($blog_id);
188 188
                 $this->do_2_2_settings_update();
189 189
             }
190
-            switch_to_blog( $original_blog_id );
190
+            switch_to_blog($original_blog_id);
191 191
         }
192 192
     }
193 193
 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
      */
197 197
     private function do_2_2_settings_update()
198 198
     {
199
-        $nogooglefont    = get_option( 'autoptimize_css_nogooglefont', '' );
200
-        $ao_extrasetting = get_option( 'autoptimize_extra_settings', '' );
201
-        if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) {
202
-            update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() );
199
+        $nogooglefont    = get_option('autoptimize_css_nogooglefont', '');
200
+        $ao_extrasetting = get_option('autoptimize_extra_settings', '');
201
+        if (($nogooglefont) && (empty($ao_extrasetting))) {
202
+            update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options());
203 203
         }
204
-        delete_option( 'autoptimize_css_nogooglefont' );
204
+        delete_option('autoptimize_css_nogooglefont');
205 205
     }
206 206
 }
Please login to merge, or discard this patch.
classes/autoptimizeBase.php 1 patch
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Base class other (more-specific) classes inherit from.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public $debug_log = false;
25 25
 
26
-    public function __construct( $content )
26
+    public function __construct($content)
27 27
     {
28 28
         $this->content = $content;
29 29
     }
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      *
36 36
      * @return bool
37 37
      */
38
-    abstract public function read( $options );
38
+    abstract public function read($options);
39 39
 
40 40
     /**
41 41
      * Joins and optimizes collected things.
@@ -66,40 +66,40 @@  discard block
 block discarded – undo
66 66
      *
67 67
      * @return bool|string
68 68
      */
69
-    public function getpath( $url )
69
+    public function getpath($url)
70 70
     {
71
-        $url = apply_filters( 'autoptimize_filter_cssjs_alter_url', $url );
71
+        $url = apply_filters('autoptimize_filter_cssjs_alter_url', $url);
72 72
 
73
-        if ( false !== strpos( $url, '%' ) ) {
74
-            $url = urldecode( $url );
73
+        if (false !== strpos($url, '%')) {
74
+            $url = urldecode($url);
75 75
         }
76 76
 
77
-        $site_host    = parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST );
78
-        $content_host = parse_url( AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST );
77
+        $site_host    = parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST);
78
+        $content_host = parse_url(AUTOPTIMIZE_WP_ROOT_URL, PHP_URL_HOST);
79 79
 
80 80
         // Normalizing attempts...
81
-        $double_slash_position = strpos( $url, '//' );
82
-        if ( 0 === $double_slash_position ) {
83
-            if ( is_ssl() ) {
84
-                $url = 'https:' . $url;
81
+        $double_slash_position = strpos($url, '//');
82
+        if (0 === $double_slash_position) {
83
+            if (is_ssl()) {
84
+                $url = 'https:'.$url;
85 85
             } else {
86
-                $url = 'http:' . $url;
86
+                $url = 'http:'.$url;
87 87
             }
88
-        } elseif ( ( false === $double_slash_position ) && ( false === strpos( $url, $site_host ) ) ) {
89
-            if ( AUTOPTIMIZE_WP_SITE_URL === $site_host ) {
90
-                $url = AUTOPTIMIZE_WP_SITE_URL . $url;
88
+        } elseif ((false === $double_slash_position) && (false === strpos($url, $site_host))) {
89
+            if (AUTOPTIMIZE_WP_SITE_URL === $site_host) {
90
+                $url = AUTOPTIMIZE_WP_SITE_URL.$url;
91 91
             } else {
92
-                $url = AUTOPTIMIZE_WP_SITE_URL . autoptimizeUtils::path_canonicalize( $url );
92
+                $url = AUTOPTIMIZE_WP_SITE_URL.autoptimizeUtils::path_canonicalize($url);
93 93
             }
94 94
         }
95 95
 
96
-        if ( $site_host !== $content_host ) {
97
-            $url = str_replace( AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL . AUTOPTIMIZE_WP_CONTENT_NAME, $url );
96
+        if ($site_host !== $content_host) {
97
+            $url = str_replace(AUTOPTIMIZE_WP_CONTENT_URL, AUTOPTIMIZE_WP_SITE_URL.AUTOPTIMIZE_WP_CONTENT_NAME, $url);
98 98
         }
99 99
 
100 100
         // First check; hostname wp site should be hostname of url!
101
-        $url_host = @parse_url( $url, PHP_URL_HOST ); // @codingStandardsIgnoreLine
102
-        if ( $url_host !== $site_host ) {
101
+        $url_host = @parse_url($url, PHP_URL_HOST); // @codingStandardsIgnoreLine
102
+        if ($url_host !== $site_host) {
103 103
             /**
104 104
              * First try to get all domains from WPML (if available)
105 105
              * then explicitely declare $this->cdn_url as OK as well
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
              */
109 109
             $multidomains = array();
110 110
 
111
-            $multidomains_wpml = apply_filters( 'wpml_setting', array(), 'language_domains' );
112
-            if ( ! empty( $multidomains_wpml ) ) {
113
-                $multidomains = array_map( array( $this, 'get_url_hostname' ), $multidomains_wpml );
111
+            $multidomains_wpml = apply_filters('wpml_setting', array(), 'language_domains');
112
+            if (!empty($multidomains_wpml)) {
113
+                $multidomains = array_map(array($this, 'get_url_hostname'), $multidomains_wpml);
114 114
             }
115 115
 
116
-            if ( ! empty( $this->cdn_url ) ) {
117
-                $multidomains[] = parse_url( $this->cdn_url, PHP_URL_HOST );
116
+            if (!empty($this->cdn_url)) {
117
+                $multidomains[] = parse_url($this->cdn_url, PHP_URL_HOST);
118 118
             }
119 119
 
120
-            $multidomains = apply_filters( 'autoptimize_filter_cssjs_multidomain', $multidomains );
120
+            $multidomains = apply_filters('autoptimize_filter_cssjs_multidomain', $multidomains);
121 121
 
122
-            if ( ! empty( $multidomains ) ) {
123
-                if ( in_array( $url_host, $multidomains ) ) {
124
-                    $url = str_replace( $url_host, $site_host, $url );
122
+            if (!empty($multidomains)) {
123
+                if (in_array($url_host, $multidomains)) {
124
+                    $url = str_replace($url_host, $site_host, $url);
125 125
                 } else {
126 126
                     return false;
127 127
                 }
@@ -131,28 +131,28 @@  discard block
 block discarded – undo
131 131
         }
132 132
 
133 133
         // Try to remove "wp root url" from url while not minding http<>https.
134
-        $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL );
134
+        $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_ROOT_URL);
135 135
 
136
-        if ( $site_host !== $content_host ) {
136
+        if ($site_host !== $content_host) {
137 137
             // As we replaced the content-domain with the site-domain, we should match against that.
138
-            $tmp_ao_root = preg_replace( '/https?:/', '', AUTOPTIMIZE_WP_SITE_URL );
138
+            $tmp_ao_root = preg_replace('/https?:/', '', AUTOPTIMIZE_WP_SITE_URL);
139 139
         }
140 140
 
141
-        $tmp_url = preg_replace( '/https?:/', '', $url );
142
-        $path    = str_replace( $tmp_ao_root, '', $tmp_url );
141
+        $tmp_url = preg_replace('/https?:/', '', $url);
142
+        $path    = str_replace($tmp_ao_root, '', $tmp_url);
143 143
 
144 144
         // If path starts with :// or //, this is not a URL in the WP context and
145 145
         // we have to assume we can't aggregate.
146
-        if ( preg_match( '#^:?//#', $path ) ) {
146
+        if (preg_match('#^:?//#', $path)) {
147 147
             // External script/css (adsense, etc).
148 148
             return false;
149 149
         }
150 150
 
151 151
         // Prepend with WP_ROOT_DIR to have full path to file.
152
-        $path = str_replace( '//', '/', WP_ROOT_DIR . $path );
152
+        $path = str_replace('//', '/', WP_ROOT_DIR.$path);
153 153
 
154 154
         // Final check: does file exist and is it readable?
155
-        if ( file_exists( $path ) && is_file( $path ) && is_readable( $path ) ) {
155
+        if (file_exists($path) && is_file($path) && is_readable($path)) {
156 156
             return $path;
157 157
         } else {
158 158
             return false;
@@ -169,18 +169,18 @@  discard block
 block discarded – undo
169 169
      *
170 170
      * @return string
171 171
      */
172
-    protected function get_url_hostname( $url )
172
+    protected function get_url_hostname($url)
173 173
     {
174 174
         // Checking that the url starts with something vaguely resembling a protocol.
175
-        if ( ( 0 !== strpos( $url, 'http' ) ) && ( 0 !== strpos( $url, '//' ) ) ) {
176
-            $url = 'http://' . $url;
175
+        if ((0 !== strpos($url, 'http')) && (0 !== strpos($url, '//'))) {
176
+            $url = 'http://'.$url;
177 177
         }
178 178
 
179 179
         // Grab the hostname.
180
-        $hostname = parse_url( $url, PHP_URL_HOST );
180
+        $hostname = parse_url($url, PHP_URL_HOST);
181 181
 
182 182
         // Fallback when parse_url() fails.
183
-        if ( empty( $hostname ) ) {
183
+        if (empty($hostname)) {
184 184
             $hostname = $url;
185 185
         }
186 186
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      *
195 195
      * @return string
196 196
      */
197
-    protected function hide_noptimize( $markup )
197
+    protected function hide_noptimize($markup)
198 198
     {
199 199
         return $this->replace_contents_with_marker_if_exists(
200 200
             'NOPTIMIZE',
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return string
213 213
      */
214
-    protected function restore_noptimize( $markup )
214
+    protected function restore_noptimize($markup)
215 215
     {
216
-        return $this->restore_marked_content( 'NOPTIMIZE', $markup );
216
+        return $this->restore_marked_content('NOPTIMIZE', $markup);
217 217
     }
218 218
 
219 219
     /**
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      *
224 224
      * @return string
225 225
      */
226
-    protected function hide_iehacks( $markup )
226
+    protected function hide_iehacks($markup)
227 227
     {
228 228
         return $this->replace_contents_with_marker_if_exists(
229 229
             'IEHACK', // Marker name...
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
      *
241 241
      * @return string
242 242
      */
243
-    protected function restore_iehacks( $markup )
243
+    protected function restore_iehacks($markup)
244 244
     {
245
-        return $this->restore_marked_content( 'IEHACK', $markup );
245
+        return $this->restore_marked_content('IEHACK', $markup);
246 246
     }
247 247
 
248 248
     /**
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      *
255 255
      * @return string
256 256
      */
257
-    protected function hide_comments( $markup )
257
+    protected function hide_comments($markup)
258 258
     {
259 259
         return $this->replace_contents_with_marker_if_exists(
260 260
             'COMMENTS',
@@ -272,9 +272,9 @@  discard block
 block discarded – undo
272 272
      *
273 273
      * @return string
274 274
      */
275
-    protected function restore_comments( $markup )
275
+    protected function restore_comments($markup)
276 276
     {
277
-        return $this->restore_marked_content( 'COMMENTS', $markup );
277
+        return $this->restore_marked_content('COMMENTS', $markup);
278 278
     }
279 279
 
280 280
     /**
@@ -285,44 +285,44 @@  discard block
 block discarded – undo
285 285
      *
286 286
      * @return string
287 287
      */
288
-    public function url_replace_cdn( $url )
288
+    public function url_replace_cdn($url)
289 289
     {
290 290
         // For 2.3 back-compat in which cdn-ing appeared to be automatically
291 291
         // including WP subfolder/subdirectory into account as part of cdn-ing,
292 292
         // even though it might've caused serious troubles in certain edge-cases.
293
-        $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed( $this->cdn_url );
293
+        $cdn_url = autoptimizeUtils::tweak_cdn_url_if_needed($this->cdn_url);
294 294
 
295 295
         // Allows API/filter to further tweak the cdn url...
296
-        $cdn_url = apply_filters( 'autoptimize_filter_base_cdnurl', $cdn_url );
297
-        if ( ! empty( $cdn_url ) ) {
298
-            $this->debug_log( 'before=' . $url );
296
+        $cdn_url = apply_filters('autoptimize_filter_base_cdnurl', $cdn_url);
297
+        if (!empty($cdn_url)) {
298
+            $this->debug_log('before='.$url);
299 299
 
300 300
             // Simple str_replace-based approach fails when $url is protocol-or-host-relative.
301
-            $is_protocol_relative = autoptimizeUtils::is_protocol_relative( $url );
302
-            $is_host_relative     = ( ! $is_protocol_relative && ( '/' === $url{0} ) );
303
-            $cdn_url              = rtrim( $cdn_url, '/' );
301
+            $is_protocol_relative = autoptimizeUtils::is_protocol_relative($url);
302
+            $is_host_relative     = (!$is_protocol_relative && ('/' === $url{0} ));
303
+            $cdn_url              = rtrim($cdn_url, '/');
304 304
 
305
-            if ( $is_host_relative ) {
305
+            if ($is_host_relative) {
306 306
                 // Prepending host-relative urls with the cdn url.
307
-                $url = $cdn_url . $url;
307
+                $url = $cdn_url.$url;
308 308
             } else {
309 309
                 // Either a protocol-relative or "regular" url, replacing it either way.
310
-                if ( $is_protocol_relative ) {
310
+                if ($is_protocol_relative) {
311 311
                     // Massage $site_url so that simple str_replace() still "works" by
312 312
                     // searching for the protocol-relative version of AUTOPTIMIZE_WP_SITE_URL.
313
-                    $site_url = str_replace( array( 'http:', 'https:' ), '', AUTOPTIMIZE_WP_SITE_URL );
313
+                    $site_url = str_replace(array('http:', 'https:'), '', AUTOPTIMIZE_WP_SITE_URL);
314 314
                 } else {
315 315
                     $site_url = AUTOPTIMIZE_WP_SITE_URL;
316 316
                 }
317
-                $this->debug_log( '`' . $site_url . '` -> `' . $cdn_url . '` in `' . $url . '`' );
318
-                $url = str_replace( $site_url, $cdn_url, $url );
317
+                $this->debug_log('`'.$site_url.'` -> `'.$cdn_url.'` in `'.$url.'`');
318
+                $url = str_replace($site_url, $cdn_url, $url);
319 319
             }
320 320
 
321
-            $this->debug_log( 'after=' . $url );
321
+            $this->debug_log('after='.$url);
322 322
         }
323 323
 
324 324
         // Allow API filter to take further care of CDN replacement.
325
-        $url = apply_filters( 'autoptimize_filter_base_replace_cdn', $url );
325
+        $url = apply_filters('autoptimize_filter_base_replace_cdn', $url);
326 326
 
327 327
         return $url;
328 328
     }
@@ -340,18 +340,18 @@  discard block
 block discarded – undo
340 340
      *
341 341
      * @return void
342 342
      */
343
-    protected function inject_in_html( $payload, $where )
343
+    protected function inject_in_html($payload, $where)
344 344
     {
345 345
         $warned   = false;
346
-        $position = autoptimizeUtils::strpos( $this->content, $where[0] );
347
-        if ( false !== $position ) {
346
+        $position = autoptimizeUtils::strpos($this->content, $where[0]);
347
+        if (false !== $position) {
348 348
             // Found the tag, setup content/injection as specified.
349
-            if ( 'after' === $where[1] ) {
350
-                $content = $where[0] . $payload;
351
-            } elseif ( 'replace' === $where[1] ) {
349
+            if ('after' === $where[1]) {
350
+                $content = $where[0].$payload;
351
+            } elseif ('replace' === $where[1]) {
352 352
                 $content = $payload;
353 353
             } else {
354
-                $content = $payload . $where[0];
354
+                $content = $payload.$where[0];
355 355
             }
356 356
             // Place where specified.
357 357
             $this->content = autoptimizeUtils::substr_replace(
@@ -360,14 +360,14 @@  discard block
 block discarded – undo
360 360
                 $position,
361 361
                 // Using plain strlen() should be safe here for now, since
362 362
                 // we're not searching for multibyte chars here still...
363
-                strlen( $where[0] )
363
+                strlen($where[0])
364 364
             );
365 365
         } else {
366 366
             // Couldn't find what was specified, just append and add a warning.
367 367
             $this->content .= $payload;
368
-            if ( ! $warned ) {
369
-                $tag_display    = str_replace( array( '<', '>' ), '', $where[0] );
370
-                $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `' . $tag_display . '` missing --><!--/noptimize-->';
368
+            if (!$warned) {
369
+                $tag_display    = str_replace(array('<', '>'), '', $where[0]);
370
+                $this->content .= '<!--noptimize--><!-- Autoptimize found a problem with the HTML in your Theme, tag `'.$tag_display.'` missing --><!--/noptimize-->';
371 371
                 $warned         = true;
372 372
             }
373 373
         }
@@ -381,10 +381,10 @@  discard block
 block discarded – undo
381 381
      *
382 382
      * @return bool
383 383
      */
384
-    protected function isremovable( $tag, $removables )
384
+    protected function isremovable($tag, $removables)
385 385
     {
386
-        foreach ( $removables as $match ) {
387
-            if ( false !== strpos( $tag, $match ) ) {
386
+        foreach ($removables as $match) {
387
+            if (false !== strpos($tag, $match)) {
388 388
                 return true;
389 389
             }
390 390
         }
@@ -399,10 +399,10 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @return string
401 401
      */
402
-    public function inject_minified_callback( $matches )
402
+    public function inject_minified_callback($matches)
403 403
     {
404 404
         static $conf = null;
405
-        if ( null === $conf ) {
405
+        if (null === $conf) {
406 406
             $conf = autoptimizeConfig::instance();
407 407
         }
408 408
 
@@ -417,62 +417,62 @@  discard block
 block discarded – undo
417 417
         $filehash = null;
418 418
 
419 419
         // Grab the parts we need.
420
-        $parts = explode( $matches[1], '|' );
421
-        if ( ! empty( $parts ) ) {
422
-            $filepath = isset( $parts[0] ) ? $parts[0] : null;
423
-            $filehash = isset( $parts[1] ) ? $parts[1] : null;
420
+        $parts = explode($matches[1], '|');
421
+        if (!empty($parts)) {
422
+            $filepath = isset($parts[0]) ? $parts[0] : null;
423
+            $filehash = isset($parts[1]) ? $parts[1] : null;
424 424
         }
425 425
 
426 426
         // Bail early if something's not right...
427
-        if ( ! $filepath || ! $filehash ) {
427
+        if (!$filepath || !$filehash) {
428 428
             return "\n";
429 429
         }
430 430
 
431
-        $filecontent = file_get_contents( $filepath );
431
+        $filecontent = file_get_contents($filepath);
432 432
 
433 433
         // Some things are differently handled for css/js...
434
-        $is_js_file = ( '.js' === substr( $filepath, -3, 3 ) );
434
+        $is_js_file = ('.js' === substr($filepath, -3, 3));
435 435
 
436 436
         $is_css_file = false;
437
-        if ( ! $is_js_file ) {
438
-            $is_css_file = ( '.css' === substr( $filepath, -4, 4 ) );
437
+        if (!$is_js_file) {
438
+            $is_css_file = ('.css' === substr($filepath, -4, 4));
439 439
         }
440 440
 
441 441
         // BOMs being nuked here unconditionally (regardless of where they are)!
442
-        $filecontent = preg_replace( "#\x{EF}\x{BB}\x{BF}#", '', $filecontent );
442
+        $filecontent = preg_replace("#\x{EF}\x{BB}\x{BF}#", '', $filecontent);
443 443
 
444 444
         // Remove comments and blank lines.
445
-        if ( $is_js_file ) {
446
-            $filecontent = preg_replace( '#^\s*\/\/.*$#Um', '', $filecontent );
445
+        if ($is_js_file) {
446
+            $filecontent = preg_replace('#^\s*\/\/.*$#Um', '', $filecontent);
447 447
         }
448 448
 
449 449
         // Nuke un-important comments.
450
-        $filecontent = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent );
450
+        $filecontent = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Um', '', $filecontent);
451 451
 
452 452
         // Normalize newlines.
453
-        $filecontent = preg_replace( '#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent );
453
+        $filecontent = preg_replace('#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#', "\n", $filecontent);
454 454
 
455 455
         // JS specifics.
456
-        if ( $is_js_file ) {
456
+        if ($is_js_file) {
457 457
             // Append a semicolon at the end of js files if it's missing.
458
-            $last_char = substr( $filecontent, -1, 1 );
459
-            if ( ';' !== $last_char && '}' !== $last_char ) {
458
+            $last_char = substr($filecontent, -1, 1);
459
+            if (';' !== $last_char && '}' !== $last_char) {
460 460
                 $filecontent .= ';';
461 461
             }
462 462
             // Check if try/catch should be used.
463
-            $opt_js_try_catch = $conf->get( 'autoptimize_js_trycatch' );
464
-            if ( 'on' === $opt_js_try_catch ) {
463
+            $opt_js_try_catch = $conf->get('autoptimize_js_trycatch');
464
+            if ('on' === $opt_js_try_catch) {
465 465
                 // It should, wrap in try/catch.
466
-                $filecontent = 'try{' . $filecontent . '}catch(e){}';
466
+                $filecontent = 'try{'.$filecontent.'}catch(e){}';
467 467
             }
468
-        } elseif ( $is_css_file ) {
469
-            $filecontent = autoptimizeStyles::fixurls( $filepath, $filecontent );
468
+        } elseif ($is_css_file) {
469
+            $filecontent = autoptimizeStyles::fixurls($filepath, $filecontent);
470 470
         } else {
471 471
             $filecontent = '';
472 472
         }
473 473
 
474 474
         // Return modified (or empty!) code/content.
475
-        return "\n" . $filecontent;
475
+        return "\n".$filecontent;
476 476
     }
477 477
 
478 478
     /**
@@ -482,14 +482,14 @@  discard block
 block discarded – undo
482 482
      *
483 483
      * @return string
484 484
      */
485
-    protected function inject_minified( $in )
485
+    protected function inject_minified($in)
486 486
     {
487 487
         $out = $in;
488 488
 
489
-        if ( false !== strpos( $in, '%%INJECTLATER%%' ) ) {
489
+        if (false !== strpos($in, '%%INJECTLATER%%')) {
490 490
             $out = preg_replace_callback(
491
-                '#\/\*\!%%INJECTLATER' . AUTOPTIMIZE_HASH . '%%(.*?)%%INJECTLATER%%\*\/#is',
492
-                array( $this, 'inject_minified_callback' ),
491
+                '#\/\*\!%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%\*\/#is',
492
+                array($this, 'inject_minified_callback'),
493 493
                 $in
494 494
             );
495 495
         }
@@ -509,9 +509,9 @@  discard block
 block discarded – undo
509 509
      *
510 510
      * @return string
511 511
      */
512
-    public static function build_injectlater_marker( $filepath, $hash )
512
+    public static function build_injectlater_marker($filepath, $hash)
513 513
     {
514
-        $contents = '/*!' . self::build_marker( 'INJECTLATER', $filepath, $hash ) . '*/';
514
+        $contents = '/*!'.self::build_marker('INJECTLATER', $filepath, $hash).'*/';
515 515
 
516 516
         return $contents;
517 517
     }
@@ -529,18 +529,18 @@  discard block
 block discarded – undo
529 529
      *
530 530
      * @return string
531 531
      */
532
-    public static function build_marker( $name, $data, $hash = null )
532
+    public static function build_marker($name, $data, $hash = null)
533 533
     {
534 534
         // Start the marker, add the data.
535
-        $marker = '%%' . $name . AUTOPTIMIZE_HASH . '%%' . base64_encode( $data );
535
+        $marker = '%%'.$name.AUTOPTIMIZE_HASH.'%%'.base64_encode($data);
536 536
 
537 537
         // Add the hash if provided.
538
-        if ( null !== $hash ) {
539
-            $marker .= '|' . $hash;
538
+        if (null !== $hash) {
539
+            $marker .= '|'.$hash;
540 540
         }
541 541
 
542 542
         // Close the marker.
543
-        $marker .= '%%' . $name . '%%';
543
+        $marker .= '%%'.$name.'%%';
544 544
 
545 545
         return $marker;
546 546
     }
@@ -560,22 +560,22 @@  discard block
 block discarded – undo
560 560
      *
561 561
      * @return string
562 562
      */
563
-    protected function replace_contents_with_marker_if_exists( $marker, $search, $re_replace_pattern, $content )
563
+    protected function replace_contents_with_marker_if_exists($marker, $search, $re_replace_pattern, $content)
564 564
     {
565 565
         $found = false;
566 566
 
567
-        $is_regex = autoptimizeUtils::str_is_valid_regex( $search );
568
-        if ( $is_regex ) {
569
-            $found = preg_match( $search, $content );
567
+        $is_regex = autoptimizeUtils::str_is_valid_regex($search);
568
+        if ($is_regex) {
569
+            $found = preg_match($search, $content);
570 570
         } else {
571
-            $found = ( false !== strpos( $content, $search ) );
571
+            $found = (false !== strpos($content, $search));
572 572
         }
573 573
 
574
-        if ( $found ) {
574
+        if ($found) {
575 575
             $content = preg_replace_callback(
576 576
                 $re_replace_pattern,
577
-                function( $matches ) use ( $marker ) {
578
-                    return autoptimizeBase::build_marker( $marker, $matches[0] );
577
+                function($matches) use ($marker) {
578
+                    return autoptimizeBase::build_marker($marker, $matches[0]);
579 579
                 },
580 580
                 $content
581 581
             );
@@ -592,13 +592,13 @@  discard block
 block discarded – undo
592 592
      *
593 593
      * @return string
594 594
      */
595
-    protected function restore_marked_content( $marker, $content )
595
+    protected function restore_marked_content($marker, $content)
596 596
     {
597
-        if ( false !== strpos( $content, $marker ) ) {
597
+        if (false !== strpos($content, $marker)) {
598 598
             $content = preg_replace_callback(
599
-                '#%%' . $marker . AUTOPTIMIZE_HASH . '%%(.*?)%%' . $marker . '%%#is',
600
-                function ( $matches ) {
601
-                    return base64_decode( $matches[1] );
599
+                '#%%'.$marker.AUTOPTIMIZE_HASH.'%%(.*?)%%'.$marker.'%%#is',
600
+                function($matches) {
601
+                    return base64_decode($matches[1]);
602 602
                 },
603 603
                 $content
604 604
             );
@@ -614,17 +614,17 @@  discard block
 block discarded – undo
614 614
      *
615 615
      * @return void
616 616
      */
617
-    protected function debug_log( $data )
617
+    protected function debug_log($data)
618 618
     {
619
-        if ( ! isset( $this->debug_log ) || ! $this->debug_log ) {
619
+        if (!isset($this->debug_log) || !$this->debug_log) {
620 620
             return;
621 621
         }
622 622
 
623
-        if ( ! is_string( $data ) && ! is_resource( $data ) ) {
624
-            $data = var_export( $data, true );
623
+        if (!is_string($data) && !is_resource($data)) {
624
+            $data = var_export($data, true);
625 625
         }
626 626
 
627
-        error_log( $data );
627
+        error_log($data);
628 628
     }
629 629
 
630 630
     /**
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
      *
635 635
      * @return bool|string to be minified code or false.
636 636
      */
637
-    protected function prepare_minify_single( $filepath )
637
+    protected function prepare_minify_single($filepath)
638 638
     {
639 639
         // Decide what we're dealing with, return false if we don't know.
640
-        if ( $this->str_ends_in( $filepath, '.js' ) ) {
640
+        if ($this->str_ends_in($filepath, '.js')) {
641 641
             $type = 'js';
642
-        } elseif ( $this->str_ends_in( $filepath, '.css' ) ) {
642
+        } elseif ($this->str_ends_in($filepath, '.css')) {
643 643
             $type = 'css';
644 644
         } else {
645 645
             return false;
@@ -648,18 +648,18 @@  discard block
 block discarded – undo
648 648
         // Bail if it looks like its already minifed (by having -min or .min
649 649
         // in filename) or if it looks like WP jquery.js (which is minified).
650 650
         $minified_variants = array(
651
-            '-min.' . $type,
652
-            '.min.' . $type,
651
+            '-min.'.$type,
652
+            '.min.'.$type,
653 653
             'js/jquery/jquery.js',
654 654
         );
655
-        foreach ( $minified_variants as $ending ) {
656
-            if ( $this->str_ends_in( $filepath, $ending ) ) {
655
+        foreach ($minified_variants as $ending) {
656
+            if ($this->str_ends_in($filepath, $ending)) {
657 657
                 return false;
658 658
             }
659 659
         }
660 660
 
661 661
         // Get file contents, bail if empty.
662
-        $contents = file_get_contents( $filepath );
662
+        $contents = file_get_contents($filepath);
663 663
 
664 664
         return $contents;
665 665
     }
@@ -672,12 +672,12 @@  discard block
 block discarded – undo
672 672
      *
673 673
      * @return string
674 674
      */
675
-    protected function build_minify_single_url( autoptimizeCache $cache )
675
+    protected function build_minify_single_url(autoptimizeCache $cache)
676 676
     {
677
-        $url = AUTOPTIMIZE_CACHE_URL . $cache->getname();
677
+        $url = AUTOPTIMIZE_CACHE_URL.$cache->getname();
678 678
 
679 679
         // CDN-replace the resulting URL if needed...
680
-        $url = $this->url_replace_cdn( $url );
680
+        $url = $this->url_replace_cdn($url);
681 681
 
682 682
         return $url;
683 683
     }
@@ -690,15 +690,15 @@  discard block
 block discarded – undo
690 690
      *
691 691
      * @return bool
692 692
      */
693
-    protected function str_ends_in( $str, $test )
693
+    protected function str_ends_in($str, $test)
694 694
     {
695 695
         // @codingStandardsIgnoreStart
696 696
         // substr_compare() is bugged on 5.5.11: https://3v4l.org/qGYBH
697 697
         // return ( 0 === substr_compare( $str, $test, -strlen( $test ) ) );
698 698
         // @codingStandardsIgnoreEnd
699 699
 
700
-        $length = strlen( $test );
700
+        $length = strlen($test);
701 701
 
702
-        return ( substr( $str, -$length, $length ) === $test );
702
+        return (substr($str, -$length, $length) === $test);
703 703
     }
704 704
 }
Please login to merge, or discard this patch.
classes/autoptimizeSpeedupper.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * new in Autoptimize 2.2
5 5
  */
6 6
 
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
     exit;
9 9
 }
10 10
 
@@ -17,94 +17,94 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function add_hooks()
19 19
     {
20
-        if ( apply_filters( 'autoptimize_js_do_minify', true ) ) {
21
-            add_filter( 'autoptimize_js_individual_script', array( $this, 'js_snippetcacher' ), 10, 2 );
22
-            add_filter( 'autoptimize_js_after_minify', array( $this, 'js_cleanup' ), 10, 1 );
20
+        if (apply_filters('autoptimize_js_do_minify', true)) {
21
+            add_filter('autoptimize_js_individual_script', array($this, 'js_snippetcacher'), 10, 2);
22
+            add_filter('autoptimize_js_after_minify', array($this, 'js_cleanup'), 10, 1);
23 23
         }
24
-        if ( apply_filters( 'autoptimize_css_do_minify', true ) ) {
25
-            add_filter( 'autoptimize_css_individual_style', array( $this, 'css_snippetcacher' ), 10, 2 );
26
-            add_filter( 'autoptimize_css_after_minify', array( $this, 'css_cleanup' ), 10, 1 );
24
+        if (apply_filters('autoptimize_css_do_minify', true)) {
25
+            add_filter('autoptimize_css_individual_style', array($this, 'css_snippetcacher'), 10, 2);
26
+            add_filter('autoptimize_css_after_minify', array($this, 'css_cleanup'), 10, 1);
27 27
         }
28 28
     }
29 29
 
30
-    public function js_snippetcacher( $jsin, $jsfilename )
30
+    public function js_snippetcacher($jsin, $jsfilename)
31 31
     {
32
-        $md5hash = 'snippet_' . md5( $jsin );
33
-        $ccheck  = new autoptimizeCache( $md5hash, 'js' );
34
-        if ( $ccheck->check() ) {
32
+        $md5hash = 'snippet_'.md5($jsin);
33
+        $ccheck  = new autoptimizeCache($md5hash, 'js');
34
+        if ($ccheck->check()) {
35 35
             $scriptsrc = $ccheck->retrieve();
36 36
         } else {
37
-            if ( false === ( strpos( $jsfilename, 'min.js' ) ) && ( false === strpos( $jsfilename, 'js/jquery/jquery.js' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_js_consider_minified', false ), '', $jsfilename ) === $jsfilename ) ) {
38
-                $tmp_jscode = trim( JSMin::minify( $jsin ) );
39
-                if ( ! empty( $tmp_jscode ) ) {
37
+            if (false === (strpos($jsfilename, 'min.js')) && (false === strpos($jsfilename, 'js/jquery/jquery.js')) && (str_replace(apply_filters('autoptimize_filter_js_consider_minified', false), '', $jsfilename) === $jsfilename)) {
38
+                $tmp_jscode = trim(JSMin::minify($jsin));
39
+                if (!empty($tmp_jscode)) {
40 40
                     $scriptsrc = $tmp_jscode;
41
-                    unset( $tmp_jscode );
41
+                    unset($tmp_jscode);
42 42
                 } else {
43 43
                     $scriptsrc = $jsin;
44 44
                 }
45 45
             } else {
46 46
                 // Removing comments, linebreaks and stuff!
47
-                $scriptsrc = preg_replace( '#^\s*\/\/.*$#Um', '', $jsin );
48
-                $scriptsrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc );
49
-                $scriptsrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc );
47
+                $scriptsrc = preg_replace('#^\s*\/\/.*$#Um', '', $jsin);
48
+                $scriptsrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $scriptsrc);
49
+                $scriptsrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc);
50 50
             }
51 51
 
52
-            $last_char = substr( $scriptsrc, -1, 1 );
53
-            if ( ';' !== $last_char && '}' !== $last_char ) {
52
+            $last_char = substr($scriptsrc, -1, 1);
53
+            if (';' !== $last_char && '}' !== $last_char) {
54 54
                 $scriptsrc .= ';';
55 55
             }
56 56
 
57
-            if ( ! empty( $jsfilename ) && str_replace( apply_filters( 'autoptimize_filter_js_speedup_cache', false ), '', $jsfilename ) === $jsfilename ) {
57
+            if (!empty($jsfilename) && str_replace(apply_filters('autoptimize_filter_js_speedup_cache', false), '', $jsfilename) === $jsfilename) {
58 58
                 // Don't cache inline CSS or if filter says no!
59
-                $ccheck->cache( $scriptsrc, 'text/javascript' );
59
+                $ccheck->cache($scriptsrc, 'text/javascript');
60 60
             }
61 61
         }
62
-        unset( $ccheck );
62
+        unset($ccheck);
63 63
 
64 64
         return $scriptsrc;
65 65
     }
66 66
 
67
-    public function css_snippetcacher( $cssin, $cssfilename )
67
+    public function css_snippetcacher($cssin, $cssfilename)
68 68
     {
69
-        $md5hash = 'snippet_' . md5( $cssin );
70
-        $ccheck  = new autoptimizeCache( $md5hash, 'css' );
71
-        if ( $ccheck->check() ) {
69
+        $md5hash = 'snippet_'.md5($cssin);
70
+        $ccheck  = new autoptimizeCache($md5hash, 'css');
71
+        if ($ccheck->check()) {
72 72
             $stylesrc = $ccheck->retrieve();
73 73
         } else {
74
-            if ( ( false === strpos( $cssfilename, 'min.css' ) ) && ( str_replace( apply_filters( 'autoptimize_filter_css_consider_minified', false ), '', $cssfilename ) === $cssfilename ) ) {
74
+            if ((false === strpos($cssfilename, 'min.css')) && (str_replace(apply_filters('autoptimize_filter_css_consider_minified', false), '', $cssfilename) === $cssfilename)) {
75 75
                 $cssmin   = new autoptimizeCSSmin();
76
-                $tmp_code = trim( $cssmin->run( $cssin ) );
76
+                $tmp_code = trim($cssmin->run($cssin));
77 77
 
78
-                if ( ! empty( $tmp_code ) ) {
78
+                if (!empty($tmp_code)) {
79 79
                     $stylesrc = $tmp_code;
80
-                    unset( $tmp_code );
80
+                    unset($tmp_code);
81 81
                 } else {
82 82
                     $stylesrc = $cssin;
83 83
                 }
84 84
             } else {
85 85
                 // .min.css -> no heavy-lifting, just some cleanup!
86
-                $stylesrc = preg_replace( '#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin );
87
-                $stylesrc = preg_replace( "#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc );
88
-                $stylesrc = autoptimizeStyles::fixurls( $cssfilename, $stylesrc );
86
+                $stylesrc = preg_replace('#^\s*\/\*[^!].*\*\/\s?#Us', '', $cssin);
87
+                $stylesrc = preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc);
88
+                $stylesrc = autoptimizeStyles::fixurls($cssfilename, $stylesrc);
89 89
             }
90
-            if ( ! empty( $cssfilename ) && ( str_replace( apply_filters( 'autoptimize_filter_css_speedup_cache', false ), '', $cssfilename ) === $cssfilename ) ) {
90
+            if (!empty($cssfilename) && (str_replace(apply_filters('autoptimize_filter_css_speedup_cache', false), '', $cssfilename) === $cssfilename)) {
91 91
                 // Only caching CSS if it's not inline and is allowed by filter!
92
-                $ccheck->cache( $stylesrc, 'text/css' );
92
+                $ccheck->cache($stylesrc, 'text/css');
93 93
             }
94 94
         }
95
-        unset( $ccheck );
95
+        unset($ccheck);
96 96
 
97 97
         return $stylesrc;
98 98
     }
99 99
 
100
-    public function css_cleanup( $cssin )
100
+    public function css_cleanup($cssin)
101 101
     {
102 102
         // Speedupper results in aggregated CSS not being minified, so the filestart-marker AO adds when aggregating needs to be removed.
103
-        return trim( str_replace( array( '/*FILESTART*/', '/*FILESTART2*/' ), '', $cssin ) );
103
+        return trim(str_replace(array('/*FILESTART*/', '/*FILESTART2*/'), '', $cssin));
104 104
     }
105 105
 
106
-    public function js_cleanup( $jsin )
106
+    public function js_cleanup($jsin)
107 107
     {
108
-        return trim( $jsin );
108
+        return trim($jsin);
109 109
     }
110 110
 }
Please login to merge, or discard this patch.
classes/autoptimizeToolbar.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Handles toolbar-related stuff.
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
     exit;
8 8
 }
9 9
 
@@ -12,32 +12,32 @@  discard block
 block discarded – undo
12 12
     public function __construct()
13 13
     {
14 14
         // If Cache is not available we don't add the toolbar.
15
-        if ( ! autoptimizeCache::cacheavail() ) {
15
+        if (!autoptimizeCache::cacheavail()) {
16 16
             return;
17 17
         }
18 18
 
19 19
         // Load admin toolbar feature once WordPress, all plugins, and the theme are fully loaded and instantiated.
20
-        add_action( 'wp_loaded', array( $this, 'load_toolbar' ) );
20
+        add_action('wp_loaded', array($this, 'load_toolbar'));
21 21
     }
22 22
 
23 23
     public function load_toolbar()
24 24
     {
25 25
         // Check permissions and that toolbar is not hidden via filter.
26
-        if ( current_user_can( 'manage_options' ) && apply_filters( 'autoptimize_filter_toolbar_show', true ) ) {
26
+        if (current_user_can('manage_options') && apply_filters('autoptimize_filter_toolbar_show', true)) {
27 27
 
28 28
             // Create a handler for the AJAX toolbar requests.
29
-            add_action( 'wp_ajax_autoptimize_delete_cache', array( $this, 'delete_cache' ) );
29
+            add_action('wp_ajax_autoptimize_delete_cache', array($this, 'delete_cache'));
30 30
 
31 31
             // Load custom styles, scripts and menu only when needed.
32
-            if ( is_admin_bar_showing() ) {
33
-                if ( is_admin() ) {
34
-                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
32
+            if (is_admin_bar_showing()) {
33
+                if (is_admin()) {
34
+                    add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
35 35
                 } else {
36
-                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
36
+                    add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
37 37
                 }
38 38
 
39 39
                 // Add the Autoptimize Toolbar to the Admin bar.
40
-                add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 );
40
+                add_action('admin_bar_menu', array($this, 'add_toolbar'), 100);
41 41
             }
42 42
         }
43 43
     }
@@ -50,17 +50,17 @@  discard block
 block discarded – undo
50 50
         $stats = autoptimizeCache::stats();
51 51
 
52 52
         // Set the Max Size recommended for cache files.
53
-        $max_size = apply_filters( 'autoptimize_filter_cachecheck_maxsize', 512 * 1024 * 1024 );
53
+        $max_size = apply_filters('autoptimize_filter_cachecheck_maxsize', 512*1024*1024);
54 54
 
55 55
         // Retrieve the current Total Files in cache.
56 56
         $files = $stats[0];
57 57
         // Retrieve the current Total Size of the cache.
58 58
         $bytes = $stats[1];
59
-        $size  = $this->format_filesize( $bytes );
59
+        $size  = $this->format_filesize($bytes);
60 60
 
61 61
         // Calculate the percentage of cache used.
62
-        $percentage = ceil( $bytes / $max_size * 100 );
63
-        if ( $percentage > 100 ) {
62
+        $percentage = ceil($bytes/$max_size*100);
63
+        if ($percentage > 100) {
64 64
             $percentage = 100;
65 65
         }
66 66
 
@@ -70,81 +70,81 @@  discard block
 block discarded – undo
70 70
          * - "orange" if over 80%.
71 71
          * - "red" if over 100%.
72 72
          */
73
-        $color = ( 100 == $percentage ) ? 'red' : ( ( $percentage > 80 ) ? 'orange' : 'green' );
73
+        $color = (100 == $percentage) ? 'red' : (($percentage > 80) ? 'orange' : 'green');
74 74
 
75 75
         // Create or add new items into the Admin Toolbar.
76 76
         // Main "Autoptimize" node.
77
-        $wp_admin_bar->add_node( array(
77
+        $wp_admin_bar->add_node(array(
78 78
             'id'    => 'autoptimize',
79
-            'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Autoptimize', 'autoptimize' ) . '</span>',
80
-            'href'  => admin_url( 'options-general.php?page=autoptimize' ),
81
-            'meta'  => array( 'class' => 'bullet-' . $color ),
79
+            'title' => '<span class="ab-icon"></span><span class="ab-label">'.__('Autoptimize', 'autoptimize').'</span>',
80
+            'href'  => admin_url('options-general.php?page=autoptimize'),
81
+            'meta'  => array('class' => 'bullet-'.$color),
82 82
         ));
83 83
 
84 84
         // "Cache Info" node.
85
-        $wp_admin_bar->add_node( array(
85
+        $wp_admin_bar->add_node(array(
86 86
             'id'     => 'autoptimize-cache-info',
87
-            'title'  => '<p>' . __( 'Cache Info', 'autoptimize' ) . '</p>' .
88
-                        '<div class="autoptimize-radial-bar" percentage="' . $percentage . '">' .
89
-                        '<div class="autoptimize-circle">' .
90
-                        '<div class="mask full"><div class="fill bg-' . $color . '"></div></div>' .
91
-                        '<div class="mask half"><div class="fill bg-' . $color . '"></div></div>' .
92
-                        '<div class="shadow"></div>' .
93
-                        '</div>' .
94
-                        '<div class="inset"><div class="percentage"><div class="numbers ' . $color . '">' . $percentage . '%</div></div></div>' .
95
-                        '</div>' .
96
-                        '<table>' .
97
-                        '<tr><td>' . __( 'Size', 'autoptimize' ) . ':</td><td class="size ' . $color . '">' . $size . '</td></tr>' .
98
-                        '<tr><td>' . __( 'Files', 'autoptimize' ) . ':</td><td class="files white">' . $files . '</td></tr>' .
87
+            'title'  => '<p>'.__('Cache Info', 'autoptimize').'</p>'.
88
+                        '<div class="autoptimize-radial-bar" percentage="'.$percentage.'">'.
89
+                        '<div class="autoptimize-circle">'.
90
+                        '<div class="mask full"><div class="fill bg-'.$color.'"></div></div>'.
91
+                        '<div class="mask half"><div class="fill bg-'.$color.'"></div></div>'.
92
+                        '<div class="shadow"></div>'.
93
+                        '</div>'.
94
+                        '<div class="inset"><div class="percentage"><div class="numbers '.$color.'">'.$percentage.'%</div></div></div>'.
95
+                        '</div>'.
96
+                        '<table>'.
97
+                        '<tr><td>'.__('Size', 'autoptimize').':</td><td class="size '.$color.'">'.$size.'</td></tr>'.
98
+                        '<tr><td>'.__('Files', 'autoptimize').':</td><td class="files white">'.$files.'</td></tr>'.
99 99
                         '</table>',
100 100
             'parent' => 'autoptimize',
101 101
         ));
102 102
 
103 103
         // "Delete Cache" node.
104
-        $wp_admin_bar->add_node( array(
104
+        $wp_admin_bar->add_node(array(
105 105
             'id'     => 'autoptimize-delete-cache',
106
-            'title'  => __( 'Delete Cache', 'autoptimize' ),
106
+            'title'  => __('Delete Cache', 'autoptimize'),
107 107
             'parent' => 'autoptimize',
108 108
         ));
109 109
     }
110 110
 
111 111
     public function delete_cache()
112 112
     {
113
-        check_ajax_referer( 'ao_delcache_nonce', 'nonce' );
113
+        check_ajax_referer('ao_delcache_nonce', 'nonce');
114 114
 
115 115
         $result = false;
116
-        if ( current_user_can( 'manage_options' ) ) {
116
+        if (current_user_can('manage_options')) {
117 117
             // We call the function for cleaning the Autoptimize cache.
118 118
             $result = autoptimizeCache::clearall();
119 119
         }
120 120
 
121
-        wp_send_json( $result );
121
+        wp_send_json($result);
122 122
     }
123 123
 
124 124
     public function enqueue_scripts()
125 125
     {
126 126
         // Autoptimize Toolbar Styles.
127
-        wp_enqueue_style( 'autoptimize-toolbar', plugins_url( '/static/toolbar.css', __FILE__ ), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all' );
127
+        wp_enqueue_style('autoptimize-toolbar', plugins_url('/static/toolbar.css', __FILE__), array(), AUTOPTIMIZE_PLUGIN_VERSION, 'all');
128 128
 
129 129
         // Autoptimize Toolbar Javascript.
130
-        wp_enqueue_script( 'autoptimize-toolbar', plugins_url( '/static/toolbar.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true );
130
+        wp_enqueue_script('autoptimize-toolbar', plugins_url('/static/toolbar.js', __FILE__), array('jquery'), AUTOPTIMIZE_PLUGIN_VERSION, true);
131 131
 
132 132
         // Localizes a registered script with data for a JavaScript variable.
133 133
         // Needed for the AJAX to work properly on the frontend.
134
-        wp_localize_script( 'autoptimize-toolbar', 'autoptimize_ajax_object', array(
135
-            'ajaxurl'     => admin_url( 'admin-ajax.php' ),
136
-            'error_msg'   => sprintf( __( 'Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize' ), admin_url( 'options-general.php?page=autoptimize' ) . ' style="white-space:nowrap;"' ),
137
-            'dismiss_msg' => __( 'Dismiss this notice.' ),
138
-            'nonce'       => wp_create_nonce( 'ao_delcache_nonce' ),
139
-        ) );
134
+        wp_localize_script('autoptimize-toolbar', 'autoptimize_ajax_object', array(
135
+            'ajaxurl'     => admin_url('admin-ajax.php'),
136
+            'error_msg'   => sprintf(__('Your Autoptimize cache might not have been purged successfully, please check on the <a href=%s>Autoptimize settings page</a>.', 'autoptimize'), admin_url('options-general.php?page=autoptimize').' style="white-space:nowrap;"'),
137
+            'dismiss_msg' => __('Dismiss this notice.'),
138
+            'nonce'       => wp_create_nonce('ao_delcache_nonce'),
139
+        ));
140 140
     }
141 141
 
142
-    public function format_filesize( $bytes, $decimals = 2 )
142
+    public function format_filesize($bytes, $decimals = 2)
143 143
     {
144
-        $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
144
+        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
145 145
 
146
-        for ( $i = 0; ( $bytes / 1024) > 0.9; $i++, $bytes /= 1024 ) {} // @codingStandardsIgnoreLine
146
+        for ($i = 0; ($bytes/1024) > 0.9; $i++, $bytes /= 1024) {} // @codingStandardsIgnoreLine
147 147
 
148
-        return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[ $i ] );
148
+        return sprintf("%1.{$decimals}f %s", round($bytes, $decimals), $units[$i]);
149 149
     }
150 150
 }
Please login to merge, or discard this patch.