'LiteSpeed Cache', 'wp-super-cache/wp-cache.php' => 'WP Super Cache', 'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache', 'wp-rocket/wp-rocket.php' => 'WP Rocket', 'wp-fastest-cache/wpFastestCache.php' => 'WP Fastest Cache', 'cache-enabler/cache-enabler.php' => 'Cache Enabler', 'breeze/breeze.php' => 'Breeze', 'comet-cache/comet-cache.php' => 'Comet Cache', 'surge/surge.php' => 'Surge', 'wp-optimize/wp-optimize.php' => 'WP-Optimize', 'nitropack/main.php' => 'NitroPack', 'swift-performance-lite/performance.php' => 'Swift Performance Lite', 'hummingbird-performance/wp-hummingbird.php' => 'Hummingbird', ); /** * Server profile, used to tell an installed cache from an operating one. * * @var ServerProfile */ private $server; /** * Constructor. * * @param ServerProfile $server Server profile. */ public function __construct( ServerProfile $server ) { $this->server = $server; } /** * Whether the `advanced-cache.php` drop-in is in place and enabled. * * @return bool True when the drop-in is active. */ public function has_drop_in(): bool { if ( ! function_exists( 'get_dropins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( ! array_key_exists( self::DROP_IN, get_dropins() ) ) { return false; } // The drop-in is only loaded when WP_CACHE is true. return defined( 'WP_CACHE' ) && WP_CACHE; } /** * Returns the active caching plugins, as display names. * * @return string[] Display names, empty when none are active. */ public function get_active_plugins(): array { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $found = array(); foreach ( self::KNOWN_PLUGINS as $file => $label ) { if ( is_plugin_active( $file ) ) { $found[ $file ] = $label; } } return $found; } /** * Whether a page cache is actually operating. * * @return bool True when responses can be served without running our gate. */ public function is_operating(): bool { return $this->has_drop_in(); } /** * Whether a caching plugin is installed but not actually caching. * * @return bool True when a cache plugin is present but inactive in practice. */ public function is_installed_but_dormant(): bool { return ! empty( $this->get_active_plugins() ) && ! $this->has_drop_in(); } /** * Returns the evidence behind the verdict, for display. * * @return array List of human-readable evidence strings. */ public function get_evidence(): array { $evidence = array(); $plugins = $this->get_active_plugins(); if ( ! empty( $plugins ) ) { $evidence[] = sprintf( /* translators: %s: Comma-separated list of plugin names. */ __( 'Caching plugin active: %s', 'ai-blackout' ), implode( ', ', $plugins ) ); } $evidence[] = $this->has_drop_in() ? __( 'The advanced-cache.php drop-in is installed and enabled, so pages can be served before plugins load.', 'ai-blackout' ) : __( 'No advanced-cache.php drop-in is installed, so WordPress is not serving pages from a plugin page cache.', 'ai-blackout' ); if ( $this->is_installed_but_dormant() ) { $evidence[] = $this->describe_dormancy(); } return $evidence; } /** * Explains why an installed caching plugin is not caching. * * @return string Human-readable explanation. */ public function describe_dormancy(): string { $plugins = $this->get_active_plugins(); if ( isset( $plugins['litespeed-cache/litespeed-cache.php'] ) && ! $this->is_litespeed_server() ) { return __( 'LiteSpeed Cache is active, but its page cache only works on a LiteSpeed server. This site is not on one, so it is not caching pages.', 'ai-blackout' ); } return __( 'A caching plugin is active but has not installed a page cache, so pages are not being served from a cache.', 'ai-blackout' ); } /** * Whether the server is LiteSpeed. * * @return bool True on LiteSpeed. */ private function is_litespeed_server(): bool { return ServerProfile::LITESPEED === $this->server->get_type(); } }