PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.6.0
MxChat – AI Chatbot & Content Generation for WordPress v2.6.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 +28 -512 3.2.52.6.0 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.5
6 + * Version: 2.6.0
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,12 +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 - 'includes/class-rest-api.php',
267 42 'admin/class-ajax-handler.php',
268 43 'admin/class-pinecone-manager.php',
269 44 'admin/class-knowledge-manager.php'
270 45 );
@@ -276,35 +51,11 @@
276 51 } else {
277 52 //error_log('MxChat: Missing class file - ' . $file);
278 53 }
279 54 }
280 -
281 - // Admin pages that aren't classes (procedural include).
282 - if (is_admin()) {
283 - $admin_api_page = plugin_dir_path(__FILE__) . 'includes/admin-api-page.php';
284 - if (file_exists($admin_api_page)) {
285 - require_once $admin_api_page;
286 - }
287 - }
288 55 }
289 56
290 57 /**
291 - * Lazy-load the PDF parser library only when needed.
292 - * Avoids loading 44 files on every page request.
293 - */
294 -function mxchat_load_pdf_parser() {
295 - if (class_exists('\Smalot\PdfParser\Parser')) {
296 - return true;
297 - }
298 - $autoload_path = plugin_dir_path(__FILE__) . 'includes/pdf-parser/alt_autoload.php';
299 - if (file_exists($autoload_path)) {
300 - require_once $autoload_path;
301 - return true;
302 - }
303 - return false;
304 -}
305 -
306 -/**
307 58 * Create URL click tracking table
308 59 */
309 60 function mxchat_create_url_clicks_table() {
310 61 global $wpdb;
@@ -572,9 +323,9 @@
572 323
573 324 // Add index for bot_id
574 325 $wpdb->query("ALTER TABLE {$table_name} ADD KEY bot_id (bot_id)");
575 326
576 - //error_log('MxChat: Successfully added bot_id column to mxchat_pinecone_roles table');
327 + error_log('MxChat: Successfully added bot_id column to mxchat_pinecone_roles table');
577 328 }
578 329
579 330 // Mark migration as complete
580 331 update_option('mxchat_pinecone_roles_migration_version', '2.5.2');
@@ -609,9 +360,9 @@
609 360
610 361 // Add index for better query performance
611 362 $wpdb->query("ALTER TABLE {$table_name} ADD KEY content_type (content_type)");
612 363
613 - //error_log('MxChat: Successfully added content_type column to mxchat_system_prompt_content table');
364 + error_log('MxChat: Successfully added content_type column to mxchat_system_prompt_content table');
614 365 }
615 366
616 367 // Mark migration as complete
617 368 update_option('mxchat_content_type_migration_version', '2.5.6');
@@ -617,33 +368,8 @@
617 368 update_option('mxchat_content_type_migration_version', '2.5.6');
618 369 }
619 370
620 371 /**
621 - * 3.2.4: Backfill the active embedding model option for installs that already
622 - * have KB content but no stamped model. The mismatch warning compares this
623 - * against the user's currently selected model — no per-row column needed.
624 - */
625 -function mxchat_backfill_active_embedding_model() {
626 - global $wpdb;
627 -
628 - if (get_option('mxchat_active_embedding_model', '') !== '') {
629 - return;
630 - }
631 -
632 - $kb_table = $wpdb->prefix . 'mxchat_system_prompt_content';
633 - if ($wpdb->get_var("SHOW TABLES LIKE '{$kb_table}'") !== $kb_table) {
634 - return;
635 - }
636 -
637 - $kb_count = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$kb_table}");
638 - if ($kb_count > 0) {
639 - $options = get_option('mxchat_options', array());
640 - $current_model = $options['embedding_model'] ?? 'text-embedding-ada-002';
641 - update_option('mxchat_active_embedding_model', $current_model, false);
642 - }
643 -}
644 -
645 -/**
646 372 * 2.5.2: Create queue processing tables for reliable background processing
647 373 */
648 374 function mxchat_create_queue_tables() {
649 375 global $wpdb;
@@ -691,32 +417,8 @@
691 417 //error_log("MxChat: Queue tables created/updated successfully");
692 418 }
693 419
694 420 /**
695 - * Create transcript translations table for persisting translations
696 - */
697 -function mxchat_create_translations_table() {
698 - global $wpdb;
699 - $charset_collate = $wpdb->get_charset_collate();
700 -
701 - $table_name = $wpdb->prefix . 'mxchat_transcript_translations';
702 - $sql = "CREATE TABLE $table_name (
703 - id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
704 - session_id varchar(255) NOT NULL,
705 - language_code varchar(10) NOT NULL,
706 - translations longtext NOT NULL,
707 - created_at datetime NOT NULL,
708 - updated_at datetime NOT NULL,
709 - PRIMARY KEY (id),
710 - UNIQUE KEY session_lang (session_id, language_code),
711 - KEY session_id (session_id)
712 - ) $charset_collate;";
713 -
714 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
715 - dbDelta($sql);
716 -}
717 -
718 -/**
719 421 * 2.5.2: Fix URL column size to support long URLs (especially with UTF-8 encoding)
720 422 * This fixes "url, source_url. The supplied values may be too long" errors
721 423 */
722 424 function mxchat_fix_url_column_size() {
@@ -739,80 +441,22 @@
739 441
740 442 /**
741 443 * Migrate deprecated AI models to their replacements
742 444 * Version 2.5.1: Migrate Claude 3.5 Sonnet (deprecated) to Claude 3.7 Sonnet
743 - * Version 3.1.2: Convert chat transcripts table to utf8mb4 for emoji support
744 - * Without utf8mb4, any bot response containing emojis silently fails to insert.
745 445 */
746 -function mxchat_migrate_transcripts_charset() {
747 - global $wpdb;
748 - $table_name = $wpdb->prefix . 'mxchat_chat_transcripts';
749 - $wpdb->query("ALTER TABLE $table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
750 -}
751 -
752 -/**
753 - * Version 3.0.55: Migrate GPT-4 series models (deprecated 2026-02-17) to GPT-5 series
754 - */
755 446 function mxchat_migrate_deprecated_models() {
756 447 $options = get_option('mxchat_options', array());
757 - $migrated = false;
758 - $migration_message = '';
759 -
760 - if (!isset($options['model'])) {
761 - return;
762 - }
763 -
764 - $current_model = $options['model'];
765 -
766 - // Migrate deprecated Claude models to Claude Opus 4.6 (recommended replacement per Anthropic)
767 - $deprecated_claude_models = array(
768 - 'claude-3-5-sonnet-20240620', // Retired Oct 28, 2025
769 - 'claude-3-5-sonnet-20241022', // Retired Oct 28, 2025
770 - 'claude-3-7-sonnet-20250219', // Retiring Feb 19, 2026
771 - 'claude-3-opus-20240229', // Retired Jan 5, 2026
772 - 'claude-3-sonnet-20240229', // Legacy
773 - 'claude-3-haiku-20240307', // Legacy
774 - );
775 - if (in_array($current_model, $deprecated_claude_models, true)) {
776 - $options['model'] = 'claude-opus-4-6';
777 - $migrated = true;
778 - $migration_message = sprintf(
779 - 'Your chatbot model has been automatically updated from %s to Claude Opus 4.6 due to Anthropic deprecating older Claude models.',
780 - $current_model
781 - );
782 - }
783 -
784 - // Migrate deprecated Claude Haiku 3.5 to Claude Haiku 4.5
785 - if ($current_model === 'claude-3-5-haiku-20241022') {
786 - $options['model'] = 'claude-haiku-4-5-20251001';
787 - $migrated = true;
788 - $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.';
789 - }
790 -
791 - // Migrate deprecated GPT-4 series and GPT-3.5 Turbo to GPT-5.1 Chat Latest
792 - if (in_array($current_model, array('gpt-4o', 'gpt-4.1-2025-04-14', 'gpt-4-turbo', 'gpt-4', 'gpt-3.5-turbo'), true)) {
793 - $options['model'] = 'gpt-5.1-chat-latest';
794 - $migrated = true;
795 - $migration_message = sprintf(
796 - 'Your chatbot model has been automatically updated from %s to GPT-5.1 Chat Latest due to OpenAI deprecating older models.',
797 - $current_model
798 - );
799 - }
800 -
801 - // Migrate deprecated GPT-4o Mini and GPT-4.1 Mini to GPT-5 Mini
802 - if (in_array($current_model, array('gpt-4o-mini', 'gpt-4.1-mini'), true)) {
803 - $options['model'] = 'gpt-5-mini';
804 - $migrated = true;
805 - $migration_message = sprintf(
806 - 'Your chatbot model has been automatically updated from %s to GPT-5 Mini due to OpenAI deprecating GPT-4 series models.',
807 - $current_model
808 - );
809 - }
810 -
811 - if ($migrated) {
448 +
449 + // Check if model is set and is the deprecated Claude 3.5 Sonnet
450 + if (isset($options['model']) && $options['model'] === 'claude-3-5-sonnet-20241022') {
451 + // Update to Claude 3.7 Sonnet (the replacement model)
452 + $options['model'] = 'claude-3-7-sonnet-20250219';
812 453 update_option('mxchat_options', $options);
454 +
455 + // Set a flag to show admin notice
813 456 update_option('mxchat_model_migrated_notice', true);
814 - update_option('mxchat_model_migration_message', $migration_message);
457 +
458 + //error_log('MxChat: Migrated deprecated Claude 3.5 Sonnet to Claude 3.7 Sonnet');
815 459 }
816 460 }
817 461
818 462 /**
@@ -819,19 +463,17 @@
819 463 * Show admin notice after model migration
820 464 */
821 465 function mxchat_show_migration_notice() {
822 466 if (get_option('mxchat_model_migrated_notice')) {
823 - $migration_message = get_option('mxchat_model_migration_message', __('Your chatbot model has been automatically updated due to a model deprecation.', 'mxchat'));
824 467 ?>
825 468 <div class="notice notice-info is-dismissible">
826 469 <p>
827 470 <strong><?php esc_html_e('MxChat Model Updated', 'mxchat'); ?></strong><br>
828 - <?php echo esc_html($migration_message); ?>
471 + <?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'); ?>
829 472 </p>
830 473 </div>
831 474 <?php
832 475 delete_option('mxchat_model_migrated_notice');
833 - delete_option('mxchat_model_migration_message');
834 476 }
835 477 }
836 478
837 479 function mxchat_activate() {
@@ -871,26 +513,13 @@
871 513 enabled_bots LONGTEXT DEFAULT NULL,
872 514 PRIMARY KEY (id)
873 515 ) $charset_collate;";
874 516
875 - // Individual Intent Phrases Table - each phrase gets its own embedding vector
876 - $intent_phrases_table = $wpdb->prefix . 'mxchat_intent_phrases';
877 - $sql_intent_phrases_table = "CREATE TABLE $intent_phrases_table (
878 - id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
879 - intent_id BIGINT(20) UNSIGNED NOT NULL,
880 - phrase TEXT NOT NULL,
881 - embedding_vector LONGTEXT NOT NULL,
882 - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
883 - PRIMARY KEY (id),
884 - KEY intent_id (intent_id)
885 - ) $charset_collate;";
886 -
887 517 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
888 518
889 519 // Create other tables
890 520 dbDelta($sql_system_prompt);
891 521 dbDelta($sql_intents_table);
892 - dbDelta($sql_intent_phrases_table);
893 522
894 523 // Create URL click tracking table
895 524 mxchat_create_url_clicks_table();
896 525
@@ -899,11 +528,8 @@
899 528
900 529 // NEW 2.5.2: Create queue processing tables
901 530 mxchat_create_queue_tables();
902 531
903 - // Create transcript translations table
904 - mxchat_create_translations_table();
905 -
906 532 // Ensure additional columns in system prompt table
907 533 $existing_system_columns = $wpdb->get_results("SHOW COLUMNS FROM $system_prompt_table");
908 534 if (!empty($existing_system_columns)) {
909 535 $existing_system_column_names = array_column($existing_system_columns, 'Field');
@@ -946,11 +572,8 @@
946 572
947 573 // Run migration for existing installations
948 574 mxchat_migrate_pinecone_roles_add_bot_id();
949 575
950 - // 3.2.4: Backfill active embedding model option (replaces 3.2.3 column-based tracking)
951 - mxchat_backfill_active_embedding_model();
952 -
953 576 // Setup cron jobs
954 577 mxchat_setup_cron_jobs();
955 578
956 579 // Update version
@@ -985,14 +608,13 @@
985 608 // Clear fallback flags if cron scheduling succeeded
986 609 delete_option('mxchat_use_fallback_rate_limits');
987 610 }
988 611
989 - // Schedule transcript cleanup if configured (bucket dropdown OR custom retention-days > 0)
612 + // Schedule transcript cleanup if configured
990 613 $transcript_options = get_option('mxchat_transcripts_options', array());
991 614 $cleanup_interval = isset($transcript_options['mxchat_auto_delete_transcripts']) ? $transcript_options['mxchat_auto_delete_transcripts'] : 'never';
992 - $custom_retention = isset($transcript_options['mxchat_retention_days']) ? (int) $transcript_options['mxchat_retention_days'] : 0;
993 -
994 - if ($cleanup_interval !== 'never' || $custom_retention > 0) {
615 +
616 + if ($cleanup_interval !== 'never') {
995 617 // Check if not already scheduled
996 618 if (!wp_next_scheduled('mxchat_cleanup_old_transcripts')) {
997 619 // Schedule to run daily at 3 AM
998 620 $next_run = strtotime('tomorrow 3:00 AM');
@@ -1069,14 +691,11 @@
1069 691
1070 692 // Version-specific migrations
1071 693 if ($current_version !== $plugin_version) {
1072 694 //error_log("MxChat: Version change detected: $current_version -> $plugin_version");
1073 -
695 +
1074 696 // Run live agent update BEFORE updating the stored version
1075 697 mxchat_handle_live_agent_update();
1076 -
1077 - // Run theme migration notice for 3.0.1 (AI theme CSS structure changes)
1078 - mxchat_handle_theme_migration_notice();
1079 698
1080 699 // Run role restriction migration for 2.4.1
1081 700 if (version_compare($current_version, '2.4.1', '<')) {
1082 701 mxchat_add_role_restriction_column();
@@ -1105,35 +724,8 @@
1105 724 mxchat_ensure_all_columns($chat_table);
1106 725 //error_log("MxChat: rag_context column migration for 2.6.0");
1107 726 }
1108 727
1109 - // 3.0.5: Migrate deprecated Gemini embedding model
1110 - if (version_compare($current_version, '3.0.5', '<')) {
1111 - mxchat_migrate_gemini_embedding_model();
1112 - }
1113 -
1114 - // 3.0.6: Migrate deprecated OpenAI and Claude models
1115 - if (version_compare($current_version, '3.0.6', '<')) {
1116 - mxchat_migrate_deprecated_models();
1117 - }
1118 -
1119 - // 3.1.2: Convert chat transcripts table to utf8mb4 for emoji support
1120 - if (version_compare($current_version, '3.1.2', '<')) {
1121 - mxchat_migrate_transcripts_charset();
1122 - }
1123 -
1124 - // 3.1.7: Clean up stale shared session email/name entries
1125 - if (version_compare($current_version, '3.1.7', '<')) {
1126 - delete_option('mxchat_email_null');
1127 - delete_option('mxchat_name_null');
1128 - }
1129 -
1130 - // 3.2.4: Backfill active embedding model option for the warning UI
1131 - // (replaces the per-row column tracking from 3.2.3, which was reverted)
1132 - if (version_compare($current_version, '3.2.4', '<')) {
1133 - mxchat_backfill_active_embedding_model();
1134 - }
1135 -
1136 728 // Run full activation to ensure everything is up to date
1137 729 mxchat_activate();
1138 730
1139 731 // Run migration functions
@@ -1265,59 +857,31 @@
1265 857 function mxchat_handle_live_agent_update() {
1266 858 // Get the CURRENT stored version (before it gets updated)
1267 859 $current_version = get_option('mxchat_plugin_version', '0.0.0');
1268 860 $new_version = '2.2.2';
1269 -
861 +
1270 862 // Only run this once for the update to 2.2.2
1271 863 $update_handled = get_option('mxchat_live_agent_update_2_2_2_handled', false);
1272 -
864 +
1273 865 // Check if we're upgrading TO 2.2.2 and haven't handled this yet
1274 866 if (version_compare($current_version, $new_version, '<') && !$update_handled) {
1275 867 $options = get_option('mxchat_options', array());
1276 -
868 +
1277 869 // Check if live agent was previously enabled
1278 870 if (isset($options['live_agent_status']) && $options['live_agent_status'] === 'on') {
1279 871 // Disable live agent
1280 872 $options['live_agent_status'] = 'off';
1281 873 update_option('mxchat_options', $options);
1282 -
874 +
1283 875 // Set flag to show the notification banner
1284 876 update_option('mxchat_show_live_agent_disabled_notice', true);
1285 877 }
1286 -
878 +
1287 879 // Mark this update as handled
1288 880 update_option('mxchat_live_agent_update_2_2_2_handled', true);
1289 881 }
1290 882 }
1291 883
1292 -/**
1293 - * Handle theme migration notice for version 3.0.1
1294 - * Shows a dismissible notice to Pro users about migrating AI-generated themes
1295 - */
1296 -function mxchat_handle_theme_migration_notice() {
1297 - // Get the CURRENT stored version (before it gets updated)
1298 - $current_version = get_option('mxchat_plugin_version', '0.0.0');
1299 - $target_version = '3.0.1';
1300 -
1301 - // Only run this once for the update to 3.0.1
1302 - $update_handled = get_option('mxchat_theme_migration_update_3_0_1_handled', false);
1303 -
1304 - // Check if we're upgrading TO 3.0.1 and haven't handled this yet
1305 - if (version_compare($current_version, $target_version, '<') && !$update_handled) {
1306 - // Check if Pro is activated - only show to Pro users
1307 - $license_status = get_option('mxchat_license_status', 'inactive');
1308 - $is_pro = ($license_status === 'active');
1309 -
1310 - if ($is_pro) {
1311 - // Set flag to show the theme migration notification banner
1312 - update_option('mxchat_show_theme_migration_notice', true);
1313 - }
1314 -
1315 - // Mark this update as handled (whether Pro or not)
1316 - update_option('mxchat_theme_migration_update_3_0_1_handled', true);
1317 - }
1318 -}
1319 -
1320 884 // Initialize plugin safely
1321 885 function mxchat_init() {
1322 886 // Include all class files first
1323 887 mxchat_include_classes();
@@ -1349,25 +913,10 @@
1349 913 // Initialize meta box class
1350 914 if (class_exists('MxChat_Meta_Box')) {
1351 915 new MxChat_Meta_Box();
1352 916 }
1353 -
1354 917 }
1355 -
1356 - // Initialize content generator globally — it registers wp_head hook
1357 - // for frontend CSS injection, plus wp_ajax_ hooks for admin.
1358 - if (class_exists('MxChat_Content_Generator')) {
1359 - new MxChat_Content_Generator();
1360 - }
1361 -
1362 - // Initialize REST API globally — endpoints must be registered on
1363 - // every request (admin and frontend) so they're reachable via /wp-json/.
1364 - // Endpoints are auth-gated and locked until the site owner generates
1365 - // a token in MxChat → API Access.
1366 - if (class_exists('MxChat_Rest_Api')) {
1367 - new MxChat_Rest_Api();
1368 - }
1369 -
918 +
1370 919 // Initialize public classes
1371 920 if (class_exists('MxChat_Public')) {
1372 921 $mxchat_public = new MxChat_Public();
1373 922 }
@@ -1411,41 +960,8 @@
1411 960 $checked = true;
1412 961
1413 962 mxchat_migrate_pinecone_roles_add_bot_id();
1414 963 mxchat_migrate_add_content_type_column();
1415 - mxchat_migrate_add_translations_table();
1416 -}
1417 -
1418 -/**
1419 - * Migration: Create transcript translations table (v3.0.4)
1420 - * For users upgrading from versions before 3.0.4
1421 - */
1422 -function mxchat_migrate_add_translations_table() {
1423 - $migration_key = 'mxchat_translations_table_created';
1424 -
1425 - // Check if migration already ran
1426 - if (get_option($migration_key)) {
1427 - return;
1428 - }
1429 -
1430 - // Create the translations table
1431 - mxchat_create_translations_table();
1432 -
1433 - // Mark migration as complete
1434 - update_option($migration_key, '3.0.4');
1435 -}
1436 -
1437 -/**
1438 - * Migration: Update deprecated Gemini embedding model (v3.0.5)
1439 - * Updates gemini-embedding-exp-03-07 to gemini-embedding-001 for users who had it selected
1440 - */
1441 -function mxchat_migrate_gemini_embedding_model() {
1442 - $options = get_option('mxchat_options', array());
1443 -
1444 - if (isset($options['embedding_model']) && $options['embedding_model'] === 'gemini-embedding-exp-03-07') {
1445 - $options['embedding_model'] = 'gemini-embedding-001';
1446 - update_option('mxchat_options', $options);
1447 - }
1448 964 }
1449 965
1450 966 // Register activation hook
1451 967 register_activation_hook(__FILE__, 'mxchat_activate');