includes/Insight/class-telemetry.php
Telemetry Class
Class Telemetry
Class Telemetry
class TelemetryConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
AUDIT_SALT_KEY | private | \'wppo_audit_salt\' | 42 |
MAX_REDIRECT_HOPS | private | 2 | 53 |
publicstatic scan()
public static function scan(string $url, string=\'manual\' $scan_type, bool=false $force): array|\\WP_ErrorScan a URL and return all performance metrics. Parameter Type Default Description $urlstring— The URL to scan. $scan_typestring=\'manual\'— Either \’manual\’ or \’scheduled\’. $forcebool=false— Whether to bypass cache.
Return: array|\\WP_Error — Associative array of metrics, or WP_Error on failure.
publicstatic get_cached_result()
public static function get_cached_result(string $url)Read a cached telemetry result without executing a scan. Parameter Type Default Description $urlstring— Scanned URL.
Return: mixed — Cached telemetry payload, or false when absent.
privatestatic read_cached_audit()
private static function read_cached_audit(string $url, string $lookup_key, bool $has_salted): mixedRead an audit cache entry for scan and query callers. Parameter Type Default Description $urlstring— Scanned URL. $lookup_keystring— Cache key to read. $has_saltedbool— Whether the salted cache layer is available.
Return: mixed — Cached telemetry payload, or false when absent.
protectedstatic execute_curl()
protected static function execute_curl(string $url): arrayExecute a single cURL request without following redirects. Parameter Type Default Description $urlstring— URL to request. string|false $raw_response Raw response (headers + body), or false on transport failure. array $info curl_getinfo() transfer info. int $error curl_errno() value (0 = success).
Return: array — {.
privatestatic parse_header_block()
private static function parse_header_block(string $header_raw): arrayParse raw response headers into a lowercase-keyed array. Parameter Type Default Description $header_rawstring— Raw header text (everything before the body).
Return: array — Lowercase header name => value map.
privatestatic resolve_redirect()
private static function resolve_redirect(string $location, string $current_url): string|falseResolve and validate a redirect Location against the current URL. Parameter Type Default Description $locationstring— Raw Location header value. $current_urlstring— URL of the response that sent the Location.
Return: string|false — Absolute validated URL, or false when the hop is not allowed.
protectedstatic fetch_via_curl()
protected static function fetch_via_curl(string $url): array|\\WP_Error|nullFetch a page via cURL, manually following validated redirects. Parameter Type Default Description $urlstring— Validated scan URL. string $body Response body. array $headers Lowercase response headers from the final hop. array $timings DNS/connect/SSL/TTFB timings in milliseconds. float $load_time Total load time of the final hop in seconds.
Return: array|\\WP_Error|null — { Success payload on a 200 response, WP_Error on an unsafe hop or exceeded hop limit, or null when the wp_remote_get() fallback should be used instead.
protectedstatic fetch_via_wp_remote()
protected static function fetch_via_wp_remote(string $url): array|\\WP_ErrorFetch a page via wp_remote_get(), manually following validated redirects. Parameter Type Default Description $urlstring— Validated scan URL.
Return: array|\\WP_Error — Success payload, or WP_Error on failure/unsafe hop/hop limit.
privatestatic parse_resources()
private static function parse_resources(string $html): arrayParse CSS, JS, and image resources from an HTML string. Parameter Type Default Description $htmlstring— The raw HTML body to parse. string[] $css Array of stylesheet href values. string[] $js Array of script src values. array[] $images Array of image data with \’src\’, \’alt\’, and \’lazy\’ keys.
Return: array — {.
privatestatic calculate_sizes()
private static function calculate_sizes(array $resources): arrayCalculate asset sizes using local filesystem paths. Parameter Type Default Description $resourcesarray— Parsed resources from parse_resources(). int $css Total CSS size in bytes. int $js Total JS size in bytes. int $images Total image size in bytes.
Return: array — {.
privatestatic check_https()
private static function check_https(string $url): boolCheck whether the URL uses HTTPS. Parameter Type Default Description $urlstring— The URL to check.
Return: bool — True if HTTPS, false otherwise.
privatestatic check_compression()
private static function check_compression($headers): boolCheck whether Gzip, Brotli, or Deflate compression is active. Parameter Type Default Description $headersobject|array— Response headers.
Return: bool — True if compressed, false otherwise.
privatestatic get_compression_type()
private static function get_compression_type($headers): stringRetrieve the raw Content-Encoding header value. Parameter Type Default Description $headersobject|array— Response headers.
Return: string — The raw header value, or \’none\’ if not set.
privatestatic check_cache_control()
private static function check_cache_control($headers): boolCheck whether Cache-Control headers are set for at least one week. Parameter Type Default Description $headersobject|array— Response headers.
Return: bool — True if max-age >= 604800, false otherwise.
privatestatic get_cache_control()
private static function get_cache_control($headers): stringRetrieve the raw Cache-Control header value. Parameter Type Default Description $headersobject|array— Response headers.
Return: string — The raw header value, or \’none\’ if not set.
privatestatic get_header_value()
private static function get_header_value($headers, string $name): stringHelper to retrieve a header value from various header structures. Parameter Type Default Description $headersobject|array— Response headers. $namestring— Header name in lowercase (e.g. \’content-encoding\’).
Return: string — Header value or empty string if not found.
privatestatic check_robots_txt()
private static function check_robots_txt(string $url): boolCheck whether a robots.txt file exists at the given URL\’s root. Parameter Type Default Description $urlstring— The page URL whose host to check.
Return: bool — True if robots.txt returns HTTP 200, false otherwise.
privatestatic check_modern_images()
private static function check_modern_images(array $images): floatCheck whether any images use modern formats (WebP or AVIF). Parameter Type Default Description $imagesarray— Array of image data from parse_resources().
Return: float — Percentage of images using modern formats (0-100).
privatestatic check_alt_attributes()
private static function check_alt_attributes(array $images): boolCheck whether all images have non-empty alt attributes. Parameter Type Default Description $imagesarray— Array of image data from parse_resources().
Return: bool — True if all images have alt text, false otherwise.
publicstatic invalidate_audit_cache()
public static function invalidate_audit_cache(): voidInvalidate the audit cache salt so future scans bypass stale cached data.
Return: void.
publicstatic register_transient_key()
public static function register_transient_key(string $key): voidRegister a transient key in the master index for safe bulk deletion. Parameter Type Default Description $keystring— The transient key to register.
Return: void.
privatestatic read_transient_index()
private static function read_transient_index(): arrayRead and normalize the transient index option.
Return: array<string, — int>.
privatestatic prune_transient_index()
private static function prune_transient_index(array $index, int $now): arrayPrune expired entries and cap the transient index size. Parameter Type Default Description $indexarray— — $nowint— Current timestamp.
Return: array<string, — int> Pruned, capped index.
Hooks
Hooks referenced in includes/Insight/class-telemetry.php: Hook Type Line Notes wppo_telemetry_verify_sslfilter 313 — wppo_telemetry_verify_sslfilter 489 — wppo_telemetry_allow_remote_headfilter 759 — wppo_telemetry_verify_sslfilter 967 —