class-lcp-preload.php

LCP/hero-preload service — LCP resolution, preload emission, and dedup/slot state.

Source includes/Images/class-lcp-preload.php25 min readPart of Performance Optimisation

includes/Images/class-lcp-preload.php

LCP/hero-preload service — LCP resolution, preload emission, and dedup/slot state.

Namespace: PerformanceOptimise\\Inc · Lines: 4434

Class Lcp_Preload

Class Lcp_Preload

Source: includes/Images/class-lcp-preload.php, line 76

final class Lcp_Preload

Tags: @since 2.4.0

Constants

ConstantVisibilityValueLine
MAX_PRELOAD_WIDTHprivate1478106
MAX_LCP_PRELOADSprivate2117

Properties

PropertyVisibilityTypeDefaultLine
$ownerprivateImage_Optimisation—89
$preload_emittedprivate staticarrayarray()135
$preload_emitted_urlsprivate staticarrayarray()151
$heuristic_lcp_memoprivate staticarray<string,array()164
$responsive_lcp_preload_emittedprivate staticboolfalse177
$lcp_priority_appliedprivateboolfalse191

public __construct()

public function __construct(Image_Optimisation $owner)

Constructor.

ParameterTypeDefaultDescription
$ownerImage_Optimisation—Image_Optimisation instance (options + memo + collaborator owner).

Tags: @since 2.4.0

Source: includes/Images/class-lcp-preload.php, line 97

publicstatic clear_lcp_preload_caches()

public static function clear_lcp_preload_caches(): void

Clear the per-request LCP/preload static caches.

Return: void.

Tags: @since 2.4.0

Source: includes/Images/class-lcp-preload.php, line 203

publicstatic clear_heuristic_lcp_memo()

public static function clear_heuristic_lcp_memo(): void

Clear the heuristic LCP memo only.

Return: void.

Tags: @since 2.4.0

Source: includes/Images/class-lcp-preload.php, line 219

privatestatic heuristic_memo_key()

private static function heuristic_memo_key(string $buffer): string

Blog-scoped key for the heuristic LCP memo.

ParameterTypeDefaultDescription
$bufferstring—HTML buffer.

Return: string — Memo key.

Tags: @since 2.4.0

Source: includes/Images/class-lcp-preload.php, line 237

publicstatic has_emitted_preload()

