From 69ccf7e078f4d149ce1f31bcd1b532dff584a763 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Tue, 1 Feb 2022 21:53:30 +0530 Subject: [PATCH 1/9] Add WebP support in site health --- .../site-health/webp-uploads-enabled/load.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules/site-health/webp-uploads-enabled/load.php diff --git a/modules/site-health/webp-uploads-enabled/load.php b/modules/site-health/webp-uploads-enabled/load.php new file mode 100644 index 0000000000..64e19cc7df --- /dev/null +++ b/modules/site-health/webp-uploads-enabled/load.php @@ -0,0 +1,80 @@ + 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' ), + 'status' => 'good', + 'badge' => array( + 'label' => __( 'Performance' ), + 'color' => 'blue', + ), + 'description' => sprintf( + '

%s

', + __( 'WebP image format is used by WordPress to boost performance of your site by generating smaller images than it usually could with default JPEG format. This means your pages will load faster and consume less data from users.' ) + ), + 'actions' => '', + 'test' => 'is_webp_uploads_enabled', + ); + + $gd_supported = false; + if ( function_exists( 'gd_info' ) ) { + $gd = gd_info(); + if ( isset( $gd[ 'WebP Support' ] ) && $gd[ 'WebP Support' ] ) { + $gd_supported = true; + } + } + + try { + $formats = Imagick::queryFormats( '*' ); + + if( in_array('WEBP', $formats ) ) { + $gd_supported = true; + } + } catch (Exception $e) { + } + + if ( ! $gd_supported ) { + $result['status'] = 'critical'; + $result['label'] = __( 'Your site does not support WebP' ); + $result['actions'] = sprintf( + '

%s

', + /* translators: Accessibility text. */ + __( 'Please contact your host and ask them to add WebP support' ) + ); + } + + return $result; +} From ddd49545216291066ba45d4248859b09fc0c75d6 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Fri, 4 Feb 2022 20:08:31 +0530 Subject: [PATCH 2/9] Improve webp support message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Crisoforo Gaspar Hernández --- modules/site-health/webp-uploads-enabled/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/site-health/webp-uploads-enabled/load.php b/modules/site-health/webp-uploads-enabled/load.php index 64e19cc7df..6d43d962f8 100644 --- a/modules/site-health/webp-uploads-enabled/load.php +++ b/modules/site-health/webp-uploads-enabled/load.php @@ -43,7 +43,7 @@ function webp_uploads_check_webp_supported_test() { ), 'description' => sprintf( '

%s

', - __( 'WebP image format is used by WordPress to boost performance of your site by generating smaller images than it usually could with default JPEG format. This means your pages will load faster and consume less data from users.' ) + __( 'WebP image format is used by WordPress to improve the performance of your site by generating smaller images than it usually could with JPEG format. This means your pages will load faster and consume less bandwidth from users.' ) ), 'actions' => '', 'test' => 'is_webp_uploads_enabled', From 3a2c858a510bda6b32f5d67e3395bff3da0a25d6 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Mon, 7 Feb 2022 16:38:41 +0530 Subject: [PATCH 3/9] Fix PHPCS errors --- .../site-health/webp-uploads-enabled/load.php | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/site-health/webp-uploads-enabled/load.php b/modules/site-health/webp-uploads-enabled/load.php index 64e19cc7df..9d5cdfdbef 100644 --- a/modules/site-health/webp-uploads-enabled/load.php +++ b/modules/site-health/webp-uploads-enabled/load.php @@ -16,9 +16,8 @@ * @param array $tests Site Health Tests. * @return array */ -function webp_uploads_add_is_webp_supported_test( $tests ) -{ - $tests['direct']['webp_supported'] = array( +function webp_uploads_add_is_webp_supported_test( $tests ) { + $tests['direct']['webp_supported'] = array( 'label' => esc_html__( 'WebP Support', 'performance-lab' ), 'test' => 'webp_uploads_check_webp_supported_test', ); @@ -35,15 +34,15 @@ function webp_uploads_add_is_webp_supported_test( $tests ) */ function webp_uploads_check_webp_supported_test() { $result = array( - 'label' => __( 'Your site supports WebP' ), + 'label' => __( 'Your site supports WebP', 'performance-lab' ), 'status' => 'good', 'badge' => array( - 'label' => __( 'Performance' ), + 'label' => __( 'Performance', 'performance-lab' ), 'color' => 'blue', ), 'description' => sprintf( '

%s

