diff --git a/src/Admin/SiteHealth.php b/src/Admin/SiteHealth.php index 61104970569..d772f4c4fdb 100644 --- a/src/Admin/SiteHealth.php +++ b/src/Admin/SiteHealth.php @@ -102,6 +102,10 @@ public function register() { add_filter( 'site_status_test_result', [ $this, 'modify_test_result' ] ); add_filter( 'site_status_test_php_modules', [ $this, 'add_extensions' ] ); + if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) && has_filter( 'amp_page_cache_good_response_time_threshold' ) ) { + add_filter( 'site_status_good_response_time_threshold', [ $this, 'get_good_response_time_threshold' ] ); + } + add_action( 'admin_print_styles-tools_page_health-check', [ $this, 'add_styles' ] ); add_action( 'admin_print_styles-site-health.php', [ $this, 'add_styles' ] ); } @@ -180,17 +184,13 @@ public function register_async_test_endpoints() { * @return array $tests The filtered tests, with tests for AMP. */ public function add_tests( $tests ) { - $tests['direct']['amp_persistent_object_cache'] = [ - 'label' => esc_html__( 'Persistent object cache', 'amp' ), - 'test' => [ $this, 'persistent_object_cache' ], - ]; - if ( ! amp_is_canonical() && QueryVar::AMP !== amp_get_slug() ) { $tests['direct']['amp_slug_definition_timing'] = [ 'label' => esc_html__( 'AMP slug (query var) definition timing', 'amp' ), 'test' => [ $this, 'slug_definition_timing' ], ]; } + $tests['direct']['amp_curl_multi_functions'] = [ 'label' => esc_html__( 'cURL multi functions', 'amp' ), 'test' => [ $this, 'curl_multi_functions' ], @@ -207,7 +207,8 @@ public function add_tests( $tests ) { 'label' => esc_html__( 'Transient caching of stylesheets', 'amp' ), 'test' => [ $this, 'css_transient_caching' ], ]; - $tests['direct']['amp_xdebug_extension'] = [ + + $tests['direct']['amp_xdebug_extension'] = [ 'label' => esc_html__( 'Xdebug extension', 'amp' ), 'test' => [ $this, 'xdebug_extension' ], ]; @@ -217,13 +218,21 @@ public function add_tests( $tests ) { 'test' => [ $this, 'publisher_logo' ], ]; - if ( $this->supports_async_rest_tests( $tests ) ) { - $tests['async'][ self::TEST_PAGE_CACHING ] = [ - 'label' => esc_html__( 'Page caching', 'amp' ), - 'test' => rest_url( self::REST_API_NAMESPACE . self::REST_API_PAGE_CACHE_ENDPOINT ), - 'has_rest' => true, - 'async_direct_test' => [ $this, 'page_cache' ], + // Only run page and object cache tests for WP < 6.1, since it has been a part of core now. + if ( version_compare( get_bloginfo( 'version' ), '6.1', '<' ) ) { + $tests['direct']['amp_persistent_object_cache'] = [ + 'label' => esc_html__( 'Persistent object cache', 'amp' ), + 'test' => [ $this, 'persistent_object_cache' ], ]; + + if ( $this->supports_async_rest_tests( $tests ) ) { + $tests['async'][ self::TEST_PAGE_CACHING ] = [ + 'label' => esc_html__( 'Page caching', 'amp' ), + 'test' => rest_url( self::REST_API_NAMESPACE . self::REST_API_PAGE_CACHE_ENDPOINT ), + 'has_rest' => true, + 'async_direct_test' => [ $this, 'page_cache' ], + ]; + } } return $tests; @@ -340,16 +349,31 @@ static function ( $available_service ) { * * @since 2.2.1 * + * @param int $threshold Threshold in milliseconds. + * * @return int Threshold. */ - public function get_good_response_time_threshold() { - /** - * Filters the threshold below which a response time is considered good. - * - * @since 2.2.1 - * @param int $threshold Threshold in milliseconds. - */ - return (int) apply_filters( 'amp_page_cache_good_response_time_threshold', 600 ); + public function get_good_response_time_threshold( $threshold = 600 ) { + if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) { + /** This filter is documented in src/Admin/SiteHealth.php */ + return (int) apply_filters_deprecated( + 'amp_page_cache_good_response_time_threshold', + [ $threshold ], + 'AMP 2.4.3', + 'site_status_good_response_time_threshold' + ); + } else { + /** + * Filters the threshold below which a response time is considered good. + * + * @since 2.2.1 + * + * @deprecated 2.4.3 Use `site_status_good_response_time_threshold` instead. + * + * @param int $threshold Threshold in milliseconds. + */ + return (int) apply_filters( 'amp_page_cache_good_response_time_threshold', 600 ); + } } /** diff --git a/tests/php/src/Admin/SiteHealthTest.php b/tests/php/src/Admin/SiteHealthTest.php index 40a075181e6..bd402b7e894 100644 --- a/tests/php/src/Admin/SiteHealthTest.php +++ b/tests/php/src/Admin/SiteHealthTest.php @@ -153,13 +153,17 @@ public function test_register_async_test_endpoints() { */ public function test_add_tests() { $tests = $this->instance->add_tests( [] ); + $this->assertArrayHasKey( 'direct', $tests ); - $this->assertArrayHasKey( 'amp_persistent_object_cache', $tests['direct'] ); - if ( version_compare( get_bloginfo( 'version' ), '5.6', '>=' ) ) { - $this->assertArrayHasKey( 'amp_page_cache', $tests['async'] ); - } elseif ( array_key_exists( 'async', $tests ) ) { - $this->assertArrayNotHasKey( 'amp_page_cache', $tests['async'] ); + if ( ! version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) { + $this->assertArrayHasKey( 'amp_persistent_object_cache', $tests['direct'] ); + + if ( version_compare( get_bloginfo( 'version' ), '5.6', '>=' ) ) { + $this->assertArrayHasKey( 'amp_page_cache', $tests['async'] ); + } elseif ( array_key_exists( 'async', $tests ) ) { + $this->assertArrayNotHasKey( 'amp_page_cache', $tests['async'] ); + } } $this->assertArrayHasKey( 'amp_curl_multi_functions', $tests['direct'] ); @@ -698,6 +702,10 @@ public function test_add_extensions() { * @covers ::get_good_response_time_threshold() */ public function test_get_good_response_time_threshold() { + if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) { + $this->markTestSkipped( '`amp_page_cache_good_response_time_threshold` is deprecated in WordPress 6.1 and above.' ); + } + $this->assertSame( 600, $this->instance->get_good_response_time_threshold() ); add_filter( @@ -918,6 +926,9 @@ public function get_page_cache_data() { * @covers ::check_for_page_caching() */ public function test_page_cache( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) { + if ( version_compare( get_bloginfo( 'version' ), '6.1', '>=' ) ) { + $this->markTestSkipped( 'AMP plugin omits page and object caching tests for Site Health if on WP>=6.1 ' ); + } $badge_color = [ 'critical' => 'red',