From 05a4dd5ec00de72b5462cf02c2a53bc052d9f95d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 23 Jan 2025 15:12:20 -0800 Subject: [PATCH] Improve strings --- .../bfcache-compatibility-headers/helper.php | 46 +++++++++++++------ .../test-bfcache-compatibility-headers.php | 12 ++--- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/helper.php b/plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/helper.php index 2a5077337..4a58c5997 100644 --- a/plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/helper.php +++ b/plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/helper.php @@ -22,13 +22,16 @@ */ function perflab_bfcache_compatibility_headers_check(): array { $result = array( - 'label' => __( 'The Cache-Control response header for pages ensures fast back/forward navigation.', 'performance-lab' ), + 'label' => __( 'The Cache-Control page header is compatible with fast back/forward navigations', 'performance-lab' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Performance', 'performance-lab' ), 'color' => 'blue', ), - 'description' => '

' . esc_html__( 'If the Cache-Control response header includes directives like no-store, no-cache, or max-age=0 then it can prevent instant back/forward navigations (using the browser bfcache). Your site is configured properly.', 'performance-lab' ) . '

', + 'description' => '

' . wp_kses( + __( 'If the Cache-Control page response header includes directives like no-store, no-cache, or max-age=0 then it can prevent instant back/forward navigations (using the browser bfcache). Your site is configured properly.', 'performance-lab' ), + array( 'code' => array() ) + ) . '

', 'actions' => '', 'test' => 'perflab_cch_cache_control_header_check', ); @@ -42,18 +45,17 @@ function perflab_bfcache_compatibility_headers_check(): array { ); if ( is_wp_error( $response ) ) { - $result['label'] = __( 'Error checking cache settings', 'performance-lab' ); + $result['label'] = __( 'Unable to check whether the Cache-Control page header is compatible with fast back/forward navigations', 'performance-lab' ); $result['status'] = 'recommended'; $result['description'] = '

' . wp_kses( sprintf( /* translators: 1: the error code, 2: the error message */ - __( 'The request to check the Cache-Control response header responded with error code %1$s and the following error message: %2$s.', 'performance-lab' ), + __( 'The request to check the Cache-Control response header for the home page resulted in an error with code %1$s and the following message: %2$s.', 'performance-lab' ), esc_html( (string) $response->get_error_code() ), esc_html( rtrim( $response->get_error_message(), '.' ) ) ), array( 'code' => array() ) ) . '

'; - return $result; } $cache_control_header = wp_remote_retrieve_header( $response, 'cache-control' ); @@ -74,17 +76,33 @@ function perflab_bfcache_compatibility_headers_check(): array { } } - $flagged_headers_string = implode( ', ', $flagged_headers ); - if ( '' !== $flagged_headers_string ) { - $result['label'] = __( 'Cache-Control header is preventing fast back/forward navigations', 'performance-lab' ); + if ( count( $flagged_headers ) > 0 ) { + $result['label'] = __( 'The Cache-Control page header is preventing fast back/forward navigations', 'performance-lab' ); $result['status'] = 'recommended'; $result['description'] = sprintf( - '

%s

', - sprintf( - /* translators: %s: Cache-Control header value */ - esc_html__( 'Cache-Control headers are set to %s. This can affect the performance of your site by preventing fast back/forward navigations (via browser bfcache).', 'performance-lab' ), - $flagged_headers_string - ) + '

%s %s

', + wp_kses( + sprintf( + /* translators: %s: problematic directive(s) */ + _n( + 'The Cache-Control response header for the home page includes the following directive: %s.', + 'The Cache-Control response header for the home page includes the following directives: %s.', + count( $flagged_headers ), + 'performance-lab' + ), + implode( + ', ', + array_map( + static function ( $header ) { + return "$header"; + }, + $flagged_headers + ) + ) + ), + array( 'code' => array() ) + ), + esc_html__( 'This can affect the performance of your site by preventing fast back/forward navigations (via browser bfcache).', 'performance-lab' ) ); break; } diff --git a/plugins/performance-lab/tests/includes/site-health/bfcache-compatibility-headers/test-bfcache-compatibility-headers.php b/plugins/performance-lab/tests/includes/site-health/bfcache-compatibility-headers/test-bfcache-compatibility-headers.php index 30945ed13..52fbbbffb 100644 --- a/plugins/performance-lab/tests/includes/site-health/bfcache-compatibility-headers/test-bfcache-compatibility-headers.php +++ b/plugins/performance-lab/tests/includes/site-health/bfcache-compatibility-headers/test-bfcache-compatibility-headers.php @@ -82,32 +82,32 @@ public function data_test_bfcache_compatibility(): array { 'headers_not_set' => array( $this->build_response( 200, array( 'cache-control' => '' ) ), 'good', - 'If the Cache-Control response header includes directives like no-store, no-cache, or max-age=0 then it can prevent instant back/forward navigations (using the browser bfcache). Your site is configured properly.', + 'If the Cache-Control page response header includes directives like', ), 'no_store' => array( $this->build_response( 200, array( 'cache-control' => 'no-store' ) ), 'recommended', - 'Cache-Control headers are set to no-store', + 'The Cache-Control response header for the home page includes the following directive: no-store', ), 'no_cache' => array( $this->build_response( 200, array( 'cache-control' => 'no-cache' ) ), 'recommended', - 'Cache-Control headers are set to no-cache', + 'The Cache-Control response header for the home page includes the following directive: no-cache', ), 'max_age_0' => array( $this->build_response( 200, array( 'cache-control' => 'max-age=0' ) ), 'recommended', - 'Cache-Control headers are set to max-age=0', + 'The Cache-Control response header for the home page includes the following directive: max-age=0', ), 'max_age_0_no_store' => array( $this->build_response( 200, array( 'cache-control' => 'max-age=0, no-store' ) ), 'recommended', - 'Cache-Control headers are set to no-store, max-age=0', + 'The Cache-Control response header for the home page includes the following directives: no-store, max-age=0', ), 'error' => array( new WP_Error( 'http_request_failed', 'HTTP request failed' ), 'recommended', - 'The request to check the Cache-Control response header responded with error code', + 'The request to check the Cache-Control response header for the home page resulted in an error with code', ), ); }