| @@ -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 | * |
| @@ -53,8 +55,11 @@ | ||
| 53 | 55 | } |
| 54 | 56 | if ( method_exists( 'LiteSpeed_Cache_API', 'purge_all' ) ) { |
| 55 | 57 | \LiteSpeed_Cache_API::purge_all(); |
| 56 | 58 | } |
| 59 | + if ( class_exists( '\LiteSpeed\Purge' ) ) { | |
| 60 | + \LiteSpeed\Purge::purge_all(); | |
| 61 | + } | |
| 57 | 62 | if ( class_exists( 'Endurance_Page_Cache' ) ) { |
| 58 | 63 | $epc = new \Endurance_Page_Cache(); |
| 59 | 64 | $epc->purge_all(); |
| 60 | 65 | } |
| @@ -154,10 +159,12 @@ | ||
| 154 | 159 | * Purge GoDaddy Managed WordPress Hosting (Varnish) |
| 155 | 160 | * |
| 156 | 161 | * Source: https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php |
| 157 | 162 | * |
| 158 | - * @param String $method | |
| 159 | - * @param String|Null $url | |
| 163 | + * @param string $method The request method. | |
| 164 | + * @param string $url The request URL. | |
| 165 | + * | |
| 166 | + * @return void | |
| 160 | 167 | */ |
| 161 | 168 | public static function godaddy_request( $method, $url = null ) { |
| 162 | 169 | $url = empty( $url ) ? home_url() : $url; |
| 163 | 170 | $host = wp_parse_url( $url, PHP_URL_HOST ); |
| @@ -209,9 +216,10 @@ | ||
| 209 | 216 | * Added data cache. |
| 210 | 217 | * |
| 211 | 218 | * @since 4.3.0 |
| 212 | 219 | * @param string $cache_key Object cache key. |
| 213 | - * @param string $data Located template. | |
| 220 | + * | |
| 221 | + * @return void | |
| 214 | 222 | */ |
| 215 | 223 | public static function set_data_cache_key( $cache_key ) { |
| 216 | 224 | $cached_data = wp_cache_get( 'shopbuilder_cached_data', 'shopbuilder' ); |
| 217 | 225 | if ( is_array( $cached_data ) ) { |
| @@ -235,10 +243,72 @@ | ||
| 235 | 243 | wp_cache_delete( 'shopbuilder_cached_data', 'shopbuilder' ); |
| 236 | 244 | } |
| 237 | 245 | } |
| 238 | 246 | |
| 247 | + /** | |
| 248 | + * Clear asset cache. | |
| 249 | + * | |
| 250 | + * @return void | |
| 251 | + */ | |
| 252 | + public static function clear_asset_cache() { | |
| 253 | + if ( ! Fns::is_optimization_enabled() ) { | |
| 254 | + return; | |
| 255 | + } | |
| 239 | 256 | |
| 257 | + $upload_dir = wp_upload_dir(); | |
| 258 | + $asset_dir = trailingslashit( $upload_dir['basedir'] ) . 'shopbuilder_uploads/cache/'; | |
| 259 | + | |
| 260 | + // Delete old assets. | |
| 261 | + if ( is_dir( $asset_dir ) ) { | |
| 262 | + self::delete_dir_contents( $asset_dir ); | |
| 263 | + } | |
| 264 | + | |
| 265 | + // Re-generate assets. | |
| 266 | + AssetRegistry::instance()->regenerate_bundles(); | |
| 267 | + } | |
| 268 | + | |
| 240 | 269 | /** |
| 270 | + * Recursively delete directory contents. | |
| 271 | + * | |
| 272 | + * @param string $dir Directory path. | |
| 273 | + * @return void | |
| 274 | + */ | |
| 275 | + public static function delete_dir_contents( $dir ) { | |
| 276 | + global $wp_filesystem; | |
| 277 | + | |
| 278 | + if ( ! function_exists( 'WP_Filesystem' ) ) { | |
| 279 | + require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 280 | + } | |
| 281 | + | |
| 282 | + if ( ! $wp_filesystem ) { | |
| 283 | + WP_Filesystem(); | |
| 284 | + } | |
| 285 | + | |
| 286 | + if ( ! $wp_filesystem->is_dir( $dir ) ) { | |
| 287 | + return; | |
| 288 | + } | |
| 289 | + | |
| 290 | + $contents = $wp_filesystem->dirlist( $dir ); | |
| 291 | + | |
| 292 | + if ( ! is_array( $contents ) ) { | |
| 293 | + return; | |
| 294 | + } | |
| 295 | + | |
| 296 | + foreach ( $contents as $item ) { | |
| 297 | + $path = trailingslashit( $dir ) . $item['name']; | |
| 298 | + | |
| 299 | + if ( 'f' === $item['type'] ) { | |
| 300 | + $wp_filesystem->delete( $path, false ); | |
| 301 | + } elseif ( 'd' === $item['type'] ) { | |
| 302 | + self::delete_dir_contents( $path ); | |
| 303 | + | |
| 304 | + $wp_filesystem->delete( $path, true ); | |
| 305 | + } | |
| 306 | + } | |
| 307 | + } | |
| 308 | + | |
| 309 | + | |
| 310 | + /** | |
| 241 | 311 | * Added data cache. |
| 242 | 312 | * |
| 243 | 313 | * @since 4.3.0 |
| 244 | 314 | * @param string $cache_key Transient cache key. |
| @@ -265,7 +335,35 @@ | ||
| 265 | 335 | foreach ( $cached_templates as $cache_key ) { |
| 266 | 336 | delete_transient( $cache_key ); |
| 267 | 337 | } |
| 268 | 338 | delete_transient( 'shopbuilder_transient_cached_data' ); |
| 339 | + } | |
| 340 | + | |
| 341 | + self::delete_all_theme_css_handle_transients(); | |
| 342 | + } | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * Clear all theme css handle transients. | |
| 346 | + * | |
| 347 | + * @return void | |
| 348 | + */ | |
| 349 | + public static function delete_all_theme_css_handle_transients() { | |
| 350 | + global $wpdb; | |
| 351 | + | |
| 352 | + $prefix = '_transient_'; | |
| 353 | + $transient_ns = 'rtsb_theme_css_handle_'; | |
| 354 | + | |
| 355 | + // Fetch all matching transient option names. | |
| 356 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 357 | + $transients = $wpdb->get_col( | |
| 358 | + $wpdb->prepare( | |
| 359 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", | |
| 360 | + $wpdb->esc_like( $prefix . $transient_ns ) . '%' | |
| 361 | + ) | |
| 362 | + ); | |
| 363 | + | |
| 364 | + foreach ( $transients as $option_name ) { | |
| 365 | + $key = str_replace( '_transient_', '', $option_name ); | |
| 366 | + delete_transient( $key ); | |
| 269 | 367 | } |
| 270 | 368 | } |
| 271 | 369 | } |