@@ -3,7 +3,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,18 +277,18 @@ discard block |
||
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 | - if ( is_array( $files ) && ! empty( $files ) ) { |
|
286 | - foreach ( $files as $file ) { |
|
287 | - $path = $parent . '/' . $file; |
|
288 | - $prefixed = ( false !== strpos( $path, $prefix ) ); |
|
284 | + $files = self::get_dir_contents($parent); |
|
285 | + if (is_array($files) && !empty($files)) { |
|
286 | + foreach ($files as $file) { |
|
287 | + $path = $parent.'/'.$file; |
|
288 | + $prefixed = (false !== strpos($path, $prefix)); |
|
289 | 289 | // Removing only our own (prefixed) directories... |
290 | - if ( is_dir( $path ) && $prefixed ) { |
|
291 | - $ok = self::rmdir( $path ); |
|
290 | + if (is_dir($path) && $prefixed) { |
|
291 | + $ok = self::rmdir($path); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | } |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | { |
309 | 309 | $pathname = self::get_pathname_base(); |
310 | 310 | |
311 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
311 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
312 | 312 | $blog_id = get_current_blog_id(); |
313 | - $pathname .= $blog_id . '/'; |
|
313 | + $pathname .= $blog_id.'/'; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | return $pathname; |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | protected static function get_pathname_base() |
325 | 325 | { |
326 | - $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR; |
|
326 | + $pathname = WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR; |
|
327 | 327 | |
328 | 328 | return $pathname; |
329 | 329 | } |
@@ -335,38 +335,38 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @return bool |
337 | 337 | */ |
338 | - public static function clearall( $propagate = true ) |
|
338 | + public static function clearall($propagate = true) |
|
339 | 339 | { |
340 | - if ( ! self::cacheavail() ) { |
|
340 | + if (!self::cacheavail()) { |
|
341 | 341 | return false; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically? |
345 | - if ( self::advanced_cache_clear_enabled() ) { |
|
345 | + if (self::advanced_cache_clear_enabled()) { |
|
346 | 346 | self::clear_cache_via_rename(); |
347 | 347 | } else { |
348 | 348 | self::clear_cache_classic(); |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Remove the transient so it gets regenerated... |
352 | - delete_transient( 'autoptimize_stats' ); |
|
352 | + delete_transient('autoptimize_stats'); |
|
353 | 353 | |
354 | 354 | // Cache was just purged, clear page cache and allow others to hook into our purging... |
355 | - if ( true === $propagate ) { |
|
356 | - if ( ! function_exists( 'autoptimize_do_cachepurged_action' ) ) { |
|
355 | + if (true === $propagate) { |
|
356 | + if (!function_exists('autoptimize_do_cachepurged_action')) { |
|
357 | 357 | function autoptimize_do_cachepurged_action() { |
358 | - do_action( 'autoptimize_action_cachepurged' ); |
|
358 | + do_action('autoptimize_action_cachepurged'); |
|
359 | 359 | } |
360 | 360 | } |
361 | - add_action( 'shutdown', 'autoptimize_do_cachepurged_action', 11 ); |
|
362 | - add_action( 'autoptimize_action_cachepurged', array( 'autoptimizeCache', 'flushPageCache' ), 10, 0 ); |
|
361 | + add_action('shutdown', 'autoptimize_do_cachepurged_action', 11); |
|
362 | + add_action('autoptimize_action_cachepurged', array('autoptimizeCache', 'flushPageCache'), 10, 0); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | // Warm cache (part of speedupper)! |
366 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
367 | - $url = site_url() . '/?ao_speedup_cachebuster=' . rand( 1, 100000 ); |
|
368 | - $cache = @wp_remote_get( $url ); // @codingStandardsIgnoreLine |
|
369 | - unset( $cache ); |
|
366 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
367 | + $url = site_url().'/?ao_speedup_cachebuster='.rand(1, 100000); |
|
368 | + $cache = @wp_remote_get($url); // @codingStandardsIgnoreLine |
|
369 | + unset($cache); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return true; |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public static function clearall_actionless() |
383 | 383 | { |
384 | - return self::clearall( false ); |
|
384 | + return self::clearall(false); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -393,8 +393,8 @@ discard block |
||
393 | 393 | { |
394 | 394 | $contents = array(); |
395 | 395 | |
396 | - foreach ( array( '', 'js', 'css' ) as $dir ) { |
|
397 | - $contents[ $dir ] = scandir( AUTOPTIMIZE_CACHE_DIR . $dir ); |
|
396 | + foreach (array('', 'js', 'css') as $dir) { |
|
397 | + $contents[$dir] = scandir(AUTOPTIMIZE_CACHE_DIR.$dir); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | return $contents; |
@@ -407,21 +407,21 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public static function stats() |
409 | 409 | { |
410 | - $stats = get_transient( 'autoptimize_stats' ); |
|
410 | + $stats = get_transient('autoptimize_stats'); |
|
411 | 411 | |
412 | 412 | // If no transient, do the actual scan! |
413 | - if ( ! is_array( $stats ) ) { |
|
414 | - if ( ! self::cacheavail() ) { |
|
413 | + if (!is_array($stats)) { |
|
414 | + if (!self::cacheavail()) { |
|
415 | 415 | return 0; |
416 | 416 | } |
417 | 417 | $stats = self::stats_scan(); |
418 | 418 | $count = $stats[0]; |
419 | - if ( $count > 100 ) { |
|
419 | + if ($count > 100) { |
|
420 | 420 | // Store results in transient. |
421 | 421 | set_transient( |
422 | 422 | 'autoptimize_stats', |
423 | 423 | $stats, |
424 | - apply_filters( 'autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS ) |
|
424 | + apply_filters('autoptimize_filter_cache_statsexpiry', HOUR_IN_SECONDS) |
|
425 | 425 | ); |
426 | 426 | } |
427 | 427 | } |
@@ -444,30 +444,30 @@ discard block |
||
444 | 444 | $size = 0; |
445 | 445 | |
446 | 446 | // Scan everything in our cache directories. |
447 | - foreach ( self::get_cache_contents() as $name => $files ) { |
|
448 | - $dir = rtrim( AUTOPTIMIZE_CACHE_DIR . $name, '/' ) . '/'; |
|
449 | - foreach ( $files as $file ) { |
|
450 | - if ( self::is_valid_cache_file( $dir, $file ) ) { |
|
451 | - if ( AUTOPTIMIZE_CACHE_NOGZIP && |
|
447 | + foreach (self::get_cache_contents() as $name => $files) { |
|
448 | + $dir = rtrim(AUTOPTIMIZE_CACHE_DIR.$name, '/').'/'; |
|
449 | + foreach ($files as $file) { |
|
450 | + if (self::is_valid_cache_file($dir, $file)) { |
|
451 | + if (AUTOPTIMIZE_CACHE_NOGZIP && |
|
452 | 452 | ( |
453 | - false !== strpos( $file, '.js' ) || |
|
454 | - false !== strpos( $file, '.css' ) || |
|
455 | - false !== strpos( $file, '.img' ) || |
|
456 | - false !== strpos( $file, '.txt' ) |
|
453 | + false !== strpos($file, '.js') || |
|
454 | + false !== strpos($file, '.css') || |
|
455 | + false !== strpos($file, '.img') || |
|
456 | + false !== strpos($file, '.txt') |
|
457 | 457 | ) |
458 | 458 | ) { |
459 | 459 | // Web server is gzipping, we count .js|.css|.img|.txt files. |
460 | 460 | $count++; |
461 | - } elseif ( ! AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos( $file, '.none' ) ) { |
|
461 | + } elseif (!AUTOPTIMIZE_CACHE_NOGZIP && false !== strpos($file, '.none')) { |
|
462 | 462 | // We are gzipping ourselves via php, counting only .none files. |
463 | 463 | $count++; |
464 | 464 | } |
465 | - $size += filesize( $dir . $file ); |
|
465 | + $size += filesize($dir.$file); |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
470 | - $stats = array( $count, $size, time() ); |
|
470 | + $stats = array($count, $size, time()); |
|
471 | 471 | |
472 | 472 | return $stats; |
473 | 473 | } |
@@ -481,29 +481,29 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public static function cacheavail() |
483 | 483 | { |
484 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
484 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
485 | 485 | // We didn't set a cache. |
486 | 486 | return false; |
487 | 487 | } |
488 | 488 | |
489 | - foreach ( array( '', 'js', 'css' ) as $dir ) { |
|
490 | - if ( ! self::check_cache_dir( AUTOPTIMIZE_CACHE_DIR . $dir ) ) { |
|
489 | + foreach (array('', 'js', 'css') as $dir) { |
|
490 | + if (!self::check_cache_dir(AUTOPTIMIZE_CACHE_DIR.$dir)) { |
|
491 | 491 | return false; |
492 | 492 | } |
493 | 493 | } |
494 | 494 | |
495 | 495 | // Using .htaccess inside our cache folder to overrule wp-super-cache. |
496 | - $htaccess = AUTOPTIMIZE_CACHE_DIR . '/.htaccess'; |
|
497 | - if ( ! is_file( $htaccess ) ) { |
|
496 | + $htaccess = AUTOPTIMIZE_CACHE_DIR.'/.htaccess'; |
|
497 | + if (!is_file($htaccess)) { |
|
498 | 498 | /** |
499 | 499 | * Create `wp-content/AO_htaccess_tmpl` file with |
500 | 500 | * whatever htaccess rules you might need |
501 | 501 | * if you want to override default AO htaccess |
502 | 502 | */ |
503 | - $htaccess_tmpl = WP_CONTENT_DIR . '/AO_htaccess_tmpl'; |
|
504 | - if ( is_file( $htaccess_tmpl ) ) { |
|
505 | - $content = file_get_contents( $htaccess_tmpl ); |
|
506 | - } elseif ( is_multisite() || ! AUTOPTIMIZE_CACHE_NOGZIP ) { |
|
503 | + $htaccess_tmpl = WP_CONTENT_DIR.'/AO_htaccess_tmpl'; |
|
504 | + if (is_file($htaccess_tmpl)) { |
|
505 | + $content = file_get_contents($htaccess_tmpl); |
|
506 | + } elseif (is_multisite() || !AUTOPTIMIZE_CACHE_NOGZIP) { |
|
507 | 507 | $content = '<IfModule mod_expires.c> |
508 | 508 | ExpiresActive On |
509 | 509 | ExpiresByType text/css A30672000 |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | </Files> |
557 | 557 | </IfModule>'; |
558 | 558 | } |
559 | - @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine |
|
559 | + @file_put_contents($htaccess, $content); // @codingStandardsIgnoreLine |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | // All OK! |
@@ -571,25 +571,25 @@ discard block |
||
571 | 571 | * |
572 | 572 | * @return bool |
573 | 573 | */ |
574 | - protected static function check_cache_dir( $dir ) |
|
574 | + protected static function check_cache_dir($dir) |
|
575 | 575 | { |
576 | 576 | // Try creating the dir if it doesn't exist. |
577 | - if ( ! file_exists( $dir ) ) { |
|
578 | - @mkdir( $dir, 0775, true ); // @codingStandardsIgnoreLine |
|
579 | - if ( ! file_exists( $dir ) ) { |
|
577 | + if (!file_exists($dir)) { |
|
578 | + @mkdir($dir, 0775, true); // @codingStandardsIgnoreLine |
|
579 | + if (!file_exists($dir)) { |
|
580 | 580 | return false; |
581 | 581 | } |
582 | 582 | } |
583 | 583 | |
584 | 584 | // If we still cannot write, bail. |
585 | - if ( ! is_writable( $dir ) ) { |
|
585 | + if (!is_writable($dir)) { |
|
586 | 586 | return false; |
587 | 587 | } |
588 | 588 | |
589 | 589 | // Create an index.html in there to avoid prying eyes! |
590 | - $idx_file = rtrim( $dir, '/\\' ) . '/index.html'; |
|
591 | - if ( ! is_file( $idx_file ) ) { |
|
592 | - @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 |
|
590 | + $idx_file = rtrim($dir, '/\\').'/index.html'; |
|
591 | + if (!is_file($idx_file)) { |
|
592 | + @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 |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | return true; |
@@ -603,59 +603,59 @@ discard block |
||
603 | 603 | // @codingStandardsIgnoreStart |
604 | 604 | public static function flushPageCache() |
605 | 605 | { |
606 | - if ( function_exists( 'wp_cache_clear_cache' ) ) { |
|
607 | - if ( is_multisite() ) { |
|
606 | + if (function_exists('wp_cache_clear_cache')) { |
|
607 | + if (is_multisite()) { |
|
608 | 608 | $blog_id = get_current_blog_id(); |
609 | - wp_cache_clear_cache( $blog_id ); |
|
609 | + wp_cache_clear_cache($blog_id); |
|
610 | 610 | } else { |
611 | 611 | wp_cache_clear_cache(); |
612 | 612 | } |
613 | - } elseif ( has_action( 'cachify_flush_cache' ) ) { |
|
614 | - do_action( 'cachify_flush_cache' ); |
|
615 | - } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) { |
|
613 | + } elseif (has_action('cachify_flush_cache')) { |
|
614 | + do_action('cachify_flush_cache'); |
|
615 | + } elseif (function_exists('w3tc_pgcache_flush')) { |
|
616 | 616 | w3tc_pgcache_flush(); |
617 | - } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) { |
|
617 | + } elseif (function_exists('wp_fast_cache_bulk_delete_all')) { |
|
618 | 618 | wp_fast_cache_bulk_delete_all(); |
619 | - } elseif ( class_exists( 'WpFastestCache' ) ) { |
|
619 | + } elseif (class_exists('WpFastestCache')) { |
|
620 | 620 | $wpfc = new WpFastestCache(); |
621 | 621 | $wpfc->deleteCache(); |
622 | - } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) { |
|
622 | + } elseif (class_exists('c_ws_plugin__qcache_purging_routines')) { |
|
623 | 623 | c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache |
624 | - } elseif ( class_exists( 'zencache' ) ) { |
|
624 | + } elseif (class_exists('zencache')) { |
|
625 | 625 | zencache::clear(); |
626 | - } elseif ( class_exists( 'comet_cache' ) ) { |
|
626 | + } elseif (class_exists('comet_cache')) { |
|
627 | 627 | comet_cache::clear(); |
628 | - } elseif ( class_exists( 'WpeCommon' ) ) { |
|
628 | + } elseif (class_exists('WpeCommon')) { |
|
629 | 629 | // WPEngine cache purge/flush methods to call by default |
630 | 630 | $wpe_methods = array( |
631 | 631 | 'purge_varnish_cache', |
632 | 632 | ); |
633 | 633 | |
634 | 634 | // More agressive clear/flush/purge behind a filter |
635 | - if ( apply_filters( 'autoptimize_flush_wpengine_aggressive', false ) ) { |
|
636 | - $wpe_methods = array_merge( $wpe_methods, array( 'purge_memcached', 'clear_maxcdn_cache' ) ); |
|
635 | + if (apply_filters('autoptimize_flush_wpengine_aggressive', false)) { |
|
636 | + $wpe_methods = array_merge($wpe_methods, array('purge_memcached', 'clear_maxcdn_cache')); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | // Filtering the entire list of WpeCommon methods to be called (for advanced usage + easier testing) |
640 | - $wpe_methods = apply_filters( 'autoptimize_flush_wpengine_methods', $wpe_methods ); |
|
640 | + $wpe_methods = apply_filters('autoptimize_flush_wpengine_methods', $wpe_methods); |
|
641 | 641 | |
642 | - foreach ( $wpe_methods as $wpe_method ) { |
|
643 | - if ( method_exists( 'WpeCommon', $wpe_method ) ) { |
|
642 | + foreach ($wpe_methods as $wpe_method) { |
|
643 | + if (method_exists('WpeCommon', $wpe_method)) { |
|
644 | 644 | WpeCommon::$wpe_method(); |
645 | 645 | } |
646 | 646 | } |
647 | - } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) { |
|
647 | + } elseif (function_exists('sg_cachepress_purge_cache')) { |
|
648 | 648 | sg_cachepress_purge_cache(); |
649 | - } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) { |
|
649 | + } elseif (file_exists(WP_CONTENT_DIR.'/wp-cache-config.php') && function_exists('prune_super_cache')) { |
|
650 | 650 | // fallback for WP-Super-Cache |
651 | 651 | global $cache_path; |
652 | - if ( is_multisite() ) { |
|
652 | + if (is_multisite()) { |
|
653 | 653 | $blog_id = get_current_blog_id(); |
654 | - prune_super_cache( get_supercache_dir( $blog_id ), true ); |
|
655 | - prune_super_cache( $cache_path . 'blogs/', true ); |
|
654 | + prune_super_cache(get_supercache_dir($blog_id), true); |
|
655 | + prune_super_cache($cache_path.'blogs/', true); |
|
656 | 656 | } else { |
657 | - prune_super_cache( $cache_path . 'supercache/', true ); |
|
658 | - prune_super_cache( $cache_path, true ); |
|
657 | + prune_super_cache($cache_path.'supercache/', true); |
|
658 | + prune_super_cache($cache_path, true); |
|
659 | 659 | } |
660 | 660 | } |
661 | 661 | } |