pending_bubble(), 'manage_options', self::SLUG, array( $this, 'render' ), 'dashicons-shield', 81 ); } /** * The approval-queue bubble appended to the menu label. * * Deliberately the markup core uses for comments awaiting moderation, so * it inherits the admin color scheme and reads as the signal admins * already know. Empty queue, empty string: absence is the all-clear, and * a "(0)" would only be noise to dismiss. */ private function pending_bubble(): string { $count = null === $this->pending_count ? 0 : ( $this->pending_count )(); if ( $count < 1 ) { return ''; } $display = $count > self::COUNT_DISPLAY_CAP ? sprintf( /* translators: %s: capped number of queued actions, e.g. "99". */ __( '%s+', 'agentic-daisy-ai-agent-firewall' ), number_format_i18n( self::COUNT_DISPLAY_CAP ) ) : number_format_i18n( $count ); // The digit is decoration for assistive tech; this sentence carries // the meaning, and the real number even when the badge is capped. $label = sprintf( /* translators: %s: number of agent actions waiting for approval. */ _n( '%s action awaiting approval', '%s actions awaiting approval', $count, 'agentic-daisy-ai-agent-firewall' ), number_format_i18n( $count ) ); return sprintf( ' ' . '' . '%3$s', $count, esc_html( $display ), esc_html( $label ) ); } /** * Enqueue the built SPA bundle; only on our own screen. * * @param string $hook_suffix Current admin screen hook. */ public function enqueue_assets( string $hook_suffix ): void { if ( self::SCREEN_HOOK !== $hook_suffix ) { return; } $this->enqueue_bundle(); } /** * Enqueue the admin bundle, its data and every premium bundle, on * whichever screen calls it - the site screen, or the Agency network * screen (AF-22.2c), whose own bundle mounts into its own root. */ public function enqueue_bundle(): void { $asset_file = ADAF_PLUGIN_PATH . 'build/index.asset.php'; if ( ! file_exists( $asset_file ) ) { return; } $asset = require $asset_file; if ( ! is_array( $asset ) ) { return; } wp_enqueue_script( 'agentic-daisy-ai-agent-firewall-admin', ADAF_PLUGIN_URL . 'build/index.js', isset( $asset['dependencies'] ) && is_array( $asset['dependencies'] ) ? $asset['dependencies'] : array(), isset( $asset['version'] ) && is_string( $asset['version'] ) ? $asset['version'] : ADAF_VERSION, true ); // Without this the admin SPA's own __() strings never receive the // wp.org language pack, so a translated site still gets an English // firewall UI. No path argument: packs for a directory-hosted plugin // install into WP_LANG_DIR/plugins, which is where WordPress looks // when none is given. wp_set_script_translations( 'agentic-daisy-ai-agent-firewall-admin', 'agentic-daisy-ai-agent-firewall' ); // What the SPA may show, built from FeatureMap and failing closed // (ADR-14 §2). Deliberately no upgrade URL: the firewall screens carry // no upsell (ADR-14 §4); the Freemius menu item is the only one. wp_localize_script( self::SCRIPT_HANDLE, 'adafAdmin', array( 'features' => adaf_feature_flags(), 'licenseTier' => adaf_license_tier(), // Whether EVALUATE_AI rules are reviewed by the AI evaluator // first, so the rule builder can say what they do on this // site (AF-21.5). The filter is the one the pipeline asks; // nothing answers it in the free build. 'aiReviewActive' => true === apply_filters( 'adaf_ai_review_active', false ), // Network-aware screens ask about the network only on one // (ADR-16). 'isMultisite' => is_multisite(), ) ); $this->enqueue_premium_bundles(); // Only enqueue the stylesheet the build actually produced; a missing // file would otherwise be requested on every admin page load. if ( file_exists( ADAF_PLUGIN_PATH . 'build/style-index.css' ) ) { wp_enqueue_style( 'agentic-daisy-ai-agent-firewall-admin', ADAF_PLUGIN_URL . 'build/style-index.css', array(), isset( $asset['version'] ) && is_string( $asset['version'] ) ? $asset['version'] : ADAF_VERSION ); } } /** * Enqueue every premium bundle this build has (AF-19.5). * * Premium UI is compiled to its own build/premium-*.js entries, which the * free build is stripped of, so on the free build nothing matches here. * Each depends on the admin bundle for React, adafAdmin and the apiFetch * middleware, and renders only what its feature flag allows. A bundle * without its asset manifest is skipped rather than loaded without its * dependencies. */ private function enqueue_premium_bundles(): void { $bundles = glob( ADAF_PLUGIN_PATH . 'build/premium-*.js' ); foreach ( false === $bundles ? array() : $bundles as $bundle ) { $name = basename( $bundle, '.js' ); $asset_file = ADAF_PLUGIN_PATH . 'build/' . $name . '.asset.php'; if ( ! file_exists( $asset_file ) ) { continue; } $asset = require $asset_file; if ( ! is_array( $asset ) ) { continue; } $handle = 'agentic-daisy-ai-agent-firewall-' . $name; wp_enqueue_script( $handle, ADAF_PLUGIN_URL . 'build/' . $name . '.js', array_merge( isset( $asset['dependencies'] ) && is_array( $asset['dependencies'] ) ? $asset['dependencies'] : array(), array( self::SCRIPT_HANDLE ) ), isset( $asset['version'] ) && is_string( $asset['version'] ) ? $asset['version'] : ADAF_VERSION, true ); wp_set_script_translations( $handle, 'agentic-daisy-ai-agent-firewall' ); } } /** * Render the SPA mount point. */ public function render(): void { echo '
'; echo esc_html__( 'Loading Agent Firewall…', 'agentic-daisy-ai-agent-firewall' ); echo '
'; } }