options = get_option('mxchat_options', array()); add_shortcode('mxchat_chatbot', array($this, 'render_chatbot_shortcode')); add_action('wp_footer', array($this, 'append_chatbot_to_body')); // Initialize testing panel for admins add_action('wp_enqueue_scripts', array($this, 'enqueue_testing_assets')); } /** * Enqueue testing panel assets for admin users */ public function enqueue_testing_assets() { // Only load for admin users or if testing parameter is present if (current_user_can('administrator') || isset($_GET['mxchat_test'])) { // Get plugin URL for assets $plugin_url = plugin_dir_url(dirname(__FILE__)); // Enqueue test panel CSS wp_enqueue_style( 'mxchat-test-panel', $plugin_url . 'css/test-panel.css', array(), '1.0.0' ); // Enqueue test panel JS wp_enqueue_script( 'mxchat-test-panel', $plugin_url . 'js/test-panel.js', array('jquery'), '1.0.0', true ); // Pass data to JavaScript wp_localize_script('mxchat-test-panel', 'mxchatTestData', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('mxchat_test_nonce'), 'isAdmin' => current_user_can('administrator'), 'testingEnabled' => true )); // Add JavaScript flag to enable testing add_action('wp_footer', array($this, 'add_testing_flag')); } } /** * Add JavaScript flag to enable testing panel */ public function add_testing_flag() { echo ''; } /** * Check if testing mode should be enabled */ private function is_testing_mode_enabled() { return (current_user_can('administrator') || isset($_GET['mxchat_test'])); } public function append_chatbot_to_body() { // Use only the options we need with isset checks $consent_category = 'marketing'; if (isset($this->options['append_to_body']) && $this->options['append_to_body'] === 'on') { // Store consent status but always render $has_consent = true; if ( isset($this->options['complianz_toggle']) && $this->options['complianz_toggle'] === 'on' && function_exists('cmplz_has_consent') ) { $has_consent = cmplz_has_consent($consent_category); } // Add consent status as a parameter to the shortcode echo do_shortcode('[mxchat_chatbot floating="yes" has_consent="' . ($has_consent ? 'yes' : 'no') . '"]'); } } private function mxchat_get_user_identifier() { return sanitize_text_field($_SERVER['REMOTE_ADDR']); } public function render_chatbot_shortcode($atts) { $attributes = shortcode_atts(array( 'floating' => 'yes', 'has_consent' => 'yes' ), $atts); $is_floating = $attributes['floating'] === 'yes'; // Check for Complianz consent if the toggle is enabled $initial_visibility = 'hidden'; $additional_class = ''; if (isset($this->options['complianz_toggle']) && $this->options['complianz_toggle'] === 'on') { $additional_class = ' no-consent'; } $visibility_class = $initial_visibility . $additional_class; $theme_options = get_option('mxchat_theme_options', array()); $custom_send_image = isset($theme_options['custom_send_button_image']) ? esc_url($theme_options['custom_send_button_image']) : ''; $send_width = isset($theme_options['send_button_width']) ? intval($theme_options['send_button_width']) : 24; $send_height = isset($theme_options['send_button_height']) ? intval($theme_options['send_button_height']) : 24; $send_rotation = isset($theme_options['send_button_rotation']) ? intval($theme_options['send_button_rotation']) : 0; // Existing variables... $bg_color = $this->options['chatbot_background_color'] ?? '#fff'; $user_message_bg_color = $this->options['user_message_bg_color'] ?? '#fff'; $user_message_font_color = $this->options['user_message_font_color'] ?? '#212121'; $bot_message_bg_color = $this->options['bot_message_bg_color'] ?? '#212121'; $bot_message_font_color = $this->options['bot_message_font_color'] ?? '#fff'; $top_bar_bg_color = $this->options['top_bar_bg_color'] ?? '#212121'; $send_button_font_color = $this->options['send_button_font_color'] ?? '#212121'; $intro_message = $this->options['intro_message'] ?? esc_html__('Hello! How can I assist you today?', 'mxchat'); $top_bar_title = $this->options['top_bar_title'] ?? esc_html__('MxChat: Basic', 'mxchat'); $chatbot_background_color = $this->options['chatbot_background_color'] ?? '#212121'; $icon_color = $this->options['icon_color'] ?? '#fff'; $chat_input_font_color = $this->options['chat_input_font_color'] ?? '#212121'; $close_button_color = $this->options['close_button_color'] ?? '#fff'; $chatbot_bg_color = $this->options['chatbot_bg_color'] ?? '#fff'; $pre_chat_message = isset($this->options['pre_chat_message']) ? sanitize_text_field(trim($this->options['pre_chat_message'])) : ''; $user_id = sanitize_key($this->mxchat_get_user_identifier()); $email_state = $this->determine_email_collection_state(); $show_email_form = $email_state['show_email_form']; $user_email = $email_state['user_email'] ?? ''; $user_name = $email_state['user_name'] ?? ''; $transient_key = 'mxchat_pre_chat_message_dismissed_' . $user_id; $input_copy = isset($this->options['input_copy']) ? esc_attr($this->options['input_copy']) : esc_attr__('How can I assist?', 'mxchat'); $rate_limit_message = isset($this->options['rate_limit_message']) ? esc_attr($this->options['rate_limit_message']) : esc_attr__('Rate limit exceeded. Please try again later.', 'mxchat'); $mode_indicator_bg_color = $this->options['mode_indicator_bg_color'] ?? '#212121'; $mode_indicator_font_color = $this->options['mode_indicator_font_color'] ?? '#fff'; $quick_questions_toggle_color = $this->options['quick_questions_toggle_color'] ?? '#212121'; $privacy_toggle = isset($this->options['privacy_toggle']) && $this->options['privacy_toggle'] === 'on'; $privacy_text = isset($this->options['privacy_text']) ? wp_kses_post($this->options['privacy_text']) : wp_kses_post(__('By chatting, you agree to our privacy policy.', 'mxchat')); $popular_question_1 = isset($this->options['popular_question_1']) ? esc_html($this->options['popular_question_1']) : ''; $popular_question_2 = isset($this->options['popular_question_2']) ? esc_html($this->options['popular_question_2']) : ''; $popular_question_3 = isset($this->options['popular_question_3']) ? esc_html($this->options['popular_question_3']) : ''; $additional_questions = isset($this->options['additional_popular_questions']) ? $this->options['additional_popular_questions'] : []; $custom_icon = isset($this->options['custom_icon']) ? esc_url($this->options['custom_icon']) : ''; $title_icon = isset($this->options['title_icon']) ? esc_url($this->options['title_icon']) : ''; $ai_agent_text = isset($this->options['ai_agent_text']) ? esc_html($this->options['ai_agent_text']) : esc_html__('AI Agent', 'mxchat'); $live_agent_message_bg_color = $this->options['live_agent_message_bg_color'] ?? '#212121'; $live_agent_message_font_color = $this->options['live_agent_message_font_color'] ?? '#fff'; $enable_email_block = isset($this->options['enable_email_block']) && ($this->options['enable_email_block'] === '1' || $this->options['enable_email_block'] === 'on'); // NEW: Add name field variables $enable_name_field = isset($this->options['enable_name_field']) && ($this->options['enable_name_field'] === '1' || $this->options['enable_name_field'] === 'on'); $name_field_placeholder = isset($this->options['name_field_placeholder']) ? esc_attr($this->options['name_field_placeholder']) : esc_attr__('Enter your name', 'mxchat'); ob_start(); // Check if floating attribute is set to 'yes' and wrap accordingly if ($is_floating) { echo '