get_chatbots(); // Get adjustments for the selected chatbot (secured with nonce) $selected_chatbot_id = 0; if ( isset($_GET['chatbot_id'], $_GET['a1ai_select_nonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['a1ai_select_nonce'] ) ), 'a1ai_select_chatbot' ) ) { $selected_chatbot_id = intval($_GET['chatbot_id']); } $adjustments = array(); if ($selected_chatbot_id > 0) { $adjustments = $data_manager->get_adjustments($selected_chatbot_id); } // Handle deletion via GET with nonce verification if ( isset($_GET['delete_adjustment']) ) { if ( current_user_can('manage_options') ) { if ( isset($_GET['_wpnonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'a1ai_delete_adjustment' ) ) { $adjustment_id = intval( $_GET['delete_adjustment'] ); if ( $adjustment_id > 0 ) { $result = $data_manager->delete_adjustment( $adjustment_id ); if ( $result ) { echo '

' . esc_html__('Adjustment deleted successfully!', 'a1ai-chatbot') . '

'; } if ( $selected_chatbot_id > 0 ) { $adjustments = $data_manager->get_adjustments( $selected_chatbot_id ); } } } else { echo '

' . esc_html__('Security check failed for deletion.', 'a1ai-chatbot') . '

'; } } else { echo '

' . esc_html__('You do not have permission to perform this action.', 'a1ai-chatbot') . '

'; } } // Handle form submissions if ( isset($_SERVER['REQUEST_METHOD']) && 'POST' === $_SERVER['REQUEST_METHOD'] ) { if ( isset($_POST['a1ai_action']) ) { $a1ai_action = sanitize_key( wp_unslash( $_POST['a1ai_action'] ) ); switch ( $a1ai_action ) { case 'save_adjustment': case 'add_adjustment': if ( ! current_user_can('manage_options') ) { echo '

' . esc_html__('You do not have permission to perform this action.', 'a1ai-chatbot') . '

'; break; } if ( ! isset($_POST['a1ai_adjustment_nonce']) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['a1ai_adjustment_nonce'] ) ), 'a1ai_save_adjustment' ) ) { echo '

' . esc_html__('Security check failed. Please try again.', 'a1ai-chatbot') . '

'; break; } if ( isset($_POST['chatbot_id'], $_POST['user_input'], $_POST['ai_output']) ) { $chatbot_id = intval( $_POST['chatbot_id'] ); $user_input = sanitize_textarea_field( wp_unslash( $_POST['user_input'] ) ); $ai_output = sanitize_textarea_field( wp_unslash( $_POST['ai_output'] ) ); // Get match types and temperature $ui_match_type = isset($_POST['ui_match_type']) ? sanitize_text_field( wp_unslash( $_POST['ui_match_type'] ) ) : 'Broad'; $ai_match_type = isset($_POST['ai_match_type']) ? sanitize_text_field( wp_unslash( $_POST['ai_match_type'] ) ) : 'Broad'; $ai_temperature = isset($_POST['ai_temperature']) ? floatval( $_POST['ai_temperature'] ) : 0.7; // Validate match types - restrict premium options to upgrade users only $valid_match_types = array('Default'); if (class_exists('A1AI_Upgrade_Helper') && A1AI_Upgrade_Helper::is_upgrade_active()) { $valid_match_types = array('Default', 'Broad', 'Phrase', 'Exact'); } if (!in_array($ui_match_type, $valid_match_types)) { $ui_match_type = 'Default'; } if (!in_array($ai_match_type, $valid_match_types)) { $ai_match_type = 'Default'; } // Validate temperature - restrict to default for free users if (!class_exists('A1AI_Upgrade_Helper') || !A1AI_Upgrade_Helper::is_upgrade_active()) { $ai_temperature = 0.7; // Force default for free users } else { // Validate temperature (0.1 to 1.0) for premium users if ($ai_temperature < 0.1 || $ai_temperature > 1.0) { $ai_temperature = 0.7; } } $result = $data_manager->add_adjustment( $chatbot_id, $user_input, $ai_output, $ui_match_type, $ai_match_type, 0, $ai_temperature ); if ( $result ) { echo '

' . esc_html__('Adjustment added successfully!', 'a1ai-chatbot') . '

'; } // Refresh adjustments list $adjustments = $selected_chatbot_id > 0 ? $data_manager->get_adjustments( $selected_chatbot_id ) : array(); } break; case 'update_adjustment': case 'edit_adjustment': if ( ! current_user_can('manage_options') ) { echo '

' . esc_html__('You do not have permission to perform this action.', 'a1ai-chatbot') . '

