includes/Edge/class-cdn.php
CDN rewrite class (LS-410 parity with LSCWP cdn.cls.php).
Class CDN
Class CDN
final class CDNProperties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$regex_cache | private static | array | array() | 34 |
$mappings_cache | private static | array | array() | 47 |
publicstatic should_bypass()
public static function should_bypass(): boolWhether bypass constant is active.
Return: bool.
publicstatic wildcard2regex()
public static function wildcard2regex(string $pattern): stringConvert wildcard pattern to regex fragment (LSCWP cdn.cls.php:188). Parameter Type Default Description $patternstring— Wildcard pattern.
Return: string — Regex fragment.
publicstatic get_mappings()
public static function get_mappings(array=array() $options): arrayGet normalized CDN mappings. Parameter Type Default Description $optionsarray=array()— Optional plugin options override. When empty, loads from DB.
Return: array.
privatestatic precompute_mapping()
private static function precompute_mapping($mapping): arrayPrecompute normalized mapping parts once per mapping. Parameter Type Default Description $mappingmixed— Raw mapping entry.
Return: array — Mapping with precomputed keys.
publicstatic find_cdn_for_url()
public static function find_cdn_for_url(string $url, array $mappings): ?stringResolve the CDN URL for an asset (first matching mapping). Parameter Type Default Description $urlstring— Asset URL. $mappingsarray— Normalized mappings from get_mappings().
Return: string|null — CDN URL or null when no mapping matches.
publicstatic find_cdn_match()
public static function find_cdn_match(string $url, array $mappings): ?arrayResolve the first matching CDN mapping for an asset URL. Parameter Type Default Description $urlstring— Asset URL. $mappingsarray— Normalized mappings from get_mappings().
Return: array{cdn:string,mapping:array}|null — Match info or null when no mapping matches.
privatestatic mapping_allows_attr()
private static function mapping_allows_attr(array $mapping, string $attr): boolWhether a mapping\’s `cdn_attr` restriction permits an attribute. Parameter Type Default Description $mappingarray— Mapping entry. $attrstring— Attribute name (lowercase, e.g. \’src\’, \’srcset\’).
Return: bool.
publicstatic rewrite_url()
public static function rewrite_url(string $url, mixed=null $mappings): stringRewrite single URL. Parameter Type Default Description $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.
publicstatic rewrite_srcset()
public static function rewrite_srcset(array $sources, mixed=null $mappings): arrayRewrite srcset array (wp_calculate_image_srcset format). Parameter Type Default Description $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.
publicstatic rewrite_buffer()
public static function rewrite_buffer(string $buffer): stringRewrite buffer (tags + inline url()). Parameter Type Default Description $bufferstring— HTML buffer.
Return: string.
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): ?stringRewrite the buffer\’s asset URLs via the WP 6.9+ HTML processor. Parameter Type Default Description $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).
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): voidRewrite asset URLs on the current tag of a HTML processor instance. Parameter Type Default Description $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.
publicstatic reset_cache()
public static function reset_cache(): voidReset per-request memos (for testing).
Return: void.
Hooks
Hooks referenced in includes/Edge/class-cdn.php: Hook Type Line Notes wppo_litespeed_can_cdnfilter 64 — wppo_cdn_auto_filetypesfilter 168 @param ×2 wppo_cdn_mapping_hostsfilter 186 @param ×1 wppo_cdn_mappingfilter 193 @param ×1 wppo_cdn_urlfilter 208 — wppo_cdn_auto_filetypesfilter 217 — wppo_cdn_mapping_hostsfilter 220 — wppo_cdn_mappingfilter 221 — wppo_cdn_url_for_assetfilter 401 @param ×3 wppo_litespeed_can_cdnfilter 512 — wppo_litespeed_can_cdnfilter 549 — wppo_cdn_bufferfilter 617 @param ×1