PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.5.7
MxChat – AI Chatbot & Content Generation for WordPress v2.5.7
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 +28 -469 3.2.22.5.7 View file →
@@ -2,9 +2,9 @@
2 2 /**
3 3 * Plugin Name: MxChat
4 4 * Plugin URI: https://mxchat.ai/
5 5 * Description: AI chatbot for WordPress with OpenAI, Claude, xAI, DeepSeek, live agent, PDF uploads, WooCommerce, and training on website data.
6 - * Version: 3.2.2
6 + * Version: 2.5.7
7 7 * Author: MxChat
8 8 * Author URI: https://mxchat.ai
9 9 * License: GPLv2 or later
10 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -15,243 +15,20 @@
15 15 if (!defined('ABSPATH')) {
16 16 exit; // Exit if accessed directly.
17 17 }
18 18
19 -
20 -if (!defined('MXCHAT_DEV_MODE')) {
21 - define('MXCHAT_DEV_MODE', false);
22 -}
23 -
19 +// Define plugin version constant for asset versioning
20 +// Reads version from plugin header automatically
24 21 if (!defined('MXCHAT_VERSION')) {
25 22 $plugin_data = get_file_data(__FILE__, array('Version' => 'Version'), 'plugin');
26 - $version = $plugin_data['Version'];
27 - if (MXCHAT_DEV_MODE) {
28 - $version .= '.' . time();
29 - }
30 - define('MXCHAT_VERSION', $version);
23 + define('MXCHAT_VERSION', $plugin_data['Version']);
31 24 }
32 25
33 26 function mxchat_load_textdomain() {
34 - $domain = 'mxchat';
35 - $locale = determine_locale();
36 -
37 - // First, try to load from /wp-content/languages/plugins/ (preserved during updates)
38 - $mo_file = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo';
39 - if (file_exists($mo_file)) {
40 - load_textdomain($domain, $mo_file);
41 - return;
42 - }
43 -
44 - // Fallback to plugin's /languages directory
45 - load_plugin_textdomain($domain, false, dirname(plugin_basename(__FILE__)) . '/languages');
27 + load_plugin_textdomain('mxchat', false, dirname(plugin_basename(__FILE__)) . '/languages');
46 28 }
47 29 add_action('init', 'mxchat_load_textdomain');
48 30
49 -/**
50 - * Exclude MxChat assets from caching plugin optimizations
51 - *
52 - * This prevents issues with WP Rocket, LiteSpeed Cache, Autoptimize, WP Super Cache,
53 - * W3 Total Cache, SG Optimizer, and similar plugins that may break the chatbot by
54 - * removing "unused" CSS, minifying/combining JS, or deferring/delaying jQuery.
55 - *
56 - * Both chat-script.js and floating-script.js depend on jQuery, so jQuery must also
57 - * be excluded from any optimization that changes load order or timing.
58 - */
59 -
60 -// ── WP Rocket ────────────────────────────────────────────────────────────────
61 -
62 -// Exclude from Remove Unused CSS (RUCSS)
63 -add_filter('rocket_rucss_inline_atts_exclusions', function($exclusions) {
64 - if (!is_array($exclusions)) $exclusions = array();
65 - $exclusions[] = 'mxchat';
66 - return $exclusions;
67 -});
68 -
69 -// Exclude CSS from minification/combination
70 -add_filter('rocket_exclude_css', function($excluded) {
71 - if (!is_array($excluded)) $excluded = array();
72 - $excluded[] = '/plugins/mxchat-basic/css/chat-style.css';
73 - return $excluded;
74 -});
75 -
76 -// Exclude JS from minification/combination
77 -add_filter('rocket_exclude_js', function($excluded) {
78 - if (!is_array($excluded)) $excluded = array();
79 - $excluded[] = '/plugins/mxchat-basic/js/chat-script.js';
80 - $excluded[] = '/plugins/mxchat-basic/js/floating-script.js';
81 - $excluded[] = '/jquery-core';
82 - $excluded[] = '/jquery.min.js';
83 - $excluded[] = '/jquery.js';
84 - $excluded[] = '/jquery-migrate';
85 - return $excluded;
86 -});
87 -
88 -// Exclude JS from defer
89 -add_filter('rocket_exclude_defer_js', function($excluded) {
90 - if (!is_array($excluded)) $excluded = array();
91 - $excluded[] = '/plugins/mxchat-basic/js/chat-script.js';
92 - $excluded[] = '/plugins/mxchat-basic/js/floating-script.js';
93 - $excluded[] = '/jquery-core';
94 - $excluded[] = '/jquery.min.js';
95 - $excluded[] = '/jquery.js';
96 - $excluded[] = '/jquery-migrate';
97 - return $excluded;
98 -});
99 -
100 -// Exclude from delay JS execution
101 -add_filter('rocket_delay_js_exclusions', function($excluded) {
102 - if (!is_array($excluded)) $excluded = array();
103 - $excluded[] = 'mxchat';
104 - $excluded[] = 'chat-script';
105 - $excluded[] = 'floating-script';
106 - $excluded[] = '/jquery-core';
107 - $excluded[] = '/jquery.min.js';
108 - $excluded[] = '/jquery.js';
109 - $excluded[] = '/jquery-migrate';
110 - return $excluded;
111 -});
112 -
113 -// ── LiteSpeed Cache ──────────────────────────────────────────────────────────
114 -
115 -// Exclude CSS from optimization
116 -add_filter('litespeed_optimize_css_excludes', function($excluded) {
117 - if (!is_array($excluded)) $excluded = array();
118 - $excluded[] = 'chat-style.css';
119 - $excluded[] = 'mxchat';
120 - return $excluded;
121 -});
122 -
123 -// Exclude from UCSS (Unique CSS) - prevents LiteSpeed from stripping "unused" MxChat CSS
124 -add_filter('litespeed_ucss_whitelist', function($whitelist) {
125 - if (!is_array($whitelist)) $whitelist = array();
126 - $whitelist[] = '.mxchat-chatbot-wrapper';
127 - $whitelist[] = '.floating-chatbot';
128 - $whitelist[] = '.floating-chatbot-button';
129 - $whitelist[] = '.chatbot-top-bar';
130 - $whitelist[] = '.mxchat-chatbot';
131 - $whitelist[] = '.chat-container';
132 - $whitelist[] = '.chat-box';
133 - $whitelist[] = '.bot-message';
134 - $whitelist[] = '.input-container';
135 - $whitelist[] = '.chat-input';
136 - $whitelist[] = '.send-button';
137 - $whitelist[] = '.pre-chat-message';
138 - $whitelist[] = '.mxchat-popular-questions';
139 - $whitelist[] = '.chat-toolbar';
140 - $whitelist[] = '.exit-chat';
141 - $whitelist[] = '.email-blocker';
142 - return $whitelist;
143 -});
144 -
145 -// Exclude CSS from CCSS (Critical CSS) generation
146 -add_filter('litespeed_optm_ccss_exc', function($excluded) {
147 - if (!is_array($excluded)) $excluded = array();
148 - $excluded[] = 'chat-style.css';
149 - $excluded[] = 'mxchat';
150 - return $excluded;
151 -});
152 -
153 -// Exclude JS from defer
154 -add_filter('litespeed_optm_js_defer_exc', function($excluded) {
155 - if (!is_array($excluded)) $excluded = array();
156 - $excluded[] = 'chat-script.js';
157 - $excluded[] = 'floating-script.js';
158 - $excluded[] = 'mxchat';
159 - $excluded[] = 'jquery.min.js';
160 - $excluded[] = 'jquery.js';
161 - return $excluded;
162 -});
163 -
164 -// Exclude JS from combining
165 -add_filter('litespeed_optm_js_exc', function($excluded) {
166 - if (!is_array($excluded)) $excluded = array();
167 - $excluded[] = 'chat-script.js';
168 - $excluded[] = 'floating-script.js';
169 - $excluded[] = 'mxchat';
170 - $excluded[] = 'jquery.min.js';
171 - $excluded[] = 'jquery.js';
172 - return $excluded;
173 -});
174 -
175 -// Exclude JS from delayed execution
176 -add_filter('litespeed_optm_js_delay_exc', function($excluded) {
177 - if (!is_array($excluded)) $excluded = array();
178 - $excluded[] = 'chat-script.js';
179 - $excluded[] = 'floating-script.js';
180 - $excluded[] = 'mxchat';
181 - return $excluded;
182 -});
183 -
184 -// Exclude from Guest Mode optimization
185 -add_filter('litespeed_guest_optm_exc', function($excluded) {
186 - if (!is_array($excluded)) $excluded = array();
187 - $excluded[] = 'mxchat';
188 - $excluded[] = 'chat-style';
189 - $excluded[] = 'chat-script';
190 - $excluded[] = 'floating-script';
191 - return $excluded;
192 -});
193 -
194 -// ── Autoptimize ──────────────────────────────────────────────────────────────
195 -
196 -// Exclude CSS from optimization (comma-separated strings)
197 -add_filter('autoptimize_filter_css_exclude', function($excluded) {
198 - if (!is_string($excluded)) $excluded = '';
199 - return $excluded . ', mxchat, chat-style.css';
200 -});
201 -
202 -// Exclude JS from optimization (comma-separated strings)
203 -add_filter('autoptimize_filter_js_exclude', function($excluded) {
204 - if (!is_string($excluded)) $excluded = '';
205 - return $excluded . ', mxchat, chat-script.js, floating-script.js, jquery.min.js, jquery.js';
206 -});
207 -
208 -// ── SG Optimizer (SiteGround) ────────────────────────────────────────────────
209 -
210 -add_filter('sgo_js_minify_exclude', function($excluded) {
211 - if (!is_array($excluded)) $excluded = array();
212 - $excluded[] = 'chat-script.js';
213 - $excluded[] = 'floating-script.js';
214 - $excluded[] = 'jquery.min.js';
215 - return $excluded;
216 -});
217 -
218 -add_filter('sgo_javascript_combine_exclude', function($excluded) {
219 - if (!is_array($excluded)) $excluded = array();
220 - $excluded[] = 'chat-script.js';
221 - $excluded[] = 'floating-script.js';
222 - $excluded[] = 'jquery.min.js';
223 - return $excluded;
224 -});
225 -
226 -add_filter('sgo_js_async_exclude', function($excluded) {
227 - if (!is_array($excluded)) $excluded = array();
228 - $excluded[] = 'chat-script.js';
229 - $excluded[] = 'floating-script.js';
230 - $excluded[] = 'jquery.min.js';
231 - return $excluded;
232 -});
233 -
234 -// ── W3 Total Cache ───────────────────────────────────────────────────────────
235 -
236 -add_filter('w3tc_minify_js_do_tag_minification', function($do_minify, $script_tag, $file) {
237 - if (strpos($file, 'chat-script.js') !== false ||
238 - strpos($file, 'floating-script.js') !== false ||
239 - strpos($file, 'jquery.min.js') !== false ||
240 - strpos($file, 'jquery.js') !== false) {
241 - return false;
242 - }
243 - return $do_minify;
244 -}, 10, 3);
245 -
246 -// ── WP Super Cache ──────────────────────────────────────────────────────────
247 -
248 -add_filter('wpsc_rejected_uri', function($rejected) {
249 - if (!is_array($rejected)) $rejected = array();
250 - $rejected[] = 'wp-admin/admin-ajax.php';
251 - return $rejected;
252 -});
253 -
254 31 // Include classes with error handling
255 32 function mxchat_include_classes() {
256 33 $class_files = array(
257 34 'includes/class-mxchat-integrator.php',
@@ -259,11 +36,10 @@
259 36 'includes/class-mxchat-public.php',
260 37 'includes/class-mxchat-utils.php',
261 38 'includes/class-mxchat-user.php',
262 39 'includes/class-mxchat-meta-box.php',
263 - 'includes/class-mxchat-chunker.php',
40 + 'includes/pdf-parser/alt_autoload.php',
264 41 'includes/class-mxchat-word-handler.php',
265 - 'includes/class-mxchat-content-generator.php',
266 42 'admin/class-ajax-handler.php',
267 43 'admin/class-pinecone-manager.php',
268 44 'admin/class-knowledge-manager.php'
269 45 );
@@ -278,24 +54,8 @@
278 54 }
279 55 }
280 56
281 57 /**
282 - * Lazy-load the PDF parser library only when needed.
283 - * Avoids loading 44 files on every page request.
284 - */
285 -function mxchat_load_pdf_parser() {
286 - if (class_exists('\Smalot\PdfParser\Parser')) {
287 - return true;
288 - }
289 - $autoload_path = plugin_dir_path(__FILE__) . 'includes/pdf-parser/alt_autoload.php';
290 - if (file_exists($autoload_path)) {
291 - require_once $autoload_path;
292 - return true;
293 - }
294 - return false;
295 -}
296 -
297 -/**
298 58 * Create URL click tracking table
299 59 */
300 60 function mxchat_create_url_clicks_table() {
301 61 global $wpdb;
@@ -378,13 +138,12 @@
378 138
379 139 // Define all required columns and their types
380 140 $required_columns = [
381 141 'user_identifier' => 'VARCHAR(255) DEFAULT NULL',
382 - 'user_email' => 'VARCHAR(255) DEFAULT NULL',
142 + 'user_email' => 'VARCHAR(255) DEFAULT NULL',
383 143 'user_name' => 'VARCHAR(100) DEFAULT NULL',
384 144 'originating_page_url' => 'TEXT DEFAULT NULL',
385 - 'originating_page_title' => 'VARCHAR(500) DEFAULT NULL',
386 - 'rag_context' => 'LONGTEXT DEFAULT NULL'
145 + 'originating_page_title' => 'VARCHAR(500) DEFAULT NULL'
387 146 ];
388 147
389 148 // Get existing columns
390 149 $existing_columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name");
@@ -563,9 +322,9 @@
563 322
564 323 // Add index for bot_id
565 324 $wpdb->query("ALTER TABLE {$table_name} ADD KEY bot_id (bot_id)");
566 325
567 - //error_log('MxChat: Successfully added bot_id column to mxchat_pinecone_roles table');
326 + error_log('MxChat: Successfully added bot_id column to mxchat_pinecone_roles table');
568 327 }
569 328
570 329 // Mark migration as complete
571 330 update_option('mxchat_pinecone_roles_migration_version', '2.5.2');
@@ -600,9 +359,9 @@
600 359
601 360 // Add index for better query performance
602 361 $wpdb->query("ALTER TABLE {$table_name} ADD KEY content_type (content_type)");
603 362
604 - //error_log('MxChat: Successfully added content_type column to mxchat_system_prompt_content table');
363 + error_log('MxChat: Successfully added content_type column to mxchat_system_prompt_content table');
605 364 }
606 365
607 366 // Mark migration as complete
608 367 update_option('mxchat_content_type_migration_version', '2.5.6');
@@ -657,32 +416,8 @@
657 416 //error_log("MxChat: Queue tables created/updated successfully");
658 417 }
659 418
660 419 /**
661 - * Create transcript translations table for persisting translations
662 - */
663 -function mxchat_create_translations_table() {
664 - global $wpdb;
665 - $charset_collate = $wpdb->get_charset_collate();
666 -
667 - $table_name = $wpdb->prefix . 'mxchat_transcript_translations';
668 - $sql = "CREATE TABLE $table_name (
669 - id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
670 - session_id varchar(255) NOT NULL,
671 - language_code varchar(10) NOT NULL,
672 - translations longtext NOT NULL,
673 - created_at datetime NOT NULL,
674 - updated_at datetime NOT NULL,
675 - PRIMARY KEY (id),
676 - UNIQUE KEY session_lang (session_id, language_code),
677 - KEY session_id (session_id)
678 - ) $charset_collate;";
679 -
680 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
681 - dbDelta($sql);
682 -}
683 -
684 -/**
685 420 * 2.5.2: Fix URL column size to support long URLs (especially with UTF-8 encoding)
686 421 * This fixes "url, source_url. The supplied values may be too long" errors
687 422 */
688 423 function mxchat_fix_url_column_size() {
@@ -705,80 +440,22 @@
705 440
706 441 /**
707 442 * Migrate deprecated AI models to their replacements
708 443 * Version 2.5.1: Migrate Claude 3.5 Sonnet (deprecated) to Claude 3.7 Sonnet
709 - * Version 3.1.2: Convert chat transcripts table to utf8mb4 for emoji support
710 - * Without utf8mb4, any bot response containing emojis silently fails to insert.
711 444 */
712 -function mxchat_migrate_transcripts_charset() {
713 - global $wpdb;
714 - $table_name = $wpdb->prefix . 'mxchat_chat_transcripts';
715 - $wpdb->query("ALTER TABLE $table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
716 -}
717 -
718 -/**
719 - * Version 3.0.55: Migrate GPT-4 series models (deprecated 2026-02-17) to GPT-5 series
720 - */
721 445 function mxchat_migrate_deprecated_models() {
722 446 $options = get_option('mxchat_options', array());
723 - $migrated = false;
724 - $migration_message = '';
725 -
726 - if (!isset($options['model'])) {
727 - return;
728 - }
729 -
730 - $current_model = $options['model'];
731 -
732 - // Migrate deprecated Claude models to Claude Opus 4.6 (recommended replacement per Anthropic)
733 - $deprecated_claude_models = array(
734 - 'claude-3-5-sonnet-20240620', // Retired Oct 28, 2025
735 - 'claude-3-5-sonnet-20241022', // Retired Oct 28, 2025
736 - 'claude-3-7-sonnet-20250219', // Retiring Feb 19, 2026
737 - 'claude-3-opus-20240229', // Retired Jan 5, 2026
738 - 'claude-3-sonnet-20240229', // Legacy
739 - 'claude-3-haiku-20240307', // Legacy
740 - );
741 - if (in_array($current_model, $deprecated_claude_models, true)) {
742 - $options['model'] = 'claude-opus-4-6';
743 - $migrated = true;
744 - $migration_message = sprintf(
745 - 'Your chatbot model has been automatically updated from %s to Claude Opus 4.6 due to Anthropic deprecating older Claude models.',
746 - $current_model
747 - );
748 - }
749 -
750 - // Migrate deprecated Claude Haiku 3.5 to Claude Haiku 4.5
751 - if ($current_model === 'claude-3-5-haiku-20241022') {
752 - $options['model'] = 'claude-haiku-4-5-20251001';
753 - $migrated = true;
754 - $migration_message = 'Your chatbot model has been automatically updated from Claude Haiku 3.5 to Claude Haiku 4.5 due to Anthropic deprecating the older model.';
755 - }
756 -
757 - // Migrate deprecated GPT-4 series and GPT-3.5 Turbo to GPT-5.1 Chat Latest
758 - if (in_array($current_model, array('gpt-4o', 'gpt-4.1-2025-04-14', 'gpt-4-turbo', 'gpt-4', 'gpt-3.5-turbo'), true)) {
759 - $options['model'] = 'gpt-5.1-chat-latest';
760 - $migrated = true;
761 - $migration_message = sprintf(
762 - 'Your chatbot model has been automatically updated from %s to GPT-5.1 Chat Latest due to OpenAI deprecating older models.',
763 - $current_model
764 - );
765 - }
766 -
767 - // Migrate deprecated GPT-4o Mini and GPT-4.1 Mini to GPT-5 Mini
768 - if (in_array($current_model, array('gpt-4o-mini', 'gpt-4.1-mini'), true)) {
769 - $options['model'] = 'gpt-5-mini';
770 - $migrated = true;
771 - $migration_message = sprintf(
772 - 'Your chatbot model has been automatically updated from %s to GPT-5 Mini due to OpenAI deprecating GPT-4 series models.',
773 - $current_model
774 - );
775 - }
776 -
777 - if ($migrated) {
447 +
448 + // Check if model is set and is the deprecated Claude 3.5 Sonnet
449 + if (isset($options['model']) && $options['model'] === 'claude-3-5-sonnet-20241022') {
450 + // Update to Claude 3.7 Sonnet (the replacement model)
451 + $options['model'] = 'claude-3-7-sonnet-20250219';
778 452 update_option('mxchat_options', $options);
453 +
454 + // Set a flag to show admin notice
779 455 update_option('mxchat_model_migrated_notice', true);
780 - update_option('mxchat_model_migration_message', $migration_message);
456 +
457 + //error_log('MxChat: Migrated deprecated Claude 3.5 Sonnet to Claude 3.7 Sonnet');
781 458 }
782 459 }
783 460
784 461 /**
@@ -785,19 +462,17 @@
785 462 * Show admin notice after model migration
786 463 */
787 464 function mxchat_show_migration_notice() {
788 465 if (get_option('mxchat_model_migrated_notice')) {
789 - $migration_message = get_option('mxchat_model_migration_message', __('Your chatbot model has been automatically updated due to a model deprecation.', 'mxchat'));
790 466 ?>
791 467 <div class="notice notice-info is-dismissible">
792 468 <p>
793 469 <strong><?php esc_html_e('MxChat Model Updated', 'mxchat'); ?></strong><br>
794 - <?php echo esc_html($migration_message); ?>
470 + <?php esc_html_e('Your chatbot model has been automatically updated from Claude 3.5 Sonnet to Claude 3.7 Sonnet due to the deprecation of the previous model by Anthropic. Claude 3.7 Sonnet offers improved performance and capabilities.', 'mxchat'); ?>
795 471 </p>
796 472 </div>
797 473 <?php
798 474 delete_option('mxchat_model_migrated_notice');
799 - delete_option('mxchat_model_migration_message');
800 475 }
801 476 }
802 477
803 478 function mxchat_activate() {
@@ -837,26 +512,13 @@
837 512 enabled_bots LONGTEXT DEFAULT NULL,
838 513 PRIMARY KEY (id)
839 514 ) $charset_collate;";
840 515
841 - // Individual Intent Phrases Table - each phrase gets its own embedding vector
842 - $intent_phrases_table = $wpdb->prefix . 'mxchat_intent_phrases';
843 - $sql_intent_phrases_table = "CREATE TABLE $intent_phrases_table (
844 - id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
845 - intent_id BIGINT(20) UNSIGNED NOT NULL,
846 - phrase TEXT NOT NULL,
847 - embedding_vector LONGTEXT NOT NULL,
848 - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
849 - PRIMARY KEY (id),
850 - KEY intent_id (intent_id)
851 - ) $charset_collate;";
852 -
853 516 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
854 517
855 518 // Create other tables
856 519 dbDelta($sql_system_prompt);
857 520 dbDelta($sql_intents_table);
858 - dbDelta($sql_intent_phrases_table);
859 521
860 522 // Create URL click tracking table
861 523 mxchat_create_url_clicks_table();
862 524
@@ -865,11 +527,8 @@
865 527
866 528 // NEW 2.5.2: Create queue processing tables
867 529 mxchat_create_queue_tables();
868 530
869 - // Create transcript translations table
870 - mxchat_create_translations_table();
871 -
872 531 // Ensure additional columns in system prompt table
873 532 $existing_system_columns = $wpdb->get_results("SHOW COLUMNS FROM $system_prompt_table");
874 533 if (!empty($existing_system_columns)) {
875 534 $existing_system_column_names = array_column($existing_system_columns, 'Field');
@@ -969,9 +628,8 @@
969 628 function mxchat_deactivate() {
970 629 // Clear scheduled cron jobs
971 630 wp_clear_scheduled_hook('mxchat_reset_rate_limits');
972 631 wp_clear_scheduled_hook('mxchat_cleanup_old_transcripts');
973 - wp_clear_scheduled_hook('mxchat_send_delayed_transcript');
974 632
975 633 // Clear fallback options
976 634 delete_option('mxchat_use_fallback_rate_limits');
977 635 delete_option('mxchat_next_rate_limit_check');
@@ -1031,14 +689,11 @@
1031 689
1032 690 // Version-specific migrations
1033 691 if ($current_version !== $plugin_version) {
1034 692 //error_log("MxChat: Version change detected: $current_version -> $plugin_version");
1035 -
693 +
1036 694 // Run live agent update BEFORE updating the stored version
1037 695 mxchat_handle_live_agent_update();
1038 -
1039 - // Run theme migration notice for 3.0.1 (AI theme CSS structure changes)
1040 - mxchat_handle_theme_migration_notice();
1041 696
1042 697 // Run role restriction migration for 2.4.1
1043 698 if (version_compare($current_version, '2.4.1', '<')) {
1044 699 mxchat_add_role_restriction_column();
@@ -1059,37 +714,9 @@
1059 714 mxchat_create_queue_tables();
1060 715 mxchat_fix_url_column_size(); // NEW: Fix URL column size for long URLs
1061 716 //error_log("MxChat: Queue tables created and URL columns updated for upgrade to 2.5.2");
1062 717 }
1063 -
1064 - // 2.6.0: Ensure rag_context column exists for retrieved documents feature
1065 - if (version_compare($current_version, '2.6.0', '<')) {
1066 - $chat_table = $wpdb->prefix . 'mxchat_chat_transcripts';
1067 - mxchat_ensure_all_columns($chat_table);
1068 - //error_log("MxChat: rag_context column migration for 2.6.0");
1069 - }
1070 -
1071 - // 3.0.5: Migrate deprecated Gemini embedding model
1072 - if (version_compare($current_version, '3.0.5', '<')) {
1073 - mxchat_migrate_gemini_embedding_model();
1074 - }
1075 -
1076 - // 3.0.6: Migrate deprecated OpenAI and Claude models
1077 - if (version_compare($current_version, '3.0.6', '<')) {
1078 - mxchat_migrate_deprecated_models();
1079 - }
1080 -
1081 - // 3.1.2: Convert chat transcripts table to utf8mb4 for emoji support
1082 - if (version_compare($current_version, '3.1.2', '<')) {
1083 - mxchat_migrate_transcripts_charset();
1084 - }
1085 -
1086 - // 3.1.7: Clean up stale shared session email/name entries
1087 - if (version_compare($current_version, '3.1.7', '<')) {
1088 - delete_option('mxchat_email_null');
1089 - delete_option('mxchat_name_null');
1090 - }
1091 -
718 +
1092 719 // Run full activation to ensure everything is up to date
1093 720 mxchat_activate();
1094 721
1095 722 // Run migration functions
@@ -1221,59 +848,31 @@
1221 848 function mxchat_handle_live_agent_update() {
1222 849 // Get the CURRENT stored version (before it gets updated)
1223 850 $current_version = get_option('mxchat_plugin_version', '0.0.0');
1224 851 $new_version = '2.2.2';
1225 -
852 +
1226 853 // Only run this once for the update to 2.2.2
1227 854 $update_handled = get_option('mxchat_live_agent_update_2_2_2_handled', false);
1228 -
855 +
1229 856 // Check if we're upgrading TO 2.2.2 and haven't handled this yet
1230 857 if (version_compare($current_version, $new_version, '<') && !$update_handled) {
1231 858 $options = get_option('mxchat_options', array());
1232 -
859 +
1233 860 // Check if live agent was previously enabled
1234 861 if (isset($options['live_agent_status']) && $options['live_agent_status'] === 'on') {
1235 862 // Disable live agent
1236 863 $options['live_agent_status'] = 'off';
1237 864 update_option('mxchat_options', $options);
1238 -
865 +
1239 866 // Set flag to show the notification banner
1240 867 update_option('mxchat_show_live_agent_disabled_notice', true);
1241 868 }
1242 -
869 +
1243 870 // Mark this update as handled
1244 871 update_option('mxchat_live_agent_update_2_2_2_handled', true);
1245 872 }
1246 873 }
1247 874
1248 -/**
1249 - * Handle theme migration notice for version 3.0.1
1250 - * Shows a dismissible notice to Pro users about migrating AI-generated themes
1251 - */
1252 -function mxchat_handle_theme_migration_notice() {
1253 - // Get the CURRENT stored version (before it gets updated)
1254 - $current_version = get_option('mxchat_plugin_version', '0.0.0');
1255 - $target_version = '3.0.1';
1256 -
1257 - // Only run this once for the update to 3.0.1
1258 - $update_handled = get_option('mxchat_theme_migration_update_3_0_1_handled', false);
1259 -
1260 - // Check if we're upgrading TO 3.0.1 and haven't handled this yet
1261 - if (version_compare($current_version, $target_version, '<') && !$update_handled) {
1262 - // Check if Pro is activated - only show to Pro users
1263 - $license_status = get_option('mxchat_license_status', 'inactive');
1264 - $is_pro = ($license_status === 'active');
1265 -
1266 - if ($is_pro) {
1267 - // Set flag to show the theme migration notification banner
1268 - update_option('mxchat_show_theme_migration_notice', true);
1269 - }
1270 -
1271 - // Mark this update as handled (whether Pro or not)
1272 - update_option('mxchat_theme_migration_update_3_0_1_handled', true);
1273 - }
1274 -}
1275 -
1276 875 // Initialize plugin safely
1277 876 function mxchat_init() {
1278 877 // Include all class files first
1279 878 mxchat_include_classes();
@@ -1305,17 +904,10 @@
1305 904 // Initialize meta box class
1306 905 if (class_exists('MxChat_Meta_Box')) {
1307 906 new MxChat_Meta_Box();
1308 907 }
1309 -
1310 908 }
1311 -
1312 - // Initialize content generator globally — it registers wp_head hook
1313 - // for frontend CSS injection, plus wp_ajax_ hooks for admin.
1314 - if (class_exists('MxChat_Content_Generator')) {
1315 - new MxChat_Content_Generator();
1316 - }
1317 -
909 +
1318 910 // Initialize public classes
1319 911 if (class_exists('MxChat_Public')) {
1320 912 $mxchat_public = new MxChat_Public();
1321 913 }
@@ -1359,41 +951,8 @@
1359 951 $checked = true;
1360 952
1361 953 mxchat_migrate_pinecone_roles_add_bot_id();
1362 954 mxchat_migrate_add_content_type_column();
1363 - mxchat_migrate_add_translations_table();
1364 -}
1365 -
1366 -/**
1367 - * Migration: Create transcript translations table (v3.0.4)
1368 - * For users upgrading from versions before 3.0.4
1369 - */
1370 -function mxchat_migrate_add_translations_table() {
1371 - $migration_key = 'mxchat_translations_table_created';
1372 -
1373 - // Check if migration already ran
1374 - if (get_option($migration_key)) {
1375 - return;
1376 - }
1377 -
1378 - // Create the translations table
1379 - mxchat_create_translations_table();
1380 -
1381 - // Mark migration as complete
1382 - update_option($migration_key, '3.0.4');
1383 -}
1384 -
1385 -/**
1386 - * Migration: Update deprecated Gemini embedding model (v3.0.5)
1387 - * Updates gemini-embedding-exp-03-07 to gemini-embedding-001 for users who had it selected
1388 - */
1389 -function mxchat_migrate_gemini_embedding_model() {
1390 - $options = get_option('mxchat_options', array());
1391 -
1392 - if (isset($options['embedding_model']) && $options['embedding_model'] === 'gemini-embedding-exp-03-07') {
1393 - $options['embedding_model'] = 'gemini-embedding-001';
1394 - update_option('mxchat_options', $options);
1395 - }
1396 955 }
1397 956
1398 957 // Register activation hook
1399 958 register_activation_hook(__FILE__, 'mxchat_activate');