WP_Site_Health::get_page_cache_detail(): WP_Error|array

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Gets page cache details.

Return

WP_Error|array Page cache detail or else a WP_Error if unable to determine.
  • status string
    Page cache status. Good, Recommended or Critical.
  • advanced_cache_present bool
    Whether page cache plugin is available or not.
  • headers string[]
    Client caching response headers detected.
  • response_time float
    Response time of site.

Source

private function get_page_cache_detail() {
	$page_cache_detail = $this->check_for_page_caching();
	if ( is_wp_error( $page_cache_detail ) ) {
		return $page_cache_detail;
	}

	// Use the median server response time.
	$response_timings = $page_cache_detail['response_timing'];
	rsort( $response_timings );
	$page_speed = $response_timings[ floor( count( $response_timings ) / 2 ) ];

	// Obtain unique set of all client caching response headers.
	$headers = array();
	foreach ( $page_cache_detail['page_caching_response_headers'] as $page_caching_response_headers ) {
		$headers = array_merge( $headers, array_keys( $page_caching_response_headers ) );
	}
	$headers = array_unique( $headers );

	// Page cache is detected if there are response headers or a page cache plugin is present.
	$has_page_caching = ( count( $headers ) > 0 || $page_cache_detail['advanced_cache_present'] );

	if ( $page_speed && $page_speed < $this->get_good_response_time_threshold() ) {
		$result = $has_page_caching ? 'good' : 'recommended';
	} else {
		$result = 'critical';
	}

	return array(
		'status'                 => $result,
		'advanced_cache_present' => $page_cache_detail['advanced_cache_present'],
		'headers'                => $headers,
		'response_time'          => $page_speed,
	);
}

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.