public static function has_emitted_preload(string $url, string=\'\' $media): bool

Whether a preload hint was already emitted for a URL this request.

ParameterTypeDefaultDescription
$urlstring—The raw preload URL.
$mediastring=\'\'—The preload media attribute.

Return: bool — True when the URL + media pair already emitted.

Tags: @since 2.2.0

Source: includes/Images/class-lcp-preload.php, line 268

publicstatic mark_preload_emitted()

public static function mark_preload_emitted(string $url, string=\'\' $media): void

Record a preload hint as emitted for this request.

ParameterTypeDefaultDescription
$urlstring—The raw preload URL.
$mediastring=\'\'—The preload media attribute.

Return: void.

Tags: @since 2.2.0

Source: includes/Images/class-lcp-preload.php, line 290

publicstatic record_direct_preload_url()

public static function record_direct_preload_url(string $url): void

Record a directly-emitted hero URL for same-response lazy exclusion.

ParameterTypeDefaultDescription
$urlstring—The raw preload URL.

Return: void.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 312

publicstatic get_direct_preload_normalized_urls()

public static function get_direct_preload_normalized_urls(): array

Normalized forms of the directly-emitted preload URLs.

Return: string[] — Normalized direct-preload URLs.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 343

publicstatic build_preload_dedup_key()

public static function build_preload_dedup_key(string $url, string $media): string

Build the dedup key for a preload item (normalized URL + query + media).

ParameterTypeDefaultDescription
$urlstring—The raw preload URL.
$mediastring—The preload media attribute.

Return: string — The dedup key.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 381

publicstatic is_hero_preload_claimed()

public static function is_hero_preload_claimed(string $url): bool

Whether any preload was already claimed for a hero URL, any media.

ParameterTypeDefaultDescription
$urlstring—The raw hero URL.

Return: bool — True when the URL already emitted with any media.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 421

public claim_hero_preload_slot()

public function claim_hero_preload_slot(string $url, string=\'\' $media, ?string=null $buffer): bool

Claim the single hero preload slot for a URL.

ParameterTypeDefaultDescription
$urlstring—The raw hero URL.
$mediastring=\'\'—The preload media attribute (\’\’ for buffer companions).
$buffer?string=null—Optional HTML buffer to scan for an existing hint.

Return: bool — True when the caller may emit (slot claimed), false to skip.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 465

publicstatic release_hero_preload_slot()

public static function release_hero_preload_slot(string $url, string=\'\' $media): void

Release a previously claimed hero preload slot.

ParameterTypeDefaultDescription
$urlstring—The raw hero URL.
$mediastring=\'\'—The preload media attribute (\’\’ for buffer companions).

Return: void.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 499

public is_cdn_preload_url()

public function is_cdn_preload_url(string $url): bool

Whether a preload candidate lives on the configured CDN.

ParameterTypeDefaultDescription
$urlstring—The candidate URL.

Return: bool — True when the URL host matches a configured CDN host.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 523

public is_allowed_hero_preload_url()

public function is_allowed_hero_preload_url(string $url): bool

Whether a hero URL may be preloaded (same-origin or configured CDN).

ParameterTypeDefaultDescription
$urlstring—The candidate URL.

Return: bool — True when the URL may be preloaded.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 581

public is_html_api_available()

public function is_html_api_available(): bool

Whether the WP HTML API may be used for hero scanning.

Return: bool — True when the HTML API may be used.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 606

public get_computed_css_hero_url()

public function get_computed_css_hero_url(?string=null $buffer): string

Server-side computed CSS-hero URL passed via filter.

ParameterTypeDefaultDescription
$buffer?string=null—Optional HTML buffer passed to the filter for context.

Return: string — The computed hero URL, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 647

public sweep_lazy_high_conflicts()

public function sweep_lazy_high_conflicts(string $buffer): string

Force eager on any element already marked fetchpriority high.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.

Return: string — The buffer with high-priority nodes forced eager.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 686

public is_occlusion_fetchpriority_low_enabled()

public function is_occlusion_fetchpriority_low_enabled(): bool

Whether occlusion-aware fetchpriority=low demotion is enabled.

Return: bool — True when occluded nodes should be demoted to low.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 757

public get_occluded_image_urls_for_request()

public function get_occluded_image_urls_for_request(): array

Resolve OD-occluded image URLs for the current request.

Return: string[] — Occluded image URLs (may be empty).

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 790

public apply_occlusion_fetchpriority_low()

public function apply_occlusion_fetchpriority_low(string $buffer, array $occluded_urls, ?string=null $lcp_url): string

Demote OD-occluded in-viewport images to fetchpriority=low.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$occluded_urlsarray—Raw occluded image URLs.
$lcp_url?string=null—Optional true-LCP URL to protect.

Return: string — The buffer with occluded nodes demoted to low.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 826

public preload_images()

public function preload_images()

Preloads images for optimization.

Tags: @since 1.0.0

Source: includes/Images/class-lcp-preload.php, line 1011

public get_all_preload_data()

public function get_all_preload_data(): array

Retrieves all preloading data from front-page, post meta, and post types.

Return: array — List of preload data items.

Tags: @since 1.5.1 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1044

public is_image_lcp_url()

public function is_image_lcp_url(string $url): bool

Whether a candidate URL is a plausible LCP image (text-LCP guard).

ParameterTypeDefaultDescription
$urlstring—The candidate URL.

Return: bool — True when the URL may be preloaded as an image.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1116

public get_manual_lcp_url()

public function get_manual_lcp_url(): string

Read the manual per-post LCP URL picker value (`_wppo_lcp_preload_url`).

Return: string — The manual LCP image URL, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1168

public is_same_origin_preload_url()

public function is_same_origin_preload_url(string $url): bool

Whether a preload candidate URL is same-origin with this site.

ParameterTypeDefaultDescription
$urlstring—The candidate URL.

Return: bool — True when the URL may be preloaded.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1229

public is_core_loading_optimization_available()

public function is_core_loading_optimization_available(): bool

Whether core\’s loading-optimization API is available.

Return: bool — True when core may be consulted for a node verdict.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1290

public get_core_loading_verdict_for_tag()

public function get_core_loading_verdict_for_tag($tags): ?array

Ask core for its loading-optimization verdict on the current tag.

ParameterTypeDefaultDescription
$tagsmixed—Tag processor positioned on an `<img>` node.

Return: array{decoding?:string}|null — Core\’s verdict, or null.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1342

public is_auto_lcp_disabled_for_post()

public function is_auto_lcp_disabled_for_post(): bool

Whether automatic (signal-driven) LCP preload is disabled for the current post.

Return: bool — True when auto-LCP must be skipped for this post.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1391

public get_stable_signal_lcp_url()

public function get_stable_signal_lcp_url(): string

Resolve the stable signal-only LCP image URL for the current page.

Return: string — The stable signal LCP image URL, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1441

public resolve_od_only_lcp_url()

public function resolve_od_only_lcp_url(): string

Resolve the OD-only LCP image URL (manual picker + OD real-visit data).

Return: string — The OD-only LCP image URL, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1528

public resolve_auto_lcp_url()

public function resolve_auto_lcp_url(?string=null $buffer): string

Resolve the single auto-detected LCP image URL for the current page.

ParameterTypeDefaultDescription
$buffer?string=null—Optional HTML buffer for the heuristic fallback.

Return: string — The LCP image URL, or empty string when none resolves.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1598

publicstatic get_lcp_responsive_data_for_url()

public static function get_lcp_responsive_data_for_url(string $lcp_url): array

Resolve responsive srcset/sizes for an LCP URL via the media library.

ParameterTypeDefaultDescription
$lcp_urlstring—The resolved LCP image URL.

Return: array{srcset: — string, sizes: string} Responsive data (empty strings when unavailable).

Tags: @since 2.2.0

Source: includes/Images/class-lcp-preload.php, line 1689

public get_lcp_srcset_for_url()

public function get_lcp_srcset_for_url(string $lcp_url, ?string=null $buffer): string

Find the responsive srcset for an LCP URL inside an HTML buffer.

ParameterTypeDefaultDescription
$lcp_urlstring—The resolved LCP image URL.
$buffer?string=null—Optional HTML buffer to scan.

Return: string — The srcset value, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1747

public get_lcp_sizes_for_url()

public function get_lcp_sizes_for_url(string $lcp_url, ?string=null $buffer): string

Find the responsive sizes value for an LCP URL inside an HTML buffer.

ParameterTypeDefaultDescription
$lcp_urlstring—The resolved LCP image URL.
$buffer?string=null—Optional HTML buffer to scan.

Return: string — The sizes value, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1797

public emit_responsive_lcp_preload()

public function emit_responsive_lcp_preload(?string=null $buffer): string

Emit a breakpoint-specific responsive LCP preload.

ParameterTypeDefaultDescription
$buffer?string=null—Optional HTML buffer for responsive fallback scans.

Return: string — The preload `<link>` tag, or empty string when skipped.

Tags: @since 2.3.0

Source: includes/Images/class-lcp-preload.php, line 1868

public get_responsive_lcp_candidate()

public function get_responsive_lcp_candidate(?string=null $buffer): array

Resolve the responsive LCP candidate (OD breakpoints → RUM field).

ParameterTypeDefaultDescription
$buffer?string=null—Optional HTML buffer for fallback scans.

Return: array{url: — string, srcset: string, sizes: string, type: string, media: string}|array Empty when unresolved.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 1950

public pick_breakpoint_winner()

public function pick_breakpoint_winner(array $entries, ?string=null $buffer): array

Pick the breakpoint winner from OD per-viewport entries.

ParameterTypeDefaultDescription
$entriesarray—OD breakpoint entries.
$buffer?string=null—Optional HTML buffer for gap-fill.

Return: array{url: — string, srcset: string, sizes: string, type: string, media: string}|array Winner or empty.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2001

public resolve_rum_fallback_candidate()

public function resolve_rum_fallback_candidate(?string=null $buffer): array

Resolve the RUM field-LCP fallback candidate.

ParameterTypeDefaultDescription
$buffer?string=null—Optional HTML buffer for gap-fill.

Return: array{url: — string, srcset: string, sizes: string, type: string, media: string}|array Candidate or empty.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2131

public response_already_has_high_preload()

public function response_already_has_high_preload(?string=null $buffer): bool

Whether the response already carries a fetchpriority-high hint.

ParameterTypeDefaultDescription
$buffer?string=null—Optional HTML buffer to inspect.

Return: bool — True when a high hint already exists.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2216

public get_manual_lcp_preload_data()

public function get_manual_lcp_preload_data(): array

Retrieves the manual per-post LCP image preload item.

Return: array — List of preload items (zero or one item).

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2248

public get_auto_lcp_preload_data()

public function get_auto_lcp_preload_data(): array

Retrieves the single auto-detected LCP image preload item.

Return: array — List of preload items (zero or one item).

Tags: @since 2.0.0 · @since 2.2.0 Resolves via the unified `resolve_auto_lcp_url()` chain (OD → stored PageSpeed → heuristic) with a text-LCP guard; emits at most one item. Adds the RUM-gated `preload_settings.autoLcpPreload` path (off by default, manual lists win, never lazy+high). · @since 2.2.0 RUM gates only the RUM-dependent tiers: with RUM unsatisfied the OD-only subset still resolves. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2296

public get_breakpoint_srcset_for_url()

public function get_breakpoint_srcset_for_url(string $lcp_url, ?string=null $buffer): array

Look up breakpoint srcset/sizes for a resolved LCP URL.

ParameterTypeDefaultDescription
$lcp_urlstring—The resolved LCP image URL.
$buffer?string=null—Optional HTML buffer for gap-fill.

Return: array{srcset: — string, sizes: string} Responsive pair.

Tags: @since 2.3.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2353

public is_auto_lcp_rum_satisfied()

public function is_auto_lcp_rum_satisfied(): bool

Whether the RUM gate for the additive auto-LCP toggle is satisfied.

Return: bool — True when RUM gating passes.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2405

public get_current_lcp_url()

public function get_current_lcp_url(): string

Resolves the currently-detected LCP image URL for the current page.

Return: string — The LCP image URL, or empty string when none is stored.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2440

public get_lcp_memo_key()

public function get_lcp_memo_key(): string

Current-URL key for the per-instance LCP memos (issue #1216).

Return: string — Memo key (possibly empty).

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2546

public get_heuristic_lcp_url()

public function get_heuristic_lcp_url(string $buffer): string

P2 DOM-first heuristic LCP URL, memoized per buffer hash (issue #1216).

ParameterTypeDefaultDescription
$bufferstring—HTML buffer to scan.

Return: string — Heuristic LCP URL, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2576

public get_lazy_lcp_exclusion_url()

public function get_lazy_lcp_exclusion_url(array $image_optimisation, ?string=null $buffer): string

Resolve the LCP-candidate URL excluded from lazy load (memoized per instance).

ParameterTypeDefaultDescription
$image_optimisationarray—Image optimisation settings.
$buffer?string=null—Optional HTML buffer for the heuristic tier.

Return: string — The candidate URL, or empty string when none applies.

Tags: @since 2.0.0 · @since 2.2.0 Resolves via the unified `resolve_auto_lcp_url()` chain so the never-lazy URL is always the same URL that gets preloaded. The optional `$buffer` enables the P2 DOM-first heuristic tier so `add_delay_load_img()` stays in parity with `maybe_preload_hero_image()` (which resolves with the buffer); without a buffer only the manual + OD + stored tiers apply. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2622

public get_effective_exclude_first_images_count()

public function get_effective_exclude_first_images_count(array $image_optimisation): int

Get the effective excludeFirstImages count, preferring OD measured data.

ParameterTypeDefaultDescription
$image_optimisationarray—Image optimisation settings.

Return: int — Exclude count.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2702

public get_front_page_preload_data()

public function get_front_page_preload_data(array $image_optimisation): array

Retrieves front page preload data if enabled.

ParameterTypeDefaultDescription
$image_optimisationarray—Image optimization configuration.

Return: array — List of preload items for the front page.

Tags: @since 1.5.1 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2767

public get_meta_preload_data()

public function get_meta_preload_data(): array

Retrieves preload data from post meta.

Return: array — List of preload items from meta.

Tags: @since 1.5.1 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2784

public get_post_type_preload_data()

public function get_post_type_preload_data(array $image_optimisation): array

Retrieves preload data for specific post types.

ParameterTypeDefaultDescription
$image_optimisationarray—Image optimization configuration.

Return: array — List of preload items for the post type.

Tags: @since 1.5.1 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2809

public get_image_url_by_post_type()

public function get_image_url_by_post_type(int $thumbnail_id): string

Retrieves the URL of the featured image for the current post type.

ParameterTypeDefaultDescription
$thumbnail_idint—The ID of the thumbnail image.

Return: string — The URL of the image.

Tags: @since 1.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2847

public should_exclude_image()

public function should_exclude_image(string $image_url, array $exclude_img_urls): bool

Check if an image should be excluded from preloading or optimization.

ParameterTypeDefaultDescription
$image_urlstring—The URL of the image.
$exclude_img_urlsarray—Array of URLs to exclude.

Return: bool — True if the image should be excluded, false otherwise.

Tags: @since 1.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2866

public parse_srcset_data()

public function parse_srcset_data($srcset, $image_optimisation): array

Parse srcset data from an image tag.

ParameterTypeDefaultDescription
$srcsetstring—The srcset string from the image tag.
$image_optimisationarray—Image optimization configuration array.

Return: array — Array of parsed sources: array( \’url\’ => string, \’width\’ => int ).

Tags: @since 1.5.1 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2884

public get_srcset_preload_items()

public function get_srcset_preload_items($srcset, $default_image, $image_optimisation): array

Retrieves preload data items from an image\’s srcset.

ParameterTypeDefaultDescription
$srcsetstring—The srcset string from the image tag.
$default_imagestring—The fallback image URL.
$image_optimisationarray—Image optimization configuration array.

Return: array — List of preload items.

Tags: @since 1.5.1 · @since 2.2.0 Keeps the largest MAX_LCP_PRELOADS widths (the likely hero variants) instead of the smallest; media ranges are generated after the slice so coverage stays gapless. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2930

public prepare_preload_item()

public function prepare_preload_item(string $img_url, string=\'\' $imagesrcset, string=\'\' $imagesizes): array

Prepares a URL for preloading, handling specific prefixes and resolving relative paths.

ParameterTypeDefaultDescription
$img_urlstring—The original URL to prepare.
$imagesrcsetstring=\'\'—Optional responsive srcset for the preload link.
$imagesizesstring=\'\'—Optional sizes for the preload link.

Return: array — Structured preload item.

Tags: @since 1.5.1 · @since 2.2.0 Adds optional $imagesrcset/$imagesizes for responsive LCP heroes. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 2987

public generate_img_preload()

public function generate_img_preload(=\'\' $img_url)

Generates a preload link for a given image URL.

ParameterTypeDefaultDescription
$img_url=\'\'—The URL of the image to preload. Empty resolves the stable signal candidate.

Return: void.

Tags: @since 1.0.0 · @since 2.2.0 Resolves the stable signal candidate when empty, enforces per-URL dedup + per-post disable + lazy-exclusion coupling with `fetchpriority=\”high\”`.

Source: includes/Images/class-lcp-preload.php, line 3072

public prioritize_lcp_in_buffer()

public function prioritize_lcp_in_buffer($filtered_output, =\'\' $output)

Post-render LCP image prioritization (optional enhancement).

ParameterTypeDefaultDescription
$filtered_outputstring—The filtered output from previous callbacks.
$output=\'\'—The raw output buffer content (unused; present for parity with the 6.9 filter signature and safe when used as an ob_start callback).

Return: string — The processed buffer.

Tags: @since 2.0.0

Source: includes/Images/class-lcp-preload.php, line 3159

public wppo_add_fetchpriority()

public function wppo_add_fetchpriority($attr, =null $attachment, =null $size)

Stamp fetchpriority=\”high\” on the LCP attachment at render time.

ParameterTypeDefaultDescription
$attrmixed—Image attributes (expected array).
$attachment=null—Attachment post object, ID, or array with ID.
$size=null—Requested image size.

Return: mixed — The (possibly stamped) attributes, unchanged on miss.

Tags: @since 2.2.0

Source: includes/Images/class-lcp-preload.php, line 3363

public resolve_fetchpriority_lcp_url()

public function resolve_fetchpriority_lcp_url(): string

Resolve the LCP candidate for the render-time fetchpriority filter, memoized per page.

Return: string — The validated LCP image URL, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3500

public fetchpriority_candidate_matches()

public function fetchpriority_candidate_matches(string $candidate, string $normalized_lcp, string $exact_lcp, bool $size_is_full): bool

Size-aware LCP candidate comparison for the fetchpriority filter.

ParameterTypeDefaultDescription
$candidatestring—The rendered file URL to test.
$normalized_lcpstring—Normalized LCP URL (size suffix stripped).
$exact_lcpstring—Normalized LCP URL (size suffix preserved).
$size_is_fullbool—Whether the requested image size is \’full\’.

Return: bool — True when the candidate corresponds to the LCP image.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3546

public prioritize_lcp_image()

public function prioritize_lcp_image(string $buffer, ?string=null $lcp_url): string

Set fetchpriority=\”high\” on the detected LCP image.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$lcp_url?string=null—Optional pre-resolved LCP URL. When null the URL is resolved via resolve_auto_lcp_url() (same-origin guarded OD/stored/heuristic chain; the stored tier internally reads get_current_lcp_url()).

Return: string — The buffer with fetchpriority=\”high\” on the LCP image.

Tags: @since 2.0.0 · @since 2.2.0 Callers pass the unified `resolve_auto_lcp_url()` target so the never-lazy/fetchpriority stamp always matches the preloaded URL. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3588

public maybe_preload_hero_image()

public function maybe_preload_hero_image(string $buffer, array $image_optimisation, ?string=null $lcp_url): string

Hero fallback: ensure the first-viewport image preloads with fetchpriority=high and is never lazy.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$image_optimisationarray—Image optimisation settings.
$lcp_url?string=null—Optional pre-resolved LCP URL. When null the URL is resolved via resolve_auto_lcp_url().

Return: string — The buffer with hero preload link injected.

Tags: @since 2.0.0 · @since 2.2.0 Resolves via the unified `resolve_auto_lcp_url()` chain (OD → stored PageSpeed → in-viewport heuristic) and emits at most one preload link with `imagesrcset` when the hero carries a srcset. Accepts a pre-resolved LCP URL so all buffer passes share one target. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3720

public get_first_image_src_in_buffer()

public function get_first_image_src_in_buffer(string $buffer): string

Get the first <img src> URL in the buffer (hero fallback).

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.

Return: string — First image src, or empty string when none found.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3888

public is_trivial_heuristic_image()

public function is_trivial_heuristic_image($tags, string $src): bool

Whether a heuristic `<img>` candidate is trivial (pixel/hidden/tiny).

ParameterTypeDefaultDescription
$tags\\WP_HTML_Tag_Processor—The tag processor on the candidate `<img>`.
$srcstring—The candidate src URL.

Return: bool — True when the candidate should be skipped.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3932

public buffer_has_image_preload()

public function buffer_has_image_preload(string $buffer, string $url): bool

Whether the buffer already contains a preload link for the image URL.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$urlstring—The image URL to look for.

Return: bool — True when a matching preload link exists.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 3977

public buffer_has_image_preload_with_tag_processor()

public function buffer_has_image_preload_with_tag_processor(string $buffer, string $needle, string $needle_exact, bool $needle_has_sizes, string $needle_query): ?bool

Tag Processor scan for an existing image preload link (WP 6.2+).

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$needlestring—Normalized target URL.
$needle_exactstring—Normalized target URL without size-suffix collapsing.
$needle_has_sizesbool—Whether the target itself carries a size suffix.
$needle_querystring—Raw query string of the target URL.

Return: bool|null — True/false on success, null on failure (fallback).

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4049

public get_url_query()

public function get_url_query(string $url): string

Get the raw query string of a URL for preload-dedup comparison.

ParameterTypeDefaultDescription
$urlstring—The URL to inspect.

Return: string — The query string without the leading `?`, or empty.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4110

public tag_matches_lcp_url()

public function tag_matches_lcp_url($tags, string $lcp_url): bool

Whether the matched image tag references the given LCP URL.

ParameterTypeDefaultDescription
$tags\\WP_HTML_Tag_Processor—The tag processor matched on an <img>.
$lcp_urlstring—The detected LCP image URL.

Return: bool — True if the image references the LCP URL.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4139

public normalize_image_url()

public function normalize_image_url(string $url, bool=true $strip_size_suffix): string

Normalize an image URL for LCP matching.

ParameterTypeDefaultDescription
$urlstring—The raw URL to normalize.
$strip_size_suffixbool=true—Whether to strip WordPress size suffixes. Default true.

Return: string — Normalized host + path, or an empty string when unparseable.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4187

publicstatic normalize_image_url_static()

public static function normalize_image_url_static(string $url, bool=true $strip_size_suffix): string

Static normalization behind normalize_image_url().

ParameterTypeDefaultDescription
$urlstring—The image URL to normalize.
$strip_size_suffixbool=true—Whether to strip WP size suffixes.

Return: string — Normalized host + path, or empty string.

Tags: @since 2.2.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4206

public get_preload_dedup_key()

public function get_preload_dedup_key(string $url, string $media): string

Build the dedup key for a preload item (normalized URL + query + media).

ParameterTypeDefaultDescription
$urlstring—The raw preload URL.
$mediastring—The preload media attribute.

Return: string — The dedup key.

Tags: @since 2.0.0 · @since 2.2.0 Delegates to build_preload_dedup_key() so the shared cross-emitter helpers use the identical key space. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4273

public buffer_has_matching_img()

public function buffer_has_matching_img(string $buffer, string $lcp_url): bool

Whether any img element in the buffer references the given LCP URL.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$lcp_urlstring—The detected LCP image URL.

Return: bool — True when an img matches the LCP URL.

Tags: @since 2.0.0 · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4290

public maybe_inject_css_hero_preload()

public function maybe_inject_css_hero_preload(string $buffer, ?string=null $lcp_url): string

Inject exactly one CSS-hero preload link into the buffer head.

ParameterTypeDefaultDescription
$bufferstring—The HTML buffer.
$lcp_url?string=null—Optional pre-resolved LCP URL. When null the URL is resolved via resolve_auto_lcp_url() (same-origin guarded OD/stored/heuristic chain), matching every other emission path.

Return: string — The buffer with at most one added preload link.

Tags: @since 2.0.0 · @since 2.2.0 Accepts a pre-resolved LCP URL so buffer passes share one unified target instead of re-resolving stored data per pass. · @since 2.2.0 Uses the centralised hero slot, the same-origin/CDN allowlist, stylesheet-block heroes, and the computed-URL filter. · @internal Formerly private on Image_Optimisation (ARCH-008 extraction bridge). Call via the Image_Optimisation facade, never directly.

Source: includes/Images/class-lcp-preload.php, line 4336

Hooks

Hooks referenced in includes/Images/class-lcp-preload.php:

HookTypeLineNotes
wppo_computed_css_hero_urlfilter655—
wppo_occlusion_fetchpriority_low_enabledfilter769@param ×1
wppo_occlusion_fetchpriority_low_urlsfilter839@param ×2
wppo_lcp_first_nfilter2742—
wppo_debug_logaction3308—