'rocket_clean_domain', 'W3TC' => 'w3tc_flush_all', 'WP Super Cache' => 'wp_cache_clear_cache', 'LiteSpeed' => 'litespeed_purge_all', ]; /** Never throws and never prints, so it is safe during activation. */ public static function flush_silently(): void { self::attempt( 'object cache', static function (): void { if ( function_exists( 'wp_cache_flush' ) ) { wp_cache_flush(); } } ); // An import can bring the other site's rewrite_rules option along, so permalinks need rebuilding after one. self::attempt( 'rewrite rules', static function (): void { if ( function_exists( 'flush_rewrite_rules' ) ) { flush_rewrite_rules( false ); } } ); foreach ( self::PAGE_CACHE_CLEANERS as $label => $callable ) { self::attempt( $label, static function () use ( $callable ): void { if ( function_exists( $callable ) ) { $callable(); } } ); } // SpeedyCache purges through a static method; the function is for older releases. self::attempt( 'SpeedyCache', static function (): void { if ( class_exists( '\SpeedyCache\Delete' ) && method_exists( '\SpeedyCache\Delete', 'run' ) ) { \SpeedyCache\Delete::run( [] ); return; } if ( function_exists( 'speedycache_delete_cache' ) ) { speedycache_delete_cache(); } } ); self::attempt( 'shiftora_flush_caches listeners', static function (): void { if ( function_exists( 'do_action' ) ) { do_action( 'shiftora_flush_caches' ); } } ); } /** Runs one flush step, broadcasting a failure through an action rather than a notice. */ private static function attempt( string $label, callable $step ): void { try { $step(); } catch ( Throwable $e ) { if ( function_exists( 'do_action' ) ) { /** * Fires when a cache flush step failed and was contained. * * @param string $label Human name of the step that failed. * @param \Throwable $e The contained error. */ do_action( 'shiftora_cache_flush_failed', $label, $e ); } } } }