enqueued) { return; } // Always enqueue styles and scripts for floating robot // (they are needed when modal opens) // Use correct path: files are in inc/bot-assistant/assets/ $assets_url = plugin_dir_url(__FILE__) . 'assets/'; $plugin_url = plugin_dir_url(dirname(dirname(__FILE__))); // Enqueue Font Awesome for icons wp_enqueue_style( 'font-awesome', $plugin_url . 'js/fontawesome/css/all.min.css', array(), defined('AIAUTOTOOL_VERSION_CACHE') ? AIAUTOTOOL_VERSION_CACHE : '7.1.0' ); // Enqueue robot CSS with higher priority and force loading wp_enqueue_style( 'floating-robot-style', $assets_url . 'css/floating-robot.css', array('font-awesome'), time() ); // Add inline CSS as fallback to ensure styles are always available $this->add_inline_css_fallback(); // Also enqueue bot assistant CSS for standalone chat wp_enqueue_style( 'bot-assistant-style-modal', $assets_url . 'css/bot-assistant.css', array(), time() ); wp_enqueue_style( 'execute-plan-button-style-modal', $assets_url . 'css/execute-plan-button.css', array(), time() ); wp_enqueue_style( 'cursor-thinking-phases-style-modal', $assets_url . 'css/cursor-thinking-phases.css', array(), time() ); // Cursor-style chat interface for standalone chat (load after bot-assistant for proper precedence) wp_enqueue_style( 'cursor-style-chat-modal', $assets_url . 'css/cursor-style-chat.css', array('bot-assistant-style-modal'), time() ); // Enqueue robot JS wp_enqueue_script( 'floating-robot-script', $assets_url . 'js/floating-robot.js', array('jquery'), time(), true ); // Also enqueue bot assistant JS for standalone chat wp_enqueue_script( 'bot-assistant-script-modal', $assets_url . 'js/bot-assistant.js?v=' . time(), array('jquery'), time(), true ); // Cursor-style chat JavaScript wp_enqueue_script( 'cursor-style-chat-script-modal', $assets_url . 'js/cursor-style-chat.js', array('jquery'), time(), true ); // Localize bot assistant data wp_localize_script('floating-robot-script', 'botAssistantData', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('bot_assistant_nonce'), 'strings' => array( 'askMe' => __('Ask me anything about your site...', 'ai-auto-tool'), 'searching' => __('Searching...', 'ai-auto-tool'), 'analyzing' => __('Analyzing...', 'ai-auto-tool'), ) )); // Localize script with data - Correct image path wp_localize_script('floating-robot-script', 'floatingRobotData', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('floating_robot_nonce'), 'robotImageUrl' => $assets_url . 'images/robotai.gif', 'botAssistantPageUrl' => admin_url('admin.php?page=aiautotool-bot-assistant'), )); // Mark as enqueued $this->enqueued = true; } /** * Add inline CSS fallback to ensure styles are always available */ private function add_inline_css_fallback() { $fallback_css = ' '; echo $fallback_css; } /** * Add CSS directly to admin head for better reliability */ public function add_css_to_head() { // Only add CSS to admin pages if (!is_admin()) { return; } // Check if bot assistant is active - default true $bot_active = get_option('aiautotool_bot_assistant_active', true); // Allow both string 'true' and boolean true if ($bot_active !== 'true' && $bot_active !== true && $bot_active !== '1') { return; } // Use correct path: files are in inc/bot-assistant/assets/ $assets_url = plugin_dir_url(__FILE__) . 'assets/'; $plugin_url = plugin_dir_url(dirname(dirname(__FILE__))); // Add Font Awesome CSS first echo ''; // Add CSS link to head echo ''; // Also add inline CSS as backup $this->add_inline_css_fallback(); } /** * Get bot name from settings */ public function get_bot_name() { check_ajax_referer('floating_robot_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Permission denied', 'ai-auto-tool'))); } $bot_name = get_option('aiautotool_bot_assistant_name', 'AIAUTOTOOL'); wp_send_json_success(array('bot_name' => $bot_name)); } /** * Get standalone chat info (lightweight AJAX endpoint) */ public function get_standalone_chat_info() { check_ajax_referer('floating_robot_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => __('Permission denied', 'ai-auto-tool'))); } $assistant_name = get_option('aiautotool_bot_assistant_name', 'AIAUTOTOOL'); $role_intro = get_option('aiautotool_bot_assistant_role_intro', ''); $use_ai = get_option('aiautotool_bot_assistant_use_ai', true); $has_ai = false; $provider_info = ''; if ($use_ai && class_exists('AIAutotool_AI_Helper')) { $has_ai = AIAutotool_AI_Helper::is_available(); if ($has_ai) { $ai_info = AIAutotool_AI_Helper::get_active_info(); if ($ai_info) { $provider_info = $ai_info['provider_name'] . ' - ' . $ai_info['model']; } } } wp_send_json_success(array( 'assistant_name' => $assistant_name, 'role_intro' => $role_intro, 'has_ai' => $has_ai, 'provider_info' => $provider_info )); } /** * Render the floating robot widget */ public function render_robot_widget() { // Check if bot assistant is active - default true $bot_active = get_option('aiautotool_bot_assistant_active', true); // Allow both string 'true' and boolean true if ($bot_active !== 'true' && $bot_active !== true && $bot_active !== '1') { return; } // Also check if we're on bot assistant page - hide widget there $current_screen = get_current_screen(); if ($current_screen && strpos($current_screen->id, 'aiautotool-bot-assistant') !== false) { return; } // Ensure scripts are loaded even if admin_enqueue_scripts didn't fire // (some admin pages don't fire this hook) if (!$this->enqueued) { $this->enqueue_scripts_force(); } // Get robot image URL - Correct path in assets folder $assets_url = plugin_dir_url(__FILE__) . 'assets/'; $robot_image_url = $assets_url . 'images/robotai.gif'; // Get bot assistant page URL $bot_assistant_url = admin_url('admin.php?page=aiautotool-bot-assistant'); ?>