really-simple-ssl
Last commit date
assets
3 months ago
core
3 months ago
languages
3 months ago
lets-encrypt
4 months ago
lib
6 months ago
mailer
7 months ago
modal
3 months ago
placeholders
9 months ago
progress
1 year ago
security
3 months ago
settings
3 months ago
testssl
5 years ago
upgrade
7 months ago
.wp-env.json
10 months ago
SECURITY.md
9 months ago
class-admin.php
3 months ago
class-cache.php
4 months ago
class-certificate.php
2 years ago
class-front-end.php
6 months ago
class-installer.php
10 months ago
class-mixed-content-fixer.php
3 years ago
class-multisite.php
4 months ago
class-server.php
4 months ago
class-site-health.php
1 year ago
class-wp-cli.php
5 months ago
compatibility.php
1 year ago
force-deactivate.txt
1 year ago
functions.php
5 months ago
index.php
2 years ago
readme.txt
3 months ago
rector.php
1 year ago
rlrsssl-really-simple-ssl.php
3 months ago
rsssl-auto-loader.php
1 year ago
sbom.json.gz
3 months ago
ssl-test-page.php
2 years ago
system-status.php
8 months ago
uninstall.php
4 months ago
upgrade.php
4 months ago
class-cache.php
160 lines
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) or die( ); |
| 3 | if ( ! class_exists( 'rsssl_cache' ) ) { |
| 4 | class rsssl_cache { |
| 5 | private static $_this; |
| 6 | |
| 7 | public function __construct() { |
| 8 | if ( isset( self::$_this ) ) { |
| 9 | wp_die( 'you cannot create a second instance.' ); |
| 10 | } |
| 11 | |
| 12 | self::$_this = $this; |
| 13 | } |
| 14 | |
| 15 | public static function this() { |
| 16 | return self::$_this; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Flushes the cache for popular caching plugins to prevent mixed content errors |
| 21 | * When .htaccess is changed, all traffic should flow over https, so clear cache when possible. |
| 22 | * Supported: W3TC, WP Optimize, LiteSpeed, Hummingbird, WP Fastest Cache, |
| 23 | * Autoptimize, WP Rocket, Cache Enabler, WP Super Cache, Cloudflare |
| 24 | * |
| 25 | * @since 2.0 |
| 26 | * |
| 27 | * @access public |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | public function flush() { |
| 32 | if ( ! rsssl_user_can_manage() ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | add_action( 'admin_head', array( $this, 'maybe_flush_w3tc_cache' ) ); |
| 37 | add_action( 'admin_head', array( $this, 'maybe_flush_wp_optimize_cache' ) ); |
| 38 | add_action( 'admin_head', array( $this, 'maybe_flush_litespeed_cache' ) ); |
| 39 | add_action( 'admin_head', array( $this, 'maybe_flush_hummingbird_cache' ) ); |
| 40 | add_action( 'admin_head', array( $this, 'maybe_flush_fastest_cache' ) ); |
| 41 | add_action( 'admin_head', array( $this, 'maybe_flush_autoptimize_cache' ) ); |
| 42 | add_action( 'admin_head', array( $this, 'maybe_flush_wp_rocket' ) ); |
| 43 | add_action( 'admin_head', array( $this, 'maybe_flush_cache_enabler' ) ); |
| 44 | add_action( 'admin_head', array( $this, 'maybe_flush_wp_super_cache' ) ); |
| 45 | add_action( 'admin_head', array( $this, 'maybe_flush_cloudflare_cache' ) ); |
| 46 | } |
| 47 | |
| 48 | public function maybe_flush_w3tc_cache() { |
| 49 | if ( ! rsssl_user_can_manage() ) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | if ( function_exists( 'w3tc_flush_all' ) ) { |
| 54 | w3tc_flush_all(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public function maybe_flush_wp_optimize_cache() { |
| 59 | if ( ! rsssl_user_can_manage() ) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if ( function_exists( 'wpo_cache_flush' ) ) { |
| 64 | wpo_cache_flush(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public function maybe_flush_litespeed_cache() { |
| 69 | if ( ! rsssl_user_can_manage() ) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if ( class_exists( 'LiteSpeed' ) ) { |
| 74 | Litespeed\Purge::purge_all(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public function maybe_flush_hummingbird_cache() { |
| 79 | if ( ! rsssl_user_can_manage() ) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | if ( is_callable( array( 'Hummingbird\WP_Hummingbird', 'flush_cache' ) ) ) { |
| 84 | Hummingbird\WP_Hummingbird::flush_cache(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | public function maybe_flush_fastest_cache() { |
| 89 | if ( ! rsssl_user_can_manage() ) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | if ( class_exists( 'WpFastestCache' ) ) { |
| 94 | // Non-static cannot be called statically :: |
| 95 | ( new WpFastestCache() )->deleteCache(); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | public function maybe_flush_autoptimize_cache() { |
| 100 | if ( ! rsssl_user_can_manage() ) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | if ( class_exists( 'autoptimizeCache' ) ) { |
| 105 | autoptimizeCache::clearall(); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | public function maybe_flush_wp_rocket() { |
| 110 | if ( ! rsssl_user_can_manage() ) { |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | if ( function_exists( 'rocket_clean_domain' ) ) { |
| 115 | rocket_clean_domain(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | public function maybe_flush_cache_enabler() { |
| 120 | if ( ! rsssl_user_can_manage() ) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if ( class_exists( 'Cache_Enabler' ) ) { |
| 125 | Cache_Enabler::clear_complete_cache(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | public function maybe_flush_wp_super_cache() { |
| 130 | if ( ! rsssl_user_can_manage() ) { |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | if ( function_exists( 'wp_cache_clear_cache' ) ) { |
| 135 | wp_cache_clear_cache(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Flush Cloudflare cache if the Cloudflare plugin is active. |
| 141 | * |
| 142 | * @see https://github.com/cloudflare/Cloudflare-WordPress |
| 143 | */ |
| 144 | public function maybe_flush_cloudflare_cache() { |
| 145 | if ( ! rsssl_user_can_manage() ) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | if ( defined( 'CLOUDFLARE_PLUGIN_DIR' ) && class_exists( '\Cloudflare\APO\WordPress\Hooks' ) ) { |
| 150 | try { |
| 151 | $cloudflare_hooks = new \Cloudflare\APO\WordPress\Hooks(); |
| 152 | $cloudflare_hooks->purgeCacheEverything(); |
| 153 | } catch ( \Throwable $e ) { |
| 154 | // Silently fail if Cloudflare API is not configured. |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | }//class closure |
| 159 | } |
| 160 |