'; break; } if ( ! isset($_POST['a1ai_edit_adjustment_nonce']) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['a1ai_edit_adjustment_nonce'] ) ), 'a1ai_edit_adjustment' ) ) { echo '

' . esc_html__('Security check failed. Please try again.', 'a1ai-chatbot') . '

'; break; } if ( isset($_POST['adjustment_id'], $_POST['user_input'], $_POST['ai_output']) ) { $adjustment_id = intval( $_POST['adjustment_id'] ); $user_input = sanitize_textarea_field( wp_unslash( $_POST['user_input'] ) ); $ai_output = sanitize_textarea_field( wp_unslash( $_POST['ai_output'] ) ); // Get match types and temperature $ui_match_type = isset($_POST['ui_match_type']) ? sanitize_text_field( wp_unslash( $_POST['ui_match_type'] ) ) : 'Broad'; $ai_match_type = isset($_POST['ai_match_type']) ? sanitize_text_field( wp_unslash( $_POST['ai_match_type'] ) ) : 'Broad'; $ai_temperature = isset($_POST['ai_temperature']) ? floatval( $_POST['ai_temperature'] ) : 0.7; // Validate match types - restrict premium options to upgrade users only $valid_match_types = array('Default'); if (class_exists('A1AI_Upgrade_Helper') && A1AI_Upgrade_Helper::is_upgrade_active()) { $valid_match_types = array('Default', 'Broad', 'Phrase', 'Exact'); } if (!in_array($ui_match_type, $valid_match_types)) { $ui_match_type = 'Default'; } if (!in_array($ai_match_type, $valid_match_types)) { $ai_match_type = 'Default'; } // Validate temperature - restrict to default for free users if (!class_exists('A1AI_Upgrade_Helper') || !A1AI_Upgrade_Helper::is_upgrade_active()) { $ai_temperature = 0.7; // Force default for free users } else { // Validate temperature (0.1 to 1.0) for premium users if ($ai_temperature < 0.1 || $ai_temperature > 1.0) { $ai_temperature = 0.7; } } $update_data = array( 'user_input' => $user_input, 'ai_output' => $ai_output, 'ui_match_type' => $ui_match_type, 'ai_match_type' => $ai_match_type, 'ai_temperature' => $ai_temperature ); $result = $data_manager->update_adjustment( $adjustment_id, $update_data ); if ( $result ) { echo '

' . esc_html__('Adjustment updated successfully!', 'a1ai-chatbot') . '

'; } // Refresh adjustments list $adjustments = $selected_chatbot_id > 0 ? $data_manager->get_adjustments( $selected_chatbot_id ) : array(); } break; case 'delete_adjustment': if ( ! current_user_can('manage_options') ) { echo '

' . esc_html__('You do not have permission to perform this action.', 'a1ai-chatbot') . '

'; break; } if ( ! isset($_POST['_wpnonce']) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'a1ai_delete_adjustment' ) ) { echo '

' . esc_html__('Security check failed. Please try again.', 'a1ai-chatbot') . '

'; break; } if ( isset($_POST['adjustment_id']) ) { $adjustment_id = intval( $_POST['adjustment_id'] ); $result = $data_manager->delete_adjustment( $adjustment_id ); if ( $result ) { echo '

' . esc_html__('Adjustment deleted successfully!', 'a1ai-chatbot') . '

'; } // Refresh adjustments list $adjustments = $selected_chatbot_id > 0 ? $data_manager->get_adjustments( $selected_chatbot_id ) : array(); } break; } } } ?>

ℹ️ Free Version: Basic adjustments with Default matching are available. View the Upgrade tab to see all premium adjustment features.

'adjustments_locked', 'title' => __('Tuning answers one at a time is the slow way', 'a1ai-chatbot'), 'body' => __('Adjustments patch individual replies. A1Ai Workspace syncs your entire site into the chatbot\'s knowledge — so the answers are right before you have to correct them, and every conversation feeds your CRM and follow-ups.', 'a1ai-chatbot'), 'points' => array( __('Sync Knowledge: whole-site crawl, AI summaries, pushed into this chatbot', 'a1ai-chatbot'), __('Watch live chats and take over as a human when it matters', 'a1ai-chatbot'), __('Every lead lands in a CRM with the follow-up already queued', 'a1ai-chatbot'), ), )); } ?>
'; if (isset($_GET['user_input'])) { echo ''; } if (isset($_GET['ai_response'])) { echo ''; } if (isset($_GET['chatbot_name'])) { echo ''; } } ?>
0) : ?>


•
•
•
•


•
•

get_chatbot($adjustment['chatbot_id']); $chatbot_name = $chatbot ? $chatbot['name'] : __('Unknown Chatbot', 'a1ai-chatbot'); ?>