Spaces:
Sleeping
Sleeping
| defined( 'ABSPATH' ) || exit; | |
| /** | |
| * Admin enqueue for the Sara bubble UI. | |
| * | |
| * Injects the Sara floating button + panel CSS/JS on Fluent Boards, | |
| * Fluent Support, and SA-Orchestration admin pages. The bubble is | |
| * gated to manage_options users; the REST endpoint behind it is | |
| * gated identically. | |
| * | |
| * The frontend reads URL/hash to detect surface + ref, then POSTs to | |
| * /sa-orch/v1/sara/invoke. No DOM mutation outside the bubble itself. | |
| * | |
| * Pages where Sara appears: | |
| * - page=fluent-boards (any view inside the Boards SPA) | |
| * - page=fluent-support (any view inside the Support SPA) | |
| * - page=sa-orchestration (and its subpages) | |
| */ | |
| class SA_Orch_Sara_Admin { | |
| const HANDLE_JS = 'sa-orch-sara-bubble'; | |
| const HANDLE_CSS = 'sa-orch-sara-bubble'; | |
| public static function register_hooks() { | |
| add_action( 'admin_enqueue_scripts', [ __CLASS__, 'maybe_enqueue' ] ); | |
| } | |
| public static function maybe_enqueue( $hook ) { | |
| if ( ! current_user_can( 'manage_options' ) ) { | |
| return; | |
| } | |
| $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; | |
| // Match the three primary admin surfaces. Sub-pages of sa-orchestration | |
| // (e.g., sa-orchestration-arbitrations) all start with the parent slug. | |
| $is_target = ( | |
| $page === 'fluent-boards' | |
| || $page === 'fluent-support' | |
| || strpos( $page, 'sa-orchestration' ) === 0 | |
| ); | |
| if ( ! $is_target ) { | |
| return; | |
| } | |
| wp_enqueue_style( | |
| self::HANDLE_CSS, | |
| SA_ORCH_URL . 'assets/sara-bubble.css', | |
| [], | |
| SA_ORCH_VERSION | |
| ); | |
| wp_enqueue_script( | |
| self::HANDLE_JS, | |
| SA_ORCH_URL . 'assets/sara-bubble.js', | |
| [], | |
| SA_ORCH_VERSION, | |
| true | |
| ); | |
| wp_localize_script( self::HANDLE_JS, 'SA_ORCH_SARA', [ | |
| 'rest_url' => esc_url_raw( rest_url( 'sa-orch/v1/sara/invoke' ) ), | |
| 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 'page' => $page, | |
| ] ); | |
| } | |
| } | |