WP_Site_Health::get_page_cache_headers()publicWP 6.1.0

Returns a list of headers and its verification callback to verify if page cache is enabled or not.

Note: key is header name and value could be callable function to verify header value. Empty value mean existence of header detect page cache is enabled.

Method of the class: WP_Site_Health{}

Return

Array. List of client caching headers and their (optional) verification callbacks.

Usage

$WP_Site_Health = new WP_Site_Health();
$WP_Site_Health->get_page_cache_headers();

Changelog

Since 6.1.0 Introduced.

WP_Site_Health::get_page_cache_headers() code WP 6.1.1

public function get_page_cache_headers() {

	$cache_hit_callback = static function ( $header_value ) {
		return false !== strpos( strtolower( $header_value ), 'hit' );
	};

	$cache_headers = array(
		'cache-control'          => static function ( $header_value ) {
			return (bool) preg_match( '/max-age=[1-9]/', $header_value );
		},
		'expires'                => static function ( $header_value ) {
			return strtotime( $header_value ) > time();
		},
		'age'                    => static function ( $header_value ) {
			return is_numeric( $header_value ) && $header_value > 0;
		},
		'last-modified'          => '',
		'etag'                   => '',
		'x-cache-enabled'        => static function ( $header_value ) {
			return 'true' === strtolower( $header_value );
		},
		'x-cache-disabled'       => static function ( $header_value ) {
			return ( 'on' !== strtolower( $header_value ) );
		},
		'x-srcache-store-status' => $cache_hit_callback,
		'x-srcache-fetch-status' => $cache_hit_callback,
	);

	/**
	 * Filters the list of cache headers supported by core.
	 *
	 * @since 6.1.0
	 *
	 * @param array $cache_headers Array of supported cache headers.
	 */
	return apply_filters( 'site_status_page_cache_supported_cache_headers', $cache_headers );
}