'Yeni Oturum Başlat', 'confirmNewSession' => 'Yeni bir oturum başlatmak istediğinizden emin misiniz? Bu işlem tüm sohbet geçmişini temizleyecektir.', 'cancel' => 'İptal', 'yesStartNewSession' => 'Evet, Yeni Oturum Başlat', 'typeMessage' => 'Mesajınızı yazın...', 'chatSupport' => 'Sohbet Desteği', 'poweredBy' => 'Destekleyen' ); case 'de_DE': return array( 'startNewSession' => 'Neue Sitzung starten', 'confirmNewSession' => 'Sind Sie sicher, dass Sie eine neue Sitzung starten möchten? Dies löscht den gesamten Chat-Verlauf.', 'cancel' => 'Abbrechen', 'yesStartNewSession' => 'Ja, neue Sitzung starten', 'typeMessage' => 'Nachricht eingeben...', 'chatSupport' => 'Chat-Support', 'poweredBy' => 'Unterstützt von' ); case 'fr_FR': return array( 'startNewSession' => 'Démarrer une Nouvelle Session', 'confirmNewSession' => 'Êtes-vous sûr de vouloir démarrer une nouvelle session ? Cela effacera tout l\'historique de chat.', 'cancel' => 'Annuler', 'yesStartNewSession' => 'Oui, Démarrer une Nouvelle Session', 'typeMessage' => 'Tapez un message...', 'chatSupport' => 'Support Chat', 'poweredBy' => 'Alimenté par' ); case 'es_ES': return array( 'startNewSession' => 'Iniciar Nueva Sesión', 'confirmNewSession' => '¿Estás seguro de que quieres iniciar una nueva sesión? Esto borrará todo el historial de chat.', 'cancel' => 'Cancelar', 'yesStartNewSession' => 'Sí, Iniciar Nueva Sesión', 'typeMessage' => 'Escribe un mensaje...', 'chatSupport' => 'Soporte de Chat', 'poweredBy' => 'Desarrollado por' ); case 'it_IT': return array( 'startNewSession' => 'Inizia Nuova Sessione', 'confirmNewSession' => 'Sei sicuro di voler iniziare una nuova sessione? Questo cancellerà tutta la cronologia chat.', 'cancel' => 'Annulla', 'yesStartNewSession' => 'Sì, Inizia Nuova Sessione', 'typeMessage' => 'Scrivi un messaggio...', 'chatSupport' => 'Supporto Chat', 'poweredBy' => 'Alimentato da' ); case 'pt_BR': return array( 'startNewSession' => 'Iniciar Nova Sessão', 'confirmNewSession' => 'Tem certeza de que deseja iniciar uma nova sessão? Isso apagará todo o histórico de chat.', 'cancel' => 'Cancelar', 'yesStartNewSession' => 'Sim, Iniciar Nova Sessão', 'typeMessage' => 'Digite uma mensagem...', 'chatSupport' => 'Suporte de Chat', 'poweredBy' => 'Desenvolvido por' ); case 'ja': return array( 'startNewSession' => '新しいセッションを開始', 'confirmNewSession' => '新しいセッションを開始してもよろしいですか?これによりすべてのチャット履歴が削除されます。', 'cancel' => 'キャンセル', 'yesStartNewSession' => 'はい、新しいセッションを開始', 'typeMessage' => 'メッセージを入力...', 'chatSupport' => 'チャットサポート', 'poweredBy' => '提供元' ); case 'ko_KR': return array( 'startNewSession' => '새 세션 시작', 'confirmNewSession' => '새 세션을 시작하시겠습니까? 모든 채팅 기록이 삭제됩니다.', 'cancel' => '취소', 'yesStartNewSession' => '예, 새 세션 시작', 'typeMessage' => '메시지를 입력하세요...', 'chatSupport' => '채팅 지원', 'poweredBy' => '제공' ); case 'zh_CN': return array( 'startNewSession' => '开始新会话', 'confirmNewSession' => '您确定要开始新会话吗?这将清除所有聊天记录。', 'cancel' => '取消', 'yesStartNewSession' => '是的,开始新会话', 'typeMessage' => '输入消息...', 'chatSupport' => '聊天支持', 'poweredBy' => '技术支持' ); case 'ar': return array( 'startNewSession' => 'بدء جلسة جديدة', 'confirmNewSession' => 'هل أنت متأكد من أنك تريد بدء جلسة جديدة؟ سيؤدي هذا إلى مسح جميع سجل المحادثة.', 'cancel' => 'إلغاء', 'yesStartNewSession' => 'نعم، بدء جلسة جديدة', 'typeMessage' => 'اكتب رسالة...', 'chatSupport' => 'دعم المحادثة', 'poweredBy' => 'مدعوم من' ); case 'no_NO': return array( 'startNewSession' => 'Start ny økt', 'confirmNewSession' => 'Er du sikker på at du vil starte en ny økt? Dette vil slette all chat-historikk.', 'cancel' => 'Avbryt', 'yesStartNewSession' => 'Ja, start ny økt', 'typeMessage' => 'Skriv en melding...', 'chatSupport' => 'Chat-støtte', 'poweredBy' => 'Drevet av' ); default: // Fallback to WordPress translations or English return array( 'startNewSession' => __('Start New Session', 'ai-chatbot-customer-support-chatfromai'), 'confirmNewSession' => __('Are you sure you want to start a new session? This will clear all chat history.', 'ai-chatbot-customer-support-chatfromai'), 'cancel' => __('Cancel', 'ai-chatbot-customer-support-chatfromai'), 'yesStartNewSession' => __('Yes, Start New Session', 'ai-chatbot-customer-support-chatfromai'), 'typeMessage' => __('Type a message...', 'ai-chatbot-customer-support-chatfromai'), 'chatSupport' => __('Chat Support', 'ai-chatbot-customer-support-chatfromai'), 'poweredBy' => __('Powered by', 'ai-chatbot-customer-support-chatfromai') ); } } // Enqueue global admin CSS for menu icon styling on all admin screens add_action('admin_enqueue_scripts', 'chatfromai_admin_global_assets'); function chatfromai_admin_global_assets($hook) { // Load small CSS to keep the admin menu icon sizing/styling consistent if (!wp_style_is('chatfromai-admin-menu-icon', 'enqueued')) { $css_path = plugin_dir_path(__FILE__) . 'assets/admin-menu-icon.css'; if (file_exists($css_path)) { $css_url = plugins_url('assets/admin-menu-icon.css', __FILE__); $css_ver = filemtime($css_path); wp_register_style('chatfromai-admin-menu-icon', $css_url, array(), $css_ver); wp_enqueue_style('chatfromai-admin-menu-icon'); } } } // Admin sayfası için gerekli JS'leri enqueue et (inline modal script vb.) add_action('admin_enqueue_scripts', 'chatfromai_admin_page_assets'); function chatfromai_admin_page_assets($hook) { if ($hook !== 'toplevel_page_chatfromai') { return; } // Enqueue admin CSS if (!wp_style_is('chatfromai-admin', 'enqueued')) { $admin_css_path = plugin_dir_path(__FILE__) . 'assets/admin.css'; $admin_css_url = plugins_url('assets/admin.css', __FILE__); $admin_css_ver = file_exists($admin_css_path) ? filemtime($admin_css_path) : null; wp_register_style('chatfromai-admin', $admin_css_url, array(), $admin_css_ver); wp_enqueue_style('chatfromai-admin'); } // Enqueue admin JS if (!wp_script_is('chatfromai-admin', 'enqueued')) { $admin_js_path = plugin_dir_path(__FILE__) . 'assets/admin.js'; $admin_js_url = plugins_url('assets/admin.js', __FILE__); $admin_js_ver = file_exists($admin_js_path) ? filemtime($admin_js_path) : null; wp_register_script('chatfromai-admin', $admin_js_url, array(), $admin_js_ver, true); wp_enqueue_script('chatfromai-admin'); } } // Translations are automatically loaded by WordPress core for plugins hosted on WordPress.org. // We intentionally avoid calling load_plugin_textdomain() to comply with Plugin Check guidance. // Plugin activation hook register_activation_hook(__FILE__, 'chatfromai_activate'); function chatfromai_activate() { add_option('chatfromai_widget_id', ''); add_option('chatfromai_show_branding', '0'); // Create legal pages (Terms & Privacy) if not exist chatfromai_maybe_create_legal_pages(); } // Plugin deactivation hook register_deactivation_hook(__FILE__, 'chatfromai_deactivate'); function chatfromai_deactivate() { // Clean up if needed } // Create Terms of Service and Privacy Policy pages once on activation function chatfromai_maybe_create_legal_pages() { if (!function_exists('wp_insert_post')) return; // Helper to create or find a page by slug $ensure_page = function ($slug, $title, $shortcode) { $existing = get_page_by_path($slug); if ($existing) return $existing->ID; $page_id = wp_insert_post(array( 'post_title' => $title, 'post_name' => $slug, 'post_content' => '['.$shortcode.']', 'post_status' => 'publish', 'post_type' => 'page', )); return $page_id; }; $ensure_page('chatfromai-terms', __('ChatFromAI Terms', 'ai-chatbot-customer-support-chatfromai'), 'chatfromai_terms'); $ensure_page('chatfromai-privacy', __('ChatFromAI Privacy Policy', 'ai-chatbot-customer-support-chatfromai'), 'chatfromai_privacy'); } // Register shortcodes for legal pages add_action('init', function(){ add_shortcode('chatfromai_terms', 'chatfromai_terms_shortcode'); add_shortcode('chatfromai_privacy', 'chatfromai_privacy_shortcode'); }); function chatfromai_terms_shortcode() { ob_start(); ?> false, 'error' => __( 'Invalid characters in Widget ID. Only letters, numbers, underscore and dash are allowed.', 'ai-chatbot-customer-support-chatfromai' )); } else { // Validate Widget ID by checking with backend API $validation_result = chatfromai_validate_widget_id($widget_id); } if ($validation_result['valid']) { update_option('chatfromai_widget_id', $widget_id); update_option('chatfromai_widget_data', wp_json_encode($validation_result['widget_data'])); update_option('chatfromai_show_branding', $show_branding); echo '
' . '✅' . ''.esc_html__("Widget ID verified and saved! Your AI chatbot is now active on your site.", 'ai-chatbot-customer-support-chatfromai').'' . '
'; } else { echo '
' . '❌' . '
' . '
'.esc_html__( 'Invalid Widget ID', 'ai-chatbot-customer-support-chatfromai' ).'
' . '
' . esc_html($validation_result['error']) . '
' . '
' . '
'; } } } // Handle reset/logout if (isset($_POST['reset']) && $chatfromai_nonce && wp_verify_nonce($chatfromai_nonce, 'chatfromai_save')) { update_option('chatfromai_widget_id', ''); echo '
' . '🔄' . ''.esc_html__( 'Widget ID cleared! The setup widget will appear again.', 'ai-chatbot-customer-support-chatfromai' ).'' . '
'; } // Demo widget ID for testing without account creation $demo_widget_id = 'e8459652-3317-48bb-a4b7-421f187a0110'; $widget_id = get_option('chatfromai_widget_id', ''); $is_demo_mode = empty($widget_id); $chatfromai_show_branding = get_option('chatfromai_show_branding', '0'); ?>

