true), 'names'); foreach ($post_types as $post_type) { add_meta_box( 'mxchat_visibility', __('MxChat Settings', 'mxchat'), array($this, 'render_meta_box'), $post_type, 'side', 'default' ); } } /** * Register meta fields for Gutenberg */ public function register_meta_fields() { register_post_meta('', '_mxchat_hide_chatbot', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'default' => '', 'auth_callback' => function() { return current_user_can('edit_posts'); } )); register_post_meta('', '_mxchat_selected_bot', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', 'default' => '', 'auth_callback' => function() { return current_user_can('edit_posts'); } )); } /** * Get available bots */ private function get_available_bots() { $bots = array(); // Check if multi-bot addon is active if (class_exists('MxChat_Multi_Bot_Manager')) { $multi_bot_manager = MxChat_Multi_Bot_Core_Manager::get_instance(); $available_bots = $multi_bot_manager->get_available_bots(); // Add the available bots foreach ($available_bots as $bot_id => $bot_name) { $bots[$bot_id] = $bot_name; } } else { // Only default bot available $bots['default'] = __('Default Bot', 'mxchat'); } return $bots; } /** * Check if global auto-show is enabled */ private function is_global_autoshow_enabled() { $options = get_option('mxchat_options', array()); return isset($options['append_to_body']) && $options['append_to_body'] === 'on'; } /** * Updated render_meta_box method with clarified copy */ public function render_meta_box($post) { wp_nonce_field('mxchat_meta_box_nonce', 'mxchat_meta_box_nonce'); $hide_chatbot = get_post_meta($post->ID, '_mxchat_hide_chatbot', true); $selected_bot = get_post_meta($post->ID, '_mxchat_selected_bot', true); $available_bots = $this->get_available_bots(); $global_autoshow = $this->is_global_autoshow_enabled(); $has_multibot = class_exists('MxChat_Multi_Bot_Manager'); ?>

1) : ?>





get_available_bots(); $global_autoshow = $this->is_global_autoshow_enabled(); $has_multibot = class_exists('MxChat_Multi_Bot_Manager'); // Enqueue the JavaScript file wp_enqueue_script( 'mxchat-meta-box', plugin_dir_url(__FILE__) . 'js/meta-box.js', array('wp-edit-post', 'wp-element', 'wp-components', 'wp-data', 'wp-plugins'), '1.0.0', true ); // Localize script with data wp_localize_script('mxchat-meta-box', 'mxchatMetaBox', array( 'availableBots' => $available_bots, 'globalAutoshow' => $global_autoshow, 'hasMultibot' => $has_multibot, 'strings' => array( 'panelTitle' => __('MxChat Settings', 'mxchat'), 'useGlobalSetting' => __('Use Global Setting', 'mxchat'), 'hideChatbot' => __('Hide chatbot on this page', 'mxchat'), 'hideChatbotHelp' => __('Prevent any chatbot from appearing on this page', 'mxchat'), 'selectBot' => __('Select Bot for this Page', 'mxchat'), 'globalAutoshowOn' => __('Global Auto-Show: ON. Use Global Setting = Default bot shows automatically. Select specific bot = That bot shows instead.', 'mxchat'), 'globalAutoshowOff' => __('Global Auto-Show: OFF. Use Global Setting = No bot shows. Select specific bot = That bot shows on this page only.', 'mxchat') ) )); } /** * Helper function to get the bot that should display on current page * Call this from your main chatbot display logic */ public static function get_page_bot_setting($post_id = null) { if (!$post_id) { $post_id = get_the_ID(); } if (!$post_id) { return null; } // Check if chatbot is hidden on this page $hide_chatbot = get_post_meta($post_id, '_mxchat_hide_chatbot', true); if ($hide_chatbot === '1') { return array('action' => 'hide'); } // Check if specific bot is selected $selected_bot = get_post_meta($post_id, '_mxchat_selected_bot', true); if (!empty($selected_bot)) { return array('action' => 'show', 'bot_id' => $selected_bot); } // Use global setting return array('action' => 'global'); } }