' . esc_html( askbot_admin_lang() === 'en' ? 'Settings' : 'Réglages' ) . ''; array_unshift( $links, $settings_link ); return $links; } /** * Icône du menu en SVG « data URI » : WordPress la colorie comme les autres * icônes du menu (gris, survol, élément actif, thèmes de couleurs de l'admin). */ function askbot_menu_icon() { $svg = file_get_contents( ASKBOT_DIR . 'assets/menu-icon.svg' ); return $svg ? 'data:image/svg+xml;base64,' . base64_encode( $svg ) : 'dashicons-format-chat'; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Format attendu par add_menu_page() pour une icône SVG. } add_action( 'admin_enqueue_scripts', 'askbot_admin_assets' ); function askbot_admin_assets( $hook ) { if ( 'toplevel_page_askbot-settings' !== $hook ) { return; } $t = askbot_admin_strings( askbot_admin_lang() ); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_media(); wp_enqueue_script( 'askbot-admin', ASKBOT_URL . 'assets/admin.js', array( 'jquery', 'wp-color-picker' ), ASKBOT_VERSION, true ); wp_localize_script( 'askbot-admin', 'askbotAdmin', array( 'mediaTitle' => $t['media_title'], 'mediaBtn' => $t['media_btn'], ) ); } add_action( 'admin_menu', 'askbot_admin_menu' ); function askbot_admin_menu() { add_menu_page( 'Youjeeb – AI Chatbot', 'Youjeeb', 'manage_options', 'askbot-settings', 'askbot_settings_page', askbot_menu_icon(), 80 ); add_submenu_page( 'askbot-settings', ( askbot_admin_lang() === 'en' ) ? 'Youjeeb Settings' : 'Réglages Youjeeb', ( askbot_admin_lang() === 'en' ) ? 'Settings' : 'Réglages', 'manage_options', 'askbot-settings', 'askbot_settings_page' ); } /** * Textes de la page de réglages (FR/EN). * * @param string $al Langue du backoffice. * @return array */ function askbot_admin_strings( $al ) { $strings = array( 'fr' => array( 'section_identity' => '🎭 Identité du chatbot', 'section_design' => '🎨 Design visuel', 'section_ai' => '🤖 Intelligence artificielle', 'section_behavior' => '⚙️ Comportement', 'section_ux' => '✨ Expérience utilisateur', 'bot_name_label' => 'Nom du chatbot', 'bot_name_desc' => "Nom affiché dans l'en-tête du chat.", 'avatar_label' => 'Avatar', 'welcome_label' => 'Message de bienvenue', 'welcome_desc' => "Premier message affiché à l'ouverture du chat.", 'colors_label' => 'Couleurs', 'colors_desc' => 'Couleurs du widget aux tons Youjeeb.', 'color_primary' => 'Couleur principale', 'color_primary_desc' => 'En-tête, bouton du chat et bouton Envoyer.', 'color_bot' => 'Bulles du chatbot', 'color_user' => 'Bulles du visiteur', 'avatar_upload' => 'Choisir une image', 'avatar_reset' => 'Image par défaut', 'avatar_desc' => 'Image carrée recommandée (au moins 128 × 128 px).', 'media_title' => "Choisir l'avatar du chatbot", 'media_btn' => 'Utiliser cette image', 'openai_key_label' => 'Clé API OpenAI', 'openai_key_desc' => 'Utilisée pour générer les réponses et indexer votre contenu. Obtenez-la sur', 'openai_model_label' => 'Modèle OpenAI', 'lang_label' => 'Langue', 'lang_desc' => 'Choisissez la langue principale de vos visiteurs. Le chatbot répondra uniquement dans cette langue.', 'sound_label' => 'Son de notification', 'sound_check' => "Activer le son à l'ouverture et à la réception d'un message", 'sound_desc' => 'Un léger "ding" pour attirer l\'attention de l\'utilisateur.', 'offset_label' => 'Décalage vertical (px)', 'offset_unit' => "px depuis le bas de l'écran", 'offset_desc' => 'Standard : 24px. Augmentez si votre thème a un bouton "retour en haut" ou une barre fixe en bas.', 'autoopen_label' => 'Ouverture automatique', 'autoopen_unit' => 'secondes (0 = désactivé)', 'autoopen_desc' => 'Le chat s\'ouvre automatiquement après X secondes sur la page. Recommandé : 5 à 10 secondes.', 'credit_label' => 'Lien « Propulsé par Youjeeb »', 'credit_check' => 'Afficher un petit lien « Propulsé par Youjeeb » en bas du chat', 'credit_desc' => 'Désactivé par défaut. Merci si vous choisissez de l\'activer !', 'save_btn' => '💾 Enregistrer les réglages', 'saved' => '✅ Paramètres enregistrés avec succès !', 'guide' => "📖 Guide d'installation complet →", 'premium_title' => '⭐ Youjeeb Premium', 'premium_desc' => 'Une extension payante, vendue séparément sur useyoujeeb.com, ajoute à ce plugin :', 'premium_features' => 'GPT-6 Sol et Claude (Anthropic) · documents PDF · catalogue WooCommerce · plusieurs langues avec détection automatique · prompt système personnalisé · suggestions rapides · collecte de leads · statistiques · masquage du chat sur certaines pages.', 'premium_btn' => 'Découvrir Youjeeb Premium →', 'privacy_title' => '🔒 Données envoyées à OpenAI', 'privacy_desc' => "Les questions de vos visiteurs, ainsi que des extraits du contenu de votre site, sont envoyées à l'API OpenAI avec votre clé pour générer les réponses. Pensez à le mentionner dans votre politique de confidentialité.", ), 'en' => array( 'section_identity' => '🎭 Chatbot Identity', 'section_design' => '🎨 Visual Design', 'section_ai' => '🤖 Artificial Intelligence', 'section_behavior' => '⚙️ Behavior', 'section_ux' => '✨ User Experience', 'bot_name_label' => 'Chatbot name', 'bot_name_desc' => 'Name displayed in the chat header.', 'avatar_label' => 'Avatar', 'welcome_label' => 'Welcome message', 'welcome_desc' => 'First message shown when the chat opens.', 'colors_label' => 'Colors', 'colors_desc' => 'Widget colors in Youjeeb tones.', 'color_primary' => 'Main color', 'color_primary_desc' => 'Header, chat button and Send button.', 'color_bot' => 'Chatbot bubbles', 'color_user' => 'Visitor bubbles', 'avatar_upload' => 'Choose an image', 'avatar_reset' => 'Default image', 'avatar_desc' => 'Square image recommended (at least 128 × 128 px).', 'media_title' => 'Choose the chatbot avatar', 'media_btn' => 'Use this image', 'openai_key_label' => 'OpenAI API Key', 'openai_key_desc' => 'Used to generate answers and index your content. Get it at', 'openai_model_label' => 'OpenAI Model', 'lang_label' => 'Language', 'lang_desc' => 'Choose the main language of your visitors. The chatbot will only respond in this language.', 'sound_label' => 'Notification sound', 'sound_check' => 'Enable sound on open and on message received', 'sound_desc' => 'A soft "ding" to attract the user\'s attention.', 'offset_label' => 'Vertical offset (px)', 'offset_unit' => 'px from bottom of screen', 'offset_desc' => 'Default: 24px. Increase if your theme has a "back to top" button or a fixed bottom bar.', 'autoopen_label' => 'Auto-open', 'autoopen_unit' => 'seconds (0 = disabled)', 'autoopen_desc' => 'The chat opens automatically after X seconds on the page. Recommended: 5 to 10 seconds.', 'credit_label' => '"Powered by Youjeeb" link', 'credit_check' => 'Show a small "Powered by Youjeeb" link at the bottom of the chat', 'credit_desc' => 'Disabled by default. Thank you if you choose to enable it!', 'save_btn' => '💾 Save Settings', 'saved' => '✅ Settings saved successfully!', 'guide' => '📖 Full installation guide →', 'premium_title' => '⭐ Youjeeb Premium', 'premium_desc' => 'A paid add-on, sold separately on useyoujeeb.com, adds to this plugin:', 'premium_features' => 'GPT-6 Sol and Claude (Anthropic) · PDF documents · WooCommerce catalog · multiple languages with auto-detection · custom system prompt · quick suggestions · lead collection · statistics · hide the chat on specific pages.', 'premium_btn' => 'Discover Youjeeb Premium →', 'privacy_title' => '🔒 Data sent to OpenAI', 'privacy_desc' => "Your visitors' questions, along with excerpts of your site content, are sent to the OpenAI API with your key to generate answers. Remember to mention it in your privacy policy.", ), ); return $strings[ $al ] ?? $strings['fr']; } // ============================================ // ENREGISTREMENT // ============================================ function askbot_save_settings() { if ( ! isset( $_POST['askbot_save_settings'] ) ) { return ''; } check_admin_referer( 'askbot_settings_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { return ''; } if ( isset( $_POST['askbot_openai_api_key'] ) ) { update_option( 'askbot_openai_api_key', sanitize_text_field( wp_unslash( $_POST['askbot_openai_api_key'] ) ) ); } $bot_name = isset( $_POST['askbot_bot_name'] ) ? sanitize_text_field( wp_unslash( $_POST['askbot_bot_name'] ) ) : ''; update_option( 'askbot_bot_name', '' !== $bot_name ? $bot_name : 'Youjeeb' ); // Champ présent uniquement quand une seule langue est configurable. if ( isset( $_POST['askbot_language'] ) ) { $language = sanitize_key( wp_unslash( $_POST['askbot_language'] ) ); if ( array_key_exists( $language, askbot_available_languages() ) ) { update_option( 'askbot_language', $language ); } } update_option( 'askbot_sound_enabled', isset( $_POST['askbot_sound_enabled'] ) ? '1' : '0' ); update_option( 'askbot_show_credit', isset( $_POST['askbot_show_credit'] ) ? '1' : '0' ); update_option( 'askbot_auto_open_delay', isset( $_POST['askbot_auto_open_delay'] ) ? min( 120, absint( $_POST['askbot_auto_open_delay'] ) ) : 0 ); update_option( 'askbot_bottom_offset', isset( $_POST['askbot_bottom_offset'] ) ? max( 16, min( 200, absint( $_POST['askbot_bottom_offset'] ) ) ) : 24 ); // Champ absent si une extension remplace la ligne « Message de bienvenue ». if ( isset( $_POST['askbot_welcome_message'] ) ) { update_option( 'askbot_welcome_message', sanitize_textarea_field( wp_unslash( $_POST['askbot_welcome_message'] ) ) ); } // Apparence : couleurs et avatar. $defaults = askbot_default_colors(); $color_fields = array( 'askbot_color_primary' => 'primary', 'askbot_color_bot_bubble' => 'bot', 'askbot_color_user_bubble' => 'user', ); foreach ( $color_fields as $field => $key ) { if ( isset( $_POST[ $field ] ) ) { $color = sanitize_hex_color( wp_unslash( $_POST[ $field ] ) ); update_option( $field, $color ? $color : $defaults[ $key ] ); } } if ( isset( $_POST['askbot_avatar_id'] ) ) { $avatar_id = absint( $_POST['askbot_avatar_id'] ); update_option( 'askbot_avatar_id', ( $avatar_id && wp_attachment_is_image( $avatar_id ) ) ? $avatar_id : 0 ); } /** * Enregistrement des réglages ajoutés par une extension (nonce et droits déjà vérifiés). */ do_action( 'askbot_save_settings' ); $t = askbot_admin_strings( askbot_admin_lang() ); return (string) apply_filters( 'askbot_settings_saved_notice', '