Smart AI Chatbots', 'ai-chatbot-customer-support-chatfromai' ) ); ?>

🤖

💰

⚡

🎧

🚀


💡

✅

✅
Widget ID:
🎉
🌐
⚙️ ChatFromAI.com.
🔴
etiketlerini kaldırır ve JS metin olarak görünür. $widget_data_json = get_option('chatfromai_widget_data', ''); $widget_data = json_decode($widget_data_json, true); // Önce loader'ı enqueque et (local file) $loader_url = plugins_url('widget-loader.js', __FILE__); $loader_path = plugin_dir_path(__FILE__) . 'widget-loader.js'; $version = file_exists($loader_path) ? filemtime($loader_path) : null; wp_register_script('chatfromai-widget', $loader_url, array(), $version, true); wp_enqueue_script('chatfromai-widget'); // Kullanılacak widgetId'yi belirle $admin_preview_widget_id = $widget_id; if ($is_demo_mode) { $admin_preview_widget_id = $demo_widget_id; } elseif ($widget_data && isset($widget_data['embedCode'])) { // embedCode içinden widgetId yakalamayı dene if (preg_match("/widgetId\s*:\s*['\"]([A-Za-z0-9_-]+)['\"]/", $widget_data['embedCode'], $m)) { $admin_preview_widget_id = $m[1]; } } // Add translations for admin preview $translations = chatfromai_get_translations(); $translations_js = 'window.chatfromaiL10n = ' . wp_json_encode($translations) . '; console.log("✅ ChatFromAI translations loaded:", window.chatfromaiL10n);'; wp_add_inline_script('chatfromai-widget', $translations_js, 'before'); // Inline init $branding_bool = get_option('chatfromai_show_branding', '0') === '1' ? 'true' : 'false'; $chatfromai_inline = "window.ChatFromAI && window.ChatFromAI.init({ widgetId: '" . esc_js($admin_preview_widget_id) . "', showBranding: " . $branding_bool . " });"; wp_add_inline_script('chatfromai-widget', $chatfromai_inline, 'after'); ?>
[chatfromai]

