PluginProbe
MaxButtons – Create buttons / 7.13.1
MaxButtons – Create buttons v7.13.1
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / assets / integrations / cache / cache.php

cache.php in MaxButtons – Create buttons 7.13.1, at assets/integrations/cache/cache.php

114 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MaxButtons;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 class MBCache
6 {
7 protected $has_supercache = false; // supercache seems to replace quite fine, without our help. @todo Test if this is needed
8 protected $has_w3tc = false;
9 protected $has_wpengine = false;
10 protected $has_fastestcache = false;
11 protected $has_siteground = false;
12
13 public function __construct()
14 {
15 add_action('mb/button/save', array($this, 'save_action'));
16 }
17
18 public function save_action($button_id)
19 {
20 $this->checkCaches();
21 $this->flushCache();
22 }
23
24 /** Checks which cache plugins are active on the moment a flush is needed */
25 public function checkCaches()
26 {
27 if ( function_exists( 'w3tc_pgcache_flush' ) )
28 $this->has_w3tc = true;
29
30 if ( function_exists('wp_cache_clean_cache') )
31 $this->has_supercache = true;
32
33 if ( class_exists( 'WpeCommon' ) )
34 $this->has_wpengine = true;
35
36 global $wp_fastest_cache;
37 if ( method_exists( 'WpFastestCache', 'deleteCache' ) && !empty( $wp_fastest_cache ) )
38 $this->has_fastestcache = true;
39
40 // SG SuperCacher
41 if (function_exists('sg_cachepress_purge_cache')) {
42 $this->has_siteground = true;
43 }
44
45 }
46
47 /* Tries to flush cache there were we have issues
48 *
49 * @param Array $args Argument Array to provide data.
50 */
51 public function flushCache()
52 {
53 // important - first check the available cache plugins
54 $this->checkCaches();
55 wp_cache_flush();
56
57 if ($this->has_supercache)
58 $this->removeSuperCache();
59
60 if ($this->has_w3tc)
61 $this->removeW3tcCache();
62
63 if ($this->has_wpengine)
64 $this->removeWpeCache();
65
66 if ($this->has_siteground)
67 $this->removeSiteGround();
68
69 if ($this->has_fastestcache)
70 $this->removeFastestCache();
71
72 }
73
74 protected function removeSuperCache()
75 {
76 global $file_prefix, $supercachedir;
77 if ( empty( $supercachedir ) && function_exists( 'get_supercache_dir' ) ) {
78 $supercachedir = get_supercache_dir();
79 }
80 wp_cache_clean_cache( $file_prefix );
81 }
82
83 protected function removeW3tcCache()
84 {
85 w3tc_pgcache_flush();
86 }
87
88 protected function removeWpeCache()
89 {
90 if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
91 \WpeCommon::purge_memcached();
92 }
93 if ( method_exists( 'WpeCommon', 'clear_maxcdn_cache' ) ) {
94 \WpeCommon::clear_maxcdn_cache();
95 }
96 if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
97 \WpeCommon::purge_varnish_cache();
98 }
99 }
100
101 protected function removeFastestCache()
102 {
103 global $wp_fastest_cache;
104 $wp_fastest_cache->deleteCache();
105 }
106
107 protected function removeSiteGround()
108 {
109 sg_cachepress_purge_cache();
110 }
111
112 }
113 $cache = new MBCache();
114