PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.15
ShopBuilder – WooCommerce Builder For Elementor v2.1.15
3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3.0 All 62 releases
shopbuilder / app / Helpers / Cache.php

Cache.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.15, at app/Helpers/Cache.php

238 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcodes Class.
4 *
5 * This class contains all the Shortcodes.
6 *
7 * @package RadiusTheme\SB
8 */
9
10 namespace RadiusTheme\SB\Helpers;
11
12 use RadiusTheme\SB\Traits\SingletonTrait;
13 use W3TC\Dispatcher;
14
15 // Do not allow directly accessing this file.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 'This script cannot be accessed directly.' );
18 }
19
20 /**
21 * CacheController Class.
22 */
23 class Cache {
24
25 /**
26 * Clear the template cache.
27 *
28 * @since 4.3.0
29 */
30 public static function clear_all_cache() {
31 self::clear_data_cache();
32 self::clear_template_cache();
33 self::clear_plugins_cache();
34 }
35 /**
36 * Clear the template cache.
37 *
38 * @since 4.3.0
39 */
40 public static function clear_plugins_cache() {
41 // Clear W3 Total Cache.
42 if ( function_exists( 'w3tc_flush_all' ) ) {
43 w3tc_flush_all();
44 }
45 // Clear WP Super Cache.
46 if ( function_exists( 'wp_cache_clear_cache' ) ) {
47 wp_cache_clear_cache();
48 }
49 // Clear WP Rocket cache.
50 if ( function_exists( 'rocket_clean_domain' ) ) {
51 rocket_clean_domain();
52 }
53 if ( method_exists( 'LiteSpeed_Cache_API', 'purge_all' ) ) {
54 \LiteSpeed_Cache_API::purge_all();
55 }
56 if ( class_exists( 'Endurance_Page_Cache' ) ) {
57 $epc = new \Endurance_Page_Cache();
58 $epc->purge_all();
59 }
60 if ( class_exists( 'SG_CachePress_Supercacher' ) && method_exists( 'SG_CachePress_Supercacher', 'purge_cache' ) ) {
61 \SG_CachePress_Supercacher::purge_cache( true );
62 }
63 if ( class_exists( 'SiteGround_Optimizer\Supercacher\Supercacher' ) ) {
64 \SiteGround_Optimizer\Supercacher\Supercacher::purge_cache();
65 }
66 if ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) {
67 $GLOBALS['wp_fastest_cache']->deleteCache( true );
68 }
69 if ( is_callable( [ 'Swift_Performance_Cache', 'clear_all_cache' ] ) ) {
70 \Swift_Performance_Cache::clear_all_cache();
71 }
72 if ( is_callable( [ 'Hummingbird\WP_Hummingbird', 'flush_cache' ] ) ) {
73 \Hummingbird\WP_Hummingbird::flush_cache( true, false );
74 }
75 if ( class_exists( 'WP_Optimize' ) ) {
76 \WP_Optimize()->get_page_cache()->purge();
77 }
78
79 // Purge WP Engine.
80 if ( class_exists( 'WpeCommon' ) ) {
81 if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
82 \WpeCommon::purge_memcached();
83 }
84 if ( method_exists( 'WpeCommon', 'clear_maxcdn_cache' ) ) {
85 \WpeCommon::clear_maxcdn_cache();
86 }
87 if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
88 \WpeCommon::purge_varnish_cache();
89 }
90 }
91 // Purge Kinsta.
92 global $kinsta_cache;
93 if ( isset( $kinsta_cache ) && class_exists( '\\Kinsta\\CDN_Enabler' ) ) {
94 if ( ! empty( $kinsta_cache->kinsta_cache_purge ) && is_callable( [ $kinsta_cache->kinsta_cache_purge, 'purge_complete_caches' ] ) ) {
95 $kinsta_cache->kinsta_cache_purge->purge_complete_caches();
96 }
97 }
98 // Purge Pagely.
99 if ( class_exists( 'PagelyCachePurge' ) ) {
100 $purge_pagely = new \PagelyCachePurge();
101 if ( is_callable( [ $purge_pagely, 'purgeAll' ] ) ) {
102 $purge_pagely->purgeAll();
103 }
104 }
105 // Purge Pressidum.
106 if ( defined( 'WP_NINUKIS_WP_NAME' ) && class_exists( 'Ninukis_Plugin' ) && is_callable( [ 'Ninukis_Plugin', 'get_instance' ] ) ) {
107 $purge_pressidum = \Ninukis_Plugin::get_instance();
108 if ( is_callable( [ $purge_pressidum, 'purgeAllCaches' ] ) ) {
109 $purge_pressidum->purgeAllCaches();
110 }
111 }
112 // Purge Savvii.
113 if ( defined( '\Savvii\CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW' ) ) {
114 $purge_savvii = new \Savvii\CacheFlusherPlugin();
115 if ( is_callable( [ $purge_savvii, 'domainflush' ] ) ) {
116 $purge_savvii->domainflush();
117 }
118 }
119 // Purge Hyper Cache.
120 if ( class_exists( 'HyperCache' ) ) {
121 do_action( 'autoptimize_action_cachepurged' );
122 }
123 // purge cache enabler.
124 if ( has_action( 'ce_clear_cache' ) ) {
125 do_action( 'ce_clear_cache' );
126 }
127 // When plugins have a simple method, add them to the array ('Plugin Name' => 'method_name').
128 $others = [
129 'WP Fastest Cache' => 'wpfc_clear_all_cache',
130 'Cachify' => 'cachify_flush_cache',
131 'Comet Cache' => [ 'comet_cache', 'clear' ],
132 'SG Optimizer' => 'sg_cachepress_purge_cache',
133 'Pantheon' => 'pantheon_wp_clear_edge_all',
134 'Zen Cache' => [ 'zencache', 'clear' ],
135 'Breeze' => [ 'Breeze_PurgeCache', 'breeze_cache_flush' ],
136 'Swift Performance' => [ 'Swift_Performance_Cache', 'clear_all_cache' ],
137 ];
138 foreach ( $others as $plugin => $method ) {
139 if ( is_callable( $method ) ) {
140 call_user_func( $method );
141 }
142 }
143 // Purge Godaddy Managed WordPress Hosting (Varnish + APC).
144 if ( class_exists( 'WPaaS\Plugin' ) ) {
145 self::godaddy_request( 'BAN' );
146 }
147
148 wp_cache_flush();
149 }
150
151
152 /**
153 * Purge GoDaddy Managed WordPress Hosting (Varnish)
154 *
155 * Source: https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php
156 *
157 * @param String $method
158 * @param String|Null $url
159 */
160 public static function godaddy_request( $method, $url = null ) {
161 $url = empty( $url ) ? home_url() : $url;
162 $host = parse_url( $url, PHP_URL_HOST );
163 $url = set_url_scheme( str_replace( $host, \WPaas\Plugin::vip(), $url ), 'http' );
164 wp_cache_flush();
165 update_option( 'gd_system_last_cache_flush', time() ); // purge apc.
166 wp_remote_request(
167 esc_url_raw( $url ),
168 [
169 'method' => $method,
170 'blocking' => false,
171 'headers' => [ 'Host' => $host ],
172 ]
173 );
174 }
175
176 /**
177 * Add a template to the template cache.
178 *
179 * @since 4.3.0
180 * @param string $cache_key Object cache key.
181 * @param string $template Located template.
182 */
183 public static function set_template_cache( $cache_key, $template ) {
184 wp_cache_set( $cache_key, $template, 'shopbuilder' );
185 $cached_templates = wp_cache_get( 'shopbuilder_cached_templates', 'shopbuilder' );
186 if ( is_array( $cached_templates ) ) {
187 $cached_templates[] = $cache_key;
188 } else {
189 $cached_templates = [ $cache_key ];
190 }
191 wp_cache_set( 'shopbuilder_cached_templates', $cached_templates, 'shopbuilder' );
192 }
193 /**
194 * Clear the template cache.
195 *
196 * @since 4.3.0
197 */
198 public static function clear_template_cache() {
199 $cached_templates = wp_cache_get( 'shopbuilder_cached_templates', 'shopbuilder' );
200 if ( is_array( $cached_templates ) ) {
201 foreach ( $cached_templates as $cache_key ) {
202 wp_cache_delete( $cache_key, 'shopbuilder' );
203 }
204 wp_cache_delete( 'shopbuilder_cached_templates', 'shopbuilder' );
205 }
206 }
207 /**
208 * Added data cache.
209 *
210 * @since 4.3.0
211 * @param string $cache_key Object cache key.
212 * @param string $data Located template.
213 */
214 public static function set_data_cache_key( $cache_key ) {
215 $cached_data = wp_cache_get( 'shopbuilder_cached_data', 'shopbuilder' );
216 if ( is_array( $cached_data ) ) {
217 $cached_data[] = $cache_key;
218 } else {
219 $cached_data = [ $cache_key ];
220 }
221 wp_cache_set( 'shopbuilder_cached_data', $cached_data, 'shopbuilder' );
222 }
223 /**
224 * Clear data cache.
225 *
226 * @since 4.3.0
227 */
228 public static function clear_data_cache() {
229 $cached_templates = wp_cache_get( 'shopbuilder_cached_data', 'shopbuilder' );
230 if ( is_array( $cached_templates ) ) {
231 foreach ( $cached_templates as $cache_key ) {
232 wp_cache_delete( $cache_key, 'shopbuilder' );
233 }
234 wp_cache_delete( 'shopbuilder_cached_data', 'shopbuilder' );
235 }
236 }
237 }
238