$cache ) { if ( $cache['present']() ) { $found[] = $name; } } return $found; } public static function purge() { foreach ( self::caches() as $cache ) { if ( $cache['present']() ) { $cache['purge'](); } } /** * Fires after the plugin asked the known page caches to purge, for a cache it doesn't know. */ do_action( 'alexibility_fixes_purge_cache' ); } /** Each cache: whether it's installed, and how to purge all of it, through its own public API. */ private static function caches() { $action = function ( $hook ) { return array( 'present' => function () use ( $hook ) { return (bool) has_action( $hook ); }, 'purge' => function () use ( $hook ) { do_action( $hook ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Another cache plugin's own purge hook, so it carries that plugin's prefix. }, ); }; $func = function ( $name ) { return array( 'present' => function () use ( $name ) { return function_exists( $name ); }, 'purge' => function () use ( $name ) { call_user_func( $name ); }, ); }; return array( 'Nginx Helper' => $action( 'rt_nginx_helper_purge_all' ), 'LiteSpeed Cache' => $action( 'litespeed_purge_all' ), 'WP Rocket' => $func( 'rocket_clean_domain' ), 'W3 Total Cache' => $func( 'w3tc_flush_all' ), 'WP Super Cache' => $func( 'wp_cache_clear_cache' ), 'WP Fastest Cache' => $action( 'wpfc_clear_all_cache' ), 'Cache Enabler' => $action( 'cache_enabler_clear_complete_cache' ), 'Breeze' => $action( 'breeze_clear_all_cache' ), 'Hummingbird' => $action( 'wphb_clear_page_cache' ), 'SiteGround Speed Optimizer' => $func( 'sg_cachepress_purge_cache' ), 'Pantheon' => $func( 'pantheon_wp_clear_edge_all' ), 'SpinupWP' => $func( 'spinupwp_purge_site' ), 'WP Engine' => array( 'present' => function () { return class_exists( 'WpeCommon' ) && method_exists( 'WpeCommon', 'purge_varnish_cache' ); }, 'purge' => function () { call_user_func( array( 'WpeCommon', 'purge_varnish_cache' ) ); }, ), ); } }