class-cdn.php

CDN rewrite class (LS-410 parity with LSCWP cdn.cls.php).

Source includes/Edge/class-cdn.php4 min readPart of Performance Optimisation

includes/Edge/class-cdn.php

CDN rewrite class (LS-410 parity with LSCWP cdn.cls.php).

Namespace: PerformanceOptimise\\Inc · Lines: 796

Class CDN

Class CDN

Source: includes/Edge/class-cdn.php, line 24

final class CDN

Tags: @since 2.0.0

Properties

PropertyVisibilityTypeDefaultLine
$regex_cacheprivate staticarrayarray()34
$mappings_cacheprivate staticarrayarray()47

publicstatic should_bypass()

public static function should_bypass(): bool

Whether bypass constant is active.

Return: bool.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 57

publicstatic wildcard2regex()

public static function wildcard2regex(string $pattern): string

Convert wildcard pattern to regex fragment (LSCWP cdn.cls.php:188).

ParameterTypeDefaultDescription
$patternstring—Wildcard pattern.

Return: string — Regex fragment.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 82

publicstatic get_mappings()

public static function get_mappings(array=array() $options): array

Get normalized CDN mappings.

ParameterTypeDefaultDescription
$optionsarray=array()—Optional plugin options override. When empty, loads from DB.

Return: array.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 118

privatestatic precompute_mapping()

private static function precompute_mapping($mapping): array

Precompute normalized mapping parts once per mapping.

ParameterTypeDefaultDescription
$mappingmixed—Raw mapping entry.

Return: array — Mapping with precomputed keys.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 245

publicstatic find_cdn_for_url()

public static function find_cdn_for_url(string $url, array $mappings): ?string

Resolve the CDN URL for an asset (first matching mapping).

ParameterTypeDefaultDescription
$urlstring—Asset URL.
$mappingsarray—Normalized mappings from get_mappings().

Return: string|null — CDN URL or null when no mapping matches.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 289

publicstatic find_cdn_match()

public static function find_cdn_match(string $url, array $mappings): ?array

Resolve the first matching CDN mapping for an asset URL.

ParameterTypeDefaultDescription
$urlstring—Asset URL.
$mappingsarray—Normalized mappings from get_mappings().

Return: array{cdn:string,mapping:array}|null — Match info or null when no mapping matches.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 306

privatestatic mapping_allows_attr()

private static function mapping_allows_attr(array $mapping, string $attr): bool

Whether a mapping\’s `cdn_attr` restriction permits an attribute.

ParameterTypeDefaultDescription
$mappingarray—Mapping entry.
$attrstring—Attribute name (lowercase, e.g. \’src\’, \’srcset\’).

Return: bool.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 426

publicstatic rewrite_url()

public static function rewrite_url(string $url, mixed=null $mappings): string

Rewrite single URL.

ParameterTypeDefaultDescription
$urlstring—URL.
$mappingsmixed=null—Optional pre-resolved mappings from get_mappings(). When this method is invoked as a `*_loader_src` / `wp_get_attachment_url` filter, WordPress passes the handle/attachment ID as the second argument — any non-array value is ignored and mappings are resolved.

Return: string — Rewritten or original.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 449

publicstatic rewrite_srcset()

public static function rewrite_srcset(array $sources, mixed=null $mappings): array

Rewrite srcset array (wp_calculate_image_srcset format).

ParameterTypeDefaultDescription
$sourcesarray—Srcset sources.
$mappingsmixed=null—Optional pre-resolved mappings from get_mappings(). Non-array values (e.g. a filter\’s handle or size array argument) are ignored and mappings are resolved via get_mappings().

Return: array.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 502

publicstatic rewrite_buffer()

public static function rewrite_buffer(string $buffer): string

Rewrite buffer (tags + inline url()).

ParameterTypeDefaultDescription
$bufferstring—HTML buffer.

Return: string.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 539

privatestatic rewrite_buffer_with_processor()

private static function rewrite_buffer_with_processor(string $buffer, array $mappings, string $site_url, string $site_url_regex, array $allowed_tags, string=\'\' $style_url_pattern): ?string

Rewrite the buffer\’s asset URLs via the WP 6.9+ HTML processor.

ParameterTypeDefaultDescription
$bufferstring—HTML buffer.
$mappingsarray—CDN mappings.
$site_urlstring—Site URL.
$site_url_regexstring—Regex matching a site-relative URL start.
$allowed_tagsarray—Tag names whose attributes may be rewritten.
$style_url_patternstring=\'\'—Precompiled inline style-url() pattern.

Return: string|null — Rewritten buffer, or null on failure (fallback).

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 646

privatestatic rewrite_tag_assets()

private static function rewrite_tag_assets(\\WP_HTML_Tag_Processor $tags, array $mappings, string $site_url, string $site_url_regex, array $allowed_tags, string=\'\' $style_url_pattern): void

Rewrite asset URLs on the current tag of a HTML processor instance.

ParameterTypeDefaultDescription
$tags\\WP_HTML_Tag_Processor—Processor positioned on the current tag.
$mappingsarray—CDN mappings.
$site_urlstring—Site URL.
$site_url_regexstring—Regex matching a site-relative URL start.
$allowed_tagsarray—Tag names whose attributes may be rewritten.
$style_url_patternstring=\'\'—Precompiled inline style-url() pattern.

Return: void.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 695

publicstatic reset_cache()

public static function reset_cache(): void

Reset per-request memos (for testing).

Return: void.

Tags: @since 2.0.0

Source: includes/Edge/class-cdn.php, line 791

Hooks

Hooks referenced in includes/Edge/class-cdn.php:

HookTypeLineNotes
wppo_litespeed_can_cdnfilter64—
wppo_cdn_auto_filetypesfilter168@param ×2
wppo_cdn_mapping_hostsfilter186@param ×1
wppo_cdn_mappingfilter193@param ×1
wppo_cdn_urlfilter208—
wppo_cdn_auto_filetypesfilter217—
wppo_cdn_mapping_hostsfilter220—
wppo_cdn_mappingfilter221—
wppo_cdn_url_for_assetfilter401@param ×3
wppo_litespeed_can_cdnfilter512—
wppo_litespeed_can_cdnfilter549—
wppo_cdn_bufferfilter617@param ×1