PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.2.2
MxChat – AI Chatbot & Content Generation for WordPress v2.2.2
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 +144 -14 2.0.32.2.2 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.3
5 + * Version: 2.2.2
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
@@ -14,8 +14,10 @@
14 14 if (!defined('ABSPATH')) {
15 15 exit; // Exit if accessed directly.
16 16 }
17 17
18 +// ADD THIS: Define plugin version constant for asset versioning
19 +define('MXCHAT_VERSION', '2.2.2');
18 20
19 21 function mxchat_load_textdomain() {
20 22 load_plugin_textdomain('mxchat', false, dirname(plugin_basename(__FILE__)) . '/languages');
21 23 }
@@ -26,12 +28,15 @@
26 28 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-admin.php';
27 29 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-public.php';
28 30 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-utils.php';
29 31 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-user.php';
30 -require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-woocommerce.php';
31 32 require_once plugin_dir_path(__FILE__) . 'includes/pdf-parser/alt_autoload.php';
32 33 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-word-handler.php';
34 +require_once plugin_dir_path(__FILE__) . 'admin/class-ajax-handler.php';
35 +require_once plugin_dir_path(__FILE__) . 'admin/class-pinecone-manager.php';
36 +require_once plugin_dir_path(__FILE__) . 'admin/class-knowledge-manager.php';
33 37
38 +
34 39 function mxchat_activate() {
35 40 global $wpdb;
36 41 $charset_collate = $wpdb->get_charset_collate();
37 42
@@ -88,11 +93,12 @@
88 93 mxchat_add_missing_columns($system_prompt_table, 'source_url', 'VARCHAR(255) DEFAULT NULL');
89 94
90 95 // Set default thresholds for existing intents
91 96 $wpdb->query("UPDATE {$intents_table} SET similarity_threshold = 0.85 WHERE similarity_threshold IS NULL");
97 + mxchat_add_missing_columns($intents_table, 'enabled', 'TINYINT(1) NOT NULL DEFAULT 1');
92 98
93 - // Update plugin version in the database
94 - update_option('mxchat_plugin_version', '2.0.3');
99 + // CHANGE THIS: Use the constant instead of hardcoded version
100 + update_option('mxchat_plugin_version', MXCHAT_VERSION);
95 101 }
96 102
97 103
98 104 function mxchat_add_missing_columns($table, $column_name, $column_type) {
@@ -103,24 +109,90 @@
103 109 }
104 110 }
105 111
106 112 function mxchat_check_for_update() {
113 + //error_log('=== mxchat_check_for_update called ===');
114 +
107 115 $current_version = get_option('mxchat_plugin_version');
108 - $plugin_version = '2.0.3'; // Update with your latest version
116 + $plugin_version = MXCHAT_VERSION;
117 +
118 + //error_log('Current stored version: ' . $current_version);
119 + //error_log('Plugin version constant: ' . $plugin_version);
109 120
110 121 if ($current_version !== $plugin_version) {
111 - mxchat_activate(); // Run the activation script to apply schema changes
112 - mxchat_migrate_live_agent_status(); // Add migration for live agent status
113 - update_option('mxchat_plugin_version', $plugin_version); // Update the version
122 + //error_log('Version mismatch detected, running updates');
123 +
124 + // IMPORTANT: Run live agent update BEFORE updating the stored version
125 + mxchat_handle_live_agent_update();
126 +
127 + // Run your existing update processes
128 + mxchat_activate();
129 + mxchat_migrate_live_agent_status();
130 +
131 + // Add the new cleanup function for version 2.1.8
132 + if (version_compare($current_version, '2.1.8', '<')) {
133 + $deleted = mxchat_cleanup_orphaned_chat_history();
134 + //error_log(sprintf('MxChat cleanup: Removed %d orphaned chat history entries', $deleted));
135 + }
136 +
137 + // Update version LAST so the live agent update logic can work
138 + update_option('mxchat_plugin_version', $plugin_version);
139 + //error_log('Version updated to: ' . $plugin_version);
140 + } else {
141 + //error_log('Versions match, no update needed');
114 142 }
115 143 }
116 144
145 +/**
146 + * Clean up orphaned chat history options from the wp_options table
147 + * @return int Number of options deleted
148 + */
149 +function mxchat_cleanup_orphaned_chat_history() {
150 + global $wpdb;
151 + $count = 0;
152 +
153 + // Get all option keys that match our pattern
154 + $history_options = $wpdb->get_results(
155 + "SELECT option_name FROM {$wpdb->options}
156 + WHERE option_name LIKE 'mxchat_history_%'"
157 + );
158 +
159 + if (!empty($history_options)) {
160 + foreach ($history_options as $option) {
161 + // Extract the session ID from the option name
162 + $session_id = str_replace('mxchat_history_', '', $option->option_name);
163 +
164 + // Check if this session still exists in the custom table
165 + $table_name = $wpdb->prefix . 'mxchat_chat_transcripts';
166 + $exists = $wpdb->get_var(
167 + $wpdb->prepare(
168 + "SELECT COUNT(*) FROM {$table_name} WHERE session_id = %s",
169 + $session_id
170 + )
171 + );
172 +
173 + // If session doesn't exist in the main table, delete the option
174 + if ($exists == 0) {
175 + delete_option($option->option_name);
176 + // Also delete related metadata
177 + delete_option("mxchat_email_{$session_id}");
178 + delete_option("mxchat_agent_name_{$session_id}");
179 + $count++;
180 + }
181 + }
182 + }
183 +
184 + return $count;
185 +}
186 +
117 187 function mxchat_migrate_live_agent_status() {
188 + //error_log('=== mxchat_migrate_live_agent_status called ===');
118 189 $options = get_option('mxchat_options', []);
119 190
120 191 // Check if live_agent_status exists
121 192 if (isset($options['live_agent_status'])) {
122 193 $current_status = $options['live_agent_status'];
194 + //error_log('Current live agent status: ' . $current_status);
123 195 $needs_update = false;
124 196
125 197 // Convert to new format if needed
126 198 if ($current_status === 'online') {
@@ -125,28 +197,84 @@
125 197 // Convert to new format if needed
126 198 if ($current_status === 'online') {
127 199 $options['live_agent_status'] = 'on';
128 200 $needs_update = true;
201 + //error_log('Converting online -> on');
129 202 } else if ($current_status === 'offline') {
130 203 $options['live_agent_status'] = 'off';
131 204 $needs_update = true;
205 + //error_log('Converting offline -> off');
132 206 } else if (!in_array($current_status, ['on', 'off'])) {
133 207 // Default to off for any unexpected values
134 208 $options['live_agent_status'] = 'off';
135 209 $needs_update = true;
210 + //error_log('Unexpected value, setting to off');
136 211 }
137 212
138 213 // Only update if needed
139 214 if ($needs_update) {
140 215 update_option('mxchat_options', $options);
216 + //error_log('Live agent status updated');
141 217 }
142 218 } else {
143 219 // If status doesn't exist, set default to off
144 220 $options['live_agent_status'] = 'off';
145 221 update_option('mxchat_options', $options);
222 + //error_log('Live agent status not set, defaulting to off');
146 223 }
147 224 }
148 225
226 +// FIXED: This function had the wrong logic
227 +function mxchat_handle_live_agent_update() {
228 + //error_log('=== mxchat_handle_live_agent_update called ===');
229 +
230 + // Get the CURRENT stored version (before it gets updated)
231 + $current_version = get_option('mxchat_plugin_version', '0.0.0');
232 + $new_version = '2.2.2';
233 +
234 + //error_log('Live Agent Update - Current stored version: ' . $current_version);
235 + //error_log('Live Agent Update - Target version: ' . $new_version);
236 +
237 + // Only run this once for the update to 2.2.2
238 + $update_handled = get_option('mxchat_live_agent_update_2_2_2_handled', false);
239 + //error_log('Live Agent Update - Already handled: ' . ($update_handled ? 'yes' : 'no'));
240 +
241 + // FIXED: Check if we're upgrading TO 2.2.2 and haven't handled this yet
242 + if (version_compare($current_version, $new_version, '<') && !$update_handled) {
243 + //error_log('Live Agent Update - Conditions met, checking live agent status');
244 +
245 + $options = get_option('mxchat_options', array());
246 + $live_agent_status = isset($options['live_agent_status']) ? $options['live_agent_status'] : 'not set';
247 + //error_log('Live Agent Update - Current status: ' . $live_agent_status);
248 +
249 + // Check if live agent was previously enabled
250 + if (isset($options['live_agent_status']) && $options['live_agent_status'] === 'on') {
251 + //error_log('Live Agent Update - Live agent was ON, disabling it');
252 +
253 + // Disable live agent
254 + $options['live_agent_status'] = 'off';
255 + update_option('mxchat_options', $options);
256 +
257 + // Set flag to show the notification banner
258 + update_option('mxchat_show_live_agent_disabled_notice', true);
259 + //error_log('Live Agent Update - Live agent disabled and banner flag set');
260 + } else {
261 + //error_log('Live Agent Update - Live agent was not ON (status: ' . $live_agent_status . '), no action taken');
262 + }
263 +
264 + // Mark this update as handled
265 + update_option('mxchat_live_agent_update_2_2_2_handled', true);
266 + //error_log('Live Agent Update - Marked as handled');
267 + } else {
268 + //error_log('Live Agent Update - Conditions not met');
269 + if (version_compare($current_version, $new_version, '>=')) {
270 + //error_log('Live Agent Update - Already on version ' . $new_version . ' or higher');
271 + }
272 + if ($update_handled) {
273 + //error_log('Live Agent Update - Already handled this update');
274 + }
275 + }
276 +}
149 277
150 278 // Run the update check function on every request
151 279 add_action('plugins_loaded', 'mxchat_check_for_update');
152 280
@@ -161,16 +289,18 @@
161 289 );
162 290 return $schedules;
163 291 });
164 292
165 -add_action('init', function() {
166 - add_action('mxchat_process_pdf_pages', array('MxChat_Admin', 'process_pdf_pages_cron'), 10, 5);
167 - add_action('mxchat_process_sitemap_urls', array('MxChat_Admin', 'process_sitemap_urls_cron'), 10, 5);
168 -});
169 293
170 -
171 294 // Instantiate classes
172 295 if (is_admin()) {
173 - $mxchat_admin = new MxChat_Admin();
296 + // Create the knowledge manager instance first
297 + $mxchat_knowledge_manager = new MxChat_Knowledge_Manager();
298 +
299 + // Pass it to your admin class
300 + $mxchat_admin = new MxChat_Admin($mxchat_knowledge_manager);
174 301 }
175 302 $mxchat_public = new MxChat_Public();
176 303 $mxchat_integrator = new MxChat_Integrator();
304 +
305 +// ADD THIS LINE HERE:
306 +register_deactivation_hook(__FILE__, array($mxchat_integrator, 'cleanup_cron_events'));