data] */ private static ?array $processed_data = null; /** @var array|null Cached result of check_global_settings(), set once per request. */ private static ?array $global_checks = null; /** @var bool True if the processor has already been executed. */ public static bool $processor_executed = false; /** @var bool True if the label CSS has already been added. */ public static bool $label_css_added = false; /** @var array> Inline assets per placement key, printed with the placement's output. */ private static array $placement_assets = []; /** @var array Asset IDs already printed this request. */ private static array $printed_assets = []; /** * @var bool True if there are placements that require JS output. * This is determined after the processor has run. */ private static bool $has_js_placements = false; /** @var array Configs from block/shortcode-rendered (virtual) placements resolved this request. */ private static array $virtual_placement_configs = []; /** @var bool True once a virtual/manual placement has signalled it needs the JS render chain. */ private static bool $virtual_render_chain_required = false; /** @var bool True once localize_frontend_data() has run - later registrations would be silently dropped. */ private static bool $frontend_data_localized = false; /** @var array Config keys (placement ID or uid) already printed inside a placeholder. */ private static array $inlined_config_keys = []; /** * Initialises the hooks for central processing and localisation. * Should be called once the plugin starts. * Early wp hook for central processing (after query and user have been determined) */ public static function hooks(): void { add_action( 'wp', [ self::class, 'maybe_execute_processor' ], 5 ); add_action( 'wp_footer', [ self::class, 'localize_frontend_data' ], 19 ); add_filter( 'adpresso_requires_frontend_logic', [ self::class, 'force_js_for_role_restriction' ], 10, 3 ); add_filter( 'adpresso_global_gates_active', [ self::class, 'role_restriction_adds_global_gate' ] ); add_filter( 'adpresso_global_gate_blocks_visitor', [ self::class, 'role_restriction_blocks_visitor' ] ); // Ajax Load More renders its templates in admin-ajax, where 'wp' never fires. add_action( 'wp_ajax_alm_get_posts', [ self::class, 'ensure_fragment_pipeline' ], 1, 0 ); add_action( 'wp_ajax_nopriv_alm_get_posts', [ self::class, 'ensure_fragment_pipeline' ], 1, 0 ); // RuntimeDebugger::hooks() already gates itself RuntimeDebugger::hooks(); } /** * Return whether there are any JS placements in the current request. * * @return bool */ public static function has_js_placements(): bool { return self::$has_js_placements; } /** * Whether the JS render chain is needed - real placements OR any virtual (block/shortcode) placement that resolved to JS mode this request. */ public static function render_chain_required(): bool { return self::$has_js_placements || self::$virtual_render_chain_required; } /** * Registers a block/shortcode-rendered (virtual) placement's frontend config. */ public static function add_virtual_placement_config( string $key, array $config ): void { if ( self::$frontend_data_localized ) { RuntimeDebugger::add_server_error_log_entry( "AdPresso Runtime: Virtual placement config for '{$key}' registered after localize_frontend_data() already ran - it will not reach the frontend." ); } self::$virtual_placement_configs[ $key ] = $config; self::$virtual_render_chain_required = true; Assets::enqueue_render_chain(); do_action( 'adpresso_virtual_placement_resolved' ); } /** * Resets every piece of per-request pipeline state. * * @return void */ public static function reset_request_state(): void { self::$processed_data = null; self::$processor_executed = false; self::$has_js_placements = false; self::$virtual_placement_configs = []; self::$virtual_render_chain_required = false; self::$frontend_data_localized = false; self::$inlined_config_keys = []; self::$label_css_added = false; self::$global_checks = null; self::$placement_assets = []; self::$printed_assets = []; Html::reset_rendered_content(); } /** * Registers an inline asset (