includes/CSS/class-used-css.php
Used_CSS class for removing unused CSS rules per page.
Class Used_CSS
Class Used_CSS
class Used_CSSConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
CACHE_ROOT_DIR | private | \'/cache/wppo\' | 33 |
USED_CSS_FILENAME | private | \'used-css.css\' | 41 |
LAST_FULL_REGEN_OPTION | public | \'wppo_used_css_last_full_regen\' | 54 |
FULL_REGEN_COOLDOWN_SECONDS | private | 18000 | 65 |
TARGETED_REGEN_OPTION | public | \'wppo_used_css_last_targeted_regen\' | 77 |
TARGETED_REGEN_COOLDOWN_SECONDS | private | 3600 | 87 |
DELIVERY_MODES | public | array( \'file\', \'delay\', \'async\', \'remove\' ) | 101 |
STALE_THRESHOLD_SECONDS | private | 86400 | 109 |
DEFAULT_USED_CSS_QUEUE_CAP | private | 50 | 121 |
MAX_USED_CSS_QUEUE_CAP | private | 500 | 129 |
VIEWPORT_VARIANTS | public | array( \'mobile\', \'desktop\' ) | 141 |
Properties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$options | private | array | — | 149 |
$safelist | private | array | array() | 157 |
$built_in_safelist | private | array | array( \'html\', \'body\', \':root\', \'*\', \'#wpcontent\', \'#wpwrap\', \'#wpadminbar\', \'.ab-\', \'.wp-admin-bar-\', \'.woocommerce-\', \'.wc-\', \'.single-product\', \'.cart-\', \'.current-menu-item\', \'.menu-item-\', \'.page-id-\', \'.postid-\', \'.attachmentid-\', \'.active\', \'.open\', \'.hidden\', \'.visible\', \'.show\', \'.hide\', \'.fade\', \'.collapsed\', \'.selected\', \'.current\', \'.focus\', \'.hover\', \'.visited\', \'.js-\', \'.is-\', \'.has-\', \'.wp-\', \'.admin-bar-\', \'.dashicons-\', \'.customize-\', // Builder / JS-state selectors (issue #966): builders inject // dynamic classes at runtime that the static DOM walk never sees. // Prefix entries ending in \'-\' or \'*\' match via prefix in // is_selector_used(); attribute entries (e.g. [data-elementor-type]) // match by attribute-name substring so compound selectors stay kept. \'.elementor-\', \'.e-con*\', \'.et_*\', \'.et_pb_*\', \'.et-pb-\', \'.bricks-\', \'.brx-\', \'.vc_*\', \'.wpb_*\', \'.oxygen-\', \'.oxy-\', \'.no-js\', \'.js-enabled\', \'[data-elementor-type]\', // Popup/modal selectors (issue #1023): popups render outside the // static DOM walk (hidden containers, JS portals), so purge keeps // Elementor + generic popup selectors by default. \'.elementor-popup-\', \'.e-popup-\', \'.dialog-\', \'.popup-\', \'.modal-\', \'.mfp-\', \'.swal2-\', \'[data-elementor-type=\"popup\"]\', ) | 165 |
$cache_root_dir | private | string | — | 242 |
$cache_root_url | private | string | — | 250 |
$domain | private | string | — | 263 |
$host_mismatch | private | bool | false | 275 |
$traversal_probe_logged | private static | bool | false | 287 |
$safelist_index | private | ?array | null | 298 |
$selector_split_cache | private | array | array() | 306 |
$source_checksum_memo | private | ?string | null | 317 |
public __construct()
public function __construct(array=array() $options)Constructor. Parameter Type Default Description $optionsarray=array()— Plugin options.
public is_host_mismatched()
public function is_host_mismatched(): boolWhether the request Host header mismatched the canonical home host.
Return: bool — True when the request host differs from the canonical host.
publicstatic get_safelist_presets()
public static function get_safelist_presets(): arraySafelist presets shipped safe-by-default (Elementor + popup selectors).
Return: string[].
private init_safelist()
private function init_safelist(): voidInitialize safelist from settings and built-in list.
Return: void.
public extract_selectors()
public function extract_selectors(string $html): arrayExtract used selectors from HTML content. Parameter Type Default Description $htmlstring— The HTML content.
Return: array{tags: — array, classes: array, ids: array, attrs: array}.
privatestatic extract_selectors_with_processor()
private static function extract_selectors_with_processor(string $html): ?arrayExtract used selectors via the WP 6.9+ HTML processor. Parameter Type Default Description $htmlstring— The HTML content.
Return: array{tags: — array, classes: array, ids: array, attrs: array}|null Selector data, or null on failure.
privatestatic collect_selectors_from_tag()
private static function collect_selectors_from_tag(\\WP_HTML_Tag_Processor $tags, array& $used): voidCollect used selectors from the current tag of a HTML processor. Parameter Type Default Description $tags\\WP_HTML_Tag_Processor— Processor positioned on the current tag. $usedarray&— Selector accumulator (passed by reference).
Return: void.
privatestatic strip_css_comments()
private static function strip_css_comments(string $css): stringStrip CSS comments while preserving quoted segments. Parameter Type Default Description $cssstring— Raw CSS content.
Return: string — CSS without comments.
public parse_css()
public function parse_css(string $css): arrayParse CSS content into structured rules. Parameter Type Default Description $cssstring— Raw CSS content.
Return: array — Parsed rules.
privatestatic find_at_rule_prelude_end()
private static function find_at_rule_prelude_end(string $css, int $offset, int $length): arrayFind the end of an at-rule prelude, skipping quoted segments. Parameter Type Default Description $cssstring— Full CSS content. $offsetint— At-rule start offset (the \’@\’). $lengthint— Length of $css.
Return: array — Indices 0 (semicolon offset or false) and 1 (brace offset or false).
privatestatic find_rule_end()
private static function find_rule_end(string $css, int $offset, int $length): intFind the end offset (one past \’}\’) of a regular rule, skipping quoted segments and backslash escapes. Parameter Type Default Description $cssstring— Full CSS content. $offsetint— Rule start offset. $lengthint— Length of $css.
Return: int — Offset one past the closing brace (or $length).
private parse_css_block_rules()
private function parse_css_block_rules(string $css): arrayParse CSS rules inside a block (e.g., @media) by delegating to parse_css(). Parameter Type Default Description $cssstring— Block content.
Return: array — Parsed child rules.
private split_selectors()
private function split_selectors(string $selector_list): arraySplit a comma-separated selector list into individual selectors. Parameter Type Default Description $selector_liststring— Comma-separated selectors.
Return: array — Individual selectors.
private get_safelist_index()
private function get_safelist_index(): arrayBuild the precomputed safelist index (once per instance).
Return: array{exact: — array<string, bool>, attrs: string[], prefixes: string[]}.
private get_cached_simple_selectors()
private function get_cached_simple_selectors(string $selector): arrayCached split of a selector into simple parts. Parameter Type Default Description $selectorstring— Selector string.
Return: string[] — Simple selector parts.
public is_selector_used()
public function is_selector_used(string $selector, array $used): boolCheck if a CSS selector matches any used element in the HTML. Parameter Type Default Description $selectorstring— A single CSS selector. $usedarray— Used selectors from extract_selectors().
Return: bool — True if the selector is used.
private extract_simple_selectors()
private function extract_simple_selectors(string $selector): arrayExtract simple selector parts from a compound selector. Parameter Type Default Description $selectorstring— A CSS selector.
Return: array — Simple selector parts.
private matches_simple_selector()
private function matches_simple_selector(string $simple, array $used): boolCheck if a simple selector matches used elements. Parameter Type Default Description $simplestring— A simple CSS selector (e.g., \”.class\”, \”#id\”, \”tag\”). $usedarray— Used selectors.
Return: bool — True if matched.
public purge_css()
public function purge_css(array $parsed_css, array $used): stringPurge unused CSS rules from parsed CSS. Parameter Type Default Description $parsed_cssarray— Parsed CSS from parse_css(). $usedarray— Used selectors from extract_selectors().
Return: string — Purged CSS content.
private is_rule_used()
private function is_rule_used(array $rule, array $used): boolCheck if a single CSS rule is used. Parameter Type Default Description $rulearray— A parsed rule. $usedarray— Used selectors.
Return: bool — True if the rule is used.
public generate_used_css()
public function generate_used_css(string $html, array $css_assets): stringGenerate used CSS for a given HTML content and CSS assets. Parameter Type Default Description $htmlstring— The page HTML. $css_assetsarray— Array of CSS content strings (keyed by handle).
Return: string — Purged CSS content, or the unprocessed combined CSS when purging is unavailable.
publicstatic sanitize_used_css_output()
public static function sanitize_used_css_output(string $css): stringSanitize + bound derived CSS before it is served or stored (issue #1347). Parameter Type Default Description $cssstring— Derived CSS content.
Return: string — Safe CSS, or \’\’ when refused.
public get_used_css_path()
public function get_used_css_path(string=\'\' $url): stringGet the used-CSS cache file path for a URL. Parameter Type Default Description $urlstring=\'\'— The page URL.
Return: string — The filesystem path, or \’\’ when refused.
public get_used_css_url()
public function get_used_css_url(string=\'\' $url): stringGet the used-CSS cache file URL for a URL. Parameter Type Default Description $urlstring=\'\'— The page URL.
Return: string — The public URL, or \’\’ when refused.
private get_url_path()
private function get_url_path(string=\'\' $url): stringGet the normalized URL path for cache storage. Parameter Type Default Description $urlstring=\'\'— The page URL.
Return: string — Normalized path, or \’\’ when refused/empty.
private is_raw_path_non_blank()
private function is_raw_path_non_blank(string $url): boolWhether the raw path component behind a sanitized-\’\’ result is non-blank. Parameter Type Default Description $urlstring— The original URL (\’\’ = current REQUEST_URI).
Return: bool — True when the raw path component is non-blank.
private is_path_contained()
private function is_path_contained(string $path): boolWhether an absolute path stays inside the used-CSS cache tree. Parameter Type Default Description $pathstring— Absolute file or directory path.
Return: bool — True when contained.
private log_traversal_probe()
private function log_traversal_probe(string $raw_input): voidLog a blocked used-CSS path traversal probe (once per request). Parameter Type Default Description $raw_inputstring— The hostile input that was rejected.
Return: void.
public save_used_css()
public function save_used_css(string $css, string=\'\' $url): boolSave used-CSS content for a URL. Parameter Type Default Description $cssstring— The purged CSS content. $urlstring=\'\'— The page URL.
Return: bool — True on success.
public stage_used_css()
public function stage_used_css(string $css, string=\'\' $url): arrayStage used-CSS output for safe-rollout preview (issue #1348). Parameter Type Default Description $cssstring— Raw used-CSS content. $urlstring=\'\'— The page URL.
Return: array{staged: — bool, reason: string, bytes: int, checksum: string, live_bytes: int, live_checksum: string, changed: bool} Preview metadata.
public promote_staged_used_css()
public function promote_staged_used_css(string=\'\' $url): boolPromote staged used-CSS over the live file (issue #1348). Parameter Type Default Description $urlstring=\'\'— The page URL.
Return: bool — True when the staged file replaced the live file.
public rollback_used_css_to_fallback()
public function rollback_used_css_to_fallback(string=\'\' $url, string=\'manual\' $reason): boolRoll back used-CSS to the retained last-good fallback (issue #1348). Parameter Type Default Description $urlstring=\'\'— The page URL. $reasonstring=\'manual\'— Machine-readable reason recorded in the activity log.
Return: bool — True when the fallback payload replaced the live file.
public get_used_css_rollout_status()
public function get_used_css_rollout_status(string=\'\' $url): arrayDescribe the used-CSS safe-rollout slot for a URL (issue #1348). Parameter Type Default Description $urlstring=\'\'— The page URL.
Return: array{live_bytes: — int, live_checksum: string, staged: bool, staged_bytes: int, staged_checksum: string, staged_changed: bool, fallback: bool} Slot description.
public verify_used_css_health()
public function verify_used_css_health(string=\'\' $url): arrayVerify used-CSS health for a URL, auto-restoring last-good (issue #1348). Parameter Type Default Description $urlstring=\'\'— The page URL.
Return: array{status: — string, reason: string, bytes: int} One of healthy|restored|degraded.
public compute_css_checksum()
public function compute_css_checksum(string $css): stringStable content hash of CSS source (issue #1038). Parameter Type Default Description $cssstring— CSS content.
Return: string — SHA-256 checksum, or \’\’ for empty input.
private get_checksum_path()
private function get_checksum_path(string $used_css_path): stringSidecar path holding the source checksum for a used-CSS file. Parameter Type Default Description $used_css_pathstring— Used-CSS file path.
Return: string — Checksum sidecar path, or \’\’ when refused.
public compute_local_source_checksum()
public function compute_local_source_checksum(): stringCombined checksum of the locally-available queued stylesheets.
Return: string — Combined checksum, or \’\’ when unavailable.
public reset_source_checksum_memo()
public function reset_source_checksum_memo(): voidReset the memoized local-source checksum.
Return: void.
private is_checksum_stale()
private function is_checksum_stale(string $used_css_path): boolWhether the cached used-CSS is stale by content checksum. Parameter Type Default Description $used_css_pathstring— Used-CSS file path.
Return: bool — True when the source changed since generation.
private persist_source_checksum()
private function persist_source_checksum(string $used_css_path): voidPersist the source checksum sidecar after a successful generation. Parameter Type Default Description $used_css_pathstring— Used-CSS file path.
Return: void.
publicstatic get_purge_fallback_path()
public static function get_purge_fallback_path(string $file_path): stringMap a used-CSS path to its sibling last-good fallback path. Parameter Type Default Description $file_pathstring— Absolute used-CSS file path.
Return: string — Sibling fallback path, or \’\’ when not applicable.
private retain_purge_fallback()
private function retain_purge_fallback(string $file_path): voidRetain a last-good fallback copy before a used-CSS file is purged. Parameter Type Default Description $file_pathstring— The used-CSS file about to be deleted.
Return: void.
public delete_used_css()
public function delete_used_css(=null $url): boolDelete used-CSS file(s) for a URL or all URLs. Parameter Type Default Description $url=null— Optional URL to delete specific page used-CSS.
Return: bool — True on success.
private delete_variant_files_for_url()
private function delete_variant_files_for_url(string $url): voidDelete the viewport-variant sidecars for a URL (issue #1220). Parameter Type Default Description $urlstring— Page URL.
Return: void.
publicstatic delete_all_used_css()
public static function delete_all_used_css(): boolDelete all used-CSS files across all domains.
Return: bool — True on success.
publicstatic purge_coupled()
public static function purge_coupled(=null $url_path): arrayPurge page cache and used CSS together via a single shared action. Parameter Type Default Description $url_path=null— Optional URL path for a single-page purge; null purges all.
Return: array{page_cache: — bool, used_css: bool} Per-store results.
private get_full_regen_cooldown()
private function get_full_regen_cooldown(): intEffective full-regeneration cooldown in seconds (issue #1107).
Return: int — Cooldown seconds (>= 0).
private is_full_regen_cooled_down()
private function is_full_regen_cooled_down(): boolWhether a non-forced full regeneration is inside the cooldown window (issue #1107).
Return: bool — True when the last full regen is newer than the cooldown.
private mark_full_regen()
private function mark_full_regen(): voidRecord a completed full-regeneration scan (issue #1107).
Return: void.
publicstatic get_used_css_delivery_mode()
public static function get_used_css_delivery_mode(?array=null $file_opts): stringEffective used-CSS delivery mode (issue #1220). Parameter Type Default Description $file_opts?array=null— Optional file_optimisation settings (defaults to plugin settings).
Return: string — One of self::DELIVERY_MODES.
publicstatic get_last_full_regen_time()
public static function get_last_full_regen_time(): intTimestamp of the last full used-CSS regeneration (issue #1220).
Return: int — Unix timestamp, or 0 when never recorded.
publicstatic get_staleness_info()
public static function get_staleness_info(): arrayStaleness signal for the admin UI (issue #1220).
Return: array{last_regen:int,last_regen_human:string,is_stale:bool,cooldown_remaining:int,delivery_mode:string}.
private get_targeted_regen_cooldown()
private function get_targeted_regen_cooldown(): intEffective targeted-regeneration cooldown in seconds (issue #1220).
Return: int — Cooldown seconds (>= 0).
privatestatic get_effective_targeted_cooldown()
private static function get_effective_targeted_cooldown(): intStatic variant of the targeted-regen cooldown (issue #1220).
Return: int — Cooldown seconds (>= 0).
private is_targeted_regen_cooled_down()
private function is_targeted_regen_cooled_down(): boolWhether a targeted regeneration is inside the cooldown window (issue #1220).
Return: bool — True when the last targeted regen is newer than the cooldown.
private mark_targeted_regen()
private function mark_targeted_regen(): voidRecord a targeted-regeneration pass (issue #1220).
Return: void.
publicstatic request_targeted_regen()
public static function request_targeted_regen(string=\'\' $reason, int=20 $cap): intCooldown-gated targeted requeue after builder/theme updates (issue #1220). Parameter Type Default Description $reasonstring=\'\'— Short reason for logging (e.g. \’builder-update\’). $capint=20— Maximum posts to requeue in this pass.
Return: int — Number of jobs queued.
private is_variant_fresh_for_post()
private function is_variant_fresh_for_post(int $post_id, string $modified_gmt, ?string=null $permalink): boolWhether the stored used-CSS variant is fresh for a post (issue #1107). Parameter Type Default Description $post_idint— Post ID. $modified_gmtstring— Post modification time (GMT, Y-m-d H:i:s). $permalink?string=null— Optional pre-resolved permalink (scan path passes its batch map so the URL is resolved once per post, not twice).
Return: bool — True when regeneration can be skipped for this post.
privatestatic is_used_css_job_live()
private static function is_used_css_job_live(array $args): boolWhether a used-CSS generation job is pending or running. Parameter Type Default Description $argsarray— Action arguments.
Return: bool — True when a matching job is pending or running.
publicstatic requeue_for_post()
public static function requeue_for_post(int $post_id, ?array=null $scheduled_hints, ?self=null $instance, ?bool&=null $already_scheduled): boolQueue used-CSS regeneration for a single post (builder-drift requeue). Parameter Type Default Description $post_idint— Post ID to requeue. $scheduled_hints?array=null— Optional hoisted pending-job map (post ID => true); null falls back to per-post lookup. $instance?self=null— Optional hoisted instance (shares parsed safelist/memo across loop calls). $already_scheduled?bool&=null— Optional out flag: set to true when the job was already pending (hint-hit, pre-check hit, or lost unique-race) rather than newly scheduled; false when a new job was inserted. Untouched (stays false) on skip/failure. Lets bulk callers count only genuinely new jobs (issue #1310).
Return: bool — True when a job was queued or already scheduled; false when skipped as fresh or on failure.
publicstatic order_post_ids_by_rum_priority()
public static function order_post_ids_by_rum_priority(array $post_ids, array=array() $permalinks, ?array=null $priority, ?array=null $trends): arrayOrder post IDs worst-p75 LCP first for used-CSS queue prioritization. Parameter Type Default Description $post_idsarray— Post IDs in FIFO order. $permalinksarray=array()— — $priority?array=null— Optional hoisted RUM path-LCP priority map (regenerate_all fetches once per run; null fetches per call). $trends?array=null— Optional hoisted PageSpeed trends (null fetches per call).
Return: int[] — Ordered post IDs (same entries).
publicstatic get_used_css_queue_cap()
public static function get_used_css_queue_cap(): intRead the configured per-run used-CSS queue cap (issue #1164).
Return: int — Per-run cap, or PHP_INT_MAX when uncapped.
publicstatic is_viewport_variants_enabled()
public static function is_viewport_variants_enabled(): boolWhether viewport-split used-CSS variants are enabled (issue #1164).
Return: bool — True when split variants should be emitted/served.
publicstatic get_variant_filename()
public static function get_variant_filename(string $variant): stringGet the viewport-split variant filename for a base filename. Parameter Type Default Description $variantstring— Variant slug (\’mobile\’|\’desktop\’).
Return: string — Variant filename, or \’\’ when refused.
public get_used_css_variant_path()
public function get_used_css_variant_path(string=\'\' $url, string=\'mobile\' $variant): stringGet the used-CSS variant file path for a URL (issue #1164). Parameter Type Default Description $urlstring=\'\'— Page URL. $variantstring=\'mobile\'— Variant slug (\’mobile\’|\’desktop\’).
Return: string — Filesystem path, or \’\’ when refused/disabled.
public resolve_used_css_path()
public function resolve_used_css_path(string=\'\' $url, string=\'mobile\' $variant): stringResolve the usable used-CSS path with fail-open fallback (issue #1164). Parameter Type Default Description $urlstring=\'\'— Page URL. $variantstring=\'mobile\'— Variant slug (\’mobile\’|\’desktop\’).
Return: string — Usable filesystem path, or \’\’ when none.
publicstatic is_safe_to_strip_handle()
public static function is_safe_to_strip_handle(string $handle): boolWhether a stylesheet handle is safe to strip when a block-library stylesheet is present (issue #1164). Parameter Type Default Description $handlestring— Stylesheet handle.
Return: bool — True when stripping is safe; false for block-library.
publicstatic passes_elementor_smoke()
public static function passes_elementor_smoke(string $html, string $purged_css): boolElementor smoke check for used-CSS output (issue #1164). Parameter Type Default Description $htmlstring— Page HTML. $purged_cssstring— Purged CSS candidate.
Return: bool — True when it is safe to serve the purged CSS.
public regenerate_all()
public function regenerate_all(bool=false $force): intQueue background used-CSS regeneration for all published posts. Parameter Type Default Description $forcebool=false— Bypass the cooldown (explicit operator paths: builder purge after a wipe, manual triggers). Per-post freshness still applies.
Return: int — Number of jobs queued.
publicstatic get_excluded_post_types()
public static function get_excluded_post_types(): arrayBuilder-template post types excluded from used-CSS generation (issue #1274).
Return: string[] — Excluded post type slugs.
publicstatic is_excluded_post()
public static function is_excluded_post(int $post_id): boolWhether a post ID belongs to an excluded builder-template type (issue #1274). Parameter Type Default Description $post_idint— Post ID.
Return: bool — True when the post should be skipped.
publicstatic process_background()
public static function process_background(int $post_id, =null $sig): voidProcess a single page for used-CSS generation (Action Scheduler callback). Parameter Type Default Description $post_idint— The post ID. $sig=null— Optional HMAC signature over the payload.
Return: void.
privatestatic fetch_and_generate_used_css()
private static function fetch_and_generate_used_css(int $post_id, string $permalink, int $timeout): stringFetch a permalink and generate its used CSS (issue #1348). Parameter Type Default Description $post_idint— The post ID (log context only). $permalinkstring— Same-site-validated permalink to fetch. $timeoutint— Fetch timeout in seconds.
Return: string — Purged CSS, or \’\’ on any failure.
public generate_preview_for_post()
public function generate_preview_for_post(int $post_id): arrayDry-run used-CSS generation for a post with staged preview (issue #1348). Parameter Type Default Description $post_idint— The post ID.
Return: array{staged: — bool, reason: string, bytes: int, checksum: string, live_bytes: int, live_checksum: string, changed: bool, post_id: int} Preview metadata.
privatestatic extract_css_assets_from_html()
private static function extract_css_assets_from_html(string $html): arrayExtract CSS assets from HTML content by finding <link rel=\”stylesheet\”> tags. Parameter Type Default Description $htmlstring— The HTML content.
Return: array — Array of CSS content strings keyed by md5 hash of URL.
privatestatic extract_css_assets_with_processor()
private static function extract_css_assets_with_processor(string $html): ?arrayExtract stylesheet URLs via the WP 6.9+ HTML processor. Parameter Type Default Description $htmlstring— The HTML content.
Return: array<string,string>|null — CSS contents keyed by URL hash, or null on failure.
privatestatic collect_css_asset_from_tag()
private static function collect_css_asset_from_tag(\\WP_HTML_Tag_Processor $tags, array& $assets): voidCollect the stylesheet content linked by the current tag. Parameter Type Default Description $tags\\WP_HTML_Tag_Processor— Processor positioned on the current tag. $assetsarray&— Asset accumulator (passed by reference).
Return: void.
privatestatic fetch_css_content_static()
private static function fetch_css_content_static(string $url)Fetch CSS content from a URL or local path (static version). Parameter Type Default Description $urlstring— The CSS URL.
Return: string|false — CSS content or false on failure.
public get_all_css_assets()
public function get_all_css_assets(): arrayGet all CSS assets (content) from enqueued styles.
Return: array — Array of CSS content strings keyed by handle.
private fetch_css_content()
private function fetch_css_content(string $url)Fetch CSS content from a URL or local path (delegates to static helper). Parameter Type Default Description $urlstring— The CSS URL.
Return: string|false — CSS content or false on failure.
private strip_stylesheet_links()
private function strip_stylesheet_links(string $buffer, array $quoted_srcs): ?arrayStrip stylesheet <link> tags for the given quoted srcs (order-agnostic, bounded). Parameter Type Default Description $bufferstring— The HTML buffer. $quoted_srcsarray— preg_quote()d src URLs (delimiter \’/\’).
Return: array|null — Array [ string $stripped, int $strip_count ] or null on PCRE error.
private resolve_effective_delivery_mode()
private function resolve_effective_delivery_mode(string $buffer_after_strip, string $mode, array $handles): stringSmoke-gate the remove delivery mode (issue #1220). Parameter Type Default Description $buffer_after_stripstring— Buffer with original links stripped. $modestring— Requested delivery mode. $handlesarray— Stripped stylesheet handles.
Return: string — Effective delivery mode.
private build_delayed_css_loader()
private function build_delayed_css_loader(): stringInline loader that swaps interaction-delayed stylesheets (issue #1220).
Return: string — Inline script tag.
private get_handle_url_with_ver()
private function get_handle_url_with_ver(string $handle): stringRegistered stylesheet URL with its version query (issue #1220). Parameter Type Default Description $handlestring— Style handle.
Return: string — Full URL with ver query, or \’\’ when unresolvable.
private get_handle_media()
private function get_handle_media(string $handle): stringRegistered stylesheet media (issue #1220). Parameter Type Default Description $handlestring— Style handle.
Return: string — Media attribute value.
private has_strict_csp()
private function has_strict_csp(string=\'\' $buffer): boolWhether the response carries a strict CSP blocking inline handlers (issue #1220). Parameter Type Default Description $bufferstring=\'\'— Optional HTML buffer to scan for a meta CSP tag.
Return: bool — True when a strict CSP is detected.
private inject_used_css()
private function inject_used_css(string $buffer, string $used_css_url, array $handles): stringInject used-CSS into the buffer: remove original <link> stylesheets and insert the used-CSS file with a <noscript> fallback. Parameter Type Default Description $bufferstring— The HTML buffer. $used_css_urlstring— The URL of the used-CSS file (with version). $handlesarray— Array of style handles to remove and include in fallback.
Return: string — Modified HTML buffer.
public is_regression_guard_enabled()
public function is_regression_guard_enabled(): boolWhether the visual regression guard is enabled (issue #966).
Return: bool.
public get_regression_threshold()
public function get_regression_threshold(): intRetained-% threshold below which trimming is deemed a mismatch.
Return: int.
public is_regression_guard_tripped()
public function is_regression_guard_tripped(string $combined_css, string $purged_css): boolWhether purged output trips the visual regression guard. Parameter Type Default Description $combined_cssstring— Full combined stylesheet. $purged_cssstring— Purged output.
Return: bool — True when the guard trips (serve the full stylesheet).
private is_safe_fallback_enabled()
private function is_safe_fallback_enabled(): boolWhether the safe CSS combine fallback is enabled.
Return: bool.
private log_used_css_fallback()
private function log_used_css_fallback(string $reason, array $handles): voidLog a used-CSS fallback with throttling. Parameter Type Default Description $reasonstring— Reason code. $handlesarray— Handles involved.
Return: void.
private is_used_css_valid()
private function is_used_css_valid(string $path): boolWhether a used-CSS file is valid. Parameter Type Default Description $pathstring— Absolute path.
Return: bool.
public process_buffer()
public function process_buffer(string $buffer): stringProcess the HTML buffer to apply used-CSS. Parameter Type Default Description $bufferstring— The HTML buffer.
Return: string — Modified HTML buffer.
Hooks
Hooks referenced in includes/CSS/class-used-css.php: Hook Type Line Notes wppo_used_css_safelistfilter 433 @param ×1 wppo_used_css_regen_cooldownfilter 2459 @param ×1 wppo_used_css_targeted_cooldownfilter 2650 @param ×1 wppo_css_preview_fetch_timeoutfilter 3973 — wppo_used_css_strict_cspfilter 4536 @param ×1 wppo_unused_css_regression_thresholdfilter 4678 —