', - __( 'WebP image format is used by WordPress to boost performance of your site by generating smaller images than it usually could with default JPEG format. This means your pages will load faster and consume less data from users.' ) + __( 'WebP image format is used by WordPress to boost performance of your site by generating smaller images than it usually could with default JPEG format. This means your pages will load faster and consume less data from users.', 'performance-lab' ) ), 'actions' => '', 'test' => 'is_webp_uploads_enabled', @@ -52,7 +51,7 @@ function webp_uploads_check_webp_supported_test() { $gd_supported = false; if ( function_exists( 'gd_info' ) ) { $gd = gd_info(); - if ( isset( $gd[ 'WebP Support' ] ) && $gd[ 'WebP Support' ] ) { + if ( isset( $gd['WebP Support'] ) && $gd['WebP Support'] ) { $gd_supported = true; } } @@ -60,19 +59,19 @@ function webp_uploads_check_webp_supported_test() { try { $formats = Imagick::queryFormats( '*' ); - if( in_array('WEBP', $formats ) ) { + if ( in_array( 'WEBP', $formats ) ) { $gd_supported = true; } - } catch (Exception $e) { + } catch ( Exception $e ) { } - if ( ! $gd_supported ) { - $result['status'] = 'critical'; - $result['label'] = __( 'Your site does not support WebP' ); + if ( $gd_supported ) { + $result['status'] = 'critical'; + $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' ) + __( 'Please contact your host and ask them to add WebP support', 'performance-lab' ) ); } From 72a8f674e3aca05f2f53e28f660ad0558f989eea Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Mon, 7 Feb 2022 16:52:57 +0530 Subject: [PATCH 4/9] Simplify checking webp suppot --- .../site-health/webp-uploads-enabled/load.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/modules/site-health/webp-uploads-enabled/load.php b/modules/site-health/webp-uploads-enabled/load.php index cac1d87c6d..1f57a7314e 100644 --- a/modules/site-health/webp-uploads-enabled/load.php +++ b/modules/site-health/webp-uploads-enabled/load.php @@ -48,24 +48,9 @@ function webp_uploads_check_webp_supported_test() { 'test' => 'is_webp_uploads_enabled', ); - $gd_supported = false; - if ( function_exists( 'gd_info' ) ) { - $gd = gd_info(); - if ( isset( $gd['WebP Support'] ) && $gd['WebP Support'] ) { - $gd_supported = true; - } - } - - try { - $formats = Imagick::queryFormats( '*' ); - - if ( in_array( 'WEBP', $formats ) ) { - $gd_supported = true; - } - } catch ( Exception $e ) { - } + $webp_supported = wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ; - if ( $gd_supported ) { + if ( ! $webp_supported ) { $result['status'] = 'critical'; $result['label'] = __( 'Your site does not support WebP', 'performance-lab' ); $result['actions'] = sprintf( From 9b0ee0162236b9e18dcb76647d2f1661e41eb81f Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Mon, 7 Feb 2022 16:54:51 +0530 Subject: [PATCH 5/9] Rename webp support module directory --- .../site-health/{webp-uploads-enabled => webp-support}/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/site-health/{webp-uploads-enabled => webp-support}/load.php (97%) diff --git a/modules/site-health/webp-uploads-enabled/load.php b/modules/site-health/webp-support/load.php similarity index 97% rename from modules/site-health/webp-uploads-enabled/load.php rename to modules/site-health/webp-support/load.php index 1f57a7314e..8586f0beb9 100644 --- a/modules/site-health/webp-uploads-enabled/load.php +++ b/modules/site-health/webp-support/load.php @@ -1,6 +1,6 @@ Date: Mon, 7 Feb 2022 17:02:05 +0530 Subject: [PATCH 6/9] Fix PHPCS errors --- modules/site-health/webp-support/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/site-health/webp-support/load.php b/modules/site-health/webp-support/load.php index 8586f0beb9..8a21de8d40 100644 --- a/modules/site-health/webp-support/load.php +++ b/modules/site-health/webp-support/load.php @@ -48,7 +48,7 @@ function webp_uploads_check_webp_supported_test() { 'test' => 'is_webp_uploads_enabled', ); - $webp_supported = wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ; + $webp_supported = wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ); if ( ! $webp_supported ) { $result['status'] = 'critical'; From 63d437b89384db6a2f6e37e7ad464e9a0c23f505 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:21:47 +0530 Subject: [PATCH 7/9] Update modules/site-health/webp-support/load.php Co-authored-by: Adam Silverstein --- modules/site-health/webp-support/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/site-health/webp-support/load.php b/modules/site-health/webp-support/load.php index 8a21de8d40..70f4216b87 100644 --- a/modules/site-health/webp-support/load.php +++ b/modules/site-health/webp-support/load.php @@ -51,7 +51,7 @@ function webp_uploads_check_webp_supported_test() { $webp_supported = wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ); if ( ! $webp_supported ) { - $result['status'] = 'critical'; + $result['status'] = 'recommended'; $result['label'] = __( 'Your site does not support WebP', 'performance-lab' ); $result['actions'] = sprintf( '

%s

', From 2ccb58457578ceee272768bb589e3e227ff1f3d8 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar Date: Mon, 14 Feb 2022 14:23:23 +0530 Subject: [PATCH 8/9] Add full stop in message --- modules/site-health/webp-support/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/site-health/webp-support/load.php b/modules/site-health/webp-support/load.php index 70f4216b87..6b1733da23 100644 --- a/modules/site-health/webp-support/load.php +++ b/modules/site-health/webp-support/load.php @@ -56,7 +56,7 @@ function webp_uploads_check_webp_supported_test() { $result['actions'] = sprintf( '

%s

', /* translators: Accessibility text. */ - __( 'Please contact your host and ask them to add WebP support', 'performance-lab' ) + __( 'Please contact your host and ask them to add WebP support.', 'performance-lab' ) ); } From 0bb6a01b0e5e65fa9d41d7d45dcc6841597a48c4 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Tue, 22 Feb 2022 21:45:19 +0530 Subject: [PATCH 9/9] Update modules/site-health/webp-support/load.php Co-authored-by: Adam Silverstein --- modules/site-health/webp-support/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/site-health/webp-support/load.php b/modules/site-health/webp-support/load.php index 6b1733da23..2cf95438aa 100644 --- a/modules/site-health/webp-support/load.php +++ b/modules/site-health/webp-support/load.php @@ -42,7 +42,7 @@ function webp_uploads_check_webp_supported_test() { ), '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 JPEG format. This means your pages will load faster and consume less bandwidth from users.', 'performance-lab' ) + __( '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',