| @@ -40,15 +40,8 @@ | ||
| 40 | 40 | add_action('wp_ajax_mxchat_update_intent_threshold', array($this, 'mxchat_update_intent_threshold')); |
| 41 | 41 | |
| 42 | 42 | add_action('wp_ajax_mxchat_save_selected_bot', array($this, 'mxchat_save_selected_bot')); |
| 43 | 43 | add_action('wp_ajax_mxchat_check_api_keys', array($this, 'mxchat_check_api_keys')); |
| 44 | - | |
| 45 | - // Debug & Optimization AJAX | |
| 46 | - add_action('wp_ajax_mxchat_toggle_debug_mode', array($this, 'mxchat_toggle_debug_mode_callback')); | |
| 47 | - add_action('wp_ajax_mxchat_get_debug_log', array($this, 'mxchat_get_debug_log_callback')); | |
| 48 | - add_action('wp_ajax_mxchat_clear_debug_log', array($this, 'mxchat_clear_debug_log_callback')); | |
| 49 | - add_action('wp_ajax_mxchat_export_settings', array($this, 'mxchat_export_settings_callback')); | |
| 50 | - add_action('wp_ajax_mxchat_reset_all_settings', array($this, 'mxchat_reset_all_settings_callback')); | |
| 51 | 44 | } |
| 52 | 45 | |
| 53 | 46 | // ======================================== |
| 54 | 47 | // SETTINGS AJAX HANDLERS |
| @@ -107,12 +100,11 @@ | ||
| 107 | 100 | 'gemini-2.0-flash', 'gemini-2.0-flash-lite', 'gemini-1.5-pro', 'gemini-1.5-flash', |
| 108 | 101 | 'grok-4-0709', 'grok-4-1-fast-reasoning', 'grok-4-1-fast-non-reasoning', 'grok-3-beta', 'grok-3-fast-beta', 'grok-3-mini-beta', |
| 109 | 102 | 'grok-3-mini-fast-beta', 'grok-2', |
| 110 | 103 | 'deepseek-chat', |
| 111 | - 'claude-opus-4-6', 'claude-opus-4-5', 'claude-sonnet-4-6', | |
| 104 | + 'claude-opus-4-6', 'claude-opus-4-5', | |
| 112 | 105 | 'claude-sonnet-4-5-20250929', 'claude-opus-4-1-20250805', 'claude-haiku-4-5-20251001', |
| 113 | 106 | 'claude-opus-4-20250514', 'claude-sonnet-4-20250514', |
| 114 | - 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'gpt-5.3-chat-latest', | |
| 115 | 107 | 'gpt-5.2', 'gpt-5.1-chat-latest', 'gpt-5.1-2025-11-13', 'gpt-5', 'gpt-5-mini', 'gpt-5-nano', |
| 116 | 108 | ); |
| 117 | 109 | |
| 118 | 110 | //error_log('MXChat Save: in_array result: ' . (in_array($value, $allowed_models) ? 'YES' : 'NO')); |
| @@ -190,14 +182,26 @@ | ||
| 190 | 182 | if ($rag_limit < 3) $rag_limit = 3; |
| 191 | 183 | if ($rag_limit > 10) $rag_limit = 10; |
| 192 | 184 | $options[$field_name] = $rag_limit; |
| 193 | 185 | break; |
| 194 | - case 'rag_chunks_limit': | |
| 195 | - // Validate and save - enforce min 8, max 20, default 15 | |
| 196 | - $chunks_limit = intval($value); | |
| 197 | - if ($chunks_limit < 8) $chunks_limit = 8; | |
| 198 | - if ($chunks_limit > 20) $chunks_limit = 20; | |
| 199 | - $options[$field_name] = $chunks_limit; | |
| 186 | + case 'user_message_bg_color': | |
| 187 | + case 'user_message_font_color': | |
| 188 | + case 'bot_message_bg_color': | |
| 189 | + case 'bot_message_font_color': | |
| 190 | + case 'top_bar_bg_color': | |
| 191 | + case 'send_button_font_color': | |
| 192 | + case 'chatbot_background_color': | |
| 193 | + case 'icon_color': | |
| 194 | + case 'chat_input_font_color': | |
| 195 | + case 'live_agent_message_bg_color': | |
| 196 | + case 'live_agent_message_font_color': | |
| 197 | + case 'mode_indicator_bg_color': | |
| 198 | + case 'mode_indicator_font_color': | |
| 199 | + case 'toolbar_icon_color': | |
| 200 | + case 'quick_questions_toggle_color': | |
| 201 | + //error_log('MXChat Save: Processing color value: ' . $field_name); | |
| 202 | + // Store color values directly | |
| 203 | + $options[$field_name] = $value; | |
| 200 | 204 | break; |
| 201 | 205 | case 'live_agent_status': |
| 202 | 206 | //error_log('MXChat Save: Processing live_agent_status'); |
| 203 | 207 | // Set the new value |
| @@ -370,9 +374,10 @@ | ||
| 370 | 374 | 'enable_streaming_toggle', |
| 371 | 375 | 'contextual_awareness_toggle', |
| 372 | 376 | 'citation_links_toggle', |
| 373 | 377 | 'enable_email_block', |
| 374 | - 'enable_name_field' | |
| 378 | + 'enable_name_field', | |
| 379 | + 'show_frontend_debugger' | |
| 375 | 380 | ])) { |
| 376 | 381 | //error_log('MXChat Save: Processing toggle: ' . $field_name); |
| 377 | 382 | $options[$field_name] = ($value === 'on') ? 'on' : 'off'; |
| 378 | 383 | } else { |
| @@ -387,20 +392,8 @@ | ||
| 387 | 392 | $updated = update_option('mxchat_options', $options); |
| 388 | 393 | //error_log('MXChat Save: Update result: ' . ($updated ? 'success' : 'unchanged') . ' for field: ' . $name); |
| 389 | 394 | //error_log('MXChat Save: Updated options array: ' . print_r($options, true)); |
| 390 | 395 | |
| 391 | - // Log the save action if debug mode is enabled | |
| 392 | - if ( class_exists( 'MxChat_Admin' ) ) { | |
| 393 | - MxChat_Admin::mxchat_log_debug( | |
| 394 | - 'settings_save', | |
| 395 | - sprintf( 'Field saved: %s', $field_name ), | |
| 396 | - array( | |
| 397 | - 'field' => $field_name, | |
| 398 | - 'updated' => $updated, | |
| 399 | - ) | |
| 400 | - ); | |
| 401 | - } | |
| 402 | - | |
| 403 | 396 | // Always return success even if WordPress says nothing changed |
| 404 | 397 | // (which happens when the value is the same as before) |
| 405 | 398 | wp_send_json_success(['message' => esc_html__('Setting saved', 'mxchat')]); |
| 406 | 399 | } |
| @@ -1134,143 +1127,8 @@ | ||
| 1134 | 1127 | 'voyage' => !empty($options['voyage_api_key']) |
| 1135 | 1128 | ); |
| 1136 | 1129 | |
| 1137 | 1130 | wp_send_json_success($api_key_status); |
| 1138 | - } | |
| 1139 | - | |
| 1140 | - // ======================================== | |
| 1141 | - // DEBUG & OPTIMIZATION AJAX HANDLERS | |
| 1142 | - // ======================================== | |
| 1143 | - | |
| 1144 | - /** | |
| 1145 | - * Toggle debug mode on/off | |
| 1146 | - */ | |
| 1147 | - public function mxchat_toggle_debug_mode_callback() { | |
| 1148 | - // Verify nonce | |
| 1149 | - if ( ! check_ajax_referer( 'mxchat_save_setting_nonce', '_ajax_nonce', false ) ) { | |
| 1150 | - wp_send_json_error( array( 'message' => esc_html__( 'Security check failed', 'mxchat' ) ) ); | |
| 1151 | - } | |
| 1152 | - | |
| 1153 | - // Check permissions | |
| 1154 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1155 | - wp_send_json_error( array( 'message' => esc_html__( 'Unauthorized', 'mxchat' ) ) ); | |
| 1156 | - } | |
| 1157 | - | |
| 1158 | - $enabled = isset( $_POST['enabled'] ) && $_POST['enabled'] === 'on'; | |
| 1159 | - | |
| 1160 | - $options = get_option( 'mxchat_options', array() ); | |
| 1161 | - | |
| 1162 | - if ( $enabled ) { | |
| 1163 | - $options['debug_mode'] = 'on'; | |
| 1164 | - update_option( 'mxchat_options', $options ); | |
| 1165 | - MxChat_Admin::mxchat_log_debug( 'debug_mode', 'Debug mode enabled' ); | |
| 1166 | - } else { | |
| 1167 | - // Log before disabling | |
| 1168 | - MxChat_Admin::mxchat_log_debug( 'debug_mode', 'Debug mode disabled' ); | |
| 1169 | - $options['debug_mode'] = 'off'; | |
| 1170 | - update_option( 'mxchat_options', $options ); | |
| 1171 | - } | |
| 1172 | - | |
| 1173 | - wp_send_json_success( array( | |
| 1174 | - 'message' => $enabled ? esc_html__( 'Debug mode enabled', 'mxchat' ) : esc_html__( 'Debug mode disabled', 'mxchat' ), | |
| 1175 | - 'enabled' => $enabled, | |
| 1176 | - ) ); | |
| 1177 | - } | |
| 1178 | - | |
| 1179 | - /** | |
| 1180 | - * Get the debug log entries | |
| 1181 | - */ | |
| 1182 | - public function mxchat_get_debug_log_callback() { | |
| 1183 | - // Verify nonce | |
| 1184 | - if ( ! check_ajax_referer( 'mxchat_save_setting_nonce', '_ajax_nonce', false ) ) { | |
| 1185 | - wp_send_json_error( array( 'message' => esc_html__( 'Security check failed', 'mxchat' ) ) ); | |
| 1186 | - } | |
| 1187 | - | |
| 1188 | - // Check permissions | |
| 1189 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1190 | - wp_send_json_error( array( 'message' => esc_html__( 'Unauthorized', 'mxchat' ) ) ); | |
| 1191 | - } | |
| 1192 | - | |
| 1193 | - $log = MxChat_Admin::mxchat_get_debug_log(); | |
| 1194 | - | |
| 1195 | - wp_send_json_success( array( | |
| 1196 | - 'log' => $log, | |
| 1197 | - 'count' => count( $log ), | |
| 1198 | - ) ); | |
| 1199 | - } | |
| 1200 | - | |
| 1201 | - /** | |
| 1202 | - * Clear the debug log | |
| 1203 | - */ | |
| 1204 | - public function mxchat_clear_debug_log_callback() { | |
| 1205 | - // Verify nonce | |
| 1206 | - if ( ! check_ajax_referer( 'mxchat_save_setting_nonce', '_ajax_nonce', false ) ) { | |
| 1207 | - wp_send_json_error( array( 'message' => esc_html__( 'Security check failed', 'mxchat' ) ) ); | |
| 1208 | - } | |
| 1209 | - | |
| 1210 | - // Check permissions | |
| 1211 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1212 | - wp_send_json_error( array( 'message' => esc_html__( 'Unauthorized', 'mxchat' ) ) ); | |
| 1213 | - } | |
| 1214 | - | |
| 1215 | - MxChat_Admin::mxchat_clear_debug_log(); | |
| 1216 | - | |
| 1217 | - // Log that the log was cleared (this will be the first entry in the new log) | |
| 1218 | - MxChat_Admin::mxchat_log_debug( 'debug_log', 'Debug log cleared by user' ); | |
| 1219 | - | |
| 1220 | - wp_send_json_success( array( 'message' => esc_html__( 'Debug log cleared', 'mxchat' ) ) ); | |
| 1221 | - } | |
| 1222 | - | |
| 1223 | - /** | |
| 1224 | - * Export settings as JSON | |
| 1225 | - */ | |
| 1226 | - public function mxchat_export_settings_callback() { | |
| 1227 | - // Verify nonce | |
| 1228 | - if ( ! check_ajax_referer( 'mxchat_save_setting_nonce', '_ajax_nonce', false ) ) { | |
| 1229 | - wp_send_json_error( array( 'message' => esc_html__( 'Security check failed', 'mxchat' ) ) ); | |
| 1230 | - } | |
| 1231 | - | |
| 1232 | - // Check permissions | |
| 1233 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1234 | - wp_send_json_error( array( 'message' => esc_html__( 'Unauthorized', 'mxchat' ) ) ); | |
| 1235 | - } | |
| 1236 | - | |
| 1237 | - $export = MxChat_Admin::mxchat_export_settings(); | |
| 1238 | - | |
| 1239 | - // Log the export | |
| 1240 | - MxChat_Admin::mxchat_log_debug( 'settings_export', 'Settings exported by user' ); | |
| 1241 | - | |
| 1242 | - wp_send_json_success( array( | |
| 1243 | - 'settings' => $export, | |
| 1244 | - 'filename' => 'mxchat-settings-' . gmdate( 'Y-m-d-His' ) . '.json', | |
| 1245 | - ) ); | |
| 1246 | - } | |
| 1247 | - | |
| 1248 | - /** | |
| 1249 | - * Reset all settings to defaults | |
| 1250 | - */ | |
| 1251 | - public function mxchat_reset_all_settings_callback() { | |
| 1252 | - // Verify nonce | |
| 1253 | - if ( ! check_ajax_referer( 'mxchat_save_setting_nonce', '_ajax_nonce', false ) ) { | |
| 1254 | - wp_send_json_error( array( 'message' => esc_html__( 'Security check failed', 'mxchat' ) ) ); | |
| 1255 | - } | |
| 1256 | - | |
| 1257 | - // Check permissions | |
| 1258 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1259 | - wp_send_json_error( array( 'message' => esc_html__( 'Unauthorized', 'mxchat' ) ) ); | |
| 1260 | - } | |
| 1261 | - | |
| 1262 | - // Require confirmation code | |
| 1263 | - $confirmation = isset( $_POST['confirmation'] ) ? sanitize_text_field( wp_unslash( $_POST['confirmation'] ) ) : ''; | |
| 1264 | - | |
| 1265 | - if ( strtoupper( $confirmation ) !== 'RESET' ) { | |
| 1266 | - wp_send_json_error( array( 'message' => esc_html__( 'Invalid confirmation code. Please type RESET to confirm.', 'mxchat' ) ) ); | |
| 1267 | - } | |
| 1268 | - | |
| 1269 | - // Perform the reset | |
| 1270 | - MxChat_Admin::mxchat_reset_all_settings(); | |
| 1271 | - | |
| 1272 | - wp_send_json_success( array( 'message' => esc_html__( 'All settings have been reset to defaults. The page will reload.', 'mxchat' ) ) ); | |
| 1273 | 1131 | } |
| 1274 | 1132 | |
| 1275 | 1133 | } |
| 1276 | 1134 | |