Skip to content

Commit 96eac80

Browse files
committed
Improve strings
1 parent f82cca9 commit 96eac80

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/helper.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
*/
2323
function perflab_bfcache_compatibility_headers_check(): array {
2424
$result = array(
25-
'label' => __( 'The Cache-Control response header for pages ensures fast back/forward navigation.', 'performance-lab' ),
25+
'label' => __( 'The Cache-Control page header is compatible with fast back/forward navigations', 'performance-lab' ),
2626
'status' => 'good',
2727
'badge' => array(
2828
'label' => __( 'Performance', 'performance-lab' ),
2929
'color' => 'blue',
3030
),
31-
'description' => '<p>' . 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' ) . '</p>',
31+
'description' => '<p>' . wp_kses(
32+
__( 'If the <code>Cache-Control</code> page response header includes directives like <code>no-store</code>, <code>no-cache</code>, or <code>max-age=0</code> then it can prevent instant back/forward navigations (using the browser bfcache). Your site is configured properly.', 'performance-lab' ),
33+
array( 'code' => array() )
34+
) . '</p>',
3235
'actions' => '',
3336
'test' => 'perflab_cch_cache_control_header_check',
3437
);
@@ -42,12 +45,12 @@ function perflab_bfcache_compatibility_headers_check(): array {
4245
);
4346

4447
if ( is_wp_error( $response ) ) {
45-
$result['label'] = __( 'Error checking cache settings', 'performance-lab' );
48+
$result['label'] = __( 'Unable to check whether the Cache-Control page header is compatible with fast back/forward navigations', 'performance-lab' );
4649
$result['status'] = 'recommended';
4750
$result['description'] = '<p>' . wp_kses(
4851
sprintf(
4952
/* translators: 1: the error code, 2: the error message */
50-
__( 'The request to check the Cache-Control response header responded with error code <code>%1$s</code> and the following error message: %2$s.', 'performance-lab' ),
53+
__( 'The request to check the <code>Cache-Control</code> response header for the home page resulted in an error with code <code>%1$s</code> and the following message: %2$s.', 'performance-lab' ),
5154
esc_html( (string) $response->get_error_code() ),
5255
esc_html( rtrim( $response->get_error_message(), '.' ) )
5356
),
@@ -74,17 +77,33 @@ function perflab_bfcache_compatibility_headers_check(): array {
7477
}
7578
}
7679

77-
$flagged_headers_string = implode( ', ', $flagged_headers );
78-
if ( '' !== $flagged_headers_string ) {
79-
$result['label'] = __( 'Cache-Control header is preventing fast back/forward navigations', 'performance-lab' );
80+
if ( count( $flagged_headers ) > 0 ) {
81+
$result['label'] = __( 'The Cache-Control page header is preventing fast back/forward navigations', 'performance-lab' );
8082
$result['status'] = 'recommended';
8183
$result['description'] = sprintf(
82-
'<p>%s</p>',
83-
sprintf(
84-
/* translators: %s: Cache-Control header value */
85-
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' ),
86-
$flagged_headers_string
87-
)
84+
'<p>%s %s</p>',
85+
wp_kses(
86+
sprintf(
87+
/* translators: %s: problematic directive(s) */
88+
_n(
89+
'The <code>Cache-Control</code> response header for the home page includes the following directive: %s.',
90+
'The <code>Cache-Control</code> response header for the home page includes the following directives: %s.',
91+
count( $flagged_headers ),
92+
'performance-lab'
93+
),
94+
implode(
95+
', ',
96+
array_map(
97+
static function ( $header ) {
98+
return "<code>$header</code>";
99+
},
100+
$flagged_headers
101+
)
102+
)
103+
),
104+
array( 'code' => array() )
105+
),
106+
esc_html__( 'This can affect the performance of your site by preventing fast back/forward navigations (via browser bfcache).', 'performance-lab' )
88107
);
89108
break;
90109
}

plugins/performance-lab/tests/includes/site-health/bfcache-compatibility-headers/test-bfcache-compatibility-headers.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,32 @@ public function data_test_bfcache_compatibility(): array {
8282
'headers_not_set' => array(
8383
$this->build_response( 200, array( 'cache-control' => '' ) ),
8484
'good',
85-
'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.',
85+
'If the <code>Cache-Control</code> page response header includes directives like',
8686
),
8787
'no_store' => array(
8888
$this->build_response( 200, array( 'cache-control' => 'no-store' ) ),
8989
'recommended',
90-
'Cache-Control headers are set to no-store',
90+
'The <code>Cache-Control</code> response header for the home page includes the following directive: <code>no-store</code>',
9191
),
9292
'no_cache' => array(
9393
$this->build_response( 200, array( 'cache-control' => 'no-cache' ) ),
9494
'recommended',
95-
'Cache-Control headers are set to no-cache',
95+
'The <code>Cache-Control</code> response header for the home page includes the following directive: <code>no-cache</code>',
9696
),
9797
'max_age_0' => array(
9898
$this->build_response( 200, array( 'cache-control' => 'max-age=0' ) ),
9999
'recommended',
100-
'Cache-Control headers are set to max-age=0',
100+
'The <code>Cache-Control</code> response header for the home page includes the following directive: <code>max-age=0</code>',
101101
),
102102
'max_age_0_no_store' => array(
103103
$this->build_response( 200, array( 'cache-control' => 'max-age=0, no-store' ) ),
104104
'recommended',
105-
'Cache-Control headers are set to no-store, max-age=0',
105+
'The <code>Cache-Control</code> response header for the home page includes the following directives: <code>no-store</code>, <code>max-age=0</code>',
106106
),
107107
'error' => array(
108108
new WP_Error( 'http_request_failed', 'HTTP request failed' ),
109109
'recommended',
110-
'The request to check the Cache-Control response header responded with error code',
110+
'The request to check the <code>Cache-Control</code> response header for the home page resulted in an error with code',
111111
),
112112
);
113113
}

0 commit comments

Comments
 (0)