-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathclass-cache.php
More file actions
159 lines (133 loc) · 3.95 KB
/
class-cache.php
File metadata and controls
159 lines (133 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
defined( 'ABSPATH' ) or die( );
if ( ! class_exists( 'rsssl_cache' ) ) {
class rsssl_cache {
private static $_this;
public function __construct() {
if ( isset( self::$_this ) ) {
wp_die( 'you cannot create a second instance.' );
}
self::$_this = $this;
}
public static function this() {
return self::$_this;
}
/**
* Flushes the cache for popular caching plugins to prevent mixed content errors
* When .htaccess is changed, all traffic should flow over https, so clear cache when possible.
* Supported: W3TC, WP Optimize, LiteSpeed, Hummingbird, WP Fastest Cache,
* Autoptimize, WP Rocket, Cache Enabler, WP Super Cache, Cloudflare
*
* @since 2.0
*
* @access public
*
*/
public function flush() {
if ( ! rsssl_user_can_manage() ) {
return;
}
add_action( 'admin_head', array( $this, 'maybe_flush_w3tc_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_wp_optimize_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_litespeed_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_hummingbird_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_fastest_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_autoptimize_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_wp_rocket' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_cache_enabler' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_wp_super_cache' ) );
add_action( 'admin_head', array( $this, 'maybe_flush_cloudflare_cache' ) );
}
public function maybe_flush_w3tc_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( function_exists( 'w3tc_flush_all' ) ) {
w3tc_flush_all();
}
}
public function maybe_flush_wp_optimize_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( function_exists( 'wpo_cache_flush' ) ) {
wpo_cache_flush();
}
}
public function maybe_flush_litespeed_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( class_exists( 'LiteSpeed' ) ) {
Litespeed\Purge::purge_all();
}
}
public function maybe_flush_hummingbird_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( is_callable( array( 'Hummingbird\WP_Hummingbird', 'flush_cache' ) ) ) {
Hummingbird\WP_Hummingbird::flush_cache();
}
}
public function maybe_flush_fastest_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( class_exists( 'WpFastestCache' ) ) {
// Non-static cannot be called statically ::
( new WpFastestCache() )->deleteCache();
}
}
public function maybe_flush_autoptimize_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( class_exists( 'autoptimizeCache' ) ) {
autoptimizeCache::clearall();
}
}
public function maybe_flush_wp_rocket() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( function_exists( 'rocket_clean_domain' ) ) {
rocket_clean_domain();
}
}
public function maybe_flush_cache_enabler() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( class_exists( 'Cache_Enabler' ) ) {
Cache_Enabler::clear_complete_cache();
}
}
public function maybe_flush_wp_super_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( function_exists( 'wp_cache_clear_cache' ) ) {
wp_cache_clear_cache();
}
}
/**
* Flush Cloudflare cache if the Cloudflare plugin is active.
*
* @see https://github.com/cloudflare/Cloudflare-WordPress
*/
public function maybe_flush_cloudflare_cache() {
if ( ! rsssl_user_can_manage() ) {
return;
}
if ( defined( 'CLOUDFLARE_PLUGIN_DIR' ) && class_exists( '\Cloudflare\APO\WordPress\Hooks' ) ) {
try {
$cloudflare_hooks = new \Cloudflare\APO\WordPress\Hooks();
$cloudflare_hooks->purgeCacheEverything();
} catch ( \Throwable $e ) {
// Silently fail if Cloudflare API is not configured.
}
}
}
}//class closure
}