'Imagify', 'wp-smushit/wp-smush.php' => 'Smush', 'shortpixel-image-optimiser/wp-shortpixel.php' => 'ShortPixel', 'ewww-image-optimizer/ewww-image-optimizer.php' => 'EWWW Image Optimizer', 'tiny-compress-images/tiny-compress-images.php' => 'TinyPNG', 'optimus/optimus.php' => 'Optimus', 'kraken-image-optimizer/kraken.php' => 'Kraken.io', 'webp-express/webp-express.php' => 'WebP Express', 'converter-for-media/converter-for-media.php' => 'Converter for Media', ); $active_optimizer = null; foreach ( $image_plugins as $plugin_path => $plugin_name ) { if ( Plugin_Theme_Helper::is_plugin_active( $plugin_path ) ) { $active_optimizer = $plugin_name; break; } } // Check for WebP support. $webp_support = static::check_webp_support(); // Count large images in media library (sample check). $large_images = static::count_large_images(); $details = array( 'active_plugin' => $active_optimizer, 'webp_support' => $webp_support, 'large_images' => $large_images, ); if ( $active_optimizer && $webp_support ) { return static::pass( sprintf( /* translators: %s: plugin name */ \__( 'Image optimization is active with %s and WebP format is supported. Your images are being served in modern, efficient formats.', '0-day-analytics' ), $active_optimizer ), $details ); } if ( $active_optimizer ) { if ( ! $webp_support ) { return static::warning( sprintf( /* translators: %s: plugin name */ \__( '%s is optimizing your images, but WebP format is not being used. WebP can reduce image sizes by an additional 25-35%% compared to JPEG/PNG.', '0-day-analytics' ), $active_optimizer ), \__( 'Enable WebP conversion in your image optimization plugin settings, or use a dedicated WebP plugin.', '0-day-analytics' ), $details ); } return static::pass( sprintf( /* translators: %s: plugin name */ \__( 'Image optimization is active with %s. Your images are being compressed to reduce file sizes.', '0-day-analytics' ), $active_optimizer ), $details ); } if ( $large_images > 10 ) { return static::fail( 'medium', sprintf( /* translators: %d: number of images */ \__( 'No image optimization detected and you have approximately %d unoptimized images. Images are often the largest files on a webpage and unoptimized images significantly slow down your site.', '0-day-analytics' ), $large_images ), \__( 'Install an image optimization plugin like Imagify, ShortPixel, or EWWW Image Optimizer. These can compress existing images and automatically optimize new uploads.', '0-day-analytics' ), $details ); } return static::warning( \__( 'No image optimization plugin detected. As your site grows, unoptimized images can significantly slow down page load times.', '0-day-analytics' ), \__( 'Consider installing an image optimization plugin to compress images and serve them in modern formats like WebP.', '0-day-analytics' ), $details ); } /** * Check for WebP support. * * @return bool * * @since 4.9.0 */ private static function check_webp_support() { // Check if there are any WebP files in uploads. $uploads_dir = wp_upload_dir(); $uploads = $uploads_dir['basedir']; // Sample only the current month's upload directory to avoid // expensive glob() on sites with millions of media files (R-04). $month_dir = isset( $uploads_dir['path'] ) ? $uploads_dir['path'] : $uploads; $webp_files = glob( $month_dir . '/*.webp' ); if ( ! empty( $webp_files ) ) { return true; } // Check if WebP conversion is configured. $webp_options = array( 'ewww_image_optimizer_webp', 'imagify_auto_webp', 'shortpixel_webp_create', ); foreach ( $webp_options as $option ) { if ( get_option( $option ) ) { return true; } } return false; } /** * Count potentially unoptimized images (estimate). * * Note: This provides a rough estimate since checking actual file sizes * for all images would be too resource-intensive. The count returned * is an approximation based on typical WordPress media library statistics. * * @return int Estimated count of potentially unoptimized images. * * @since 4.9.0 */ private static function count_large_images() { global $wpdb; // Count total images in the media library. $total_images = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} p INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id WHERE p.post_type = 'attachment' AND p.post_mime_type LIKE 'image/%' AND pm.meta_key = '_wp_attached_file'" ); // Return 0 if no images found. if ( $total_images <= 0 ) { return 0; } // Estimate: Without an optimization plugin, approximately 30% of images // in a typical media library are larger than optimal for web delivery. // This is a conservative estimate based on common WordPress usage patterns. return (int) ceil( $total_images * 0.3 ); } } }