2

3

4

5

false, 'error' => __( 'Widget ID cannot be empty', 'ai-chatbot-customer-support-chatfromai' )); } // Make API request to validate widget $api_url = 'https://chatfromai.com/api/public/widgets/' . urlencode($widget_id); $response = wp_remote_get($api_url, array( 'timeout' => 10, 'headers' => array( 'Content-Type' => 'application/json' ) )); if (is_wp_error($response)) { return array('valid' => false, 'error' => __( 'API connection error: ', 'ai-chatbot-customer-support-chatfromai' ) . $response->get_error_message()); } $response_code = wp_remote_retrieve_response_code($response); $response_body = wp_remote_retrieve_body($response); if ($response_code === 404) { return array('valid' => false, 'error' => __( 'Widget ID not found. Please get the correct Widget ID from ChatFromAI.com.', 'ai-chatbot-customer-support-chatfromai' )); } if ($response_code !== 200) { /* translators: %d is the HTTP status code returned from the validation request */ return array('valid' => false, 'error' => sprintf( __( 'Widget validation error (HTTP %d)', 'ai-chatbot-customer-support-chatfromai' ), $response_code)); } $widget_data = json_decode($response_body, true); if (!$widget_data || !isset($widget_data['data']['id'])) { return array('valid' => false, 'error' => __( 'Invalid widget data', 'ai-chatbot-customer-support-chatfromai' )); } return array( 'valid' => true, 'widget_data' => $widget_data['data'], // sadece data bölümünü al 'embed_code' => isset($widget_data['data']['embedCode']) ? $widget_data['data']['embedCode'] : null ); } // Enqueue widget script on frontend when a Widget ID is configured or in demo mode add_action('wp_enqueue_scripts', 'chatfromai_enqueue_widget_script'); function chatfromai_enqueue_widget_script() { if (is_admin()) { return; } $widget_id = get_option('chatfromai_widget_id', ''); $demo_widget_id = 'e8459652-3317-48bb-a4b7-421f187a0110'; // Use demo widget ID if no widget ID is configured if (empty($widget_id)) { $widget_id = $demo_widget_id; } // Register and enqueue loader with cache-busting version $handle = 'chatfromai-widget-loader'; if (!wp_script_is($handle, 'enqueued')) { $loader_url = plugins_url('widget-loader.js', __FILE__); $loader_path = plugin_dir_path(__FILE__) . 'widget-loader.js'; $version = file_exists($loader_path) ? filemtime($loader_path) : null; wp_register_script($handle, $loader_url, array(), $version, true); wp_enqueue_script($handle); } // Add translations as inline script BEFORE the widget loader $current_locale = get_locale(); // Manual translations for supported languages switch ($current_locale) { case 'tr_TR': $translations = array( 'startNewSession' => 'Yeni Oturum Başlat', 'confirmNewSession' => 'Yeni bir oturum başlatmak istediğinizden emin misiniz? Bu işlem tüm sohbet geçmişini temizleyecektir.', 'cancel' => 'İptal', 'yesStartNewSession' => 'Evet, Yeni Oturum Başlat', 'typeMessage' => 'Mesajınızı yazın...', 'chatSupport' => 'Sohbet Desteği', 'poweredBy' => 'Destekleyen' ); break; case 'de_DE': $translations = array( 'startNewSession' => 'Neue Sitzung starten', 'confirmNewSession' => 'Sind Sie sicher, dass Sie eine neue Sitzung starten möchten? Dies löscht den gesamten Chat-Verlauf.', 'cancel' => 'Abbrechen', 'yesStartNewSession' => 'Ja, neue Sitzung starten', 'typeMessage' => 'Nachricht eingeben...', 'chatSupport' => 'Chat-Support', 'poweredBy' => 'Unterstützt von' ); break; case 'fr_FR': $translations = array( 'startNewSession' => 'Démarrer une Nouvelle Session', 'confirmNewSession' => 'Êtes-vous sûr de vouloir démarrer une nouvelle session ? Cela effacera tout l\'historique de chat.', 'cancel' => 'Annuler', 'yesStartNewSession' => 'Oui, Démarrer une Nouvelle Session', 'typeMessage' => 'Tapez un message...', 'chatSupport' => 'Support Chat', 'poweredBy' => 'Alimenté par' ); break; case 'es_ES': $translations = array( 'startNewSession' => 'Iniciar Nueva Sesión', 'confirmNewSession' => '¿Estás seguro de que quieres iniciar una nueva sesión? Esto borrará todo el historial de chat.', 'cancel' => 'Cancelar', 'yesStartNewSession' => 'Sí, Iniciar Nueva Sesión', 'typeMessage' => 'Escribe un mensaje...', 'chatSupport' => 'Soporte de Chat', 'poweredBy' => 'Desarrollado por' ); break; case 'it_IT': $translations = array( 'startNewSession' => 'Inizia Nuova Sessione', 'confirmNewSession' => 'Sei sicuro di voler iniziare una nuova sessione? Questo cancellerà tutta la cronologia chat.', 'cancel' => 'Annulla', 'yesStartNewSession' => 'Sì, Inizia Nuova Sessione', 'typeMessage' => 'Scrivi un messaggio...', 'chatSupport' => 'Supporto Chat', 'poweredBy' => 'Alimentato da' ); break; case 'pt_BR': $translations = array( 'startNewSession' => 'Iniciar Nova Sessão', 'confirmNewSession' => 'Tem certeza de que deseja iniciar uma nova sessão? Isso apagará todo o histórico de chat.', 'cancel' => 'Cancelar', 'yesStartNewSession' => 'Sim, Iniciar Nova Sessão', 'typeMessage' => 'Digite uma mensagem...', 'chatSupport' => 'Suporte de Chat', 'poweredBy' => 'Desenvolvido por' ); break; case 'ja': $translations = array( 'startNewSession' => '新しいセッションを開始', 'confirmNewSession' => '新しいセッションを開始してもよろしいですか?これによりすべてのチャット履歴が削除されます。', 'cancel' => 'キャンセル', 'yesStartNewSession' => 'はい、新しいセッションを開始', 'typeMessage' => 'メッセージを入力...', 'chatSupport' => 'チャットサポート', 'poweredBy' => '提供元' ); break; case 'ko_KR': $translations = array( 'startNewSession' => '새 세션 시작', 'confirmNewSession' => '새 세션을 시작하시겠습니까? 모든 채팅 기록이 삭제됩니다.', 'cancel' => '취소', 'yesStartNewSession' => '예, 새 세션 시작', 'typeMessage' => '메시지를 입력하세요...', 'chatSupport' => '채팅 지원', 'poweredBy' => '제공' ); break; case 'zh_CN': $translations = array( 'startNewSession' => '开始新会话', 'confirmNewSession' => '您确定要开始新会话吗?这将清除所有聊天记录。', 'cancel' => '取消', 'yesStartNewSession' => '是的,开始新会话', 'typeMessage' => '输入消息...', 'chatSupport' => '聊天支持', 'poweredBy' => '技术支持' ); break; case 'ar': $translations = array( 'startNewSession' => 'بدء جلسة جديدة', 'confirmNewSession' => 'هل أنت متأكد من أنك تريد بدء جلسة جديدة؟ سيؤدي هذا إلى مسح جميع سجل المحادثة.', 'cancel' => 'إلغاء', 'yesStartNewSession' => 'نعم، بدء جلسة جديدة', 'typeMessage' => 'اكتب رسالة...', 'chatSupport' => 'دعم المحادثة', 'poweredBy' => 'مدعوم من' ); break; case 'no_NO': $translations = array( 'startNewSession' => 'Start ny økt', 'confirmNewSession' => 'Er du sikker på at du vil starte en ny økt? Dette vil slette all chat-historikk.', 'cancel' => 'Avbryt', 'yesStartNewSession' => 'Ja, start ny økt', 'typeMessage' => 'Skriv en melding...', 'chatSupport' => 'Chat-støtte', 'poweredBy' => 'Drevet av' ); break; default: // Fallback to WordPress translations or English $translations = array( 'startNewSession' => __('Start New Session', 'ai-chatbot-customer-support-chatfromai'), 'confirmNewSession' => __('Are you sure you want to start a new session? This will clear all chat history.', 'ai-chatbot-customer-support-chatfromai'), 'cancel' => __('Cancel', 'ai-chatbot-customer-support-chatfromai'), 'yesStartNewSession' => __('Yes, Start New Session', 'ai-chatbot-customer-support-chatfromai'), 'typeMessage' => __('Type a message...', 'ai-chatbot-customer-support-chatfromai'), 'chatSupport' => __('Chat Support', 'ai-chatbot-customer-support-chatfromai'), 'poweredBy' => __('Powered by', 'ai-chatbot-customer-support-chatfromai') ); break; } $translations_js = 'window.chatfromaiL10n = ' . wp_json_encode($translations) . '; console.log("✅ ChatFromAI translations loaded:", window.chatfromaiL10n);'; wp_add_inline_script($handle, $translations_js, 'before'); // Safe polling init with branding preference $branding_bool = get_option('chatfromai_show_branding', '0') === '1' ? 'true' : 'false'; $init_js = '(function(){function _cfInit(){if(window.ChatFromAI&&window.ChatFromAI.init){window.ChatFromAI.init({widgetId: ' . wp_json_encode($widget_id) . ', showBranding: ' . $branding_bool . '});}else{setTimeout(_cfInit,100);}}_cfInit();})();'; wp_add_inline_script($handle, $init_js, 'after'); } // This function is duplicate and can be removed since chatfromai_enqueue_widget_script already handles this // Enqueue setup assets only when Widget ID is missing (frontend only) add_action('wp_enqueue_scripts', 'chatfromai_enqueue_setup_assets'); function chatfromai_enqueue_setup_assets() { if (is_admin()) { return; } $widget_id = get_option('chatfromai_widget_id', ''); if (!empty($widget_id)) { return; } // Styles $setup_css_path = plugin_dir_path(__FILE__) . 'assets/frontend-setup.css'; $setup_css_url = plugins_url('assets/frontend-setup.css', __FILE__); $setup_css_ver = file_exists($setup_css_path) ? filemtime($setup_css_path) : null; if (!wp_style_is('chatfromai-frontend-setup', 'enqueued')) { wp_register_style('chatfromai-frontend-setup', $setup_css_url, array(), $setup_css_ver); wp_enqueue_style('chatfromai-frontend-setup'); } // Scripts $setup_js_path = plugin_dir_path(__FILE__) . 'assets/frontend-setup.js'; $setup_js_url = plugins_url('assets/frontend-setup.js', __FILE__); $setup_js_ver = file_exists($setup_js_path) ? filemtime($setup_js_path) : null; if (!wp_script_is('chatfromai-frontend-setup', 'enqueued')) { wp_register_script('chatfromai-frontend-setup', $setup_js_url, array(), $setup_js_ver, true); wp_enqueue_script('chatfromai-frontend-setup'); } } // Add widget container to footer or show setup message if no Widget ID add_action('wp_footer', 'chatfromai_add_widget'); function chatfromai_add_widget() { if (is_admin()) { return; } $widget_id = get_option('chatfromai_widget_id', ''); $demo_widget_id = 'e8459652-3317-48bb-a4b7-421f187a0110'; // Use demo widget ID if no widget ID is configured (demo mode) if (empty($widget_id)) { $widget_id = $demo_widget_id; } // Output container for the widget - translations are already handled in enqueue function ?>
'; }