deleteCache( true ); $cleared[] = 'WP Fastest Cache'; } // Cache Enabler. if ( has_action( 'cache_enabler_clear_complete_cache' ) ) { do_action( 'cache_enabler_clear_complete_cache' ); $cleared[] = 'Cache Enabler'; } // SiteGround Optimizer. if ( function_exists( 'sg_cachepress_purge_cache' ) ) { sg_cachepress_purge_cache(); $cleared[] = 'SiteGround Optimizer'; } // Nginx Helper (used by several managed hosts). if ( has_action( 'rt_nginx_helper_purge_all' ) ) { do_action( 'rt_nginx_helper_purge_all' ); $cleared[] = 'Nginx Helper'; } // Kinsta. if ( has_action( 'kinsta_cache_purge_all' ) ) { do_action( 'kinsta_cache_purge_all' ); $cleared[] = 'Kinsta'; } // Autoptimize keeps its own store of combined assets. if ( class_exists( '\autoptimizeCache' ) && method_exists( '\autoptimizeCache', 'clearall' ) ) { \autoptimizeCache::clearall(); $cleared[] = 'Autoptimize'; } // Breeze (Cloudways). if ( class_exists( '\Breeze_PurgeCache' ) && method_exists( '\Breeze_PurgeCache', 'breeze_cache_flush' ) ) { \Breeze_PurgeCache::breeze_cache_flush(); $cleared[] = 'Breeze'; } // Hummingbird. if ( has_action( 'wphb_clear_page_cache' ) ) { do_action( 'wphb_clear_page_cache' ); $cleared[] = 'Hummingbird'; } // The persistent object cache, if one is in use: our own transients // live there, and a stale board is as confusing as a stale page. if ( function_exists( 'wp_cache_flush_group' ) && wp_using_ext_object_cache() ) { $cleared[] = 'Object cache'; } /** * Fires after the plugin has cleared what it recognises. * * For a cache this list does not know about — a host's own, or one * written since this shipped. * * @param string[] $cleared Labels cleared so far. */ do_action( 'airanksuite/cache/purged', $cleared ); return $cleared; } /** * Which caching and optimising plugins are active. * * Reported on the Developer screen so a support conversation can start * from what is actually installed rather than from a guess. * * @return array */ public static function detect(): array { $found = array(); $page = array( 'LiteSpeed' => defined( 'LSCWP_V' ), 'WP Rocket' => function_exists( 'rocket_clean_domain' ), 'W3 Total Cache' => function_exists( 'w3tc_flush_all' ), 'WP Super Cache' => function_exists( 'wp_cache_clear_cache' ), 'WP Fastest Cache' => isset( $GLOBALS['wp_fastest_cache'] ), 'Cache Enabler' => has_action( 'cache_enabler_clear_complete_cache' ), 'SiteGround Optimizer' => function_exists( 'sg_cachepress_purge_cache' ), 'Nginx Helper' => has_action( 'rt_nginx_helper_purge_all' ), 'Kinsta' => has_action( 'kinsta_cache_purge_all' ), 'Breeze' => class_exists( '\Breeze_PurgeCache' ), 'Hummingbird' => has_action( 'wphb_clear_page_cache' ), ); foreach ( $page as $label => $active ) { if ( $active ) { $found[] = array( 'label' => $label, 'kind' => 'page' ); } } if ( class_exists( '\autoptimizeCache' ) ) { $found[] = array( 'label' => 'Autoptimize', 'kind' => 'optimiser' ); } if ( wp_using_ext_object_cache() ) { $found[] = array( 'label' => 'Persistent object cache', 'kind' => 'object' ); } return $found; } /** * Ask every optimiser we know of to leave this plugin's admin script alone. * * Combining JavaScript merges separate files into one. Whatever the build * ships, that transformation is not something a plugin can be sure of * surviving — it once turned the admin bundle into a file the browser * refused outright. These filters are the supported way to opt a script * out, and they cost nothing when the optimiser is not installed. * * The plugin's own build is defensive too (one self-contained file rather * than a module graph), because a filter only helps where it is honoured. */ public static function protect_admin_assets(): void { $needle = 'ai-rank-suite/assets/'; // LiteSpeed: exclude from combine, defer and delay. foreach ( array( 'litespeed_optm_js_defer_exc', 'litespeed_optm_gm_js_exc', 'litespeed_optimize_js_excludes' ) as $hook ) { add_filter( $hook, static function ( $excludes ) use ( $needle ) { $excludes = is_array( $excludes ) ? $excludes : array(); $excludes[] = $needle; return $excludes; } ); } // Autoptimize. add_filter( 'autoptimize_filter_js_exclude', static function ( $exclude ) use ( $needle ) { return is_string( $exclude ) && '' !== $exclude ? $exclude . ',' . $needle : $needle; } ); // WP Rocket: excluded from both combining and delaying. foreach ( array( 'rocket_exclude_js', 'rocket_minify_excluded_external_js', 'rocket_delay_js_exclusions' ) as $hook ) { add_filter( $hook, static function ( $excludes ) use ( $needle ) { $excludes = is_array( $excludes ) ? $excludes : array(); $excludes[] = $needle; return $excludes; } ); } } }