name. A paid edition is listed beside its free one * where it installs under another folder. */ const PLUGINS = array( 'wp-rocket/wp-rocket.php' => 'WP Rocket', 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache', 'wp-super-cache/wp-cache.php' => 'WP Super Cache', 'litespeed-cache/litespeed-cache.php' => 'LiteSpeed Cache', 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache', 'cache-enabler/cache-enabler.php' => 'Cache Enabler', 'sg-cachepress/sg-cachepress.php' => 'SiteGround Speed Optimizer', 'breeze/breeze.php' => 'Breeze', 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird', 'wp-hummingbird/wp-hummingbird.php' => 'Hummingbird', 'comet-cache/comet-cache.php' => 'Comet Cache', 'comet-cache-pro/comet-cache-pro.php' => 'Comet Cache', 'swift-performance-lite/performance.php' => 'Swift Performance', 'swift-performance/performance.php' => 'Swift Performance', ); /** * The page cache that looks active. * * @return string|null The plugin's name, '' for a cache that cannot be named, or null when * none looks active. */ public function detected() { $name = $this->plugin_name(); $detected = '' !== $name || $this->wp_cache(); /** * Filters whether a page cache counts as detected for the contact form's warning. * * @param bool $detected Whether a page cache looks active. * @param string $name The caching plugin found, or '' when none was recognised. */ // The name is written out, not read from self::FILTER, so a code checker can see its prefix. $detected = (bool) apply_filters( 'adminkeep_contact_form_page_cache_detected', $detected, $name ); return $detected ? $name : null; } /** * The first known page-cache plugin that is active, or ''. * * @return string */ private function plugin_name() { $active = $this->active_plugins(); foreach ( self::PLUGINS as $file => $name ) { if ( in_array( $file, $active, true ) ) { return $name; } } return ''; } /** * Whether WP_CACHE is on. Its own method so a test can say so: PHP would never let a test * undefine the real constant. * * @return bool */ protected function wp_cache() { return defined( 'WP_CACHE' ) && WP_CACHE; } /** * The active plugins' files, network-active ones included. Read from the options rather than * is_plugin_active(), which exists only in the admin: the settings panel's state is also read * over REST and by WP-CLI. * * @return string[] */ protected function active_plugins() { $active = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) { $active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); } return array_map( 'strval', $active ); } }