class-util.php

PerformanceOptimise Utility Class

Source includes/class-util.php41 min readPart of Performance Optimisation

includes/class-util.php

PerformanceOptimise Utility Class

Namespace: PerformanceOptimise\\Inc · Lines: 4791

Class Util

Utility class for performing various file system and resource management tasks.

Source: includes/class-util.php, line 29

class Util

Tags: @since 1.0.0

Constants

ConstantVisibilityValueLine
ALLOWED_SETTINGS_KEYSpublicSettings_Store::ALLOWED_SETTINGS_KEYS50
ALLOWED_SETTINGS_TABSpublicSettings_Store::ALLOWED_SETTINGS_TABS66
UNINSTALL_OPTIONSpublicarray( \'wppo_settings\', \'wppo_img_info\', \'wppo_transient_index\', \'wppo_preload_cron_offset\', \'wppo_last_db_cleanup\', \'wppo_version\', \'wppo_block_assets_migrated\', \'wppo_cache_last_cleared\', \'wppo_cache_last_cleared_time\', \'wppo_activation_time\', \'wppo_activity_cache_version\', \'wppo_audit_salt\', \'wppo_db_cleanup_salt\', \'wppo_activity_log_salt\', \'wppo_img_info_salt\', \'wppo_review_dismissed\', \'wppo_review_snoozed_until\', \'wppo_web_vitals_rum\', \'wppo_ai_model\', \'wppo_web_vitals_trends\', \'wppo_web_vitals_trends_lock\', \'wppo_web_vitals_last_rescan\', \'wppo_preload_cron_last_id\', \'wppo_preload_cron_migrated\', \'wppo_img_scan_cursor\', \'wppo_img_scan_cursor_max\', \'wppo_litespeed_purge_queue\', \'wppo_autoload_remediated\', \'wppo_autoload_migrated\', \'wppo_ccss_salt\', \'wppo_sysinfo_salt\', \'wppo_rum_top_url_gen\', \'wppo_remove_query_strings_deprecated_logged\', \'wppo_ai_anomaly_last_alarm\', \'wppo_object_cache_circuit\', \'wppo_object_cache_circuit_dismissed\', \'wppo_used_css_last_full_regen\', \'wppo_used_css_last_targeted_regen\', \'wppo_ccss_last_full_regen\', \'wppo_ccss_last_targeted_regen\', \'wppo_settings_snapshot\', \'wppo_preload_queue\', \'wppo_ai_css_refresh_snapshots\', \'wppo_ai_anomaly_breach_state\', \'wppo_ai_deploy_notes\', \'wppo_callback_secret\', \'wppo_last_purge\', )89
FRONT_PAGE_LCP_OPTION_PREFIXpublic\'wppo_front_page_lcp_\'151
EDITOR_PREVIEW_PARAMSpublicarray( \'elementor-preview\', \'et_fb\', \'et_pb_preview\', \'vc_action\', \'vc_editable\', \'bricks\', \'preview\', \'preview_id\', \'customize_changeset_uuid\', \'customizer\', )163
SETTINGS_SNAPSHOT_OPTIONpublic\'wppo_settings_snapshot\'202
OPTIMIZATION_PRESET_NAMESpublicarray( \'safe\', \'balanced\', \'aggressive\' )253
CALLBACK_SECRET_OPTIONpublic\'wppo_callback_secret\'2677
CSS_STORAGE_MAX_BYTESpublic10485762689

Properties

PropertyVisibilityTypeDefaultLine
$permalink_cacheprivate staticarrayarray()1213
$callback_secret_memoprivate static?stringnull2866
$html_processor_availableprivate static?boolnull4012
$committed_inline_bytesprivate staticint04551

publicstatic get_allowed_settings_keys()

public static function get_allowed_settings_keys(): array

Get the allowlisted top-level settings keys.

Return: string[].

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 183

publicstatic get_settings_snapshot()

public static function get_settings_snapshot(): ?array

Read the stored prior-settings snapshot.

Return: array|null — Snapshot array with `settings` + `taken_at` keys, or null when absent/malformed.

Tags: @since 2.2.0

Source: includes/class-util.php, line 212

publicstatic take_settings_snapshot()

public static function take_settings_snapshot(?array=null $settings): bool

Store the given settings as the one-click-undo snapshot.

ParameterTypeDefaultDescription
$settings?array=null—Settings to snapshot (defaults to the current stored settings).

Return: bool — True when the snapshot was written.

Tags: @since 2.2.0

Source: includes/class-util.php, line 228

publicstatic restore_settings_snapshot()

public static function restore_settings_snapshot(): ?array

Restore `wppo_settings` from the stored snapshot.

Return: array|null — The restored settings array, or null when no valid snapshot exists or the write failed.

Tags: @since 2.2.0

Source: includes/class-util.php, line 243

publicstatic get_preset_safety_guards()

public static function get_preset_safety_guards(): array

Fail-safe keys that presets must never turn off.

Return: array<string, — array<string, bool>> Guards keyed by tab.

Tags: @since 2.3.0

Source: includes/class-util.php, line 266

publicstatic get_optimization_presets()

public static function get_optimization_presets(): array

One-click Safe / Balanced / Aggressive preset definitions.

Return: array<string, — array<string, array<string, mixed>>> Preset name => tab => key => value.

Tags: @since 2.3.0

Source: includes/class-util.php, line 293

publicstatic get_preset_diff()

public static function get_preset_diff(string $preset, ?array=null $current): array

Diff a preset against the current settings (preview before apply).

ParameterTypeDefaultDescription
$presetstring—Preset name (safe|balanced|aggressive).
$current?array=null—Optional current settings (defaults to get_settings()).

Return: array[] — List of {tab, key, from, to} entries that would change.

Tags: @since 2.3.0

Source: includes/class-util.php, line 389

publicstatic apply_optimization_preset()

public static function apply_optimization_preset(string $preset): ?array

Apply a one-click optimization preset on top of the current settings.

ParameterTypeDefaultDescription
$presetstring—Preset name (safe|balanced|aggressive).

Return: array|null — {preset, settings, diff} on success, null on failure.

Tags: @since 2.3.0

Source: includes/class-util.php, line 459

publicstatic get_default_settings()

public static function get_default_settings(): array

Get default settings structure for fresh installs.

Return: array<string, — array<string, mixed>> Default settings keyed by tab.

Tags: @since 2.0.0 · @since NEXT Delegates canonical defaults to Settings_Store.

Source: includes/class-util.php, line 533

publicstatic get_settings_schema()

public static function get_settings_schema(): array

Canonical settings schema for verify/validation.

Return: array<string, — array<string, string>> Schema keyed by tab.

Tags: @since 2.0.0

Source: includes/class-util.php, line 555

publicstatic is_woo_safe_mode_enabled()

public static function is_woo_safe_mode_enabled(?array=null $settings): bool

Whether WooCommerce safe mode is enabled.

ParameterTypeDefaultDescription
$settings?array=null—Optional settings array (defaults to get_settings()).

Return: bool — True when safe mode is enabled.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 679

publicstatic is_woo_store_api_path()

public static function is_woo_store_api_path(string $path): bool

Whether a normalized request path is a WooCommerce Store API route.

ParameterTypeDefaultDescription
$pathstring—Request path (leading slash optional) or a `rest_route` value.

Return: bool — True when the path is a Store API route.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 699

publicstatic is_woo_store_api_request()

public static function is_woo_store_api_request(string=\'\' $path, ?string=null $query_string, ?string=null $rest_route): bool

Whether the current request targets a WooCommerce Store API route.

ParameterTypeDefaultDescription
$pathstring=\'\'—Request path (leading slash optional).
$query_string?string=null—Optional raw query string (defaults to `$_SERVER[\’QUERY_STRING\’]`).
$rest_route?string=null—Optional `rest_route` value (defaults to `$_GET[\’rest_route\’]`).

Return: bool — True when the request is a Store API request.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 718

publicstatic is_woo_dynamic_path()

public static function is_woo_dynamic_path(string $path): bool

Whether a request path belongs to a WooCommerce dynamic page.

ParameterTypeDefaultDescription
$pathstring—Request path (leading slash optional).

Return: bool — True when the path is Woo-dynamic.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 738

publicstatic get_woo_excluded_paths()

public static function get_woo_excluded_paths(): array

Relative paths treated as WooCommerce endpoints for static-cache bypass.

Return: string[] — Relative paths (e.g. `cart`, `shop/basket`), unique, lowercased.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 759

publicstatic is_woo_active()

public static function is_woo_active(): bool

Whether WooCommerce is active on the current site.

Return: bool — True when any WooCommerce symbol is available.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 775

publicstatic is_woo_faceted_query()

public static function is_woo_faceted_query(?string=null $query_string): bool

Whether a query string carries WooCommerce layered-nav / faceted-filter params.

ParameterTypeDefaultDescription
$query_string?string=null—Raw query string. Defaults to `$_SERVER[\’QUERY_STRING\’]`.

Return: bool — True when faceted params are present.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 796

publicstatic is_admin_path()

public static function is_admin_path(string $path): bool

Whether a request path targets a wp-admin / login / AJAX entry point.

ParameterTypeDefaultDescription
$pathstring—Request path (leading slash optional).

Return: bool — True when the path is an admin entry point.

Tags: @since 2.2.0

Source: includes/class-util.php, line 812

publicstatic is_editor_preview_path()

public static function is_editor_preview_path(string=\'\' $path, string=\'\' $query_string, string=\'\' $rest_route): bool

Whether path/query values indicate a builder or core preview context.

ParameterTypeDefaultDescription
$pathstring=\'\'—Request path (leading slash optional).
$query_stringstring=\'\'—Raw query string (without leading `?`).
$rest_routestring=\'\'—Optional `rest_route` value (plain permalinks).

Return: bool — True when the values indicate a preview context.

Tags: @since 2.2.0

Source: includes/class-util.php, line 842

publicstatic is_woo_ajax_request()

public static function is_woo_ajax_request(string=\'\' $path, string=\'\' $query_string): bool

Whether path/query values indicate a WooCommerce AJAX endpoint.

ParameterTypeDefaultDescription
$pathstring=\'\'—Request path (leading slash optional).
$query_stringstring=\'\'—Raw query string (without leading `?`).

Return: bool — True when the values indicate a wc-ajax request.

Tags: @since 2.3.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 909

publicstatic is_woo_add_to_cart_request()

public static function is_woo_add_to_cart_request(string=\'\' $query_string): bool

Whether a query string carries a WooCommerce add-to-cart action.

ParameterTypeDefaultDescription
$query_stringstring=\'\'—Raw query string (without leading `?`).

Return: bool — True when the query carries an add-to-cart action.

Tags: @since 2.3.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 929

publicstatic is_woo_excluded_url()

public static function is_woo_excluded_url(string $url, string=\'\' $query, string=\'\' $rest_route): bool

Whether an absolute URL targets a WooCommerce dynamic route.

ParameterTypeDefaultDescription
$urlstring—Absolute URL.
$querystring=\'\'—Optional pre-parsed query string (parsed from $url when \’\’).
$rest_routestring=\'\'—Optional pre-parsed rest_route value.

Return: bool — True when the URL must not be cached/preloaded.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 950

publicstatic is_editor_preview_url()

public static function is_editor_preview_url(string $url): bool

Whether an absolute URL targets an admin or preview context.

ParameterTypeDefaultDescription
$urlstring—Absolute URL.

Return: bool — True when the URL must bypass cache/preload.

Tags: @since 2.2.0

Source: includes/class-util.php, line 966

publicstatic is_editor_preview_request()

public static function is_editor_preview_request(): bool

Whether the current request is an admin, AJAX/REST, or preview context.

Return: bool — True when the current request must bypass the cache.

Tags: @since 2.2.0

Source: includes/class-util.php, line 1011

publicstatic woo_cache_self_test()

public static function woo_cache_self_test(): array

Verifiable WooCommerce cart/checkout cache-exclusion self-test.

Return: array{woo_active: — bool, safe_mode: bool, runnable: bool, excluded_paths: string[], donotcachepage_honored: bool, checks: array<int, array{url: string, path: string, is_dynamic: bool, cacheable: bool, donotcachepage_honored: bool, pass: bool, error?: string}>, fragment_checks: array<int, array{url: string, path: string, is_dynamic: bool, cacheable: bool, donotcachepage_honored: bool, pass: bool, error?: string}>, editor_checks: array<int, array{url: string, bypass: bool, cacheable: bool, donotcachepage_honored: bool, pass: bool, error?: string}>, preload_checks: array<int, array{url: string, path: string, skipped: bool, pass: bool, error?: string}>, cart_checks: array<int, array{key: string, url: string, bypass: bool, cacheable: bool, donotcachepage_honored: bool, pass: bool, error?: string}>, force_exclude: bool, all_pass: bool} Structured self-test result.

Tags: @since 2.0.0 · @since 2.2.0 Added additive `editor_checks` (wp-admin + builder/core preview bypass probes). · @since 2.2.0 Added additive `fragment_checks` (wc-ajax / add-to-cart / plain-permalink Store API fragment probes, issue #1197). · @since 2.2.0 Added additive `preload_checks` (faceted-URL preload-skip probes), `cart_checks` (guest-cart survival probes) and `force_exclude` (fail-closed recommendation, issue #1256). · @since 2.4.0 Facade proxy delegating to Woo_Detect (REF-013).

Source: includes/class-util.php, line 1164

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.0.0

Source: includes/class-util.php, line 1177

publicstatic reset_runtime_caches()

public static function reset_runtime_caches(): void

Resets all Util runtime memos (test-isolation entry point).

Return: void.

Tags: @since 2.2.0

Source: includes/class-util.php, line 1192

public static function memoized_permalink(int $post_id): string

Get a permalink through the per-request memo.

ParameterTypeDefaultDescription
$post_idint—Post ID.

Return: string — Permalink, or \’\’ when unavailable (false from get_permalink()).

Tags: @since 2.0.0

Source: includes/class-util.php, line 1226

public static function clear_permalink_cache(): void

Clear the per-request permalink memo (testing isolation, switch_blog).

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1241

privatestatic current_blog_id()

private static function current_blog_id(): int

Resolve current blog ID safely (handles Brain Monkey stub mis-configuration in tests).

Return: int — Blog ID.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1253

publicstatic get_settings()

public static function get_settings(): array

Get wppo_settings with per-request memoization.

Return: array — The plugin settings.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1278

publicstatic set_settings_cache()

public static function set_settings_cache(array $settings): void

Set the settings cache to a known value (e.g. after update_option in same request).

ParameterTypeDefaultDescription
$settingsarray—The settings to cache.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1292

publicstatic save_settings()

public static function save_settings(array $settings): bool

Persist wppo_settings with autoload disabled (audit #1325).

ParameterTypeDefaultDescription
$settingsarray—Settings array to store.

Return: bool — True on success (mirrors update_option()).

Tags: @since 2.2.0

Source: includes/class-util.php, line 1310

publicstatic clear_settings_cache()

public static function clear_settings_cache(=null $blog_id): void

Clear the settings memo (e.g. in tests or on delete).

ParameterTypeDefaultDescription
$blog_id=null—Optional blog ID to clear. Null clears all.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1332

publicstatic on_switch_blog()

public static function on_switch_blog($new_blog_id, $prev_blog_id): void

Handler for switch_blog — clears stale memo association.

ParameterTypeDefaultDescription
$new_blog_idint—New blog ID.
$prev_blog_idint—Previous blog ID.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1350

publicstatic register_settings_cache_hooks()

public static function register_settings_cache_hooks(): void

Register the settings-cache invalidation hooks eagerly.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1380

privatestatic ensure_settings_cache_hook()

private static function ensure_settings_cache_hook(): void

Ensure the invalidation hooks for wppo_settings are registered once per request.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1395

publicstatic on_settings_update()

public static function on_settings_update($old_value, $value): void

Invalidate/update the memo when wppo_settings is updated.

ParameterTypeDefaultDescription
$old_valuemixed—Previous value.
$valuemixed—New value.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1415

publicstatic on_settings_add()

public static function on_settings_add($option, $value): void

Populate the memo when wppo_settings is added.

ParameterTypeDefaultDescription
$optionstring—Option name.
$valuemixed—Option value.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1429

publicstatic prepare_cache_dir()

public static function prepare_cache_dir($cache_dir): bool

Recursively creates cache directory if not exists.

ParameterTypeDefaultDescription
$cache_dirstring—Path to the cache directory.

Return: bool — True if created or exists, false otherwise.

Tags: @since 1.0.0

Source: includes/class-util.php, line 1442

publicstatic init_filesystem()

public static function init_filesystem()

Initializes the WP_Filesystem API.

Return: mixed — WP_Filesystem_Base|false The filesystem object or false on failure.

Tags: @since 1.0.0

Source: includes/class-util.php, line 1454

publicstatic get_local_path()

public static function get_local_path(string $url): string

Gets the local file path from a URL.

ParameterTypeDefaultDescription
$urlstring—The URL to process.

Return: string — The local file path.

Tags: @since 1.0.0

Source: includes/class-util.php, line 1467

publicstatic get_minify_allowed_roots()

public static function get_minify_allowed_roots(): array

Gets the allow-listed filesystem roots for minify/combine file serving.

Return: string[] — Normalized absolute root paths.

Tags: @since 2.2.0

Source: includes/class-util.php, line 1485

publicstatic is_minify_path_allowed()

public static function is_minify_path_allowed($path): bool

Whether a minify/combine source path is allowed to be read.

ParameterTypeDefaultDescription
$pathmixed—Candidate filesystem path.

Return: bool — True when the path resolves inside an allowed root.

Tags: @since 2.2.0

Source: includes/class-util.php, line 1509

publicstatic validate_minify_path()

public static function validate_minify_path($path): string

Validates a minify/combine source path and returns its resolved form.

ParameterTypeDefaultDescription
$pathmixed—Candidate filesystem path.

Return: string — Resolved allowed path, or \’\’ when rejected.

Tags: @since 2.2.0

Source: includes/class-util.php, line 1525

publicstatic get_js_css_minified_file()

public static function get_js_css_minified_file()

Gets the number of minified JS and CSS files.

Return: array — Associative array with counts for JS and CSS files.

Tags: @since 1.0.0

Source: includes/class-util.php, line 1537

publicstatic get_image_mime_type()

public static function get_image_mime_type($url)

Gets MIME type based on image URL extension.

ParameterTypeDefaultDescription
$urlstring—The image URL.

Return: string — The MIME type.

Tags: @since 1.0.0

Source: includes/class-util.php, line 1548

public static function generate_preload_link($href, $rel, =\'\' $resource_type, =false $crossorigin, =\'\' $type, =\'\' $media, =\'\' $fetchpriority, =\'\' $imagesrcset, =\'\' $imagesizes)

Generates a preload link tag for resources.

ParameterTypeDefaultDescription
$hrefstring—The resource URL.
$relstring—The relationship attribute.
$resource_type=\'\'—The type of the resource (optional).
$crossorigin=false—If the resource should be crossorigin (optional).
$type=\'\'—The type attribute (optional).
$media=\'\'—The media attribute (optional).
$fetchpriority=\'\'—The fetchpriority attribute (optional).
$imagesrcset=\'\'—Responsive srcset for image preloads (optional).
$imagesizes=\'\'—Responsive sizes for image preloads (optional).

Tags: @since 1.0.0 · @since 2.0.0 Echoes only in front-end HTML contexts; returns the tag and delegates building to get_preload_link(). · @since 2.2.0 Adds $imagesrcset/$imagesizes for LCP image preloads.

Source: includes/class-util.php, line 1609

public static function get_preload_link($href, $rel, =\'\' $resource_type, =false $crossorigin, =\'\' $type, =\'\' $media, =\'\' $fetchpriority, =\'\' $imagesrcset, =\'\' $imagesizes): string

Build a sanitized preload <link> tag and return it.

ParameterTypeDefaultDescription
$hrefstring—The resource URL.
$relstring—The relationship attribute.
$resource_type=\'\'—The type of the resource (optional).
$crossorigin=false—If the resource should be crossorigin (optional).
$type=\'\'—The type attribute (optional).
$media=\'\'—The media attribute (optional).
$fetchpriority=\'\'—The fetchpriority attribute (optional).
$imagesrcset=\'\'—Responsive srcset for image preloads (optional).
$imagesizes=\'\'—Responsive sizes for image preloads (optional).

Return: string — The sanitized `<link …>` tag.

Tags: @since 2.0.0 · @since 2.2.0 Adds $imagesrcset/$imagesizes for LCP image preloads.

Source: includes/class-util.php, line 1652

public static function get_preload_link_args(string $href, array=array() $args): string

Build a sanitized preload <link> tag from an args array.

ParameterTypeDefaultDescription
$hrefstring—Resource URL.
$argsarray=array()—Optional args: rel, as, crossorigin, type, media, fetchpriority, imagesrcset, imagesizes.

Return: string — Sanitized `<link …>` tag.

Tags: @since 2.2.0

Source: includes/class-util.php, line 1721

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 1.0.0

Source: includes/class-util.php, line 1745

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.2.0

Source: includes/class-util.php, line 1763

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.0.0

Source: includes/class-util.php, line 1784

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.0.0

Source: includes/class-util.php, line 1800

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.0.0

Source: includes/class-util.php, line 1820

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.0.0

Source: includes/class-util.php, line 1839

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.2.0

Source: includes/class-util.php, line 1856

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.2.0

Source: includes/class-util.php, line 1872

publicstatic mint_placeholder_namespace()

public static function mint_placeholder_namespace(): string

Mint a per-request placeholder token namespace.

Return: string — Non-empty namespace string.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1892

publicstatic min_cache_base_dir()

public static function min_cache_base_dir(): string

Base (shared) minify cache directory.

Return: string — Normalized absolute path to the shared min cache root.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1936

publicstatic min_cache_dir()

public static function min_cache_dir(string=\'\' $subdir): string

Get the current site\’s blog-scoped minify cache directory.

ParameterTypeDefaultDescription
$subdirstring=\'\'—Optional \’css\’ or \’js\’ subdirectory.

Return: string — Normalized absolute path to the site-scoped min cache dir.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1953

publicstatic min_cache_url()

public static function min_cache_url(string=\'\' $subdir, string=\'\' $filename): string

Get the content URL for a file in the current site\’s min cache dir.

ParameterTypeDefaultDescription
$subdirstring=\'\'—Optional \’css\’ or \’js\’ subdirectory.
$filenamestring=\'\'—Optional file name appended to the URL.

Return: string — The blog-scoped content URL.

Tags: @since 2.0.0

Source: includes/class-util.php, line 1969

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.0.0

Source: includes/class-util.php, line 2003

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.2.0

Source: includes/class-util.php, line 2027

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.0.0

Source: includes/class-util.php, line 2045

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.2.0

Source: includes/class-util.php, line 2063

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.2.0

Source: includes/class-util.php, line 2091

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.2.0

Source: includes/class-util.php, line 2105

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.3.0

Source: includes/class-util.php, line 2132

publicstatic normalize_cache_host()

public static function normalize_cache_host(string $raw_host): string

Normalize a raw host value into a safe cache-key domain.

ParameterTypeDefaultDescription
$raw_hoststring—Raw host value (e.g. $_SERVER[\’HTTP_HOST\’] or a home_url() host).

Return: string — Normalized lowercase host, or \’\’ when invalid.

Tags: @since 2.0.0

Source: includes/class-util.php, line 2151

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.0.0

Source: includes/class-util.php, line 2171

publicstatic sanitize_cache_url_path()

public static function sanitize_cache_url_path(?string $url_path, ?string=null $allowed_host): string

Sanitize a URL path for cache file mapping.

ParameterTypeDefaultDescription
$url_path?string—Raw URL path or URL.
$allowed_host?string=null—Optional canonical host (alias: $domain / $canonical_host at call-sites); same-host absolute URLs map to their path, others refuse.

Return: string — Sanitized relative path or empty string.

Tags: @since 2.0.0 · @since 2.2.0 Added the optional $allowed_host foreign-host refusal.

Source: includes/class-util.php, line 2208

publicstatic get_cache_query_allowlist()

public static function get_cache_query_allowlist(): array

Filterable list of cache-neutral (tracking/marketing) query params.

Return: string[] — Lowercase cache-neutral query param names.

Tags: @since 2.2.0

Source: includes/class-util.php, line 2233

publicstatic has_uncacheable_query()

public static function has_uncacheable_query(?string=null $query_string): bool

Whether a query string forces a dynamic (uncached) response.

ParameterTypeDefaultDescription
$query_string?string=null—Raw query string. Defaults to `$_SERVER[\’QUERY_STRING\’]`.

Return: bool — True when the request must bypass the cache.

Tags: @since 2.2.0

Source: includes/class-util.php, line 2314

publicstatic is_cache_path_contained()

public static function is_cache_path_contained(string $cache_root_dir, string $domain, string $path): bool

Whether an absolute path stays inside the cache tree.

ParameterTypeDefaultDescription
$cache_root_dirstring—Absolute cache root directory.
$domainstring—Canonical domain directory segment.
$pathstring—Absolute file or directory path to check.

Return: bool — True when contained.

Tags: @since 2.0.0

Source: includes/class-util.php, line 2398

publicstatic is_realpath_contained()

public static function is_realpath_contained(string $cache_root_dir, string $domain, string $path): bool

Symlink-aware containment check for cache write targets.

ParameterTypeDefaultDescription
$cache_root_dirstring—Absolute cache root directory.
$domainstring—Canonical domain directory segment.
$pathstring—Absolute file or directory path to check.

Return: bool — True when contained.

Tags: @since 2.2.0

Source: includes/class-util.php, line 2444

publicstatic resolve_realpath()

public static function resolve_realpath(string $lexical_path): ?string

Resolve a path via realpath(), keeping the lexical remainder.

ParameterTypeDefaultDescription
$lexical_pathstring—Normalized absolute path to resolve.

Return: string|null — Resolved absolute path, or null when unresolvable.

Tags: @since 2.2.0

Source: includes/class-util.php, line 2467

publicstatic validate_cache_write_path()

public static function validate_cache_write_path(string $cache_root_dir, string $domain, string $path): bool

Single-call validator for absolute cache write targets.

ParameterTypeDefaultDescription
$cache_root_dirstring—Absolute cache root directory.
$domainstring—Canonical domain directory segment.
$pathstring—Absolute file path to validate.

Return: bool — True when the target may be written.

Tags: @since 2.2.0

Source: includes/class-util.php, line 2490

publicstatic is_htaccess_path_allowed()

public static function is_htaccess_path_allowed(string $htaccess_file): bool

Whether an .htaccess target may be written by the plugin.

ParameterTypeDefaultDescription
$htaccess_filestring—Absolute .htaccess path candidate.

Return: bool — True when the target may be written.

Tags: @since 2.2.0

Source: includes/class-util.php, line 2513

publicstatic sanitize_cache_path()

public static function sanitize_cache_path(string $cache_root_dir, string $domain, $url_path_or_url, string $filename): string

Build a contained absolute cache file path from its parts.

ParameterTypeDefaultDescription
$cache_root_dirstring—Absolute cache root directory.
$domainstring—Canonical domain directory segment.
$url_path_or_urlstring|null—Raw URL path or URL.
$filenamestring—File name (e.g. `index.html`).

Return: string — Contained absolute path, or \’\’ when refused.

Tags: @since 2.0.0

Source: includes/class-util.php, line 2546

publicstatic atomic_tmp_path()

public static function atomic_tmp_path(string $final_path): string

Build a unique sibling tmp path for atomic writes.

ParameterTypeDefaultDescription
$final_pathstring—Final file path the tmp sits beside.

Return: string — Tmp sibling path (\’\’ when input is empty).

Tags: @since 2.0.0

Source: includes/class-util.php, line 2563

publicstatic atomic_file_put_contents()

public static function atomic_file_put_contents($fs, string $path, string $contents): bool

Atomically write contents via tmp-file + rename.

ParameterTypeDefaultDescription
$fsmixed—Filesystem object exposing put_contents()/move()/delete().
$pathstring—Final file path.
$contentsstring—File contents.

Return: bool — True on success.

Tags: @since 2.0.0

Source: includes/class-util.php, line 2584

publicstatic verify_php_syntax()

public static function verify_php_syntax(string $code, string=\'\' $tmp_file_for_lint): bool

Check that PHP code parses without a syntax error.

ParameterTypeDefaultDescription
$codestring—PHP source to check.
$tmp_file_for_lintstring=\'\'—Optional tmp file holding $code for `php -l`.

Return: bool — True when the code looks parseable.

Tags: @since 2.0.0 · @since 2.3.0 Added the `wppo_allow_php_lint` filter gate for the `php -l` layer.

Source: includes/class-util.php, line 2610

publicstatic atomic_write_php_verified()

public static function atomic_write_php_verified($fs, string $path, string $contents, =null $expect): ?bool

Atomically write PHP source with syntax verification and rollback.

ParameterTypeDefaultDescription
$fsmixed—Filesystem object exposing exists()/get_contents()/put_contents()/move()/copy()/delete().
$pathstring—Final file path.
$contentsstring—New file contents.
$expect=null—Optional assertion receiving contents, returning bool.

Return: bool|null — True on verified success, false on verified failure, null when unsupported.

Tags: @since 2.0.0

Source: includes/class-util.php, line 2640

publicstatic compute_css_checksum()

public static function compute_css_checksum(string $css): string

Stable content hash of CSS source (issue #1038 / audit #7).

ParameterTypeDefaultDescription
$cssstring—CSS content.

Return: string — SHA-256 checksum, or \’\’ for empty input.

Tags: @since 2.0.0

Source: includes/class-util.php, line 2659

publicstatic sanitize_css_for_storage()

public static function sanitize_css_for_storage(string $css): string

Sanitize derived CSS for safe storage inside <style> or a .css file.

ParameterTypeDefaultDescription
$cssstring—Raw CSS content.

Return: string — Sanitized CSS, or \’\’ when empty or on failure.

Tags: @since 2.3.0

Source: includes/class-util.php, line 2721

publicstatic css_within_storage_bounds()

public static function css_within_storage_bounds(string $css, int=self::CSS_STORAGE_MAX_BYTES $max_bytes): bool

Whether derived CSS is within the size/charset storage bounds.

ParameterTypeDefaultDescription
$cssstring—CSS content.
$max_bytesint=self::CSS_STORAGE_MAX_BYTES—Maximum accepted size in bytes.

Return: bool — True when the payload may be stored.

Tags: @since 2.3.0

Source: includes/class-util.php, line 2842

publicstatic reset_callback_secret_memo()

public static function reset_callback_secret_memo(): void

Reset the per-request callback-secret memo (tests, switch_blog).

Return: void.

Tags: @since 2.3.0

Source: includes/class-util.php, line 2874

publicstatic get_callback_secret()

public static function get_callback_secret(bool=true $create): string

Read (or lazily create) the per-site callback HMAC secret.

ParameterTypeDefaultDescription
$createbool=true—Whether a missing secret may be created. Verify paths pass false (read-only) so a background worker never writes options on the hot verify path.

Return: string — Site secret, or \’\’ when unavailable.

Tags: @since 2.3.0

Source: includes/class-util.php, line 2898

publicstatic sign_callback_payload()

public static function sign_callback_payload(array $payload): string

Sign a regeneration-callback payload with the site secret.

ParameterTypeDefaultDescription
$payloadarray—Job payload (scalar values).

Return: string — Hex signature, or \’\’ when unavailable.

Tags: @since 2.3.0

Source: includes/class-util.php, line 2972

publicstatic verify_callback_signature()

public static function verify_callback_signature(array $payload, string $signature): bool

Verify a regeneration-callback payload signature.

ParameterTypeDefaultDescription
$payloadarray—Job payload as signed.
$signaturestring—Hex signature to check.

Return: bool — True when the signature is valid.

Tags: @since 2.3.0

Source: includes/class-util.php, line 3011

publicstatic supports_script_strategy()

public static function supports_script_strategy(): bool

Whether core supports the native `strategy` script args (WP 6.3+).

Return: bool — True on WP 6.3+.

Tags: @since 2.2.0

Source: includes/class-util.php, line 3050

publicstatic transient_key()

public static function transient_key(string $key): string

Qualify a transient key with the current blog ID on multisite.

ParameterTypeDefaultDescription
$keystring—The bare transient key.

Return: string — Blog-ID-prefixed key on multisite, or the original key.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3069

publicstatic option_key()

public static function option_key(string $key): string

Qualify an option name with the current blog ID on multisite.

ParameterTypeDefaultDescription
$keystring—The bare option name.

Return: string — Blog-ID-prefixed option name on multisite, or the original name.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3088

publicstatic supports_action_scheduler_unique()

public static function supports_action_scheduler_unique(): bool

Whether the loaded Action Scheduler supports atomic unique actions.

Return: bool — True when the `$unique` parameter may be passed.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3113

publicstatic reset_action_scheduler_unique_cache()

public static function reset_action_scheduler_unique_cache(): void

Reset the memoized Action Scheduler unique-support probes.

Return: void.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3130

publicstatic enqueue_unique_async_action()

public static function enqueue_unique_async_action(string $hook, array=array() $args, string=\'\' $group, array=array() $extra_groups): int

Enqueue an async Action Scheduler job with atomic dedup when available.

ParameterTypeDefaultDescription
$hookstring—Action hook.
$argsarray=array()—Action arguments.
$groupstring=\'\'—Action group.
$extra_groupsarray=array()—Additional groups probed by the legacy fallback guard (e.g. the CCSS legacy group).

Return: int — Action ID, or 0 when deduped, unavailable, or on failure.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3153

publicstatic schedule_unique_single_action()

public static function schedule_unique_single_action(int $timestamp, string $hook, array=array() $args, string=\'\' $group, array=array() $extra_groups): int

Schedule a one-off Action Scheduler job with atomic dedup when available.

ParameterTypeDefaultDescription
$timestampint—When the job will run.
$hookstring—Action hook.
$argsarray=array()—Action arguments.
$groupstring=\'\'—Action group.
$extra_groupsarray=array()—Additional groups probed by the legacy fallback guard (e.g. the CCSS legacy group).

Return: int — Action ID, or 0 when deduped, unavailable, or on failure.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3174

publicstatic is_stampede_guard_enabled()

public static function is_stampede_guard_enabled(): bool

Whether the stampede guard is enabled.

Return: bool — True when coalescing is active.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3192

publicstatic stampede_lock_ttl()

public static function stampede_lock_ttl(): int

Effective stampede lock TTL in seconds, clamped to 2-5s.

Return: int — Lock TTL clamped to 2-5 seconds.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3212

publicstatic generate_stampede_owner()

public static function generate_stampede_owner(): string

Generate a unique stampede lock owner token.

Return: string — Unique owner token (never empty).

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3228

publicstatic acquire_stampede_lock()

public static function acquire_stampede_lock(string $lock_key, string $owner, int=5 $ttl, string=\'wppo\' $group): bool

Atomically acquire a named stampede lock.

ParameterTypeDefaultDescription
$lock_keystring—Blog-aware lock key (use transient_key()).
$ownerstring—Unique owner token from generate_stampede_owner().
$ttlint=5—Lock TTL in seconds (clamped to 2-5s; best-effort bound — rebuilds slower than the TTL, e.g. a slow- origin telemetry fetch, may let the lock expire mid-rebuild and duplicate work).
$groupstring=\'wppo\'—Object-cache group for the lock.

Return: bool — True when this worker owns the lock.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3259

publicstatic release_stampede_lock()

public static function release_stampede_lock(string $lock_key, string $owner, string=\'wppo\' $group): void

Release a stampede lock only when this worker still owns it.

ParameterTypeDefaultDescription
$lock_keystring—Blog-aware lock key.
$ownerstring—Owner token that acquired the lock.
$groupstring=\'wppo\'—Object-cache group for the lock.

Return: void.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Scheduler (REF-014).

Source: includes/class-util.php, line 3278

publicstatic stampede_stale_key()

public static function stampede_stale_key(string $key): string

Derive the stale-copy transient key for a guarded value key.

ParameterTypeDefaultDescription
$keystring—Value cache key as passed to get_with_stampede_lock().

Return: string — Stale-copy key.

Tags: @since 2.2.0

Source: includes/class-util.php, line 3298

publicstatic register_transient_index_key()

public static function register_transient_index_key(string $key, int $ttl): void

Best-effort registration of a stale-copy key in `wppo_transient_index`.

ParameterTypeDefaultDescription
$keystring—Stale-copy transient key.
$ttlint—Stale TTL in seconds (converted to an absolute expiry).

Return: void.

Tags: @since 2.2.0

Source: includes/class-util.php, line 3321

publicstatic get_with_stampede_lock()

public static function get_with_stampede_lock(string $key, callable $rebuild, array=array() $args): mixed

Get a cached value or rebuild it under an atomic owner lock.

ParameterTypeDefaultDescription
$keystring—Value cache key as read/written by $args get/set (caller-qualified).
$rebuildcallable—Zero-arg rebuild callback. Returning false or WP_Error means \”not cacheable\” (stale served when available).
$argsarray=array()—Optional arguments accepting `ttl`, `stale_ttl`, `lock_ttl`, `retries`, `retry_delay_us`, `group`, `force`, `get_cached`, and `set_cached` keys.

Return: mixed — Fresh value, stale fallback, rebuild result, or false on total miss failure.

Tags: @since 2.2.0

Source: includes/class-util.php, line 3382

publicstatic get_alloptions_with_stampede_lock()

public static function get_alloptions_with_stampede_lock(callable $rebuild, array=array() $args): mixed

Coalesce concurrent alloptions loads behind a stampede lock.

ParameterTypeDefaultDescription
$rebuildcallable—Zero-arg rebuild callback performing the single database query. Returning false or WP_Error means \”not cacheable\” (stale served when available).
$argsarray=array()—Optional overrides for `ttl`, `stale_ttl`, `lock_ttl`, `retries`, `retry_delay_us`, and `group` (see get_with_stampede_lock()).

Return: mixed — Fresh value, stale fallback, rebuild result, or false on total miss failure.

Tags: @since 2.3.0

Source: includes/class-util.php, line 3600

publicstatic get_role_hash()

public static function get_role_hash(\\WP_User $user): string

Compute a stable 12-char hex hash of a user\’s sorted roles, salted with the site\’s secret to prevent cookie forgery.

ParameterTypeDefaultDescription
$user\\WP_User—The user whose roles to hash.

Return: string — 12-char hex hash, or empty string if the user has no roles.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3635

publicstatic is_cache_eligible_for_current_user()

public static function is_cache_eligible_for_current_user(array $cache_settings): bool

Whether the current user is eligible for logged-in caching based on the cache settings (enableLoggedInCache + loggedInCacheRoles).

ParameterTypeDefaultDescription
$cache_settingsarray—The cache_settings sub-array from wppo_settings.

Return: bool — True if the current user may receive cached pages / optimisations.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3654

publicstatic is_auto_sizes_available()

public static function is_auto_sizes_available(): bool

Whether the current WordPress version supports auto-sizes for lazy-loaded images.

Return: bool — True when auto-sizes is available.

Tags: @since 1.9.0

Source: includes/class-util.php, line 3691

publicstatic content_has_block()

public static function content_has_block(string $content, string $block_name): bool

Whether content contains a block type via streaming processor.

ParameterTypeDefaultDescription
$contentstring—Post content.
$block_namestring—Block name e.g. \’core/image\’.

Return: bool — True when the block type is present.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3709

publicstatic count_blocks_by_type()

public static function count_blocks_by_type(string $content, string $block_name): int

Count blocks of a given type in post content.

ParameterTypeDefaultDescription
$contentstring—Post content.
$block_namestring—Block name e.g. \’core/gallery\’.

Return: int — Number of matching blocks.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3747

privatestatic blocks_contain_type()

private static function blocks_contain_type(array $blocks, string $block_name): bool

Whether a parsed block tree contains a block type (recursive).

ParameterTypeDefaultDescription
$blocksarray—Parsed blocks from parse_blocks().
$block_namestring—Block name.

Return: bool.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3781

privatestatic count_blocks_recursive()

private static function count_blocks_recursive(array $blocks, string $block_name): int

Count blocks of type in a parsed block tree (recursive).

ParameterTypeDefaultDescription
$blocksarray—Parsed blocks.
$block_namestring—Block name.

Return: int.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3803

publicstatic wildcard2regex()

public static function wildcard2regex(string $pattern): string

Convert wildcard pattern to regex fragment (mirrors CDN::wildcard2regex / LSCWP cdn.cls.php:188).

ParameterTypeDefaultDescription
$patternstring—Wildcard pattern.

Return: string — Regex fragment.

Tags: @since 2.0.0

Source: includes/class-util.php, line 3823

publicstatic sanitize_mode_value()

public static function sanitize_mode_value($value): string

Sanitize the LiteSpeed integration `mode` value against its allowlist.

ParameterTypeDefaultDescription
$valuemixed—Raw value.

Return: string — Allowlisted mode (\’auto\’ fallback).

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3846

publicstatic sanitize_ttl_overrides()

public static function sanitize_ttl_overrides($value): array

Sanitize per-post-type cache TTL overrides.

ParameterTypeDefaultDescription
$valuearray—Raw overrides.

Return: array — Sanitized overrides.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3860

publicstatic sanitize_cdn_mapping()

public static function sanitize_cdn_mapping($value): array

Sanitize the one-to-many CDN mapping list.

ParameterTypeDefaultDescription
$valuearray—Raw mapping entries.

Return: array — Sanitized mapping.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3874

publicstatic sanitize_scalar_setting()

public static function sanitize_scalar_setting(string $safe_key, $value)

Sanitize a scalar settings value with the generic fallback rules.

ParameterTypeDefaultDescription
$safe_keystring—Sanitized key.
$valuemixed—Raw value.

Return: mixed — Sanitized value.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3891

publicstatic get_settings_sanitizer_map()

public static function get_settings_sanitizer_map(): array

Map of setting-tab slugs to their dedicated sanitizer methods.

Return: array<string,string> — Tab slug => sanitizer method name.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3910

publicstatic sanitize_cache_settings()

public static function sanitize_cache_settings($settings): array

Sanitize the `cache_settings` tab.

ParameterTypeDefaultDescription
$settingsarray—Raw tab settings.

Return: array — Sanitized tab settings.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3926

publicstatic sanitize_file_optimisation()

public static function sanitize_file_optimisation($settings): array

Sanitize the `file_optimisation` tab.

ParameterTypeDefaultDescription
$settingsarray—Raw tab settings.

Return: array — Sanitized tab settings.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3942

publicstatic sanitize_settings_recursively()

public static function sanitize_settings_recursively($settings)

Sanitizes the settings array recursively.

ParameterTypeDefaultDescription
$settingsarray—The settings array.

Return: array — The sanitized settings array.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Settings_Store (REF-011).

Source: includes/class-util.php, line 3958

publicstatic remove_sensitive_settings_from_response()

public static function remove_sensitive_settings_from_response(array& $settings): void

Strips sensitive values from a settings array before it leaves the server.

ParameterTypeDefaultDescription
$settingsarray&—The settings array passed by reference.

Return: void.

Tags: @since 2.4.0

Source: includes/class-util.php, line 3973

publicstatic cache_salt()

public static function cache_salt(string $option): string

Current value of a salted-cache salt (option-backed).

ParameterTypeDefaultDescription
$optionstring—Option key holding the salt.

Return: string — Current salt value (\’0\’ until the first bump).

Tags: @since 2.0.0

Source: includes/class-util.php, line 3999

publicstatic should_use_html_processor()

public static function should_use_html_processor(): bool

Whether the WP 6.9+ HTML API token serializer is available.

Return: bool — True when `WP_HTML_Processor::serialize_token()` is public.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4027

publicstatic reset_html_processor_memo()

public static function reset_html_processor_memo(): void

Reset the memoized HTML-processor availability probe.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4054

publicstatic create_html_processor()

public static function create_html_processor(string $html): ?\\WP_HTML_Processor

Create a WP_HTML_Processor for full-buffer rewrites.

ParameterTypeDefaultDescription
$htmlstring—HTML document or fragment.

Return: \\WP_HTML_Processor|null — Processor instance, or null on failure.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4077

publicstatic safe_css_fallback_enabled()

public static function safe_css_fallback_enabled(): bool

Whether the safe CSS combine/used-CSS fallback is enabled.

Return: bool — True when fallback guards are active.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4111

publicstatic is_purge_fallback_enabled()

public static function is_purge_fallback_enabled(): bool

Whether the post-purge last-good fallback is enabled.

Return: bool — True when purge-fallback retention/serving is active.

Tags: @since 2.2.0

Source: includes/class-util.php, line 4141

publicstatic get_purge_fallback_path_for()

public static function get_purge_fallback_path_for(string $file_path): string

Map a derived asset path to its sibling last-good fallback path.

ParameterTypeDefaultDescription
$file_pathstring—Absolute derived-asset path.

Return: string — Sibling fallback path, or \’\’ when not applicable.

Tags: @since 2.2.0

Source: includes/class-util.php, line 4166

publicstatic retain_purge_fallback_file()

public static function retain_purge_fallback_file($fs, callable $is_allowed, string $file_path): void

Retain a last-good fallback copy before a derived file is purged.

ParameterTypeDefaultDescription
$fsobject—Filesystem exposing exists()/size()/copy()/get_contents()/put_contents().
$is_allowedcallable—Containment validator: fn( string $path ): bool.
$file_pathstring—The derived file about to be deleted.

Return: void.

Tags: @since 2.2.0

Source: includes/class-util.php, line 4192

publicstatic is_purge_fallback_payload_valid()

public static function is_purge_fallback_payload_valid($fs, string $fallback): bool

Whether a retained fallback file holds a servable payload.

ParameterTypeDefaultDescription
$fsobject—Filesystem exposing size()/get_contents().
$fallbackstring—Absolute fallback path.

Return: bool — True when the fallback exists with non-empty content.

Tags: @since 2.2.0

Source: includes/class-util.php, line 4211

publicstatic get_staged_path_for()

public static function get_staged_path_for(string $file_path): string

Map a derived CSS/JS file to its sibling staged-rollout path.

ParameterTypeDefaultDescription
$file_pathstring—Absolute live derived-file path.

Return: string — Sibling staged path, or \’\’ when not applicable.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4238

publicstatic promote_staged_file()

public static function promote_staged_file($fs, callable $is_allowed, string $live_path): bool

Promote a staged-rollout file over its live sibling (issue #1348).

ParameterTypeDefaultDescription
$fsobject—Filesystem exposing exists()/size()/get_contents()/move()/copy()/delete().
$is_allowedcallable—Containment validator: fn( string $path ): bool.
$live_pathstring—Absolute live derived-file path.

Return: bool — True when the staged file replaced the live file.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4261

publicstatic restore_fallback_file()

public static function restore_fallback_file($fs, callable $is_allowed, string $live_path): bool

Restore a derived file from its retained last-good fallback (issue #1348).

ParameterTypeDefaultDescription
$fsobject—Filesystem exposing copy()/delete() plus the fallback-validity surface.
$is_allowedcallable—Containment validator: fn( string $path ): bool.
$live_pathstring—Absolute live derived-file path.

Return: bool — True when the fallback payload replaced the live file.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4282

publicstatic describe_rollout_slot()

public static function describe_rollout_slot($fs, string $live_path): array

Describe the safe-rollout slot triple for a live file (issue #1348).

ParameterTypeDefaultDescription
$fsobject—Filesystem exposing exists()/size()/get_contents().
$live_pathstring—Absolute live derived-file path.

Return: array{live_bytes: — int, live_checksum: string, staged: bool, staged_bytes: int, staged_checksum: string, staged_changed: bool, fallback: bool} Slot description.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4302

publicstatic purge_fallback_should_log()

public static function purge_fallback_should_log(): bool

A single blog-prefixed transient (`wppo_purge_fallback_served`) gates all fallback-serve log rows (both Cache and used-CSS share it) so a post-purge miss storm writes one row per day instead of one per directory.

Return: bool — True when the caller should write its log row.

Tags: @since 2.2.0

Source: includes/class-util.php, line 4319

publicstatic css_file_valid()

public static function css_file_valid(string $path): bool

Whether a generated CSS file is valid (exists, readable, non-empty).

ParameterTypeDefaultDescription
$pathstring—Absolute path to the CSS file.

Return: bool — True when the file is usable.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4336

publicstatic log_css_fallback()

public static function log_css_fallback(string $reason, array $handles, string $context): void

Log a guarded CSS fallback (combine or used-CSS) event with throttling.

ParameterTypeDefaultDescription
$reasonstring—Machine-readable reason code (empty_payload, write_failure, head_match_failure, …).
$handlesarray—Handles preserved by the fallback.
$contextstring—\’combine\’ or \’usedcss\’ — selects the log-key prefix and message.

Return: void.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4356

publicstatic is_php85_or_greater()

public static function is_php85_or_greater(?string=null $php_version): bool

Whether the current runtime deprecates explicit handle-close calls (PHP 8.5+).

ParameterTypeDefaultDescription
$php_version?string=null—Optional version string for testing; defaults to PHP_VERSION.

Return: bool — True on PHP 8.5+, false below.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4371

publicstatic close_curl_handle()

public static function close_curl_handle(& $ch, ?string=null $php_version): void

Release a cURL handle without triggering the PHP 8.5 deprecation.

ParameterTypeDefaultDescription
$ch&—cURL handle to release (nulled in the caller scope).
$php_version?string=null—Optional version override for testing; defaults to PHP_VERSION.

Return: void.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4387

publicstatic close_curl_multi_handle()

public static function close_curl_multi_handle(& $mh, ?string=null $php_version): void

Release a cURL multi handle without triggering the PHP 8.5 deprecation.

ParameterTypeDefaultDescription
$mh&—cURL multi handle to release (nulled in the caller scope).
$php_version?string=null—Optional version override for testing; defaults to PHP_VERSION.

Return: void.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4403

publicstatic destroy_gd_image()

public static function destroy_gd_image(& $image, ?string=null $php_version): void

Release a GD image without triggering the PHP 8.5 deprecation.

ParameterTypeDefaultDescription
$image&—GD image to release (nulled in the caller scope).
$php_version?string=null—Optional version override for testing; defaults to PHP_VERSION.

Return: void.

Tags: @since 2.0.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4419

publicstatic close_curl_share_handle()

public static function close_curl_share_handle(& $sh, ?string=null $php_version): void

Release a cURL share handle without triggering the PHP 8.5 deprecation.

ParameterTypeDefaultDescription
$sh&—cURL share handle to release (nulled in the caller scope).
$php_version?string=null—Optional version override for testing; defaults to PHP_VERSION.

Return: void.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4435

publicstatic close_finfo_handle()

public static function close_finfo_handle(& $finfo, ?string=null $php_version): void

Release a finfo handle without triggering the PHP 8.5 deprecation.

ParameterTypeDefaultDescription
$finfo&—Finfo handle to release (nulled in the caller scope).
$php_version?string=null—Optional version override for testing; defaults to PHP_VERSION.

Return: void.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4451

publicstatic free_xml_parser()

public static function free_xml_parser(& $parser, ?string=null $php_version): void

Release an XML parser without triggering the PHP 8.5 deprecation.

ParameterTypeDefaultDescription
$parser&—XML parser to release (nulled in the caller scope).
$php_version?string=null—Optional version override for testing; defaults to PHP_VERSION.

Return: void.

Tags: @since 2.2.0 · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4467

publicstatic get_last_response_headers()

public static function get_last_response_headers(?array=null $legacy_source): array

Return the last HTTP response headers without touching the deprecated global.

ParameterTypeDefaultDescription
$legacy_source?array=null—Optional explicit header lines for the legacy path (string-filtered).

Return: string[] — List of response header lines, or empty array when unavailable.

Tags: @since 2.2.0 · @since 2.2.0 `$legacy_source` parameter for the scope-blind legacy path. · @since 2.4.0 Facade proxy delegating to Http (REF-015).

Source: includes/class-util.php, line 4484

publicstatic get_styles_inline_limit()

public static function get_styles_inline_limit(): int

Read core\’s `styles_inline_size_limit` budget.

Return: int — The inline size limit in bytes.

Tags: @since 2.0.0

Source: includes/class-util.php, line 4503

publicstatic get_styles_inline_default()

public static function get_styles_inline_default(): int

Unfiltered core inline default for the invalid-limit fallback (issue #1462).

Return: int — The default inline size limit in bytes.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4523

publicstatic add_committed_inline_bytes()

public static function add_committed_inline_bytes(int $bytes): void

Record bytes just inlined on this request (issue #1462).

ParameterTypeDefaultDescription
$bytesint—Bytes just committed to inline output.

Return: void.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4566

publicstatic get_committed_inline_bytes()

public static function get_committed_inline_bytes(): int

Bytes committed to inline output so far on this request (issue #1462).

Return: int — Committed inline bytes (>= 0).

Tags: @since 2.3.0

Source: includes/class-util.php, line 4584

publicstatic reset_committed_inline_bytes()

public static function reset_committed_inline_bytes(): void

Reset the request-global committed-bytes ledger (unit tests).

Return: void.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4603

publicstatic get_remaining_inline_budget()

public static function get_remaining_inline_budget(int=0 $already_inlined, ?int=null $limit): int

Remaining inline budget after bytes already committed (issue #1462).

ParameterTypeDefaultDescription
$already_inlinedint=0—Bytes already committed to inline output on this request.
$limit?int=null—Optional budget override (defaults to get_styles_inline_limit()).

Return: int — Remaining bytes available for inline output (>= 0).

Tags: @since 2.3.0

Source: includes/class-util.php, line 4622

publicstatic split_css_for_inline_budget()

public static function split_css_for_inline_budget(string $css, ?int=null $limit): array

Split CSS into an inline prefix and a deferred remainder (issue #1462).

ParameterTypeDefaultDescription
$cssstring—CSS content to split.
$limit?int=null—Optional budget override (defaults to get_styles_inline_limit()).

Return: array{inline: — string, deferred: string} Inline prefix and deferred remainder.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4658

privatestatic find_top_level_css_cut()

private static function find_top_level_css_cut(string $css, int $budget): ?int

Offset of the last top-level `}` at or under the budget (issue #1462).

ParameterTypeDefaultDescription
$cssstring—CSS content.
$budgetint—Maximum bytes for the inline prefix.

Return: int|null — Offset of the cut brace, or null when nothing fits.

Tags: @since 2.3.0

Source: includes/class-util.php, line 4715

Hooks

Hooks referenced in includes/class-util.php:

HookTypeLineNotes
wppo_cache_query_allowlistfilter2271—
wppo_safe_css_combine_fallbackfilter4122@param ×1