$results['status'], 'score' => $results['score'], 'plugins' => $results['plugins'], 'server_cache' => $results['server_cache'], 'cdn' => $results['cdn'], 'object_cache' => $results['object_cache'], 'advanced_cache' => $results['advanced_cache'], 'active_test' => $results['active_test'], ); // Status: active - Caching is working. if ( 'active' === $results['status'] ) { $cache_source = static::get_cache_source( $results ); return static::pass( sprintf( /* translators: %s: cache source */ \__( 'Page caching is active and working using %s. Your pages are being served from cache, reducing server load and improving load times.', '0-day-analytics' ), $cache_source ), $details ); } // Status: inactive - Plugin installed but not working. if ( 'inactive' === $results['status'] ) { $plugin_names = static::get_installed_plugin_names( $results['plugins'] ); $issues = static::get_configuration_issues( $results ); return static::fail( 'high', sprintf( /* translators: %s: plugin names */ \__( 'Cache plugin detected (%s) but caching is not active. Your site is not benefiting from page caching.', '0-day-analytics' ), $plugin_names ), $issues, $details ); } // Status: none - No caching detected. return static::fail( 'high', \__( 'No page caching detected. Every visitor request requires WordPress to rebuild the entire page from scratch, significantly slowing down your site.', '0-day-analytics' ), \__( 'Install a caching plugin. Free options: LiteSpeed Cache (if on LiteSpeed server), WP Super Cache, or Cache Enabler. Premium option: WP Rocket. Check if your host offers built-in caching first.', '0-day-analytics' ), $details ); } /** * Get the active cache source name. * * @param array $results Detection results. * * @return string Cache source name. * * @since 4.9.0 */ private static function get_cache_source( $results ) { // Check for active plugin first. foreach ( $results['plugins'] as $plugin ) { if ( $plugin['activated'] && ( true === $plugin['enabled'] || 'unknown' === $plugin['enabled'] ) ) { return $plugin['name']; } } // Check for server-level cache. foreach ( $results['server_cache'] as $cache ) { if ( isset( $cache['status'] ) && in_array( $cache['status'], array( 'active', 'present' ), true ) ) { return $cache['type']; } } // Check for CDN. if ( ! empty( $results['cdn'] ) ) { return $results['cdn'][0]['name']; } // Check advanced-cache.php. if ( ! empty( $results['advanced_cache']['created_by'] ) ) { return $results['advanced_cache']['created_by']; } return \__( 'Server Cache', '0-day-analytics' ); } /** * Get installed plugin names. * * @param array $plugins Plugin detection results. * * @return string Comma-separated plugin names. * * @since 4.9.0 */ private static function get_installed_plugin_names( $plugins ) { $names = array(); foreach ( $plugins as $plugin ) { if ( $plugin['installed'] || $plugin['activated'] ) { $names[] = $plugin['name']; } } return implode( ', ', $names ) ?: \__( 'Unknown', '0-day-analytics' ); } /** * Get specific configuration issues. * * @param array $results Detection results. * * @return string Recommendation text. * * @since 4.9.0 */ private static function get_configuration_issues( $results ) { $issues = array(); // Check WP_CACHE constant. if ( ! $results['advanced_cache']['wp_cache_constant'] ) { $issues[] = \__( "Add define('WP_CACHE', true); to your wp-config.php file.", '0-day-analytics' ); } // Check advanced-cache.php. if ( ! $results['advanced_cache']['exists'] ) { $issues[] = \__( 'The advanced-cache.php drop-in is missing. Try deactivating and reactivating your cache plugin.', '0-day-analytics' ); } // Check for plugins that are activated but not enabled. foreach ( $results['plugins'] as $plugin ) { if ( $plugin['activated'] && false === $plugin['enabled'] ) { $issues[] = sprintf( /* translators: %s: plugin name */ \__( '%s is active but caching is disabled in its settings. Open the plugin settings and enable page caching.', '0-day-analytics' ), $plugin['name'] ); } } if ( empty( $issues ) ) { return \__( 'Check your cache plugin settings to ensure page caching is enabled. You may need to clear the cache and check file permissions.', '0-day-analytics' ); } return implode( ' ', $issues ); } } }