PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.0.3
MxChat – AI Chatbot & Content Generation for WordPress v3.0.3
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
mxchat-basic / includes / admin-settings-page.php

admin-settings-page.php in MxChat – AI Chatbot & Content Generation for WordPress 3.0.3, at includes/admin-settings-page.php

1,161 lines 74.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MxChat Admin Settings Page - Redesigned with Sidebar Navigation
4 *
5 * @package MxChat
6 * @since 2.7.0
7 */
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 /**
14 * Render the new sidebar-based admin settings page
15 */
16 function mxchat_render_settings_page($admin_instance) {
17 $is_activated = $admin_instance->is_activated();
18 $options = get_option('mxchat_options', array());
19 $plugin_url = plugin_dir_url(dirname(__FILE__));
20 ?>
21 <div class="mxch-admin-wrapper">
22 <!-- Mobile Header -->
23 <header class="mxch-mobile-header">
24 <a href="#" class="mxch-mobile-logo">
25 <div class="mxch-mobile-logo-icon">
26 <img src="<?php echo esc_url($plugin_url . 'images/icon-128x128.png'); ?>" alt="MxChat">
27 </div>
28 <span class="mxch-mobile-logo-text">MxChat</span>
29 </a>
30 <button type="button" class="mxch-mobile-menu-btn" aria-label="<?php esc_attr_e('Open menu', 'mxchat'); ?>">
31 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
32 </button>
33 </header>
34
35 <!-- Mobile Menu Overlay -->
36 <div class="mxch-mobile-overlay"></div>
37
38 <!-- Mobile Menu Modal -->
39 <div class="mxch-mobile-menu">
40 <div class="mxch-mobile-menu-header">
41 <span class="mxch-mobile-menu-title"><?php esc_html_e('Settings', 'mxchat'); ?></span>
42 <button type="button" class="mxch-mobile-menu-close" aria-label="<?php esc_attr_e('Close menu', 'mxchat'); ?>">
43 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
44 </button>
45 </div>
46 <nav class="mxch-mobile-menu-nav">
47 <!-- Configuration Section -->
48 <div class="mxch-mobile-nav-section">
49 <div class="mxch-mobile-nav-section-title"><?php esc_html_e('Configuration', 'mxchat'); ?></div>
50 <button class="mxch-mobile-nav-link" data-parent="chatbot">
51 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2"/><path d="M20 14h2"/><path d="M15 13v2"/><path d="M9 13v2"/></svg>
52 <span><?php esc_html_e('Chatbot', 'mxchat'); ?></span>
53 <svg class="mxch-mobile-nav-arrow" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
54 </button>
55 <div class="mxch-mobile-nav-sub" data-parent="chatbot">
56 <button class="mxch-mobile-nav-sub-link active" data-target="chatbot-ai-models"><?php esc_html_e('AI Models', 'mxchat'); ?></button>
57 <button class="mxch-mobile-nav-sub-link" data-target="chatbot-behavior"><?php esc_html_e('Behavior', 'mxchat'); ?></button>
58 <button class="mxch-mobile-nav-sub-link" data-target="chatbot-display"><?php esc_html_e('Display', 'mxchat'); ?></button>
59 <button class="mxch-mobile-nav-sub-link" data-target="chatbot-lead-capture"><?php esc_html_e('Lead Capture', 'mxchat'); ?></button>
60 <button class="mxch-mobile-nav-sub-link" data-target="chatbot-quick-questions"><?php esc_html_e('Quick Questions', 'mxchat'); ?></button>
61 <button class="mxch-mobile-nav-sub-link" data-target="chatbot-rate-limits"><?php esc_html_e('Rate Limits', 'mxchat'); ?></button>
62 </div>
63 <button class="mxch-mobile-nav-link" data-target="api-keys">
64 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21 2-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0 3 3L22 7l-3-3m-3.5 3.5L19 4"/></svg>
65 <span><?php esc_html_e('API Keys', 'mxchat'); ?></span>
66 </button>
67 </div>
68 <!-- Integrations Section -->
69 <div class="mxch-mobile-nav-section">
70 <div class="mxch-mobile-nav-section-title"><?php esc_html_e('Integrations', 'mxchat'); ?></div>
71 <button class="mxch-mobile-nav-link" data-parent="integrations">
72 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>
73 <span><?php esc_html_e('Integrations', 'mxchat'); ?></span>
74 <svg class="mxch-mobile-nav-arrow" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
75 </button>
76 <div class="mxch-mobile-nav-sub" data-parent="integrations">
77 <button class="mxch-mobile-nav-sub-link" data-target="integrations-toolbar"><?php esc_html_e('Toolbar', 'mxchat'); ?></button>
78 <button class="mxch-mobile-nav-sub-link" data-target="integrations-loops"><?php esc_html_e('Loops', 'mxchat'); ?></button>
79 <button class="mxch-mobile-nav-sub-link" data-target="integrations-brave"><?php esc_html_e('Brave Search', 'mxchat'); ?></button>
80 <button class="mxch-mobile-nav-sub-link" data-target="integrations-slack"><?php esc_html_e('Slack', 'mxchat'); ?></button>
81 <button class="mxch-mobile-nav-sub-link" data-target="integrations-telegram"><?php esc_html_e('Telegram', 'mxchat'); ?></button>
82 </div>
83 </div>
84 <!-- Resources Section -->
85 <div class="mxch-mobile-nav-section">
86 <div class="mxch-mobile-nav-section-title"><?php esc_html_e('Resources', 'mxchat'); ?></div>
87 <button class="mxch-mobile-nav-link" data-target="tutorials">
88 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2" ry="2"/></svg>
89 <span><?php esc_html_e('Tutorials', 'mxchat'); ?></span>
90 </button>
91 </div>
92 <?php if (!$is_activated): ?>
93 <div class="mxch-mobile-menu-footer">
94 <a href="https://mxchat.ai/" target="_blank" class="mxch-mobile-upgrade-btn">
95 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"/><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"/><path d="M4 22h16"/><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"/><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"/><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"/></svg>
96 <?php esc_html_e('Upgrade to Pro', 'mxchat'); ?>
97 </a>
98 </div>
99 <?php endif; ?>
100 </nav>
101 </div>
102
103 <!-- Sidebar Navigation -->
104 <aside class="mxch-sidebar">
105 <div class="mxch-sidebar-header">
106 <a href="#" class="mxch-sidebar-logo">
107 <div class="mxch-sidebar-logo-icon">
108 <img src="<?php echo esc_url($plugin_url . 'images/icon-128x128.png'); ?>" alt="MxChat">
109 </div>
110 <span class="mxch-sidebar-logo-text">MxChat</span>
111 <span class="mxch-sidebar-version">v<?php echo esc_html(MXCHAT_VERSION ?? '2.7.0'); ?></span>
112 </a>
113 </div>
114
115 <nav class="mxch-sidebar-nav">
116 <!-- Chatbot Section -->
117 <div class="mxch-nav-section">
118 <div class="mxch-nav-section-title"><?php esc_html_e('Configuration', 'mxchat'); ?></div>
119
120 <div class="mxch-nav-item expanded" data-section="chatbot">
121 <button class="mxch-nav-link active">
122 <span class="mxch-nav-link-icon">
123 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2"/><path d="M20 14h2"/><path d="M15 13v2"/><path d="M9 13v2"/></svg>
124 </span>
125 <span class="mxch-nav-link-text"><?php esc_html_e('Chatbot', 'mxchat'); ?></span>
126 <svg class="mxch-nav-link-arrow" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
127 </button>
128 <div class="mxch-nav-sub">
129 <button class="mxch-nav-sub-link active" data-target="chatbot-ai-models"><?php esc_html_e('AI Models', 'mxchat'); ?></button>
130 <button class="mxch-nav-sub-link" data-target="chatbot-behavior"><?php esc_html_e('Behavior', 'mxchat'); ?></button>
131 <button class="mxch-nav-sub-link" data-target="chatbot-display"><?php esc_html_e('Display', 'mxchat'); ?></button>
132 <button class="mxch-nav-sub-link" data-target="chatbot-lead-capture"><?php esc_html_e('Lead Capture', 'mxchat'); ?></button>
133 <button class="mxch-nav-sub-link" data-target="chatbot-quick-questions"><?php esc_html_e('Quick Questions', 'mxchat'); ?></button>
134 <button class="mxch-nav-sub-link" data-target="chatbot-rate-limits"><?php esc_html_e('Rate Limits', 'mxchat'); ?></button>
135 </div>
136 </div>
137
138 <div class="mxch-nav-item" data-section="api-keys">
139 <button class="mxch-nav-link" data-target="api-keys">
140 <span class="mxch-nav-link-icon">
141 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21 2-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0 3 3L22 7l-3-3m-3.5 3.5L19 4"/></svg>
142 </span>
143 <span class="mxch-nav-link-text"><?php esc_html_e('API Keys', 'mxchat'); ?></span>
144 </button>
145 </div>
146 </div>
147
148 <!-- Integrations Section -->
149 <div class="mxch-nav-section">
150 <div class="mxch-nav-section-title"><?php esc_html_e('Integrations', 'mxchat'); ?></div>
151
152 <div class="mxch-nav-item" data-section="integrations">
153 <button class="mxch-nav-link">
154 <span class="mxch-nav-link-icon">
155 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>
156 </span>
157 <span class="mxch-nav-link-text"><?php esc_html_e('Integrations', 'mxchat'); ?></span>
158 <svg class="mxch-nav-link-arrow" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
159 </button>
160 <div class="mxch-nav-sub">
161 <button class="mxch-nav-sub-link" data-target="integrations-toolbar"><?php esc_html_e('Toolbar', 'mxchat'); ?></button>
162 <button class="mxch-nav-sub-link" data-target="integrations-loops"><?php esc_html_e('Loops', 'mxchat'); ?></button>
163 <button class="mxch-nav-sub-link" data-target="integrations-brave"><?php esc_html_e('Brave Search', 'mxchat'); ?></button>
164 <button class="mxch-nav-sub-link" data-target="integrations-slack"><?php esc_html_e('Slack', 'mxchat'); ?></button>
165 <button class="mxch-nav-sub-link" data-target="integrations-telegram"><?php esc_html_e('Telegram', 'mxchat'); ?></button>
166 </div>
167 </div>
168 </div>
169
170 <!-- Resources Section -->
171 <div class="mxch-nav-section">
172 <div class="mxch-nav-section-title"><?php esc_html_e('Resources', 'mxchat'); ?></div>
173
174 <div class="mxch-nav-item" data-section="tutorials">
175 <button class="mxch-nav-link" data-target="tutorials">
176 <span class="mxch-nav-link-icon">
177 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2" ry="2"/></svg>
178 </span>
179 <span class="mxch-nav-link-text"><?php esc_html_e('Tutorials', 'mxchat'); ?></span>
180 </button>
181 </div>
182 </div>
183 </nav>
184
185 <?php if (!$is_activated): ?>
186 <div class="mxch-sidebar-footer">
187 <a href="https://mxchat.ai/" target="_blank" class="mxch-sidebar-upgrade-v2">
188 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
189 <?php esc_html_e('Pro Upgrade', 'mxchat'); ?>
190 </a>
191 </div>
192 <?php endif; ?>
193 </aside>
194
195 <!-- Main Content Area -->
196 <main class="mxch-content">
197 <?php if (!$is_activated): ?>
198 <div class="mxch-pro-banner">
199 <div class="mxch-pro-banner-content">
200 <h3 class="mxch-pro-banner-title"><?php esc_html_e('MxChat Pro — Lifetime Access', 'mxchat'); ?></h3>
201 <p class="mxch-pro-banner-text"><?php esc_html_e('One-time purchase. Unlock 10+ premium add-ons: Admin AI Assistant, Forms Builder, Chatbot Themes, and more.', 'mxchat'); ?></p>
202 </div>
203 <a href="https://mxchat.ai/" target="_blank" class="mxch-pro-banner-btn"><span><?php esc_html_e('Learn More', 'mxchat'); ?></span></a>
204 </div>
205 <?php endif; ?>
206
207 <?php
208 // Show theme migration notice for Pro users
209 $admin_instance->show_theme_migration_banner();
210 ?>
211
212 <!-- ========================================
213 CHATBOT - AI MODELS
214 ======================================== -->
215 <div id="chatbot-ai-models" class="mxch-section active">
216 <div class="mxch-content-header">
217 <h1 class="mxch-content-title"><?php esc_html_e('AI Models', 'mxchat'); ?></h1>
218 <p class="mxch-content-subtitle"><?php esc_html_e('Configure the AI models your chatbot will use for conversations and embeddings.', 'mxchat'); ?></p>
219 </div>
220
221 <div class="mxch-card">
222 <div class="mxch-card-body mxchat-autosave-section">
223 <?php
224 // Chat Model
225 mxchat_render_field_wrapper('model', __('Chat Model', 'mxchat'), function() use ($admin_instance) {
226 $admin_instance->mxchat_model_callback();
227 }, __('Select the AI model your chatbot will use for conversations.', 'mxchat'));
228
229 // Embedding Model
230 mxchat_render_field_wrapper('embedding_model', __('Embedding Model', 'mxchat'), function() use ($admin_instance) {
231 $admin_instance->embedding_model_callback();
232 }, __('Vector embedding model for knowledge base matching. Changing models requires reconfiguring knowledge data.', 'mxchat'));
233
234 // Enable Streaming
235 mxchat_render_field_wrapper('enable_streaming', __('Enable Streaming', 'mxchat'), function() use ($admin_instance) {
236 $admin_instance->enable_streaming_toggle_callback();
237 }, __('Enable real-time streaming responses for supported models (OpenAI, Claude, DeepSeek, Grok).', 'mxchat'));
238
239 // Enable Web Search (OpenAI only)
240 mxchat_render_field_wrapper('enable_web_search', __('Enable Web Search', 'mxchat'), function() use ($admin_instance) {
241 $admin_instance->enable_web_search_toggle_callback();
242 }, __('Allow the chatbot to search the web for current information (OpenAI models only).', 'mxchat'));
243 ?>
244 </div>
245 </div>
246 </div>
247
248 <!-- ========================================
249 CHATBOT - BEHAVIOR
250 ======================================== -->
251 <div id="chatbot-behavior" class="mxch-section">
252 <div class="mxch-content-header">
253 <h1 class="mxch-content-title"><?php esc_html_e('Behavior', 'mxchat'); ?></h1>
254 <p class="mxch-content-subtitle"><?php esc_html_e('Control how your AI chatbot responds and processes queries.', 'mxchat'); ?></p>
255 </div>
256
257 <div class="mxch-card">
258 <div class="mxch-card-body mxchat-autosave-section">
259 <?php
260 // AI Instructions
261 mxchat_render_field_wrapper('system_prompt_instructions', __('AI Instructions (Behavior)', 'mxchat'), function() use ($admin_instance) {
262 $admin_instance->system_prompt_instructions_callback();
263 }, __('Provide system-level instructions to guide the AI\'s behavior and responses.', 'mxchat'));
264
265 // Similarity Threshold
266 mxchat_render_field_wrapper('similarity_threshold', __('Similarity Threshold', 'mxchat'), function() use ($admin_instance) {
267 $admin_instance->mxchat_similarity_threshold_callback();
268 }, __('Adjust threshold for content matching. Lower values = more matches, higher values = stricter matching.', 'mxchat'));
269
270 // Contextual Awareness
271 mxchat_render_field_wrapper('contextual_awareness', __('Contextual Awareness', 'mxchat'), function() use ($admin_instance) {
272 $admin_instance->mxchat_contextual_awareness_callback();
273 }, __('Allow the chatbot to understand and reference the current page content for more relevant responses.', 'mxchat'));
274
275 // Citation Links
276 mxchat_render_field_wrapper('citation_links', __('Citation Links', 'mxchat'), function() use ($admin_instance) {
277 $admin_instance->mxchat_citation_links_toggle_callback();
278 }, __('Allow the AI to include citation links from your knowledge database in responses. If disabled, ensure your AI Behavior settings do not mention links or the AI may fabricate URLs.', 'mxchat'));
279
280 // Frontend Debugger
281 mxchat_render_field_wrapper('frontend_debugger', __('Frontend Debugger', 'mxchat'), function() use ($admin_instance) {
282 $admin_instance->mxchat_frontend_debugger_callback();
283 }, __('Show debug panel on frontend for admins. Displays similarity scores and query analysis.', 'mxchat'));
284 ?>
285 </div>
286 </div>
287 </div>
288
289 <!-- ========================================
290 CHATBOT - DISPLAY
291 ======================================== -->
292 <div id="chatbot-display" class="mxch-section">
293 <div class="mxch-content-header">
294 <h1 class="mxch-content-title"><?php esc_html_e('Display Settings', 'mxchat'); ?></h1>
295 <p class="mxch-content-subtitle"><?php esc_html_e('Customize how and where your chatbot appears on your website.', 'mxchat'); ?></p>
296 </div>
297
298 <div class="mxch-card">
299 <div class="mxch-card-header">
300 <h3 class="mxch-card-title">
301 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="9" y1="21" x2="9" y2="9"/></svg>
302 <?php esc_html_e('Visibility', 'mxchat'); ?>
303 </h3>
304 </div>
305 <div class="mxch-card-body mxchat-autosave-section">
306 <?php
307 // Auto-Display
308 mxchat_render_field_wrapper('auto_display', __('Auto-Display Chatbot', 'mxchat'), function() use ($admin_instance) {
309 $admin_instance->mxchat_append_to_body_callback();
310 }, __('Show chatbot automatically on all pages. Disable to use shortcode [mxchat_chatbot] instead.', 'mxchat'));
311
312 // Open Links in New Tab
313 mxchat_render_field_wrapper('link_target', __('Open Links in New Tab', 'mxchat'), function() use ($admin_instance) {
314 $admin_instance->mxchat_link_target_toggle_callback();
315 }, __('Open links clicked in chat responses in a new browser tab.', 'mxchat'));
316
317 // Chat Persistence
318 mxchat_render_field_wrapper('chat_persistence', __('Chat Persistence', 'mxchat'), function() use ($admin_instance) {
319 $admin_instance->mxchat_chat_persistence_toggle_callback();
320 }, __('Keep chat history when users navigate or return within 24 hours.', 'mxchat'));
321 ?>
322 </div>
323 </div>
324
325 <div class="mxch-card">
326 <div class="mxch-card-header">
327 <h3 class="mxch-card-title">
328 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
329 <?php esc_html_e('Text & Labels', 'mxchat'); ?>
330 </h3>
331 </div>
332 <div class="mxch-card-body mxchat-autosave-section">
333 <?php
334 // Top Bar Title
335 mxchat_render_field_wrapper('top_bar_title', __('Top Bar Title', 'mxchat'), function() use ($admin_instance) {
336 $admin_instance->mxchat_top_bar_title_callback();
337 }, __('Title text shown in the chatbot header.', 'mxchat'));
338
339 // AI Agent Text
340 mxchat_render_field_wrapper('ai_agent_text', __('AI Agent Text', 'mxchat'), function() use ($admin_instance) {
341 $admin_instance->mxchat_ai_agent_text_callback();
342 }, __('Text shown for AI agents in the status indicator.', 'mxchat'));
343
344 // Intro Message
345 mxchat_render_field_wrapper('intro_message', __('Introductory Message', 'mxchat'), function() use ($admin_instance) {
346 $admin_instance->mxchat_intro_message_callback();
347 }, __('First message shown when chat opens. HTML allowed.', 'mxchat'));
348
349 // Input Placeholder
350 mxchat_render_field_wrapper('input_copy', __('Input Placeholder', 'mxchat'), function() use ($admin_instance) {
351 $admin_instance->mxchat_input_copy_callback();
352 }, __('Placeholder text in the chat input field.', 'mxchat'));
353
354 // Chat Teaser
355 mxchat_render_field_wrapper('pre_chat_message', __('Chat Teaser Pop-up', 'mxchat'), function() use ($admin_instance) {
356 $admin_instance->mxchat_pre_chat_message_callback();
357 }, __('Message shown before users start chatting.', 'mxchat'));
358 ?>
359 </div>
360 </div>
361 </div>
362
363 <!-- ========================================
364 CHATBOT - LEAD CAPTURE
365 ======================================== -->
366 <div id="chatbot-lead-capture" class="mxch-section">
367 <div class="mxch-content-header">
368 <h1 class="mxch-content-title"><?php esc_html_e('Lead Capture', 'mxchat'); ?></h1>
369 <p class="mxch-content-subtitle"><?php esc_html_e('Collect user information and manage privacy settings.', 'mxchat'); ?></p>
370 </div>
371
372 <div class="mxch-card">
373 <div class="mxch-card-header">
374 <h3 class="mxch-card-title">
375 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg>
376 <?php esc_html_e('Email Capture', 'mxchat'); ?>
377 </h3>
378 </div>
379 <div class="mxch-card-body mxchat-autosave-section">
380 <?php
381 // Require Email
382 mxchat_render_field_wrapper('enable_email_block', __('Require Email to Chat', 'mxchat'), function() use ($admin_instance) {
383 $admin_instance->enable_email_block_callback();
384 }, __('Require users to enter their email before chatting. Shows for non-logged-in users.', 'mxchat'));
385
386 // Email Form Content
387 mxchat_render_field_wrapper('email_blocker_header', __('Email Form Content', 'mxchat'), function() use ($admin_instance) {
388 $admin_instance->email_blocker_header_content_callback();
389 }, __('HTML content shown above the email form.', 'mxchat'));
390
391 // Email Button Text
392 mxchat_render_field_wrapper('email_blocker_button', __('Submit Button Text', 'mxchat'), function() use ($admin_instance) {
393 $admin_instance->email_blocker_button_text_callback();
394 }, __('Text for the email form submit button.', 'mxchat'));
395
396 // Require Name
397 mxchat_render_field_wrapper('enable_name_field', __('Also Require Name', 'mxchat'), function() use ($admin_instance) {
398 $admin_instance->enable_name_field_callback();
399 }, __('Also require users to enter their name with email.', 'mxchat'));
400
401 // Name Placeholder
402 mxchat_render_field_wrapper('name_placeholder', __('Name Field Placeholder', 'mxchat'), function() use ($admin_instance) {
403 $admin_instance->name_field_placeholder_callback();
404 }, __('Placeholder text for the name input field.', 'mxchat'));
405 ?>
406 </div>
407 </div>
408
409 <div class="mxch-card">
410 <div class="mxch-card-header">
411 <h3 class="mxch-card-title">
412 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
413 <?php esc_html_e('Privacy & Compliance', 'mxchat'); ?>
414 </h3>
415 </div>
416 <div class="mxch-card-body mxchat-autosave-section">
417 <?php
418 // Privacy Notice
419 mxchat_render_field_wrapper('privacy_toggle', __('Privacy Notice', 'mxchat'), function() use ($admin_instance) {
420 $admin_instance->mxchat_privacy_toggle_callback();
421 }, __('Show privacy notice below the chat widget.', 'mxchat'));
422
423 // Complianz
424 mxchat_render_field_wrapper('complianz_toggle', __('Complianz Integration', 'mxchat'), function() use ($admin_instance) {
425 $admin_instance->mxchat_complianz_toggle_callback();
426 }, __('Apply Complianz consent logic to the chatbot (requires Complianz plugin).', 'mxchat'));
427 ?>
428 </div>
429 </div>
430 </div>
431
432 <!-- ========================================
433 CHATBOT - QUICK QUESTIONS
434 ======================================== -->
435 <div id="chatbot-quick-questions" class="mxch-section">
436 <div class="mxch-content-header">
437 <h1 class="mxch-content-title"><?php esc_html_e('Quick Questions', 'mxchat'); ?></h1>
438 <p class="mxch-content-subtitle"><?php esc_html_e('Pre-defined questions displayed above the chat input to help users get started.', 'mxchat'); ?></p>
439 </div>
440
441 <div class="mxch-card">
442 <div class="mxch-card-body mxchat-autosave-section">
443 <?php
444 // Quick Question 1
445 mxchat_render_field_wrapper('popular_question_1', __('Quick Question 1', 'mxchat'), function() use ($admin_instance) {
446 $admin_instance->mxchat_popular_question_1_callback();
447 });
448
449 // Quick Question 2
450 mxchat_render_field_wrapper('popular_question_2', __('Quick Question 2', 'mxchat'), function() use ($admin_instance) {
451 $admin_instance->mxchat_popular_question_2_callback();
452 });
453
454 // Quick Question 3
455 mxchat_render_field_wrapper('popular_question_3', __('Quick Question 3', 'mxchat'), function() use ($admin_instance) {
456 $admin_instance->mxchat_popular_question_3_callback();
457 });
458
459 // Additional Questions
460 mxchat_render_field_wrapper('additional_questions', __('Additional Questions', 'mxchat'), function() use ($admin_instance) {
461 $admin_instance->mxchat_additional_popular_questions_callback();
462 }, __('Add as many quick questions as you need.', 'mxchat'));
463 ?>
464 </div>
465 </div>
466 </div>
467
468 <!-- ========================================
469 CHATBOT - RATE LIMITS
470 ======================================== -->
471 <div id="chatbot-rate-limits" class="mxch-section">
472 <div class="mxch-content-header">
473 <h1 class="mxch-content-title"><?php esc_html_e('Rate Limits', 'mxchat'); ?></h1>
474 <p class="mxch-content-subtitle"><?php esc_html_e('Set message limits for each user role to manage API usage.', 'mxchat'); ?></p>
475 </div>
476
477 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 24px;">
478 <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
479 <div>
480 <strong><?php esc_html_e('Placeholders available:', 'mxchat'); ?></strong>
481 <code>{limit}</code>, <code>{timeframe}</code>, <code>{count}</code>, <code>{remaining}</code>
482 <br>
483 <strong><?php esc_html_e('Markdown links supported:', 'mxchat'); ?></strong>
484 <code>[Link text](https://example.com)</code>
485 </div>
486 </div>
487
488 <div class="mxch-card">
489 <div class="mxch-card-body mxchat-autosave-section">
490 <?php
491 // Render rate limits with accordion
492 mxchat_render_rate_limits_accordion($admin_instance);
493 ?>
494 </div>
495 </div>
496 </div>
497
498 <!-- ========================================
499 API KEYS
500 ======================================== -->
501 <div id="api-keys" class="mxch-section">
502 <div class="mxch-content-header">
503 <h1 class="mxch-content-title"><?php esc_html_e('API Keys', 'mxchat'); ?></h1>
504 <p class="mxch-content-subtitle"><?php esc_html_e('Manage API keys for AI providers and integrations.', 'mxchat'); ?></p>
505 </div>
506
507 <div class="mxch-card">
508 <div class="mxch-card-header">
509 <h3 class="mxch-card-title">
510 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2"/><path d="M20 14h2"/><path d="M15 13v2"/><path d="M9 13v2"/></svg>
511 <?php esc_html_e('AI Providers', 'mxchat'); ?>
512 </h3>
513 </div>
514 <div class="mxch-card-body mxchat-autosave-section">
515 <table class="form-table">
516 <?php do_settings_fields('mxchat-api-keys', 'mxchat_api_keys_section'); ?>
517 </table>
518 </div>
519 </div>
520 </div>
521
522 <!-- ========================================
523 INTEGRATIONS - TOOLBAR
524 ======================================== -->
525 <div id="integrations-toolbar" class="mxch-section">
526 <div class="mxch-content-header">
527 <h1 class="mxch-content-title"><?php esc_html_e('Toolbar Settings', 'mxchat'); ?></h1>
528 <p class="mxch-content-subtitle"><?php esc_html_e('Configure the chat toolbar and document upload features.', 'mxchat'); ?></p>
529 </div>
530
531 <div class="mxch-card">
532 <div class="mxch-card-body mxchat-autosave-section">
533 <table class="form-table">
534 <?php do_settings_fields('mxchat-embed', 'mxchat_pdf_intent_section'); ?>
535 </table>
536 </div>
537 </div>
538 </div>
539
540 <!-- ========================================
541 INTEGRATIONS - LOOPS
542 ======================================== -->
543 <div id="integrations-loops" class="mxch-section">
544 <div class="mxch-content-header">
545 <h1 class="mxch-content-title"><?php esc_html_e('Loops Integration', 'mxchat'); ?></h1>
546 <p class="mxch-content-subtitle"><?php esc_html_e('Configure email capture with Loops for mailing list growth.', 'mxchat'); ?></p>
547 </div>
548
549 <div class="mxch-card">
550 <div class="mxch-card-body mxchat-autosave-section">
551 <table class="form-table">
552 <?php do_settings_fields('mxchat-embed', 'mxchat_loops_section'); ?>
553 </table>
554 </div>
555 </div>
556 </div>
557
558 <!-- ========================================
559 INTEGRATIONS - BRAVE SEARCH
560 ======================================== -->
561 <div id="integrations-brave" class="mxch-section">
562 <div class="mxch-content-header">
563 <h1 class="mxch-content-title"><?php esc_html_e('Brave Search', 'mxchat'); ?></h1>
564 <p class="mxch-content-subtitle"><?php esc_html_e('Configure Brave Search API for web search capabilities.', 'mxchat'); ?></p>
565 </div>
566
567 <div class="mxch-card">
568 <div class="mxch-card-body mxchat-autosave-section">
569 <table class="form-table">
570 <?php do_settings_fields('mxchat-embed', 'mxchat_brave_section'); ?>
571 </table>
572 </div>
573 </div>
574 </div>
575
576 <!-- ========================================
577 INTEGRATIONS - SLACK
578 ======================================== -->
579 <div id="integrations-slack" class="mxch-section">
580 <div class="mxch-content-header">
581 <h1 class="mxch-content-title"><?php esc_html_e('Slack', 'mxchat'); ?></h1>
582 <p class="mxch-content-subtitle"><?php esc_html_e('Connect your chatbot to Slack for live human support.', 'mxchat'); ?></p>
583 </div>
584
585 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 24px;">
586 <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
587 <div>
588 <?php printf(
589 esc_html__('Visit our %s for setup instructions.', 'mxchat'),
590 '<a href="https://mxchat.ai/documentation/#slack_integration" target="_blank">' . esc_html__('documentation page', 'mxchat') . '</a>'
591 ); ?>
592 </div>
593 </div>
594
595 <div class="mxch-card">
596 <div class="mxch-card-body mxchat-autosave-section">
597 <table class="form-table">
598 <?php do_settings_fields('mxchat-embed', 'mxchat_live_agent_section'); ?>
599 </table>
600 </div>
601 </div>
602
603 <div class="mxch-card" style="margin-top: 24px;">
604 <div class="mxch-card-header">
605 <h3 class="mxch-card-title">
606 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
607 <?php esc_html_e('Test Connection', 'mxchat'); ?>
608 </h3>
609 </div>
610 <div class="mxch-card-body">
611 <p class="mxch-field-description" style="margin-bottom: 16px;">
612 <?php esc_html_e('Test your Slack bot token to verify it has the required permissions. This will check if the bot can authenticate and create channels.', 'mxchat'); ?>
613 </p>
614 <button type="button" id="mxchat-test-slack-connection" class="mxch-btn mxch-btn-secondary">
615 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="margin-right: 8px;"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
616 <?php esc_html_e('Test Slack Connection', 'mxchat'); ?>
617 </button>
618 <div id="mxchat-slack-test-result" style="margin-top: 16px; display: none;"></div>
619 </div>
620 </div>
621
622 <div class="mxch-card" style="margin-top: 24px;">
623 <div class="mxch-card-header">
624 <h3 class="mxch-card-title">
625 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
626 <?php esc_html_e('Required OAuth Scopes', 'mxchat'); ?>
627 </h3>
628 </div>
629 <div class="mxch-card-body">
630 <p class="mxch-field-description" style="margin-bottom: 12px;">
631 <?php esc_html_e('Your Slack app needs these Bot Token Scopes (OAuth & Permissions > Scopes):', 'mxchat'); ?>
632 </p>
633 <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; background: #f8f9fa; padding: 16px; border-radius: 8px; font-family: monospace; font-size: 13px;">
634 <code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px;">channels:manage</code>
635 <code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px;">channels:read</code>
636 <code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px;">chat:write</code>
637 <code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px;">chat:write.public</code>
638 <code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px;">groups:write</code>
639 <code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px;">users:read</code>
640 </div>
641 <p class="mxch-field-description" style="margin-top: 12px;">
642 <?php esc_html_e('After adding scopes, reinstall the app to your workspace.', 'mxchat'); ?>
643 </p>
644 </div>
645 </div>
646 </div>
647
648 <!-- ========================================
649 INTEGRATIONS - TELEGRAM
650 ======================================== -->
651 <div id="integrations-telegram" class="mxch-section">
652 <div class="mxch-content-header">
653 <h1 class="mxch-content-title"><?php esc_html_e('Telegram', 'mxchat'); ?></h1>
654 <p class="mxch-content-subtitle"><?php esc_html_e('Connect your chatbot to Telegram for live human support.', 'mxchat'); ?></p>
655 </div>
656
657 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 24px;">
658 <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
659 <div>
660 <?php esc_html_e('Telegram Live Agent requires a Telegram bot and a supergroup with forum topics enabled.', 'mxchat'); ?>
661 <a href="https://mxchat.ai/documentation-bot/" target="_blank" style="margin-left: 5px;"><?php esc_html_e('Chat with our advanced doc bot for assistance setting up.', 'mxchat'); ?></a>
662 </div>
663 </div>
664
665 <div class="mxch-card">
666 <div class="mxch-card-body mxchat-autosave-section">
667 <table class="form-table">
668 <?php do_settings_fields('mxchat-embed', 'mxchat_telegram_section'); ?>
669 </table>
670 </div>
671 </div>
672
673 <div class="mxch-card" style="margin-top: 24px;">
674 <div class="mxch-card-header">
675 <h3 class="mxch-card-title">
676 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>
677 <?php esc_html_e('Webhook Setup', 'mxchat'); ?>
678 </h3>
679 </div>
680 <div class="mxch-card-body">
681 <?php
682 $telegram_bot_token = $options['telegram_bot_token'] ?? '';
683 $telegram_webhook_secret = $options['telegram_webhook_secret'] ?? '';
684 $webhook_url = rest_url('mxchat/v1/telegram-webhook');
685 ?>
686
687 <p class="mxch-field-description" style="margin-bottom: 8px;">
688 <strong><?php esc_html_e('Your Webhook URL:', 'mxchat'); ?></strong>
689 </p>
690 <div class="mxch-webhook-url-display" style="margin-bottom: 20px;">
691 <code id="mxch-telegram-webhook-url"><?php echo esc_url($webhook_url); ?></code>
692 <button type="button" class="mxch-btn mxch-btn-secondary mxch-btn-sm" onclick="navigator.clipboard.writeText(document.getElementById('mxch-telegram-webhook-url').textContent); this.textContent='Copied!'; setTimeout(() => this.textContent='Copy', 2000);">
693 <?php esc_html_e('Copy', 'mxchat'); ?>
694 </button>
695 </div>
696
697 <?php if (!empty($telegram_bot_token)) : ?>
698 <p class="mxch-field-description" style="margin-bottom: 8px;">
699 <strong><?php esc_html_e('Register Webhook URL:', 'mxchat'); ?></strong><br>
700 <?php esc_html_e('Copy and paste this URL into your browser to register the webhook with Telegram:', 'mxchat'); ?>
701 </p>
702 <?php
703 $registration_url = 'https://api.telegram.org/bot' . $telegram_bot_token . '/setWebhook?url=' . urlencode($webhook_url);
704 if (!empty($telegram_webhook_secret)) {
705 $registration_url .= '&secret_token=' . urlencode($telegram_webhook_secret);
706 }
707 ?>
708 <div class="mxch-webhook-url-display" style="margin-bottom: 12px;">
709 <code id="mxch-telegram-registration-url" style="word-break: break-all; font-size: 12px;"><?php echo esc_url($registration_url); ?></code>
710 <button type="button" class="mxch-btn mxch-btn-secondary mxch-btn-sm" onclick="navigator.clipboard.writeText(document.getElementById('mxch-telegram-registration-url').textContent); this.textContent='Copied!'; setTimeout(() => this.textContent='Copy', 2000);">
711 <?php esc_html_e('Copy', 'mxchat'); ?>
712 </button>
713 </div>
714 <p class="mxch-field-description" style="color: #22c55e;">
715 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align: middle; margin-right: 4px;"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
716 <?php esc_html_e('You should see {"ok":true,"result":true,"description":"Webhook was set"} after visiting the URL.', 'mxchat'); ?>
717 </p>
718 <?php else : ?>
719 <p class="mxch-field-description" style="color: #f59e0b;">
720 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align: middle; margin-right: 4px;"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
721 <?php esc_html_e('Enter your Bot Token above and save to generate the registration URL.', 'mxchat'); ?>
722 </p>
723 <?php endif; ?>
724 </div>
725 </div>
726 </div>
727
728 <!-- ========================================
729 TUTORIALS
730 ======================================== -->
731 <div id="tutorials" class="mxch-section">
732 <div class="mxch-content-header">
733 <h1 class="mxch-content-title"><?php esc_html_e('Video Tutorials', 'mxchat'); ?></h1>
734 <p class="mxch-content-subtitle"><?php esc_html_e('Learn how to get the most out of MxChat with our video guides.', 'mxchat'); ?></p>
735 </div>
736
737 <div class="mxch-card" style="margin-bottom: 24px;">
738 <div class="mxch-card-body">
739 <div style="display: flex; align-items: flex-start; gap: 16px;">
740 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color: var(--mxch-warning); flex-shrink: 0;"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
741 <div>
742 <h3 style="margin: 0 0 8px 0; font-size: 16px; font-weight: 600;"><?php esc_html_e('Need Help?', 'mxchat'); ?></h3>
743 <p style="margin: 0 0 12px 0; color: var(--mxch-text-secondary);"><?php esc_html_e('If you\'re having trouble or believe something is not working as expected, please submit a support ticket.', 'mxchat'); ?></p>
744 <a href="https://wordpress.org/support/plugin/mxchat-basic/" target="_blank" class="mxch-btn mxch-btn-secondary mxch-btn-sm">
745 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9a2 2 0 0 1-2 2H6l-4 4V4c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v5Z"/><path d="M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"/></svg>
746 <?php esc_html_e('Submit Support Ticket', 'mxchat'); ?>
747 </a>
748 </div>
749 </div>
750 </div>
751 </div>
752
753 <div class="mxch-tutorials-grid">
754 <?php
755 $tutorials = array(
756 array(
757 'title' => __('AI Theme Generator', 'mxchat'),
758 'description' => __('Learn how to instantly restyle your chatbot using plain English prompts with real-time previews.', 'mxchat'),
759 'url' => 'https://www.youtube.com/watch?v=rSQDW2qbtRU&t'
760 ),
761 array(
762 'title' => __('MxChat Forms', 'mxchat'),
763 'description' => __('Create and manage smart forms that automatically trigger during chat conversations.', 'mxchat'),
764 'url' => 'https://www.youtube.com/watch?v=3MrWy5dRalA'
765 ),
766 array(
767 'title' => __('Admin Assistant Add-on', 'mxchat'),
768 'description' => __('Bring a ChatGPT-like experience directly inside your WordPress dashboard.', 'mxchat'),
769 'url' => 'https://youtu.be/AdEA1k-UCFM'
770 ),
771 array(
772 'title' => __('Intent Tester Guide', 'mxchat'),
773 'description' => __('Fine-tune your chatbot\'s responses and ensure accurate query understanding.', 'mxchat'),
774 'url' => 'https://www.youtube.com/watch?v=uTr14tn59Hc'
775 ),
776 array(
777 'title' => __('Theme Customizer', 'mxchat'),
778 'description' => __('Customize appearance with real-time previews to match your brand.', 'mxchat'),
779 'url' => 'https://youtu.be/MfbB9mZi6ag'
780 ),
781 array(
782 'title' => __('WooCommerce Integration', 'mxchat'),
783 'description' => __('Provide product recommendations and shopping assistance to customers.', 'mxchat'),
784 'url' => 'https://www.youtube.com/watch?v=WsqAppHRGdA'
785 ),
786 array(
787 'title' => __('Knowledge Base Setup', 'mxchat'),
788 'description' => __('Set up your knowledge base using PDFs, sitemaps, and manual entries.', 'mxchat'),
789 'url' => 'https://www.youtube.com/watch?v=8Ztjs66-VTo'
790 ),
791 array(
792 'title' => __('Document Chat', 'mxchat'),
793 'description' => __('Chat with PDF and Word documents for enhanced document analysis.', 'mxchat'),
794 'url' => 'https://www.youtube.com/watch?v=j_c45WWCTG0'
795 ),
796 array(
797 'title' => __('Perplexity Integration', 'mxchat'),
798 'description' => __('Enable real-time web search capabilities for your chatbot.', 'mxchat'),
799 'url' => 'https://youtu.be/wpKkbt24-bo'
800 ),
801 array(
802 'title' => __('Brave Search Intent', 'mxchat'),
803 'description' => __('Leverage Brave Search for improved query understanding.', 'mxchat'),
804 'url' => 'https://www.youtube.com/watch?v=7vDL5H7vToc'
805 ),
806 array(
807 'title' => __('Loops Email Capture', 'mxchat'),
808 'description' => __('Set up email capture with Loops to grow your mailing list.', 'mxchat'),
809 'url' => 'https://www.youtube.com/watch?v=CNgm5TYDyTc'
810 ),
811 array(
812 'title' => __('AI Agent Testing', 'mxchat'),
813 'description' => __('Evaluate and improve your chatbot\'s performance and accuracy.', 'mxchat'),
814 'url' => 'https://www.youtube.com/watch?v=A0jowbpyX54'
815 ),
816 );
817
818 foreach ($tutorials as $tutorial): ?>
819 <div class="mxch-tutorial-card">
820 <div class="mxch-tutorial-content">
821 <h3 class="mxch-tutorial-title"><?php echo esc_html($tutorial['title']); ?></h3>
822 <p class="mxch-tutorial-description"><?php echo esc_html($tutorial['description']); ?></p>
823 <a href="<?php echo esc_url($tutorial['url']); ?>" target="_blank" rel="noopener" class="mxch-tutorial-link">
824 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="5 3 19 12 5 21 5 3"/></svg>
825 <?php esc_html_e('Watch Tutorial', 'mxchat'); ?>
826 </a>
827 </div>
828 </div>
829 <?php endforeach; ?>
830 </div>
831 </div>
832
833 </main>
834 </div>
835
836 <script>
837 document.addEventListener('DOMContentLoaded', function() {
838 // Sidebar navigation
839 const navLinks = document.querySelectorAll('.mxch-nav-link, .mxch-nav-sub-link');
840 const sections = document.querySelectorAll('.mxch-section');
841 const navItems = document.querySelectorAll('.mxch-nav-item');
842
843 function showSection(target) {
844 // Show target section
845 sections.forEach(section => {
846 section.classList.remove('active');
847 if (section.id === target) {
848 section.classList.add('active');
849 }
850 });
851
852 // Scroll content area to top
853 const contentArea = document.querySelector('.mxch-content');
854 if (contentArea) {
855 contentArea.scrollTop = 0;
856 }
857 }
858
859 function setActiveNav(clickedLink) {
860 // Remove active from all links
861 navLinks.forEach(l => l.classList.remove('active'));
862
863 // Add active to clicked link
864 clickedLink.classList.add('active');
865
866 // If clicking a sub-link, also highlight parent
867 if (clickedLink.classList.contains('mxch-nav-sub-link')) {
868 const parent = clickedLink.closest('.mxch-nav-item');
869 if (parent) {
870 parent.querySelector('.mxch-nav-link').classList.add('active');
871 }
872 }
873 }
874
875 navLinks.forEach(link => {
876 link.addEventListener('click', function(e) {
877 e.preventDefault();
878 e.stopPropagation();
879 const target = this.dataset.target;
880 const parentItem = this.closest('.mxch-nav-item');
881 const hasSubmenu = parentItem && parentItem.querySelector('.mxch-nav-sub');
882
883 // If this is a parent nav link WITH children (expandable menu)
884 if (this.classList.contains('mxch-nav-link') && hasSubmenu) {
885 const wasExpanded = parentItem.classList.contains('expanded');
886
887 // Collapse all other expandable items
888 navItems.forEach(item => {
889 if (item !== parentItem && item.querySelector('.mxch-nav-sub')) {
890 item.classList.remove('expanded');
891 }
892 });
893
894 // Toggle this item
895 parentItem.classList.toggle('expanded');
896
897 // If expanding, show the first sub-item's content and mark it active
898 if (!wasExpanded) {
899 const firstSubLink = parentItem.querySelector('.mxch-nav-sub-link');
900 if (firstSubLink) {
901 const firstTarget = firstSubLink.dataset.target;
902 showSection(firstTarget);
903 setActiveNav(firstSubLink);
904 // Also mark parent as active
905 this.classList.add('active');
906 history.replaceState(null, null, '#' + firstTarget);
907 }
908 }
909 }
910 // If this is a nav link WITHOUT children (like API Keys, Tutorials)
911 else if (this.classList.contains('mxch-nav-link') && !hasSubmenu && target) {
912 // Collapse all expandable items
913 navItems.forEach(item => {
914 if (item.querySelector('.mxch-nav-sub')) {
915 item.classList.remove('expanded');
916 }
917 });
918
919 // Show the section
920 showSection(target);
921 setActiveNav(this);
922 history.replaceState(null, null, '#' + target);
923 }
924 // If this is a sub-link
925 else if (this.classList.contains('mxch-nav-sub-link') && target) {
926 // Ensure parent stays expanded
927 if (parentItem) {
928 parentItem.classList.add('expanded');
929 }
930 showSection(target);
931 setActiveNav(this);
932 history.replaceState(null, null, '#' + target);
933 }
934 });
935 });
936
937 // Handle initial hash
938 const hash = window.location.hash.slice(1);
939 if (hash) {
940 const targetLink = document.querySelector('[data-target="' + hash + '"]');
941 if (targetLink) {
942 // Expand parent if it's a sub-link
943 const parentItem = targetLink.closest('.mxch-nav-item');
944 if (parentItem && targetLink.classList.contains('mxch-nav-sub-link')) {
945 parentItem.classList.add('expanded');
946 }
947 showSection(hash);
948 setActiveNav(targetLink);
949 }
950 }
951
952 // Rate limit accordion
953 const rateLimitHeaders = document.querySelectorAll('.mxch-rate-limit-header');
954 rateLimitHeaders.forEach(header => {
955 header.addEventListener('click', function(e) {
956 e.preventDefault();
957 e.stopPropagation();
958 const item = this.closest('.mxch-rate-limit-item');
959 item.classList.toggle('expanded');
960 });
961 });
962
963 // =====================================================
964 // Mobile Menu Functionality
965 // =====================================================
966 const mobileMenuBtn = document.querySelector('.mxch-mobile-menu-btn');
967 const mobileMenuClose = document.querySelector('.mxch-mobile-menu-close');
968 const mobileMenu = document.querySelector('.mxch-mobile-menu');
969 const mobileOverlay = document.querySelector('.mxch-mobile-overlay');
970 const mobileNavLinks = document.querySelectorAll('.mxch-mobile-nav-link, .mxch-mobile-nav-sub-link');
971
972 function openMobileMenu() {
973 mobileMenu.classList.add('open');
974 mobileOverlay.classList.add('open');
975 document.body.style.overflow = 'hidden';
976 }
977
978 function closeMobileMenu() {
979 mobileMenu.classList.remove('open');
980 mobileOverlay.classList.remove('open');
981 document.body.style.overflow = '';
982 }
983
984 if (mobileMenuBtn) {
985 mobileMenuBtn.addEventListener('click', openMobileMenu);
986 }
987
988 if (mobileMenuClose) {
989 mobileMenuClose.addEventListener('click', closeMobileMenu);
990 }
991
992 if (mobileOverlay) {
993 mobileOverlay.addEventListener('click', closeMobileMenu);
994 }
995
996 // Mobile navigation links
997 mobileNavLinks.forEach(link => {
998 link.addEventListener('click', function(e) {
999 e.preventDefault();
1000 e.stopPropagation();
1001
1002 const target = this.dataset.target;
1003 const parentId = this.dataset.parent;
1004
1005 // If this is an expandable parent link
1006 if (parentId && !target) {
1007 const subNav = document.querySelector('.mxch-mobile-nav-sub[data-parent="' + parentId + '"]');
1008 if (subNav) {
1009 const isExpanded = subNav.classList.contains('expanded');
1010 // Collapse all sub navs
1011 document.querySelectorAll('.mxch-mobile-nav-sub').forEach(nav => {
1012 nav.classList.remove('expanded');
1013 });
1014 document.querySelectorAll('.mxch-mobile-nav-link').forEach(l => {
1015 l.classList.remove('expanded');
1016 });
1017 // Toggle this one
1018 if (!isExpanded) {
1019 subNav.classList.add('expanded');
1020 this.classList.add('expanded');
1021 }
1022 }
1023 }
1024 // If this is a direct link or sub-link with a target
1025 else if (target) {
1026 // Update mobile nav active state
1027 document.querySelectorAll('.mxch-mobile-nav-link, .mxch-mobile-nav-sub-link').forEach(l => {
1028 l.classList.remove('active');
1029 });
1030 this.classList.add('active');
1031
1032 // Also update desktop sidebar nav
1033 const desktopLink = document.querySelector('.mxch-sidebar [data-target="' + target + '"]');
1034 if (desktopLink) {
1035 setActiveNav(desktopLink);
1036 const parentItem = desktopLink.closest('.mxch-nav-item');
1037 if (parentItem && desktopLink.classList.contains('mxch-nav-sub-link')) {
1038 parentItem.classList.add('expanded');
1039 }
1040 }
1041
1042 // Show section and close menu
1043 showSection(target);
1044 history.replaceState(null, null, '#' + target);
1045 closeMobileMenu();
1046 }
1047 });
1048 });
1049
1050 // Close mobile menu on escape key
1051 document.addEventListener('keydown', function(e) {
1052 if (e.key === 'Escape' && mobileMenu && mobileMenu.classList.contains('open')) {
1053 closeMobileMenu();
1054 }
1055 });
1056 });
1057 </script>
1058 <?php
1059 }
1060
1061 /**
1062 * Helper function to render a field with consistent wrapper
1063 */
1064 function mxchat_render_field_wrapper($id, $label, $callback, $description = '') {
1065 ?>
1066 <div class="mxch-field">
1067 <label class="mxch-field-label"><?php echo esc_html($label); ?></label>
1068 <div class="mxch-field-control">
1069 <?php $callback(); ?>
1070 </div>
1071 <?php if ($description): ?>
1072 <p class="mxch-field-description"><?php echo esc_html($description); ?></p>
1073 <?php endif; ?>
1074 </div>
1075 <?php
1076 }
1077
1078 /**
1079 * Render rate limits as collapsible accordion
1080 */
1081 function mxchat_render_rate_limits_accordion($admin_instance) {
1082 $all_options = get_option('mxchat_options', []);
1083 $rate_limits = array('1', '3', '5', '10', '15', '20', '50', '100', 'unlimited');
1084 $timeframes = array(
1085 'hourly' => __('Per Hour', 'mxchat'),
1086 'daily' => __('Per Day', 'mxchat'),
1087 'weekly' => __('Per Week', 'mxchat'),
1088 'monthly' => __('Per Month', 'mxchat')
1089 );
1090
1091 $roles = wp_roles()->get_names();
1092 $roles['logged_out'] = __('Logged Out Users', 'mxchat');
1093
1094 echo '<div class="mxch-rate-limits">';
1095
1096 foreach ($roles as $role_id => $role_name) {
1097 $default_limit = ($role_id === 'logged_out') ? '10' : '100';
1098 $default_timeframe = 'daily';
1099 $default_message = __('Rate limit exceeded. Please try again later.', 'mxchat');
1100
1101 $selected_limit = isset($all_options['rate_limits'][$role_id]['limit'])
1102 ? $all_options['rate_limits'][$role_id]['limit']
1103 : $default_limit;
1104
1105 $selected_timeframe = isset($all_options['rate_limits'][$role_id]['timeframe'])
1106 ? $all_options['rate_limits'][$role_id]['timeframe']
1107 : $default_timeframe;
1108
1109 $custom_message = isset($all_options['rate_limits'][$role_id]['message'])
1110 ? $all_options['rate_limits'][$role_id]['message']
1111 : $default_message;
1112
1113 $timeframe_label = isset($timeframes[$selected_timeframe]) ? $timeframes[$selected_timeframe] : $selected_timeframe;
1114 ?>
1115 <div class="mxch-rate-limit-item">
1116 <div class="mxch-rate-limit-header">
1117 <span class="mxch-rate-limit-role"><?php echo esc_html($role_name); ?></span>
1118 <div class="mxch-rate-limit-summary">
1119 <span class="mxch-rate-limit-badge"><?php echo esc_html($selected_limit . ' / ' . $timeframe_label); ?></span>
1120 <svg class="mxch-rate-limit-arrow" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>
1121 </div>
1122 </div>
1123 <div class="mxch-rate-limit-body mxchat-autosave-section">
1124 <div class="mxch-rate-limit-controls">
1125 <div class="mxch-field">
1126 <label class="mxch-field-label" for="rate_limits_<?php echo esc_attr($role_id); ?>_limit"><?php esc_html_e('Limit', 'mxchat'); ?></label>
1127 <select id="rate_limits_<?php echo esc_attr($role_id); ?>_limit"
1128 name="mxchat_options[rate_limits][<?php echo esc_attr($role_id); ?>][limit]"
1129 class="mxch-select mxchat-autosave-field">
1130 <?php foreach ($rate_limits as $limit): ?>
1131 <option value="<?php echo esc_attr($limit); ?>" <?php selected($selected_limit, $limit); ?>><?php echo esc_html($limit); ?></option>
1132 <?php endforeach; ?>
1133 </select>
1134 </div>
1135 <div class="mxch-field">
1136 <label class="mxch-field-label" for="rate_limits_<?php echo esc_attr($role_id); ?>_timeframe"><?php esc_html_e('Timeframe', 'mxchat'); ?></label>
1137 <select id="rate_limits_<?php echo esc_attr($role_id); ?>_timeframe"
1138 name="mxchat_options[rate_limits][<?php echo esc_attr($role_id); ?>][timeframe]"
1139 class="mxch-select mxchat-autosave-field">
1140 <?php foreach ($timeframes as $value => $label): ?>
1141 <option value="<?php echo esc_attr($value); ?>" <?php selected($selected_timeframe, $value); ?>><?php echo esc_html($label); ?></option>
1142 <?php endforeach; ?>
1143 </select>
1144 </div>
1145 </div>
1146 <div class="mxch-field">
1147 <label class="mxch-field-label" for="rate_limits_<?php echo esc_attr($role_id); ?>_message"><?php esc_html_e('Custom Message', 'mxchat'); ?></label>
1148 <textarea id="rate_limits_<?php echo esc_attr($role_id); ?>_message"
1149 name="mxchat_options[rate_limits][<?php echo esc_attr($role_id); ?>][message]"
1150 class="mxch-textarea mxchat-autosave-field"
1151 rows="2"
1152 placeholder="<?php esc_attr_e('Message shown when rate limit is reached', 'mxchat'); ?>"><?php echo esc_textarea($custom_message); ?></textarea>
1153 </div>
1154 </div>
1155 </div>
1156 <?php
1157 }
1158
1159 echo '</div>';
1160 }
1161