class-url.php

URL boundary — construction, comparison, normalization, and exclusion.

Source includes/Support/class-url.php6 min readPart of Performance Optimisation

includes/Support/class-url.php

URL boundary — construction, comparison, normalization, and exclusion.

Namespace: PerformanceOptimise\\Inc · Lines: 883

Class Url

Class Url

Source: includes/Support/class-url.php, line 48

final class Url

Tags: @since 2.4.0

Properties

PropertyVisibilityTypeDefaultLine
$home_url_cacheprivate staticarrayarray()56
$canonical_host_cacheprivate staticarrayarray()64
$same_site_home_hostprivate staticarrayarray()72
$exclusion_rule_cacheprivate staticarrayarray()86
$content_url_cacheprivate staticarrayarray()94

publicstatic reset_cached_home_urls()

public static function reset_cached_home_urls(): void

Resets the home_url static cache for testing isolation.

Return: void.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 108

publicstatic process_urls()

public static function process_urls($urls)

Normalize and deduplicate a list of URLs.

ParameterTypeDefaultDescription
$urlsstring|array—Raw URLs as a newline-delimited string or an array of strings.

Return: array — Cleaned list of unique, trimmed URLs with empty values removed and numeric keys reindexed.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 128

publicstatic coerce_string_list()

public static function coerce_string_list($raw): array

Coerce an untrusted string list (e.g. filter output) to a clean list.

ParameterTypeDefaultDescription
$rawmixed—Untrusted list value.

Return: string[] — Clean list.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 147

publicstatic is_url_excluded()

public static function is_url_excluded(string $url, array $exclude_urls): bool

Check whether a URL matches any of the exclusion rules.

ParameterTypeDefaultDescription
$urlstring—The URL to check.
$exclude_urlsarray—List of exclusion rules.

Return: bool — True when the URL matches any exclusion rule, false otherwise.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 184

publicstatic get_current_url()

public static function get_current_url(): string

Get the current front-end URL including scheme and host.

Return: string — Current URL.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 258

publicstatic normalize_rum_path()

public static function normalize_rum_path(string $path): string

Normalize a RUM page path for storage and lookup.

ParameterTypeDefaultDescription
$pathstring—Raw page path.

Return: string — Normalized path (e.g. \’/hero-page\’, \’/\’).

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 278

publicstatic normalize_url()

public static function normalize_url(string $url): string

Normalize a URL for LCP matching.

ParameterTypeDefaultDescription
$urlstring—The raw URL to normalize.

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

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 308

publicstatic normalize_site_url()

public static function normalize_site_url(string $url): string

Resolve a site URL to an absolute https URL.

ParameterTypeDefaultDescription
$urlstring—Raw URL.

Return: string — Absolute URL or \’\’ when empty/data:.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 348

publicstatic normalize_image_key()

public static function normalize_image_key(string $url): string

Normalize a URL to a stable image/cache key (host + path).

ParameterTypeDefaultDescription
$urlstring—Raw URL.

Return: string — Normalized key or \’\’.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 372

publicstatic cached_content_url()

public static function cached_content_url($path)

Get a content URL, cached per site per request.

ParameterTypeDefaultDescription
$pathstring—Path relative to the content directory.

Return: string — The content URL for the given path.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 397

privatestatic pin_url_scheme()

private static function pin_url_scheme(string $url): string

Rewrite a URL\’s scheme to the site\’s canonical scheme.

ParameterTypeDefaultDescription
$urlstring—URL to normalize.

Return: string — URL carrying the canonical scheme.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 431

publicstatic canonical_scheme()

public static function canonical_scheme(): string

The site\’s canonical URL scheme, independent of the current request.

Return: string — Either \’http\’ or \’https\’.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 462

publicstatic cached_home_url()

public static function cached_home_url(string=\'\' $path): string

Get the home URL, cached per site per request.

ParameterTypeDefaultDescription
$pathstring=\'\'—Optional. Path relative to the home URL. Default empty.

Return: string — The untrailingslashed home URL, with path appended if provided.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 493

publicstatic is_same_site_host()

public static function is_same_site_host(string $url): bool

Whether a URL\’s host matches the home host (case-insensitive).

ParameterTypeDefaultDescription
$urlstring—URL to check.

Return: bool — True when hosts match and home host is known.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 523

privatestatic normalize_host_for_compare()

private static function normalize_host_for_compare(string $host): string

Normalize a host for case-insensitive same-site comparison.

ParameterTypeDefaultDescription
$hoststring—Raw host value.

Return: string — Normalized host.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 555

publicstatic is_same_site_url()

public static function is_same_site_url(string $url): bool

Whether a URL is same-site and safe for server-side fetching.

ParameterTypeDefaultDescription
$urlstring—URL to check.

Return: bool — True when safe.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 585

privatestatic is_allowed_same_site_port()

private static function is_allowed_same_site_port(array $parsed): bool

Whether a parsed URL\’s port is allowed by the same-site policy.

ParameterTypeDefaultDescription
$parsedarray——

Return: bool — True when the port leg passes.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 618

privatestatic home_effective_port()

private static function home_effective_port(): ?int

Effective port of the home URL (explicit port or scheme default).

Return: int|null — Effective home port, or null when indeterminable (fail closed).

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 640

publicstatic same_site_url_or_home()

public static function same_site_url_or_home(string $url, string $fallback): string

Validate a caller-supplied URL as same-site, else the fallback.

ParameterTypeDefaultDescription
$urlstring—Caller URL (already esc_url_raw\’d by caller).
$fallbackstring—Fallback (home URL, or \’\’ to fail closed).

Return: string — Same-site URL or the fallback.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 667

publicstatic resolve_same_host_redirect()

public static function resolve_same_host_redirect(string $location, string $current_url): string|false

Resolve a redirect Location against the current URL and validate it.

ParameterTypeDefaultDescription
$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.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 697

privatestatic normalize_redirect_target()

private static function normalize_redirect_target(string $target): string

Normalize a redirect target (path + optional ?query/#fragment).

ParameterTypeDefaultDescription
$targetstring—Path with optional query/fragment suffix.

Return: string — Normalized target.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 772

privatestatic remove_dot_segments()

private static function remove_dot_segments(string $path): string

Remove RFC 3986 section 5.2.4 dot segments from a URL path.

ParameterTypeDefaultDescription
$pathstring—URL path to normalize.

Return: string — Normalized path (always starting with \’/\’).

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 800

publicstatic get_canonical_host()

public static function get_canonical_host(): string

Resolve the canonical host for cache keying from home_url().

Return: string — Canonical lowercase host, or \’\’ when it cannot be resolved.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 834

privatestatic resolve_canonical_host()

private static function resolve_canonical_host(): string

Uncached canonical-host resolution backing get_canonical_host().

Return: string — Canonical lowercase host, or \’\’ when unresolvable.

Tags: @since 2.4.0

Source: includes/Support/class-url.php, line 858