id ) { return; } ?> enqueue_i18n_loader(); // Localize chat configuration. $screen = get_current_screen(); // Chatbot CSS + JS loads on every admin page where the chat float is enabled. if ( $this->is_chat_enabled( $screen ) ) { wp_enqueue_style( 'aisentic-admin-chatbot-style' ); wp_enqueue_script( 'aisentic-admin-chatbot-scripts' ); wp_localize_script( 'aisentic-admin-chatbot-scripts', 'aisentic', [ 'enabled' => true, 'currentPage' => $screen ? $screen->id : '', 'adminUrl' => admin_url(), 'siteUrl' => site_url(), 'time_format' => get_option( 'time_format' ), // Message times render in the site's timezone, not the viewer's browser // clock, so a live message and the same message after a reload agree. 'gmt_offset' => (float) get_option( 'gmt_offset', 0 ), 'date_format' => get_option( 'date_format' ), 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), /* * Whether an account exists. False makes the widget answer the * first prompt with its activation card instead of calling the * agent — registration happens in the chat, not on a separate * onboarding screen. Absent on the storefront bundle, which must * never show an account signup to a site visitor. */ 'registered' => '' !== (string) aisentic_get_option( 'llmProviders.aisentic.apiKey', '' ), 'currentUser' => [ 'displayName' => wp_get_current_user()->display_name, 'email' => wp_get_current_user()->user_email, 'username' => wp_get_current_user()->user_login, ], ] ); // Hide third-party HelpScout Beacon when aisentic chatbot is active on this page. wp_add_inline_style( 'aisentic-admin-chatbot-style', '#beacon-container { display: none !important; }' ); wp_add_inline_script( 'aisentic-admin-chatbot-scripts', 'if (typeof window.Beacon === "function") { window.Beacon("destroy"); }', 'after' ); } // Dashboard CSS + JS loads only on the plugin's main page. if ( ! $screen || 'toplevel_page_aisentic' !== $screen->id ) { return; } if ( $screen && 'plugins' !== $screen->id ) { wp_enqueue_style( 'aisentic-admin-style' ); } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_media(); wp_enqueue_script( 'aisentic-dashboard-scripts' ); } /** * Render chat container div in admin footer. * * @return void */ public function render_chat_container(): void { $screen = get_current_screen(); if ( ! $this->is_chat_enabled( $screen ) ) { return; } echo '
'; } /** * Check if chat should be enabled on current page. * * Public because Presence shares this gate — it advertises `chatAvailable` to * consumer plugins, which is true only on screens where this bundle loads. * * @param \WP_Screen|null $screen Current screen object. * * @return bool True if chat should be enabled, false otherwise. */ public function is_chat_enabled( $screen ): bool { $enabled = $this->resolve_chat_enabled( $screen ); /** * Filter whether the chat is enabled on the current screen. * * @since 1.0.0 * * @param bool $enabled Whether chat is enabled. * @param \WP_Screen|null $screen Current screen object. */ return (bool) apply_filters( 'aisentic_chat_enabled', $enabled, $screen ); } /** * Resolve the unfiltered chat-enabled state for a screen. * * @param \WP_Screen|null $screen Current screen object. * * @return bool True if chat should be enabled, false otherwise. */ private function resolve_chat_enabled( $screen ): bool { if ( ! $screen ) { return false; } $show_chatbot = aisentic_get_option( 'show_chatbot', 'plugins_pages' ); if ( 'all_pages' === $show_chatbot ) { $disabled_pages = $this->get_disabled_pages(); return ! in_array( $screen->id, $disabled_pages, true ); } // 'plugins_pages': always show on the aisentic page itself. if ( 'toplevel_page_aisentic' === $screen->id ) { return true; } // Show on any page belonging to a connected integration. $plugin_id = Screen_Id_To_Plugin_Mapper::get( $screen->id ); if ( empty( $plugin_id ) || 'aisentic' === $plugin_id ) { return false; } $saved = get_option( 'aisentic_integration_settings', [] ); return isset( $saved[ $plugin_id ]['status'] ) && Integration_Status::CONNECTED === $saved[ $plugin_id ]['status']; } /** * Get list of disabled page screen IDs. * * @return array Array of screen IDs where chat should be disabled. */ private function get_disabled_pages(): array { /** * Filter the list of admin pages where chat should be disabled. * * @since 1.0.0 * * @param array $disabled_pages Array of screen IDs where chat should be disabled. */ return apply_filters( 'aisentic_chat_disabled_pages', [ 'plugins' ] ); } /** * Get all scripts * * @return array List register scripts */ public function get_scripts(): array { $scripts = [ 'aisentic-i18n-loader' => [ 'src' => aisentic()->assets_url . '/build/js/i18n-loader.js', 'in_footer' => true, ], 'aisentic-dashboard-scripts' => [ 'src' => aisentic()->assets_url . '/build/js/dashboard.js', 'deps' => [ 'aisentic-i18n-loader' ], 'in_footer' => true, ], 'aisentic-admin-chatbot-scripts' => [ 'src' => aisentic()->assets_url . '/build/js/admin-chatbot.js', 'deps' => [ 'aisentic-i18n-loader' ], 'in_footer' => true, ], ]; return apply_filters( 'aisentic_admin_assets', $scripts ); } /** * List of register styles * * @return array */ public function get_styles(): array { $styles = [ 'aisentic-admin-style' => [ 'src' => aisentic()->assets_url . '/build/css/admin.css', ], 'aisentic-admin-chatbot-style' => [ 'src' => aisentic()->assets_url . '/build/css/chatbot.css', ], ]; return apply_filters( 'aisentic_admin_styles', $styles ); } }