Skip to content

Commit 05a4dd5

Browse files
committed
Improve strings
1 parent f82cca9 commit 05a4dd5

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

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

Lines changed: 32 additions & 14 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,18 +45,17 @@ 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
),
5457
array( 'code' => array() )
5558
) . '</p>';
56-
return $result;
5759
}
5860

5961
$cache_control_header = wp_remote_retrieve_header( $response, 'cache-control' );
@@ -74,17 +76,33 @@ function perflab_bfcache_compatibility_headers_check(): array {
7476
}
7577
}
7678

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

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)