Skip to content

Commit 37d9c19

Browse files
committed
Fix check_for_page_caching to account for wp_remote_retrieve_header() returning arrays
1 parent ae407f9 commit 37d9c19

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Admin/SiteHealth.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,17 +624,21 @@ public function check_for_page_caching() {
624624
$response_headers = [];
625625

626626
foreach ( $caching_headers as $header => $callback ) {
627-
$header_value = wp_remote_retrieve_header( $http_response, $header );
627+
$header_values = wp_remote_retrieve_header( $http_response, $header );
628+
if ( empty( $header_values ) ) {
629+
continue;
630+
}
631+
$header_values = (array) $header_values;
628632
if (
629-
$header_value
630-
&&
633+
empty( $callback )
634+
||
631635
(
632-
empty( $callback )
633-
||
634-
( is_callable( $callback ) && true === $callback( $header_value ) )
636+
is_callable( $callback )
637+
&&
638+
count( array_filter( $header_values, $callback ) ) > 0
635639
)
636640
) {
637-
$response_headers[ $header ] = $header_value;
641+
$response_headers[ $header ] = $header_values;
638642
}
639643
}
640644

tests/php/src/Admin/SiteHealthTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,11 @@ public function get_page_cache_data() {
751751
'expected_status' => 'recommended',
752752
'expected_label' => $recommended_label,
753753
],
754+
'no-cache-arrays' => [
755+
'responses' => array_fill( 0, 3, [ 'cache-control' => [ 'no-cache', 'no-store' ] ] ),
756+
'expected_status' => 'recommended',
757+
'expected_label' => $recommended_label,
758+
],
754759
'no-cache-with-delayed-response' => [
755760
'responses' => array_fill( 0, 3, [ 'cache-control' => 'no-cache' ] ),
756761
'expected_status' => 'critical',

0 commit comments

Comments
 (0)