PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.5
ShopBuilder – WooCommerce Builder For Elementor v3.2.5
3.4.2 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 All 63 releases
← All changes | app/Helpers/Cache.php +99 -4 2.2.13.2.5 View file →
@@ -8,10 +8,11 @@
8 8 */
9 9
10 10 namespace RadiusTheme\SB\Helpers;
11 11
12 +use W3TC\Dispatcher;
12 13 use RadiusTheme\SB\Traits\SingletonTrait;
13 -use W3TC\Dispatcher;
14 +use RadiusTheme\SB\Controllers\AssetRegistry;
14 15
15 16 // Do not allow directly accessing this file.
16 17 if ( ! defined( 'ABSPATH' ) ) {
17 18 exit( 'This script cannot be accessed directly.' );
@@ -31,8 +32,9 @@
31 32 self::clear_data_cache();
32 33 self::clear_template_cache();
33 34 self::clear_plugins_cache();
34 35 self::clear_transient_cache();
36 + self::clear_asset_cache();
35 37 }
36 38 /**
37 39 * Clear the template cache.
38 40 *
@@ -154,10 +156,12 @@
154 156 * Purge GoDaddy Managed WordPress Hosting (Varnish)
155 157 *
156 158 * Source: https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php
157 159 *
158 - * @param String $method
159 - * @param String|Null $url
160 + * @param string $method The request method.
161 + * @param string $url The request URL.
162 + *
163 + * @return void
160 164 */
161 165 public static function godaddy_request( $method, $url = null ) {
162 166 $url = empty( $url ) ? home_url() : $url;
163 167 $host = wp_parse_url( $url, PHP_URL_HOST );
@@ -209,9 +213,10 @@
209 213 * Added data cache.
210 214 *
211 215 * @since 4.3.0
212 216 * @param string $cache_key Object cache key.
213 - * @param string $data Located template.
217 + *
218 + * @return void
214 219 */
215 220 public static function set_data_cache_key( $cache_key ) {
216 221 $cached_data = wp_cache_get( 'shopbuilder_cached_data', 'shopbuilder' );
217 222 if ( is_array( $cached_data ) ) {
@@ -235,10 +240,72 @@
235 240 wp_cache_delete( 'shopbuilder_cached_data', 'shopbuilder' );
236 241 }
237 242 }
238 243
244 + /**
245 + * Clear asset cache.
246 + *
247 + * @return void
248 + */
249 + public static function clear_asset_cache() {
250 + if ( ! Fns::is_optimization_enabled() ) {
251 + return;
252 + }
239 253
254 + $upload_dir = wp_upload_dir();
255 + $asset_dir = trailingslashit( $upload_dir['basedir'] ) . 'shopbuilder_uploads/cache/';
256 +
257 + // Delete old assets.
258 + if ( is_dir( $asset_dir ) ) {
259 + self::delete_dir_contents( $asset_dir );
260 + }
261 +
262 + // Re-generate assets.
263 + AssetRegistry::instance()->regenerate_bundles();
264 + }
265 +
240 266 /**
267 + * Recursively delete directory contents.
268 + *
269 + * @param string $dir Directory path.
270 + * @return void
271 + */
272 + public static function delete_dir_contents( $dir ) {
273 + global $wp_filesystem;
274 +
275 + if ( ! function_exists( 'WP_Filesystem' ) ) {
276 + require_once ABSPATH . 'wp-admin/includes/file.php';
277 + }
278 +
279 + if ( ! $wp_filesystem ) {
280 + WP_Filesystem();
281 + }
282 +
283 + if ( ! $wp_filesystem->is_dir( $dir ) ) {
284 + return;
285 + }
286 +
287 + $contents = $wp_filesystem->dirlist( $dir );
288 +
289 + if ( ! is_array( $contents ) ) {
290 + return;
291 + }
292 +
293 + foreach ( $contents as $item ) {
294 + $path = trailingslashit( $dir ) . $item['name'];
295 +
296 + if ( 'f' === $item['type'] ) {
297 + $wp_filesystem->delete( $path, false );
298 + } elseif ( 'd' === $item['type'] ) {
299 + self::delete_dir_contents( $path );
300 +
301 + $wp_filesystem->delete( $path, true );
302 + }
303 + }
304 + }
305 +
306 +
307 + /**
241 308 * Added data cache.
242 309 *
243 310 * @since 4.3.0
244 311 * @param string $cache_key Transient cache key.
@@ -265,7 +332,35 @@
265 332 foreach ( $cached_templates as $cache_key ) {
266 333 delete_transient( $cache_key );
267 334 }
268 335 delete_transient( 'shopbuilder_transient_cached_data' );
336 + }
337 +
338 + self::delete_all_theme_css_handle_transients();
339 + }
340 +
341 + /**
342 + * Clear all theme css handle transients.
343 + *
344 + * @return void
345 + */
346 + public static function delete_all_theme_css_handle_transients() {
347 + global $wpdb;
348 +
349 + $prefix = '_transient_';
350 + $transient_ns = 'rtsb_theme_css_handle_';
351 +
352 + // Fetch all matching transient option names.
353 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
354 + $transients = $wpdb->get_col(
355 + $wpdb->prepare(
356 + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
357 + $wpdb->esc_like( $prefix . $transient_ns ) . '%'
358 + )
359 + );
360 +
361 + foreach ( $transients as $option_name ) {
362 + $key = str_replace( '_transient_', '', $option_name );
363 + delete_transient( $key );
269 364 }
270 365 }
271 366 }