PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / addons / wp_optimize / purge-plugins-cache-class.php

purge-plugins-cache-class.php in InfiniteWP Client trunk, at addons/wp_optimize/purge-plugins-cache-class.php

331 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined('ABSPATH') )
4 die();
5
6 class IWP_MMB_PURGE_CACHE extends IWP_MMB_Core
7 {
8
9 function __construct()
10 {
11 parent::__construct();
12 }
13 /*
14 * Public function, Will Clear all cache plugins
15 */
16 public function purgeAllCache($params = array()){
17 $cleanup_values = array();
18 $cleanup_values['value_array'] = array();
19 $text = '';
20 if (empty($params) || isset($params['wpfc_cache'])) {
21 $response = $this->deleteALLWPFCCache();
22 if (!empty($response['success'])) {
23 $text .= "<span class='wpm_results_db'> WP Fastest Cache"." : " . $response['success'] . "</span><br>";
24 $cleanup_values['value_array']['wpfc_cache'] = 1;
25 }elseif(!empty($response['error'])){
26 $text .= "<span class='wpm_results_db'> WP Fastest Cache"." : " . $response['error'] . "</span><br>";
27 $cleanup_values['value_array']['wpfc_cache'] = 'WP Fastest Cache';
28 }
29 }
30 if (empty($params) || isset($params['wp_super_cache'])) {
31 $response = $this->deleteALLWPSuperCache();
32 if (!empty($response['success'])) {
33 $text .= "<span class='wpm_results_db'> WP Super Cache"." : " . $response['success'] . "</span><br>";
34 $cleanup_values['value_array']['wp_super_cache'] = 1;
35 }elseif(!empty($response['error'])){
36 $text .= "<span class='wpm_results_db'> WP Super Cache"." : " . $response['error'] . "</span><br>";
37 $cleanup_values['value_array']['wp_super_cache'] = 'WP Super Cache';
38 }
39 }
40 if (empty($params) || isset($params['w3_total_cache'])) {
41 $response = $this->deleteALLW3TotalCache();
42 if (!empty($response['success'])) {
43 $text .= "<span class='wpm_results_db'> W3 Total Cache"." : " . $response['success'] . "</span><br>";
44 $cleanup_values['value_array']['w3_total_cache'] = 1;
45 }elseif(!empty($response['error'])){
46 $text .= "<span class='wpm_results_db'> W3 Total Cache"." : " . $response['error'] . "</span><br>";
47 $cleanup_values['value_array']['w3_total_cache'] = 'W3 Total Cache';
48 }
49 }
50 if (empty($params) || isset($params['wp_rocket_cache'])) {
51 $response = $this->deleteALLWPRocketCache();
52 if (!empty($response['success'])) {
53 $text .= "<span class='wpm_results_db'> WP Rocket Cache"." : " . $response['success'] . "</span><br>";
54 $cleanup_values['value_array']['wp_rocket_cache'] = 1;
55 }elseif(!empty($response['error'])){
56 $text .= "<span class='wpm_results_db'> WP Rocket Cache"." : " . $response['error'] . "</span><br>";
57 $cleanup_values['value_array']['wp_rocket_cache'] = 'WP Rocket Cache';
58 }
59 }
60 if (empty($params) || isset($params['comet_cache'])) {
61 $response = $this->deleteALLCometCache();
62 if (!empty($response['success'])) {
63 $text .= "<span class='wpm_results_db'> Comet Cache"." : " . $response['success'] . "</span><br>";
64 $cleanup_values['value_array']['comet_cache'] = 1;
65 }elseif(!empty($response['error'])){
66 $text .= "<span class='wpm_results_db'> Comet Cache"." : " . $response['error'] . "</span><br>";
67 $cleanup_values['value_array']['comet_cache'] = 'Comet Cache';
68 }
69 }
70
71 if (empty($params) || isset($params['auto_optimize'])) {
72 $response = $this->deleteAllautoptimizeCache();
73 if (!empty($response['success'])) {
74 $text .= "<span class='wpm_results_db'> Autoptimize"." : " . $response['success'] . "</span><br>";
75 $cleanup_values['value_array']['auto_optimize'] = 1;
76 }elseif(!empty($response['error'])){
77 $text .= "<span class='wpm_results_db'> Autoptimize"." : " . $response['error'] . "</span><br>";
78 $cleanup_values['value_array']['auto_optimize'] = 'Autoptimize';
79 }
80 }
81
82 if (empty($params) || isset($params['litespeed-cache'])) {
83 $response = $this->deleteAllLiteSpeedCache();
84 if (!empty($response['success'])) {
85 $text .= "<span class='wpm_results_db'> Litespeed Cache"." : " . $response['success'] . "</span><br>";
86 $cleanup_values['value_array']['litespeed-cache'] = 1;
87 }elseif(!empty($response['error'])){
88 $text .= "<span class='wpm_results_db'> Litespeed Cache"." : " . $response['error'] . "</span><br>";
89 $cleanup_values['value_array']['auto_optimize'] = 'Litespeed Cache';
90 }
91 }
92
93 if ($text !==''){
94 $cleanup_values['message'] = $text;
95 return $cleanup_values;
96 }
97 }
98 /*
99 * Public function, Will return the WpFastestCache is loaded or not
100 */
101
102 public function checkWPFCPlugin() {
103 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
104 if ( is_plugin_active( 'wp-fastest-cache/wpFastestCache.php' ) ) {
105 @include_once(WP_PLUGIN_DIR . '/wp-fastest-cache/wpFastestCache.php');
106 if (class_exists('WpFastestCache')) {
107 return true;
108 }
109 }
110 return false;
111 }
112
113 /*
114 * Public function, Will return the WP Super cache Plugin is loaded or not
115 */
116
117 public function checkWPSuperCachePlugin() {
118 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
119 if ( is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
120 @include_once(WP_PLUGIN_DIR . '/wp-super-cache/wp-cache.php');
121 if (function_exists('wp_cache_clean_cache')) {
122 return true;
123 }
124 }
125 return false;
126 }
127
128 /*
129 * Public function, Will return the W3 Total cache Plugin is loaded or not
130 */
131
132 public function checkW3TotalCachePlugin() {
133 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
134 if ( is_plugin_active( 'w3-total-cache/w3-total-cache.php' ) ) {
135 @include_once(WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php');
136 if (function_exists('w3tc_flush_all')) {
137 return true;
138 }
139 }
140 return false;
141 }
142
143 public function checkLiteSpeedCachePlugin() {
144 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
145 if ( is_plugin_active( 'litespeed-cache/litespeed-cache.php' ) ) {
146 @include_once(WP_PLUGIN_DIR . '/litespeed-cache/litespeed-cache.php');
147 return true;
148 }
149 return false;
150 }
151
152 /*
153 * Public function, Will return the Comet cache plugin is loaded or not
154 */
155
156 public function checkCometCachePlugin() {
157 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
158 if ( is_plugin_active( 'comet-cache/comet-cache.php' ) ) {
159 // @include_once(WP_PLUGIN_DIR . '/comet-cache/comet-cache.php');
160 //if (class_exists('ApiBase')) {
161 return true;
162 // }
163 }
164 return false;
165 }
166
167 /*
168 * Public function, Will return the Comet cache plugin is loaded or not
169 */
170
171 public function checkWPRocketPlugin() {
172 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
173 if ( is_plugin_active( 'wp-rocket/wp-rocket.php' ) ) {
174 @include_once(WP_PLUGIN_DIR . '/wp-rocket/wp-rocket.php');
175 if (function_exists('rocket_clean_domain') && function_exists('rocket_clean_minify') && function_exists('rocket_clean_cache_busting') && function_exists('create_rocket_uniqid')) {
176 return true;
177 }
178 }
179 return false;
180 }
181
182 /*
183 * Public function, Will return the Comet cache plugin is loaded or not
184 */
185
186 public function checkAutoptimizePlugin() {
187 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
188 if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
189 @include_once(WP_PLUGIN_DIR . 'autoptimize/autoptimize.php');
190 if (class_exists('autoptimizeCache')) {
191 return true;
192 }
193 }
194 return false;
195 }
196
197 /*
198 * This function will delete all cache files for WP Fastest Plugin
199 */
200
201 public function deleteALLWPFCCache(){
202 if($this->checkWPFCPlugin()) {
203 $wpfc = new IWP_MMB_WPFC_CACHE();
204 $wpfc->deleteMinifiedCache();
205 if( !empty($GLOBALS['iwp_wpfc_delete_cache']) && $GLOBALS['iwp_wpfc_delete_cache'] == true ){
206 return array('success' => 'All cache files have been deleted');
207 }else{
208 return array('error' => 'Unable to perform WP Fastest cache', 'error_code' => 'wpfc_plugin_delete_cache');
209 }
210 } else {
211 return array('error'=>"WP fastest cache not activated", 'error_code' => 'wpfc_plugin_is_not_activated');
212 }
213 }
214
215 /*
216 * This function will delete all cache files for WP Super Cache Plugin
217 */
218
219 public function deleteALLWPSuperCache(){
220 if($this->checkWPSuperCachePlugin()) {
221 global $file_prefix;
222 $wp_super_cache = wp_cache_clean_cache($file_prefix, true);
223 if ($wp_super_cache == false) {
224 return array('error' => 'Unable to perform WP Super cache', 'error_code' => 'wp_super_cache_plugin_delete_cache');
225 }
226 return array('success' => 'All cache files have been deleted');
227 } else {
228 return array('error'=>"WP Super cache not activated", 'error_code' => 'wp_super_cache_plugin_is_not_activated');
229 }
230 }
231
232 /*
233 * This function will delete all cache files for W3 Total Cache Plugin
234 */
235
236 public function deleteALLW3TotalCache(){
237 if($this->checkW3TotalCachePlugin()) {
238 w3tc_flush_all();
239 return array('success' => 'All cache files have been deleted');
240 } else {
241 return array('error'=>"W3 Total cache not activated", 'error_code' => 'wp_super_cache_plugin_is_not_activated');
242 }
243 }
244
245 /*
246 * This function will delete all cache files for Comet Cache Plugin
247 */
248
249 public function deleteALLCometCache(){
250 if($this->checkCometCachePlugin()) {
251 global $iwp_mmb_plugin_dir;
252 require_once("$iwp_mmb_plugin_dir/addons/wp_optimize/comet-cache-class.php");
253 return clearCometCacheIWP();
254 } else {
255 return array('error'=>"Comet cache not activated", 'error_code' => 'comet_cache_plugin_is_not_activated');
256 }
257 }
258
259 /*
260 * This function will delete all cache files for WP Rocket Plugin
261 */
262
263 public function deleteALLWPRocketCache(){
264 if($this->checkWPRocketPlugin()) {
265 $lang = '';
266 // Remove all cache files.
267 rocket_clean_domain( $lang );
268
269 // Remove all minify cache files.
270 rocket_clean_minify();
271
272 // Remove cache busting files.
273 rocket_clean_cache_busting();
274
275 // Generate a new random key for minify cache file.
276 $options = get_option( WP_ROCKET_SLUG );
277 $options['minify_css_key'] = create_rocket_uniqid();
278 $options['minify_js_key'] = create_rocket_uniqid();
279 remove_all_filters( 'update_option_' . WP_ROCKET_SLUG );
280 update_option( WP_ROCKET_SLUG, $options );
281 rocket_dismiss_box( 'rocket_warning_plugin_modification' );
282 return array('success' => 'All cache files have been deleted');
283 } else {
284 return array('error'=>"WP Rocket not activated", 'error_code' => 'comet_cache_plugin_is_not_activated');
285 }
286 }
287
288 public function deleteAllautoptimizeCache(){
289 if ($this->checkAutoptimizePlugin()) {
290 $wp_auto_optimize = autoptimizeCache::clearall();
291 if ($wp_auto_optimize == false) {
292 return array('error' => 'Unable to perform Autoptimize cache', 'error_code' => 'auto_optimize_cache_plugin_delete_cache');
293 }
294 return array('success' => 'All cache files have been deleted');
295 }else {
296 return array('error'=>"Autoptimize not activated", 'error_code' => 'auto_optimize_plugin_is_not_activated');
297 }
298 }
299
300 public function deleteAllLiteSpeedCache(){
301 if ($this->checkLiteSpeedCachePlugin()) {
302 do_action('litespeed_purge_all');
303 return array('success' => 'Purged all caches successfully');
304 }else {
305 return array('error'=>"Litespeed cache not activated", 'error_code' => 'litespeed_cache_plugin_is_not_activated');
306 }
307 }
308
309 }
310
311 if(class_exists('WpFastestCache')){
312 class IWP_MMB_WPFC_CACHE extends WpFastestCache{
313
314 public function __construct(){
315 add_action('wpfc_delete_cache', array($this, 'wpfc_delete_cache'));
316 }
317
318 public function deleteALLCache(){
319 $this->deleteCacheToolbar();
320 }
321
322 public function deleteMinifiedCache(){
323 $this->deleteCache();
324 }
325
326 public function wpfc_delete_cache(){
327 $GLOBALS['iwp_wpfc_delete_cache'] = true;
328 }
329 }
330 }
331