PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.2.0
MxChat – AI Chatbot & Content Generation for WordPress v2.2.0
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
← All changes | mxchat-basic.php +59 -5 2.0.62.2.0 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /**
3 3 * Plugin Name: MxChat
4 4 * Description: AI chatbot for WordPress with OpenAI, Claude, xAI, DeepSeek, live agent, PDF uploads, WooCommerce, and training on website data.
5 - * Version: 2.0.6
5 + * Version: 2.2.0
6 6 * Author: MxChat
7 7 * Author URI: https://mxchat.ai
8 8 * License: GPLv2 or later
9 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -87,11 +87,12 @@
87 87 mxchat_add_missing_columns($system_prompt_table, 'source_url', 'VARCHAR(255) DEFAULT NULL');
88 88
89 89 // Set default thresholds for existing intents
90 90 $wpdb->query("UPDATE {$intents_table} SET similarity_threshold = 0.85 WHERE similarity_threshold IS NULL");
91 + mxchat_add_missing_columns($intents_table, 'enabled', 'TINYINT(1) NOT NULL DEFAULT 1');
91 92
92 93 // Update plugin version in the database
93 - update_option('mxchat_plugin_version', '2.0.6');
94 + update_option('mxchat_plugin_version', '2.2.0');
94 95 }
95 96
96 97
97 98 function mxchat_add_missing_columns($table, $column_name, $column_type) {
@@ -103,15 +104,68 @@
103 104 }
104 105
105 106 function mxchat_check_for_update() {
106 107 $current_version = get_option('mxchat_plugin_version');
107 - $plugin_version = '2.0.6'; // Update with your latest version
108 -
108 + $plugin_version = '2.2.0'; // Increment to your next version
109 +
109 110 if ($current_version !== $plugin_version) {
111 + // Run your existing update processes
110 112 mxchat_activate(); // Run the activation script to apply schema changes
111 113 mxchat_migrate_live_agent_status(); // Add migration for live agent status
112 - update_option('mxchat_plugin_version', $plugin_version); // Update the version
114 +
115 + // Add the new cleanup function for version 2.1.8
116 + if (version_compare($current_version, '2.1.8', '<')) {
117 + // Call the cleanup function
118 + $deleted = mxchat_cleanup_orphaned_chat_history();
119 + // Optionally log the results
120 + error_log(sprintf('MxChat cleanup: Removed %d orphaned chat history entries', $deleted));
121 + }
122 +
123 + // Update the stored version number
124 + update_option('mxchat_plugin_version', $plugin_version);
113 125 }
126 +}
127 +
128 +/**
129 + * Clean up orphaned chat history options from the wp_options table
130 + * @return int Number of options deleted
131 + */
132 +function mxchat_cleanup_orphaned_chat_history() {
133 + global $wpdb;
134 + $count = 0;
135 +
136 + // Get all option keys that match our pattern
137 + $history_options = $wpdb->get_results(
138 + "SELECT option_name FROM {$wpdb->options}
139 + WHERE option_name LIKE 'mxchat_history_%'"
140 + );
141 +
142 + if (!empty($history_options)) {
143 + foreach ($history_options as $option) {
144 + // Extract the session ID from the option name
145 + $session_id = str_replace('mxchat_history_', '', $option->option_name);
146 +
147 + // Check if this session still exists in the custom table
148 + $table_name = $wpdb->prefix . 'mxchat_chat_transcripts';
149 + $exists = $wpdb->get_var(
150 + $wpdb->prepare(
151 + "SELECT COUNT(*) FROM {$table_name} WHERE session_id = %s",
152 + $session_id
153 + )
154 + );
155 +
156 + // If session doesn't exist in the main table, delete the option
157 + if ($exists == 0) {
158 + delete_option($option->option_name);
159 + // Also delete related metadata
160 + delete_option("mxchat_email_{$session_id}");
161 + delete_option("mxchat_agent_name_{$session_id}");
162 + $count++;
163 + }
164 + }
165 + }
166 +
167 + return $count;
114 168 }
115 169
116 170 function mxchat_migrate_live_agent_status() {
117 171 $options = get_option('mxchat_options', []);