PluginProbe
Autoptimize / trunk
Autoptimize vtrunk
3.1.16 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 All 108 releases
← All changes | classes/autoptimizeCache.php +40 -6 2.7.7 → trunk View file →
@@ -90,12 +90,17 @@
90 90 *
91 91 * @param string $data Data to cache.
92 92 * @param string $mime Mimetype.
93 93 *
94 - * @return void
94 + * @return void|bool
95 95 */
96 96 public function cache( $data, $mime )
97 97 {
98 + // readonly FS explicitly OK'ed by developer, so just pretend all is OK.
99 + if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
100 + return true;
101 + }
102 +
98 103 // off by default; check if cachedirs exist every time before caching
99 104 //
100 105 // to be activated for users that experience these ugly errors;
101 106 // PHP Warning: file_put_contents failed to open stream: No such file or directory.
@@ -376,9 +381,21 @@
376 381 * @return bool
377 382 */
378 383 public static function clearall( $propagate = true )
379 384 {
380 - if ( ! self::cacheavail() ) {
385 + if ( defined( 'ET_CORE_VERSION' ) && 'Divi' === get_template() ) {
386 + // see https://blog.futtta.be/2018/11/17/warning-divi-purging-autoptimizes-cache/ .
387 + $dbt = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );
388 + $caller = isset( $dbt[1]['function'] ) ? $dbt[1]['function'] : null;
389 + if ( 'et_core_clear_wp_cache' === $caller ) {
390 + if ( apply_filters( 'autoptimize_filter_cache_divi_wrong_complain', true ) ) {
391 + _doing_it_wrong( 'autoptimizeCache::clearall', 'Divi devs: please don\'t clear Autoptimize\'s cache, it is unneeded and can break sites. You can contact me at [email protected] to discuss.', 'Autoptimize 2.9.6' );
392 + }
393 + return false;
394 + }
395 + }
396 +
397 + if ( ! self::cacheavail() || true === apply_filters( 'autoptimize_filter_cache_clearall_disabled', false ) ) {
381 398 return false;
382 399 }
383 400
384 401 // TODO/FIXME: If cache is big, switch to advanced/new cache clearing automatically?
@@ -528,8 +545,13 @@
528 545 * @return bool
529 546 */
530 547 public static function cacheavail()
531 548 {
549 + // readonly FS explicitly OK'ed by dev, let's assume the cache dirs are there!
550 + if ( defined( 'AUTOPTIMIZE_CACHE_READONLY' ) ) {
551 + return true;
552 + }
553 +
532 554 if ( false === autoptimizeCache::check_and_create_dirs() ) {
533 555 return false;
534 556 }
535 557
@@ -621,12 +643,16 @@
621 643 $_fallback_filename = 'autoptimize_404_handler.php';
622 644 $_fallback_php = trailingslashit( WP_CONTENT_DIR ) . $_fallback_filename;
623 645 $_fallback_status = true;
624 646
625 - if ( ! file_exists( $_fallback_php ) ) {
647 + if ( ! file_exists( $_fallback_php ) && is_writable( WP_CONTENT_DIR ) ) {
626 648 $_fallback_php_contents = file_get_contents( AUTOPTIMIZE_PLUGIN_DIR . 'config/' . $_fallback_filename );
627 649 $_fallback_php_contents = str_replace( '<?php exit;', '<?php', $_fallback_php_contents );
628 650 $_fallback_php_contents = str_replace( '<!--ao-cache-dir-->', AUTOPTIMIZE_CACHE_DIR, $_fallback_php_contents );
651 + $_fallback_php_contents = str_replace( '<!--ao-cachefile-prefix-->', AUTOPTIMIZE_CACHEFILE_PREFIX, $_fallback_php_contents );
652 + if ( is_multisite() ) {
653 + $_fallback_php_contents = str_replace( '$multisite = false;', '$multisite = true;', $_fallback_php_contents );
654 + }
629 655 if ( apply_filters( 'autoptimize_filter_cache_fallback_log_errors', false ) ) {
630 656 $_fallback_php_contents = str_replace( '// error_log', 'error_log', $_fallback_php_contents );
631 657 }
632 658 $_fallback_status = file_put_contents( $_fallback_php, $_fallback_php_contents );
@@ -646,9 +672,9 @@
646 672 public static function do_fallback() {
647 673 static $_do_fallback = null;
648 674
649 675 if ( null === $_do_fallback ) {
650 - $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) );
676 + $_do_fallback = (bool) apply_filters( 'autoptimize_filter_cache_do_fallback', autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) );
651 677 }
652 678
653 679 return $_do_fallback;
654 680 }
@@ -670,9 +696,9 @@
670 696 $fallback_path = AUTOPTIMIZE_CACHE_DIR . $js_or_css . '/autoptimize_fallback.' . $js_or_css;
671 697
672 698 // prepare for Shakeeb's Unused CSS files to be 404-handled as well.
673 699 if ( strpos( $original_request, 'uucss/uucss-' ) !== false ) {
674 - $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request );
700 + $original_request = preg_replace( '/uucss\/uucss-[a-z0-9]{32}-/', 'css/', $original_request );
675 701 }
676 702
677 703 // set fallback URL.
678 704 $fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request );
@@ -760,8 +786,10 @@
760 786 } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
761 787 w3tc_pgcache_flush();
762 788 } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
763 789 wp_fast_cache_bulk_delete_all();
790 + } elseif ( function_exists( 'rapidcache_clear_cache' ) ) {
791 + rapidcache_clear_cache();
764 792 } elseif ( class_exists( 'Swift_Performance_Cache' ) ) {
765 793 Swift_Performance_Cache::clear_all_cache();
766 794 } elseif ( class_exists( 'WpFastestCache' ) ) {
767 795 $wpfc = new WpFastestCache();
@@ -796,13 +824,16 @@
796 824 } elseif ( array_key_exists( 'KINSTA_CACHE_ZONE', $_SERVER ) ) {
797 825 $_kinsta_clear_cache_url = 'https://localhost/kinsta-clear-cache-all';
798 826 $_kinsta_response = wp_remote_get(
799 827 $_kinsta_clear_cache_url,
800 - array(
828 + array(
801 829 'sslverify' => false,
802 830 'timeout' => 5,
803 831 )
804 832 );
833 + } elseif ( class_exists( 'RaidboxesNginxCacheFunctions' ) ) {
834 + $rb_cache_helper = new RaidboxesNginxCacheFunctions();
835 + $rb_cache_helper->purge_cache();
805 836 } elseif ( defined('NGINX_HELPER_BASENAME') ) {
806 837 do_action( 'rt_nginx_helper_purge_all' );
807 838 } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
808 839 // fallback for WP-Super-Cache
@@ -814,8 +845,11 @@
814 845 } else {
815 846 prune_super_cache( $cache_path . 'supercache/', true );
816 847 prune_super_cache( $cache_path, true );
817 848 }
849 + } elseif ( class_exists( 'NginxCache' ) ) {
850 + $nginx_cache = new NginxCache();
851 + $nginx_cache->purge_zone_once();
818 852 }
819 853 }
820 854 // @codingStandardsIgnoreEnd
821 855 }