includes/Insight/class-od-bridge.php
Optimization Detective (OD) bridge.
Class OD_Bridge
Optimization Detective bridge.
class OD_BridgeConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
SETTINGS_KEY | public | \'od_integration\' | 39 |
FILTER_SHOULD_OPTIMIZE | public | \'wppo_od_should_optimize\' | 48 |
Properties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$request_memo | private static | array | array() | 67 |
publicstatic clear_request_memo()
public static function clear_request_memo(): voidReset the per-request OD memo.
Return: void.
privatestatic request_memo_key()
private static function request_memo_key(string $prefix): stringMemo key for the current URL with the given prefix. Parameter Type Default Description $prefixstring— Memo namespace prefix.
Return: string — Memo key.
privatestatic request_memo_set()
private static function request_memo_set(string $key, $value): voidStore a memo value, bounding the map. Parameter Type Default Description $keystring— Memo key. $valuemixed— Memo value.
Return: void.
privatestatic debug_log()
private static function debug_log(string $message): voidLog a Throwable diagnostic to the server error log when WP_DEBUG is on. Parameter Type Default Description $messagestring— Message to log.
Return: void.
publicstatic is_od_available()
public static function is_od_available(): boolWhether the Optimization Detective plugin is available.
Return: bool — True when OD is active.
publicstatic is_enabled()
public static function is_enabled(): boolWhether OD optimization is enabled for the current request.
Return: bool — True when OD data should be consumed.
publicstatic get_lcp_url()
public static function get_lcp_url(): stringGet the LCP image URL from OD viewport groups.
Return: string — LCP image URL or empty string.
publicstatic get_stable_lcp_url()
public static function get_stable_lcp_url(): stringGet the stable LCP image URL from OD viewport groups.
Return: string — Stable LCP image URL or empty string.
publicstatic get_exclude_first_images_count()
public static function get_exclude_first_images_count(): intGet the lazy-load threshold (excludeFirstImages) from OD data.
Return: int — Number of first images to exclude, 1-3.
privatestatic collect_lcp_urls()
private static function collect_lcp_urls(): arrayCollect distinct LCP URLs from OD metrics.
Return: string[] — Distinct LCP image URLs.
privatestatic collect_raw_lcp_urls()
private static function collect_raw_lcp_urls(): arrayCollect raw (non-deduplicated) LCP URLs from OD metrics.
Return: string[] — Raw LCP image URLs (may contain duplicates).
privatestatic count_viewport_groups()
private static function count_viewport_groups(): intCount viewport groups from OD data.
Return: int — Number of viewport groups (0 when unavailable).
publicstatic get_occluded_image_urls()
public static function get_occluded_image_urls(): arrayGet normalized occluded image URLs for the current URL.
Return: string[] — Normalized occluded image URLs (may be empty).
privatestatic element_is_occluded()
private static function element_is_occluded($element): boolWhether an OD element is occluded (hidden but in-viewport). Parameter Type Default Description $elementmixed— Element object or array.
Return: bool — True when occluded.
privatestatic element_geometry_is_occluded()
private static function element_geometry_is_occluded(array $data): boolGeometry fallback for occlusion detection. Parameter Type Default Description $dataarray— Element data as an array.
Return: bool — True when geometry implies occlusion.
publicstatic get_breakpoint_lcp_elements()
public static function get_breakpoint_lcp_elements(): arrayGet per-breakpoint LCP element detail for responsive preloads.
Return: array<int, — array{url: string, srcset: string, sizes: string, media: string, type: string}> Breakpoint LCP entries.
privatestatic collect_lcp_elements_from_metric()
private static function collect_lcp_elements_from_metric($metric): arrayCollect LCP elements (not just URLs) from a single OD metric. Parameter Type Default Description $metricmixed— Single OD metric object or array.
Return: array — List of LCP elements.
privatestatic extract_element_attr()
private static function extract_element_attr($element, string $name): stringExtract a string attribute from an OD element (method → property → array). Parameter Type Default Description $elementmixed— Element object or array. $namestring— Attribute name (e.g. \’srcset\’).
Return: string — Attribute value or empty string.
privatestatic extract_srcset_from_element()
private static function extract_srcset_from_element($element): stringExtract the srcset value from an OD element. Parameter Type Default Description $elementmixed— Element object or array.
Return: string — Srcset value or empty string.
privatestatic extract_sizes_from_element()
private static function extract_sizes_from_element($element): stringExtract the sizes value from an OD element. Parameter Type Default Description $elementmixed— Element object or array.
Return: string — Sizes value or empty string.
privatestatic extract_media_from_element()
private static function extract_media_from_element($element): stringExtract the media value from an OD element. Parameter Type Default Description $elementmixed— Element object or array.
Return: string — Media value or empty string.
privatestatic extract_type_from_element()
private static function extract_type_from_element($element): stringExtract the LCP element type for per-type preload coverage. Parameter Type Default Description $elementmixed— Element object or array.
Return: string — Element type.
privatestatic get_url_metrics()
private static function get_url_metrics(): arrayRetrieve URL metrics via the OD API.
Return: array — List of metric objects/arrays.
privatestatic element_is_lcp()
private static function element_is_lcp($element): boolWhether an OD element is the LCP element. Parameter Type Default Description $elementmixed— Element object or array.
Return: bool — True when LCP.
privatestatic extract_url_from_element()
private static function extract_url_from_element($element): stringExtract an image URL from an OD element. Parameter Type Default Description $elementmixed— Element object or array.
Return: string — URL or empty string.