WP_Site_Health::get_page_cache_detail()
Gets page cache details.
Method of the class: WP_Site_Health{}
No Hooks.
Return
WP_Error|Array
. Page cache detail or else a WP_Error if unable to determine.
Usage
// private - for code of main (parent) class only $result = $this->get_page_cache_detail();
Changelog
Since 6.1.0 | Introduced. |
WP_Site_Health::get_page_cache_detail() WP Site Health::get page cache detail code WP 6.4.3
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, ); }