' . esc_html( $t['saved'] ) . '

' ); } // ============================================ // LIGNES PAR DÉFAUT (remplaçables par une extension) // ============================================ add_action( 'askbot_settings_avatar_row', 'askbot_default_avatar_row', 10, 2 ); function askbot_default_avatar_row( $t, $al ) { $avatar_id = (int) get_option( 'askbot_avatar_id', 0 ); ?>

array( $colors['primary'], $t['color_primary'], $t['color_primary_desc'] ), 'askbot_color_bot_bubble' => array( $colors['bot'], $t['color_bot'], '' ), 'askbot_color_user_bubble' => array( $colors['user'], $t['color_user'], '' ), ); ?>

$row ) : ?>

Youjeeb – AI Chatbot

—

platform.openai.com/api-keys



prefix . 'askbot_embeddings'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Table propre au plugin. $indexed_count = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE doc_type IN (%s, %s)', $embed_table, 'PAGE', 'ARTICLE' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Table propre au plugin. $indexed_docs = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(DISTINCT post_id) FROM %i WHERE doc_type IN (%s, %s)', $embed_table, 'PAGE', 'ARTICLE' ) ); $indexed_at = get_option( 'askbot_embeddings_indexed_at', '' ); if ( '' === askbot_get_openai_key() ) : ?>

0 ) : ?>

0 ) : ?>