diff --git a/modules/site-health/webp-support/load.php b/modules/site-health/webp-support/load.php new file mode 100644 index 0000000000..2cf95438aa --- /dev/null +++ b/modules/site-health/webp-support/load.php @@ -0,0 +1,64 @@ + esc_html__( 'WebP Support', 'performance-lab' ), + 'test' => 'webp_uploads_check_webp_supported_test', + ); + return $tests; +} +add_filter( 'site_status_tests', 'webp_uploads_add_is_webp_supported_test' ); + +/** + * Callback for webp_enabled test. + * + * @since 1.0.0 + * + * @return array + */ +function webp_uploads_check_webp_supported_test() { + $result = array( + 'label' => __( 'Your site supports WebP', 'performance-lab' ), + 'status' => 'good', + 'badge' => array( + 'label' => __( 'Performance', 'performance-lab' ), + 'color' => 'blue', + ), + 'description' => sprintf( + '

%s

', + __( 'WebP image format is used by WordPress to improve the performance of your site by generating smaller images than it usually could with the JPEG format. This means your pages will load faster and consume less bandwidth.', 'performance-lab' ) + ), + 'actions' => '', + 'test' => 'is_webp_uploads_enabled', + ); + + $webp_supported = wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ); + + if ( ! $webp_supported ) { + $result['status'] = 'recommended'; + $result['label'] = __( 'Your site does not support WebP', 'performance-lab' ); + $result['actions'] = sprintf( + '

%s

', + /* translators: Accessibility text. */ + __( 'Please contact your host and ask them to add WebP support.', 'performance-lab' ) + ); + } + + return $result; +}