class-builder-purge-watcher.php

Builder-purge watcher — purge stale page-builder CSS on builder updates.

Source includes/Integrations/class-builder-purge-watcher.php11 min readPart of Performance Optimisation

includes/Integrations/class-builder-purge-watcher.php

Builder-purge watcher — purge stale page-builder CSS on builder updates.

Namespace: PerformanceOptimise\\Inc · Lines: 2110

Class Builder_Purge_Watcher

Purge builder + WPPO caches after a page-builder update.

Source: includes/Integrations/class-builder-purge-watcher.php, line 33

class Builder_Purge_Watcher

Tags: @since 2.0.0

Constants

ConstantVisibilityValueLine
NOTICE_TRANSIENTpublic\'wppo_builder_purge_notice\'41
DRIFT_PURGE_HOOKpublic\'wppo_builder_drift_purge\'56
DRIFT_PURGE_LOCKpublic\'wppo_builder_drift_purge_lock\'68
BUILDER_MAPprivatearray( \'elementor\' => array( \'label\' => \'Elementor\', \'plugins\' => array( \'elementor/elementor.php\', \'elementor-pro/elementor-pro.php\' ), \'themes\' => array(), \'upload_subdirs\' => array( \'elementor/css\' ), \'content_subdirs\' => array(), \'clear_hooks\' => array( \'elementor/core/files/clear_cache\' ), ), \'divi\' => array( \'label\' => \'Divi\', \'plugins\' => array( \'divi-builder/divi-builder.php\' ), \'themes\' => array( \'Divi\' ), \'upload_subdirs\' => array(), \'content_subdirs\' => array( \'et-cache\' ), \'clear_hooks\' => array( \'et_core_cache_clear\' ), ), \'bricks\' => array( \'label\' => \'Bricks\', \'plugins\' => array(), \'themes\' => array( \'bricks\' ), \'upload_subdirs\' => array( \'bricks\' ), \'content_subdirs\' => array(), \'clear_hooks\' => array(), \'css_only\' => true, ), \'wpbakery\' => array( \'label\' => \'WPBakery\', \'plugins\' => array( \'js_composer/js_composer.php\' ), \'themes\' => array(), \'upload_subdirs\' => array( \'js_composer\' ), \'content_subdirs\' => array(), \'clear_hooks\' => array(), \'css_only\' => true, ), )89
LAST_PURGE_OPTIONpublic\'wppo_last_purge\'136
UPGRADE_PURGE_HOOKpublic\'wppo_upgrade_purge\'147
UPGRADE_PURGE_LOCKpublic\'wppo_upgrade_purge_lock\'160
BULK_REGEN_THRESHOLDprivate5269

Properties

PropertyVisibilityTypeDefaultLine
$upgrade_purged_hashesprivate staticarrayarray()177
$resolved_builder_map_cacheprivate staticarrayarray()190
$drift_suspendedprivate staticboolfalse203
$drift_handled_this_requestprivate staticboolfalse215
$elementor_purgedprivate staticarrayarray()231
$shared_purge_cacheprivate staticmixed|nullnull243
$bulk_regen_coalescedprivate staticboolfalse256

publicstatic reset_elementor_purge_memo()

public static function reset_elementor_purge_memo(): void

Reset the Elementor per-request purge set (for tests).

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 277

publicstatic reset_drift_state()

public static function reset_drift_state(): void

Reset the drift-signal per-request state (for tests).

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 292

publicstatic is_watcher_enabled()

public static function is_watcher_enabled(): bool

Whether the builder purge watcher is enabled (issue #1288).

Return: bool — True when the watcher may run.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 306

publicstatic is_drift_log_enabled()

public static function is_drift_log_enabled(): bool

Whether drift-path activity-log entries are enabled (issue #1288).

Return: bool — True when drift purges should write a log entry.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 320

privatestatic is_file_flag_enabled()

private static function is_file_flag_enabled(string $key): bool

Read an additive file_optimisation flag, fail-open to true (issue #1288).

ParameterTypeDefaultDescription
$keystring—Flag key inside file_optimisation.

Return: bool — True when the flag is enabled or unreadable.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 335

public register()

public function register(): void

Register the upgrader hook plus builder-drift hooks.

Return: void.

Tags: @since 2.0.0 · @since 2.2.0 Guarded behind function_exists + watcher setting.

Source: includes/Integrations/class-builder-purge-watcher.php, line 372

public on_builder_drift()

public function on_builder_drift(): void

Handle Elementor asset-regen signals: defer the derived-cache purge.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 431

protected schedule_deferred_drift_purge()

protected function schedule_deferred_drift_purge(): bool

Schedule the heavy drift purge as a single background event.

Return: bool — True when a new event was enqueued. False when already pending (stays retryable) or on failure.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 478

protected is_drift_purge_locked()

protected function is_drift_purge_locked(): bool

Whether the drift-purge transient lock is currently held (issue #1288).

Return: bool — True when the drift-purge lock transient exists.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 528

public run_deferred_drift_purge()

public function run_deferred_drift_purge(): void

Background callback: run the heavy derived-cache purge.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 547

public on_builder_drift_save()

public function on_builder_drift_save($post_id, $editor_data): void

Handle Elementor editor saves: requeue the saved post\’s used CSS.

ParameterTypeDefaultDescription
$post_idint—Post ID saved in the editor.
$editor_datamixed—Editor data (unused).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 596

public on_elementor_css_regen()

public function on_elementor_css_regen($css_file, =null $post_id): void

Handle Elementor per-post CSS regeneration (issue #1259).

ParameterTypeDefaultDescription
$css_filemixed—Elementor post CSS-file object or post ID.
$post_id=null—Optional second action payload (post ID) when Elementor passes two args.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 694

protected resolve_elementor_post_id()

protected function resolve_elementor_post_id($css_file, =null $post_id): int

Resolve an Elementor CSS-regen payload to a post ID (issue #1259).

ParameterTypeDefaultDescription
$css_filemixed—CSS-file object or post ID.
$post_id=null—Optional second action payload (post ID fallback).

Return: int — Post ID, or 0 when unresolvable.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 742

private coerce_post_id()

private function coerce_post_id($value): int

Coerce a scalar payload to a post ID (issue #1259).

ParameterTypeDefaultDescription
$valuemixed—Raw payload.

Return: int — Post ID, or 0 when not a clean integer payload.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 783

protected purge_post_static_cache()

protected function purge_post_static_cache(int $post_id, bool=true $bump_stats): void

Purge a single post\’s static HTML + derived CSS caches (issue #1259).

ParameterTypeDefaultDescription
$post_idint—Post ID whose cache must be purged.
$bump_statsbool=true—Whether to bump dashboard stats. Bulk-regen callers pass false: the deferred full purge bumps once instead of N inline option writes.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 827

protected requeue_used_css_for_elementor_post()

protected function requeue_used_css_for_elementor_post(int $post_id): bool

Requeue Used-CSS for one Elementor post, coalesced for bulk regen (issue #1259).

ParameterTypeDefaultDescription
$post_idint—Post ID whose Used-CSS must be requeued.

Return: bool — True when a job was queued or already scheduled.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 876

protected purge_post_url_caches()

protected function purge_post_url_caches(int $post_id): bool

Purge page-cache + used-CSS sidecars for a single post URL (issue #1288).

ParameterTypeDefaultDescription
$post_idint—Post ID just saved in the builder.

Return: bool — True when a purge seam ran without throwing.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 908

protected resolve_post_url_path()

protected function resolve_post_url_path(int $post_id): string

Resolve a post ID to its cache URL path (issue #1288).

ParameterTypeDefaultDescription
$post_idint—Post ID.

Return: string — URL path (e.g. \’/my-page/\’) or \’\’ when unresolvable.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 948

protected maybe_coalesce_bulk_regen()

protected function maybe_coalesce_bulk_regen(): void

Schedule the deferred full purge once bulk regen is detected (issue #1259).

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1002

protected write_drift_purge_log()

protected function write_drift_purge_log(bool=true $succeeded): void

Log a builder-drift purge outcome (issue #1288).

ParameterTypeDefaultDescription
$succeededbool=true—Whether the page-cache clear succeeded.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1036

protected write_drift_save_log()

protected function write_drift_save_log(int $post_id, bool=true $purged, bool=true $queued): void

Write the drift-save audit entry for an editor save (issue #1288).

ParameterTypeDefaultDescription
$post_idint—Post ID saved in the builder.
$purgedbool=true—Whether the URL-scoped purge succeeded.
$queuedbool=true—Whether regeneration was requeued.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1072

publicstatic get_builder_map()

public static function get_builder_map(): array

Get the builder map, filterable by hosts and themes.

Return: array<string,array> — Builder map keyed by builder slug.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1113

public on_builder_update()

public function on_builder_update($upgrader, $hook_extra): void

Handle upgrader_process_complete: purge when a builder was updated.

ParameterTypeDefaultDescription
$upgradermixed—Upgrader instance (unused).
$hook_extramixed—Update context (action/type/plugin/plugins/theme/themes).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1147

private match_builders()

private function match_builders(array $plugins, array $themes, array $map): array

Intersect updated plugin/theme slugs with the builder map.

ParameterTypeDefaultDescription
$pluginsarray—Updated plugin files.
$themesarray—Updated theme slugs.
$maparray—Builder map (resolved once per update).

Return: string[] — Matched builder keys.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1197

protected collect_updated_slugs()

protected function collect_updated_slugs($hook_extra): array

Collect updated plugin/theme slugs from an upgrader payload.

ParameterTypeDefaultDescription
$hook_extramixed—Update context.

Return: array{0:string[],1:string[]} — Tuple of (plugins, themes).

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1234

protected upgrade_payload_hash()

protected function upgrade_payload_hash($hook_extra): string

Hash an upgrader payload for per-request dedupe.

ParameterTypeDefaultDescription
$hook_extramixed—Update context.

Return: string — Payload hash.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1270

protected is_upgrade_purged()

protected function is_upgrade_purged($hook_extra): bool

Check whether this payload already purged this request.

ParameterTypeDefaultDescription
$hook_extramixed—Update context.

Return: bool — True when the payload hash was already recorded.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1295

protected mark_upgrade_purged()

protected function mark_upgrade_purged($hook_extra): void

Record a payload hash as purged for this request.

ParameterTypeDefaultDescription
$hook_extramixed—Update context.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1306

protected purge_for_builders()

protected function purge_for_builders(array $matched, array $map): void

Run the purge chain for the matched builders.

ParameterTypeDefaultDescription
$matchedarray—Matched builder keys.
$maparray—Builder map (resolved once per update).

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1321

public on_any_upgrade()

public function on_any_upgrade($upgrader, $hook_extra): void

Handle any plugin/theme/core update: auto-purge derived caches (issue #1276).

ParameterTypeDefaultDescription
$upgradermixed—Upgrader instance (unused).
$hook_extramixed—Update context (action/type/plugin/plugins/theme/themes).

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1370

protected describe_upgrade()

protected function describe_upgrade(string $type, array $plugins, array $themes): string

Describe an upgrade payload for logs + SPA last-purge reason.

ParameterTypeDefaultDescription
$typestring—Upgrade type (plugin/theme/core).
$pluginsarray—Updated plugin files.
$themesarray—Updated theme slugs.

Return: string — Human-readable description (bounded length).

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1483

protected schedule_deferred_upgrade_purge()

protected function schedule_deferred_upgrade_purge(string=\'\' $reason): bool

Schedule the heavy generic-upgrade purge as a background event.

ParameterTypeDefaultDescription
$reasonstring=\'\'—Optional upgrade description (ignored, kept for backward compatibility).

Return: bool — True when an event was enqueued or already pending.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1524

public run_deferred_upgrade_purge()

public function run_deferred_upgrade_purge(string=\'\' $reason): void

Background callback: run the heavy generic-upgrade purge.

ParameterTypeDefaultDescription
$reasonstring=\'\'—Optional legacy upgrade description.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1577

public purge_derived_caches()

public function purge_derived_caches(string=\'manual purge\' $reason): void

Manual purge entry point for the SPA button + REST route (issue #1276).

ParameterTypeDefaultDescription
$reasonstring=\'manual purge\'—Human-readable reason stored for the SPA.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1606

protected bump_combined_asset_versions()

protected function bump_combined_asset_versions(): void

Invalidate cached asset manifests/stats after a purge (issue #1276).

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1631

publicstatic get_last_purge()

public static function get_last_purge(): array

Get the last derived-cache purge record for the SPA (issue #1276).

Return: array{reason:string,time:int} — Last-purge record.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1650

protected record_last_purge()

protected function record_last_purge(string $reason): void

Record the last derived-cache purge reason (issue #1276).

ParameterTypeDefaultDescription
$reasonstring—Human-readable purge reason.

Return: void.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1681

publicstatic get_safe_preview_url()

public static function get_safe_preview_url(): string

Safe-mode preview URL that bypasses minify (issue #1276).

Return: string — Preview URL, or \’\’ when unresolvable.

Tags: @since 2.2.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1719

protected purge_builder_directories()

protected function purge_builder_directories(array $matched, array $map): array

Delete the matched builders\’ regenerable cache directories.

ParameterTypeDefaultDescription
$matchedarray—Matched builder keys.
$maparray—Builder map.

Return: string[] — Deleted paths (for tests and logging).

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1748

private scoped_cache_dir()

private function scoped_cache_dir(string $base, $sub): string

Resolve a builder cache subdirectory strictly inside its base dir.

ParameterTypeDefaultDescription
$basestring—Base directory (normalized).
$submixed—Relative subdirectory from the map.

Return: string — Normalized absolute path, or \’\’ when unsafe.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1822

private delete_css_files_only()

private function delete_css_files_only($fs, string $dir, array& $deleted): void

Delete only top-level *.css files inside a builder directory.

ParameterTypeDefaultDescription
$fsobject—WP_Filesystem instance.
$dirstring—Scoped directory (already containment-checked).
$deletedarray&—Deleted paths accumulator.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1864

protected fire_builder_regeneration_hooks()

protected function fire_builder_regeneration_hooks(array $matched, array $map): void

Fire builder-native cache-regeneration hooks (best-effort).

ParameterTypeDefaultDescription
$matchedarray—Matched builder keys.
$maparray—Builder map.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 1912

protected purge_wppo_derived_caches()

protected function purge_wppo_derived_caches(): bool

Purge WPPO\’s derived caches (page cache, used-CSS, critical-CSS).

Return: bool — True when the page-cache clear succeeded.

Tags: @since 2.0.0 · @since 2.2.0 Used-CSS path switched from forced full regen to targeted regen. · @since 2.2.0 Returns whether the page-cache clear succeeded.

Source: includes/Integrations/class-builder-purge-watcher.php, line 1958

protected write_purge_log()

protected function write_purge_log(array $labels): void

Write the audit-trail entry for a builder purge.

ParameterTypeDefaultDescription
$labelsarray—Human-readable builder names.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 2063

protected store_admin_notice()

protected function store_admin_notice(array $labels): void

Stage the one-time admin success notice for the purge.

ParameterTypeDefaultDescription
$labelsarray—Human-readable builder names.

Return: void.

Tags: @since 2.0.0

Source: includes/Integrations/class-builder-purge-watcher.php, line 2091

Hooks

Hooks referenced in includes/Integrations/class-builder-purge-watcher.php:

HookTypeLineNotes
wppo_builder_drift_requeueaction460—
wppo_builder_drift_requeueaction658@param ×1
wppo_builder_purge_mapfilter1126@param ×1
wppo_after_builder_purgeaction1343@param ×1
wppo_after_upgrade_purgeaction1464@param ×1
wppo_builder_used_css_full_regenfilter1980@param ×1
wppo_builder_ccss_full_regenfilter2031@param ×1