self::get_bot_choices(), )); register_block_type('mxchat/chatbot', array( 'api_version' => 2, 'editor_script' => 'mxchat-chatbot-block', 'editor_style' => 'mxchat-chatbot-block-editor', 'render_callback' => array(__CLASS__, 'render'), 'attributes' => array( 'displayMode' => array('type' => 'string', 'default' => 'inline'), 'botId' => array('type' => 'string', 'default' => ''), ), )); } /** * Bot choices for the editor's select. Empty array when Multi-Bot is * inactive — the JS hides the control entirely rather than showing a * one-entry dropdown. Guard mirrors class-mxchat-public.php:869. * * Public: the Elementor widget (class-mxchat-elementor-widget.php) builds * its Bot control from this same list — one source, never a second copy. */ public static function get_bot_choices() { if (!class_exists('MxChat_Multi_Bot_Manager') || !class_exists('MxChat_Multi_Bot_Core_Manager')) { return array(); } $manager = MxChat_Multi_Bot_Core_Manager::get_instance(); if (!method_exists($manager, 'get_available_bots')) { return array(); } $choices = array(); foreach ($manager->get_available_bots() as $bot_id => $bot_name) { $choices[] = array( 'value' => $bot_id === 'default' ? '' : (string) $bot_id, 'label' => (string) $bot_name, ); } return $choices; } /** * Front-end render: delegate to the shortcode. * * Consent mirrors append_chatbot_to_body() exactly (class-mxchat-public.php) * so a block placement cannot bypass a Complianz gate the footer path * respects. Everything else — bot resolution, per-page settings, the * floating/Auto-Display collision — is the shortcode's existing logic. */ public static function render($attributes) { $floating = isset($attributes['displayMode']) && $attributes['displayMode'] === 'floating'; $bot_id = isset($attributes['botId']) ? sanitize_key($attributes['botId']) : ''; $options = get_option('mxchat_options', array()); $has_consent = true; if (is_array($options) && isset($options['complianz_toggle']) && $options['complianz_toggle'] === 'on' && function_exists('cmplz_has_consent') ) { $has_consent = cmplz_has_consent('marketing'); } $shortcode = sprintf( '[mxchat_chatbot floating="%s" has_consent="%s"', $floating ? 'yes' : 'no', $has_consent ? 'yes' : 'no' ); // Omit bot_id when unset: determine_bot_for_shortcode() then honors the // page-level bot selection, same as a bare shortcode. if ($bot_id !== '' && $bot_id !== 'default') { $shortcode .= ' bot_id="' . esc_attr($bot_id) . '"'; } $shortcode .= ']'; return do_shortcode($shortcode); } }