includes/CSS/class-ccss-store.php
Critical-CSS file lifecycle + status store (FUT-001).
Class Ccss_Store
Class Ccss_Store
class Ccss_StoreConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
CCSS_DIR | public | \'/cache/wppo/ccss\' | 57 |
TEMPLATE_HASH_PATTERN | public | \'/^[A-Za-z0-9_\\-]{1,128}$/\' | 69 |
VIEWPORT_VARIANTS | public | array( \'mobile\', \'desktop\' ) | 82 |
Properties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$ccss_exists_cache | private static | array | array() | 93 |
$ccss_content_cache | private static | array | array() | 104 |
$sample_url_cache | private static | array | array() | 115 |
$templates_memo | private static | ?array | null | 126 |
$status_cache_reader | private static | callable|null | null | 141 |
publicstatic set_status_cache_reader()
public static function set_status_cache_reader($reader): voidInject (or clear) the generation-status reader. Parameter Type Default Description $readercallable|null— Status reader: fn( string $hash ): string|false.
Return: void.
publicstatic get_ccss_dir()
public static function get_ccss_dir(): stringGet the CCSS directory path.
Return: string.
publicstatic get_ccss_url()
public static function get_ccss_url(): stringGet the CCSS directory URL.
Return: string.
publicstatic get_ccss_file()
public static function get_ccss_file(string $template_hash): stringGet the CCSS file path for a template hash. Parameter Type Default Description $template_hashstring— The template hash.
Return: string — Full file path.
publicstatic is_ccss_path_contained()
public static function is_ccss_path_contained(string $path): boolWhether a path stays inside the CCSS directory (issue #1348). Parameter Type Default Description $pathstring— Absolute path to check.
Return: bool — True when contained.
publicstatic is_valid_template_hash()
public static function is_valid_template_hash($hash): boolWhether a template hash is safe to queue, store, or log. Parameter Type Default Description $hashmixed— Candidate hash.
Return: bool — True when the hash is a valid template hash.
publicstatic stage_ccss_for_template()
public static function stage_ccss_for_template(string $template_hash, string $css): arrayStage critical CSS for a template without going live (issue #1348). Parameter Type Default Description $template_hashstring— Validated template hash. $cssstring— Raw critical-CSS content.
Return: array{staged: — bool, reason: string, bytes: int, checksum: string, live_bytes: int, live_checksum: string, changed: bool} Preview metadata.
publicstatic promote_staged_ccss()
public static function promote_staged_ccss(string $template_hash): boolPromote staged critical CSS over the live file (issue #1348). Parameter Type Default Description $template_hashstring— Validated template hash.
Return: bool — True when the staged file replaced the live file.
publicstatic rollback_ccss_to_fallback()
public static function rollback_ccss_to_fallback(string $template_hash, string=\'manual\' $reason): boolRoll back critical CSS to the retained last-good fallback (issue #1348). Parameter Type Default Description $template_hashstring— Validated template hash. $reasonstring=\'manual\'— Machine-readable reason recorded in the activity log.
Return: bool — True when the fallback payload replaced the live file.
publicstatic get_ccss_rollout_status()
public static function get_ccss_rollout_status(string $template_hash): arrayDescribe the critical-CSS safe-rollout slot (issue #1348). Parameter Type Default Description $template_hashstring— Validated template hash.
Return: array{live_bytes: — int, live_checksum: string, staged: bool, staged_bytes: int, staged_checksum: string, staged_changed: bool, fallback: bool, health: string} Slot description.
publicstatic verify_ccss_health()
public static function verify_ccss_health(string $template_hash): arrayVerify critical-CSS health, auto-restoring last-good (issue #1348). Parameter Type Default Description $template_hashstring— Validated template hash.
Return: array{status: — string, reason: string, bytes: int} One of healthy|restored|degraded.
publicstatic get_ccss_variant_file()
public static function get_ccss_variant_file(string $template_hash, string $variant): stringGet the CCSS file path for a viewport-split variant. Parameter Type Default Description $template_hashstring— Template hash. $variantstring— Variant slug (\’mobile\’|\’desktop\’).
Return: string — Full file path, or \’\’ when refused.
publicstatic get_ccss_variant_content()
public static function get_ccss_variant_content(string $template_hash, string $variant): ?stringRead a viewport-split variant with fail-open fallback (issue #1164). Parameter Type Default Description $template_hashstring— Template hash. $variantstring— Variant slug (\’mobile\’|\’desktop\’).
Return: string|null — Variant or single CCSS content, or null when missing.
publicstatic is_variant_stale()
public static function is_variant_stale(string $template_hash, string $variant): boolWhether a viewport-split variant is stale (issue #1164). Parameter Type Default Description $template_hashstring— Template hash. $variantstring— Variant slug (\’mobile\’|\’desktop\’).
Return: bool — True when the variant must not be served.
publicstatic invalidate_stale_variants()
public static function invalidate_stale_variants(string $template_hash): voidDelete stale viewport-split variants for a template (issue #1164). Parameter Type Default Description $template_hashstring— Template hash.
Return: void.
publicstatic get_ccss_file_url()
public static function get_ccss_file_url(string $template_hash): stringFile-first CCSS URL with mtime cache busting. Parameter Type Default Description $template_hashstring— Template hash.
Return: string — File URL with mtime version, or \’\’ when unavailable.
publicstatic get_ccss_meta()
public static function get_ccss_meta(string $template_hash): arraySize metadata for a stored CCSS variant. Parameter Type Default Description $template_hashstring— Template hash.
Return: array{size: — int, truncated: bool, mtime: int} Size in bytes, over-cap flag, and file mtime (0 when missing).
publicstatic ccss_exists()
public static function ccss_exists(string $template_hash): boolCheck if CCSS exists for a template hash. Parameter Type Default Description $template_hashstring— The template hash.
Return: bool.
publicstatic get_ccss_content()
public static function get_ccss_content(string $template_hash): ?stringRead the critical CSS for a template hash through a per-request content memo keyed by mtime. Parameter Type Default Description $template_hashstring— Template hash.
Return: string|null.
publicstatic get_status_all()
public static function get_status_all(): arrayGet all registered template hashes and their status.
Return: array<string, — array{status: string, label: string, size: int, truncated: bool}> Template hash => status + label + size.
publicstatic get_templates()
public static function get_templates(): arrayGet the list of supported templates.
Return: array<string, — string> Template identifier => Label.
publicstatic get_sample_url()
public static function get_sample_url(string $template): string|falseGet a sample URL for a given template. Parameter Type Default Description $templatestring— Template identifier.
Return: string|false — URL or false if not found.
publicstatic reset_ccss_memo()
public static function reset_ccss_memo(): voidReset the per-request CCSS storage memos (existence/content/sample-URL/templates).
Return: void.
publicstatic invalidate_ccss_memo()
public static function invalidate_ccss_memo(string $template_hash): voidInvalidate the per-request CCSS memos for a single template hash. Parameter Type Default Description $template_hashstring— The template hash.
Return: void.