| @@ -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.3 | |
| 6 | + * Version: 2.6.2 | |
| 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,20 +15,13 @@ | ||
| 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 | 27 | $domain = 'mxchat'; |
| @@ -45,213 +38,8 @@ | ||
| 45 | 38 | load_plugin_textdomain($domain, false, dirname(plugin_basename(__FILE__)) . '/languages'); |
| 46 | 39 | } |
| 47 | 40 | add_action('init', 'mxchat_load_textdomain'); |
| 48 | 41 | |
| 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 | 42 | // Include classes with error handling |
| 255 | 43 | function mxchat_include_classes() { |
| 256 | 44 | $class_files = array( |
| 257 | 45 | 'includes/class-mxchat-integrator.php', |
| @@ -259,11 +47,10 @@ | ||
| 259 | 47 | 'includes/class-mxchat-public.php', |
| 260 | 48 | 'includes/class-mxchat-utils.php', |
| 261 | 49 | 'includes/class-mxchat-user.php', |
| 262 | 50 | 'includes/class-mxchat-meta-box.php', |
| 263 | - 'includes/class-mxchat-chunker.php', | |
| 51 | + 'includes/pdf-parser/alt_autoload.php', | |
| 264 | 52 | 'includes/class-mxchat-word-handler.php', |
| 265 | - 'includes/class-mxchat-content-generator.php', | |
| 266 | 53 | 'admin/class-ajax-handler.php', |
| 267 | 54 | 'admin/class-pinecone-manager.php', |
| 268 | 55 | 'admin/class-knowledge-manager.php' |
| 269 | 56 | ); |
| @@ -278,24 +65,8 @@ | ||
| 278 | 65 | } |
| 279 | 66 | } |
| 280 | 67 | |
| 281 | 68 | /** |
| 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 | 69 | * Create URL click tracking table |
| 299 | 70 | */ |
| 300 | 71 | function mxchat_create_url_clicks_table() { |
| 301 | 72 | global $wpdb; |
| @@ -563,9 +334,9 @@ | ||
| 563 | 334 | |
| 564 | 335 | // Add index for bot_id |
| 565 | 336 | $wpdb->query("ALTER TABLE {$table_name} ADD KEY bot_id (bot_id)"); |
| 566 | 337 | |
| 567 | - //error_log('MxChat: Successfully added bot_id column to mxchat_pinecone_roles table'); | |
| 338 | + error_log('MxChat: Successfully added bot_id column to mxchat_pinecone_roles table'); | |
| 568 | 339 | } |
| 569 | 340 | |
| 570 | 341 | // Mark migration as complete |
| 571 | 342 | update_option('mxchat_pinecone_roles_migration_version', '2.5.2'); |
| @@ -600,9 +371,9 @@ | ||
| 600 | 371 | |
| 601 | 372 | // Add index for better query performance |
| 602 | 373 | $wpdb->query("ALTER TABLE {$table_name} ADD KEY content_type (content_type)"); |
| 603 | 374 | |
| 604 | - //error_log('MxChat: Successfully added content_type column to mxchat_system_prompt_content table'); | |
| 375 | + error_log('MxChat: Successfully added content_type column to mxchat_system_prompt_content table'); | |
| 605 | 376 | } |
| 606 | 377 | |
| 607 | 378 | // Mark migration as complete |
| 608 | 379 | update_option('mxchat_content_type_migration_version', '2.5.6'); |
| @@ -608,54 +379,8 @@ | ||
| 608 | 379 | update_option('mxchat_content_type_migration_version', '2.5.6'); |
| 609 | 380 | } |
| 610 | 381 | |
| 611 | 382 | /** |
| 612 | - * 3.2.3: Add embedding_model column to KB and intent tables so we can detect | |
| 613 | - * when the active embedding model is changed while content is already embedded. | |
| 614 | - */ | |
| 615 | -function mxchat_add_embedding_model_columns() { | |
| 616 | - global $wpdb; | |
| 617 | - | |
| 618 | - $migration_version = get_option('mxchat_embedding_model_migration_version', '0'); | |
| 619 | - if (version_compare($migration_version, '3.2.3', '>=')) { | |
| 620 | - return; | |
| 621 | - } | |
| 622 | - | |
| 623 | - $tables = array( | |
| 624 | - $wpdb->prefix . 'mxchat_system_prompt_content', | |
| 625 | - $wpdb->prefix . 'mxchat_intents', | |
| 626 | - $wpdb->prefix . 'mxchat_intent_phrases', | |
| 627 | - ); | |
| 628 | - | |
| 629 | - foreach ($tables as $table) { | |
| 630 | - if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") !== $table) { | |
| 631 | - continue; | |
| 632 | - } | |
| 633 | - $col_exists = $wpdb->get_results("SHOW COLUMNS FROM {$table} LIKE 'embedding_model'"); | |
| 634 | - if (empty($col_exists)) { | |
| 635 | - $wpdb->query("ALTER TABLE {$table} ADD COLUMN embedding_model VARCHAR(64) DEFAULT NULL"); | |
| 636 | - } | |
| 637 | - } | |
| 638 | - | |
| 639 | - // Best-effort backfill: if any existing content lacks a stamped model, assume | |
| 640 | - // it was embedded with whatever model is currently selected. This is the | |
| 641 | - // safest assumption for installations upgrading to 3.2.3 — if it was wrong | |
| 642 | - // already, the mismatch detection will surface it on the next switch. | |
| 643 | - $options = get_option('mxchat_options', array()); | |
| 644 | - $current_model = $options['embedding_model'] ?? 'text-embedding-ada-002'; | |
| 645 | - | |
| 646 | - if (get_option('mxchat_active_embedding_model', '') === '') { | |
| 647 | - $kb_table = $wpdb->prefix . 'mxchat_system_prompt_content'; | |
| 648 | - $kb_count = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$kb_table}"); | |
| 649 | - if ($kb_count > 0) { | |
| 650 | - update_option('mxchat_active_embedding_model', $current_model, false); | |
| 651 | - } | |
| 652 | - } | |
| 653 | - | |
| 654 | - update_option('mxchat_embedding_model_migration_version', '3.2.3'); | |
| 655 | -} | |
| 656 | - | |
| 657 | -/** | |
| 658 | 383 | * 2.5.2: Create queue processing tables for reliable background processing |
| 659 | 384 | */ |
| 660 | 385 | function mxchat_create_queue_tables() { |
| 661 | 386 | global $wpdb; |
| @@ -703,32 +428,8 @@ | ||
| 703 | 428 | //error_log("MxChat: Queue tables created/updated successfully"); |
| 704 | 429 | } |
| 705 | 430 | |
| 706 | 431 | /** |
| 707 | - * Create transcript translations table for persisting translations | |
| 708 | - */ | |
| 709 | -function mxchat_create_translations_table() { | |
| 710 | - global $wpdb; | |
| 711 | - $charset_collate = $wpdb->get_charset_collate(); | |
| 712 | - | |
| 713 | - $table_name = $wpdb->prefix . 'mxchat_transcript_translations'; | |
| 714 | - $sql = "CREATE TABLE $table_name ( | |
| 715 | - id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 716 | - session_id varchar(255) NOT NULL, | |
| 717 | - language_code varchar(10) NOT NULL, | |
| 718 | - translations longtext NOT NULL, | |
| 719 | - created_at datetime NOT NULL, | |
| 720 | - updated_at datetime NOT NULL, | |
| 721 | - PRIMARY KEY (id), | |
| 722 | - UNIQUE KEY session_lang (session_id, language_code), | |
| 723 | - KEY session_id (session_id) | |
| 724 | - ) $charset_collate;"; | |
| 725 | - | |
| 726 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
| 727 | - dbDelta($sql); | |
| 728 | -} | |
| 729 | - | |
| 730 | -/** | |
| 731 | 432 | * 2.5.2: Fix URL column size to support long URLs (especially with UTF-8 encoding) |
| 732 | 433 | * This fixes "url, source_url. The supplied values may be too long" errors |
| 733 | 434 | */ |
| 734 | 435 | function mxchat_fix_url_column_size() { |
| @@ -751,80 +452,22 @@ | ||
| 751 | 452 | |
| 752 | 453 | /** |
| 753 | 454 | * Migrate deprecated AI models to their replacements |
| 754 | 455 | * Version 2.5.1: Migrate Claude 3.5 Sonnet (deprecated) to Claude 3.7 Sonnet |
| 755 | - * Version 3.1.2: Convert chat transcripts table to utf8mb4 for emoji support | |
| 756 | - * Without utf8mb4, any bot response containing emojis silently fails to insert. | |
| 757 | 456 | */ |
| 758 | -function mxchat_migrate_transcripts_charset() { | |
| 759 | - global $wpdb; | |
| 760 | - $table_name = $wpdb->prefix . 'mxchat_chat_transcripts'; | |
| 761 | - $wpdb->query("ALTER TABLE $table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); | |
| 762 | -} | |
| 763 | - | |
| 764 | -/** | |
| 765 | - * Version 3.0.55: Migrate GPT-4 series models (deprecated 2026-02-17) to GPT-5 series | |
| 766 | - */ | |
| 767 | 457 | function mxchat_migrate_deprecated_models() { |
| 768 | 458 | $options = get_option('mxchat_options', array()); |
| 769 | - $migrated = false; | |
| 770 | - $migration_message = ''; | |
| 771 | - | |
| 772 | - if (!isset($options['model'])) { | |
| 773 | - return; | |
| 774 | - } | |
| 775 | - | |
| 776 | - $current_model = $options['model']; | |
| 777 | - | |
| 778 | - // Migrate deprecated Claude models to Claude Opus 4.6 (recommended replacement per Anthropic) | |
| 779 | - $deprecated_claude_models = array( | |
| 780 | - 'claude-3-5-sonnet-20240620', // Retired Oct 28, 2025 | |
| 781 | - 'claude-3-5-sonnet-20241022', // Retired Oct 28, 2025 | |
| 782 | - 'claude-3-7-sonnet-20250219', // Retiring Feb 19, 2026 | |
| 783 | - 'claude-3-opus-20240229', // Retired Jan 5, 2026 | |
| 784 | - 'claude-3-sonnet-20240229', // Legacy | |
| 785 | - 'claude-3-haiku-20240307', // Legacy | |
| 786 | - ); | |
| 787 | - if (in_array($current_model, $deprecated_claude_models, true)) { | |
| 788 | - $options['model'] = 'claude-opus-4-6'; | |
| 789 | - $migrated = true; | |
| 790 | - $migration_message = sprintf( | |
| 791 | - 'Your chatbot model has been automatically updated from %s to Claude Opus 4.6 due to Anthropic deprecating older Claude models.', | |
| 792 | - $current_model | |
| 793 | - ); | |
| 794 | - } | |
| 795 | - | |
| 796 | - // Migrate deprecated Claude Haiku 3.5 to Claude Haiku 4.5 | |
| 797 | - if ($current_model === 'claude-3-5-haiku-20241022') { | |
| 798 | - $options['model'] = 'claude-haiku-4-5-20251001'; | |
| 799 | - $migrated = true; | |
| 800 | - $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.'; | |
| 801 | - } | |
| 802 | - | |
| 803 | - // Migrate deprecated GPT-4 series and GPT-3.5 Turbo to GPT-5.1 Chat Latest | |
| 804 | - if (in_array($current_model, array('gpt-4o', 'gpt-4.1-2025-04-14', 'gpt-4-turbo', 'gpt-4', 'gpt-3.5-turbo'), true)) { | |
| 805 | - $options['model'] = 'gpt-5.1-chat-latest'; | |
| 806 | - $migrated = true; | |
| 807 | - $migration_message = sprintf( | |
| 808 | - 'Your chatbot model has been automatically updated from %s to GPT-5.1 Chat Latest due to OpenAI deprecating older models.', | |
| 809 | - $current_model | |
| 810 | - ); | |
| 811 | - } | |
| 812 | - | |
| 813 | - // Migrate deprecated GPT-4o Mini and GPT-4.1 Mini to GPT-5 Mini | |
| 814 | - if (in_array($current_model, array('gpt-4o-mini', 'gpt-4.1-mini'), true)) { | |
| 815 | - $options['model'] = 'gpt-5-mini'; | |
| 816 | - $migrated = true; | |
| 817 | - $migration_message = sprintf( | |
| 818 | - 'Your chatbot model has been automatically updated from %s to GPT-5 Mini due to OpenAI deprecating GPT-4 series models.', | |
| 819 | - $current_model | |
| 820 | - ); | |
| 821 | - } | |
| 822 | - | |
| 823 | - if ($migrated) { | |
| 459 | + | |
| 460 | + // Check if model is set and is the deprecated Claude 3.5 Sonnet | |
| 461 | + if (isset($options['model']) && $options['model'] === 'claude-3-5-sonnet-20241022') { | |
| 462 | + // Update to Claude 3.7 Sonnet (the replacement model) | |
| 463 | + $options['model'] = 'claude-3-7-sonnet-20250219'; | |
| 824 | 464 | update_option('mxchat_options', $options); |
| 465 | + | |
| 466 | + // Set a flag to show admin notice | |
| 825 | 467 | update_option('mxchat_model_migrated_notice', true); |
| 826 | - update_option('mxchat_model_migration_message', $migration_message); | |
| 468 | + | |
| 469 | + //error_log('MxChat: Migrated deprecated Claude 3.5 Sonnet to Claude 3.7 Sonnet'); | |
| 827 | 470 | } |
| 828 | 471 | } |
| 829 | 472 | |
| 830 | 473 | /** |
| @@ -831,19 +474,17 @@ | ||
| 831 | 474 | * Show admin notice after model migration |
| 832 | 475 | */ |
| 833 | 476 | function mxchat_show_migration_notice() { |
| 834 | 477 | if (get_option('mxchat_model_migrated_notice')) { |
| 835 | - $migration_message = get_option('mxchat_model_migration_message', __('Your chatbot model has been automatically updated due to a model deprecation.', 'mxchat')); | |
| 836 | 478 | ?> |
| 837 | 479 | <div class="notice notice-info is-dismissible"> |
| 838 | 480 | <p> |
| 839 | 481 | <strong><?php esc_html_e('MxChat Model Updated', 'mxchat'); ?></strong><br> |
| 840 | - <?php echo esc_html($migration_message); ?> | |
| 482 | + <?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'); ?> | |
| 841 | 483 | </p> |
| 842 | 484 | </div> |
| 843 | 485 | <?php |
| 844 | 486 | delete_option('mxchat_model_migrated_notice'); |
| 845 | - delete_option('mxchat_model_migration_message'); | |
| 846 | 487 | } |
| 847 | 488 | } |
| 848 | 489 | |
| 849 | 490 | function mxchat_activate() { |
| @@ -864,9 +505,8 @@ | ||
| 864 | 505 | embedding_vector LONGTEXT, |
| 865 | 506 | source_url TEXT DEFAULT NULL, |
| 866 | 507 | role_restriction VARCHAR(50) DEFAULT 'public', |
| 867 | 508 | content_type VARCHAR(50) DEFAULT 'content', |
| 868 | - embedding_model VARCHAR(64) DEFAULT NULL, | |
| 869 | 509 | timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 870 | 510 | PRIMARY KEY (id), |
| 871 | 511 | KEY content_type (content_type) |
| 872 | 512 | ) $charset_collate;"; |
| @@ -881,31 +521,16 @@ | ||
| 881 | 521 | callback_function VARCHAR(255) NOT NULL, |
| 882 | 522 | similarity_threshold FLOAT DEFAULT 0.85, |
| 883 | 523 | enabled TINYINT(1) NOT NULL DEFAULT 1, |
| 884 | 524 | enabled_bots LONGTEXT DEFAULT NULL, |
| 885 | - embedding_model VARCHAR(64) DEFAULT NULL, | |
| 886 | 525 | PRIMARY KEY (id) |
| 887 | 526 | ) $charset_collate;"; |
| 888 | 527 | |
| 889 | - // Individual Intent Phrases Table - each phrase gets its own embedding vector | |
| 890 | - $intent_phrases_table = $wpdb->prefix . 'mxchat_intent_phrases'; | |
| 891 | - $sql_intent_phrases_table = "CREATE TABLE $intent_phrases_table ( | |
| 892 | - id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, | |
| 893 | - intent_id BIGINT(20) UNSIGNED NOT NULL, | |
| 894 | - phrase TEXT NOT NULL, | |
| 895 | - embedding_vector LONGTEXT NOT NULL, | |
| 896 | - embedding_model VARCHAR(64) DEFAULT NULL, | |
| 897 | - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, | |
| 898 | - PRIMARY KEY (id), | |
| 899 | - KEY intent_id (intent_id) | |
| 900 | - ) $charset_collate;"; | |
| 901 | - | |
| 902 | 528 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 903 | 529 | |
| 904 | 530 | // Create other tables |
| 905 | 531 | dbDelta($sql_system_prompt); |
| 906 | 532 | dbDelta($sql_intents_table); |
| 907 | - dbDelta($sql_intent_phrases_table); | |
| 908 | 533 | |
| 909 | 534 | // Create URL click tracking table |
| 910 | 535 | mxchat_create_url_clicks_table(); |
| 911 | 536 | |
| @@ -914,11 +539,8 @@ | ||
| 914 | 539 | |
| 915 | 540 | // NEW 2.5.2: Create queue processing tables |
| 916 | 541 | mxchat_create_queue_tables(); |
| 917 | 542 | |
| 918 | - // Create transcript translations table | |
| 919 | - mxchat_create_translations_table(); | |
| 920 | - | |
| 921 | 543 | // Ensure additional columns in system prompt table |
| 922 | 544 | $existing_system_columns = $wpdb->get_results("SHOW COLUMNS FROM $system_prompt_table"); |
| 923 | 545 | if (!empty($existing_system_columns)) { |
| 924 | 546 | $existing_system_column_names = array_column($existing_system_columns, 'Field'); |
| @@ -961,11 +583,8 @@ | ||
| 961 | 583 | |
| 962 | 584 | // Run migration for existing installations |
| 963 | 585 | mxchat_migrate_pinecone_roles_add_bot_id(); |
| 964 | 586 | |
| 965 | - // 3.2.3: Add embedding_model column to KB and intent tables | |
| 966 | - mxchat_add_embedding_model_columns(); | |
| 967 | - | |
| 968 | 587 | // Setup cron jobs |
| 969 | 588 | mxchat_setup_cron_jobs(); |
| 970 | 589 | |
| 971 | 590 | // Update version |
| @@ -1083,14 +702,11 @@ | ||
| 1083 | 702 | |
| 1084 | 703 | // Version-specific migrations |
| 1085 | 704 | if ($current_version !== $plugin_version) { |
| 1086 | 705 | //error_log("MxChat: Version change detected: $current_version -> $plugin_version"); |
| 1087 | - | |
| 706 | + | |
| 1088 | 707 | // Run live agent update BEFORE updating the stored version |
| 1089 | 708 | mxchat_handle_live_agent_update(); |
| 1090 | - | |
| 1091 | - // Run theme migration notice for 3.0.1 (AI theme CSS structure changes) | |
| 1092 | - mxchat_handle_theme_migration_notice(); | |
| 1093 | 709 | |
| 1094 | 710 | // Run role restriction migration for 2.4.1 |
| 1095 | 711 | if (version_compare($current_version, '2.4.1', '<')) { |
| 1096 | 712 | mxchat_add_role_restriction_column(); |
| @@ -1119,34 +735,8 @@ | ||
| 1119 | 735 | mxchat_ensure_all_columns($chat_table); |
| 1120 | 736 | //error_log("MxChat: rag_context column migration for 2.6.0"); |
| 1121 | 737 | } |
| 1122 | 738 | |
| 1123 | - // 3.0.5: Migrate deprecated Gemini embedding model | |
| 1124 | - if (version_compare($current_version, '3.0.5', '<')) { | |
| 1125 | - mxchat_migrate_gemini_embedding_model(); | |
| 1126 | - } | |
| 1127 | - | |
| 1128 | - // 3.0.6: Migrate deprecated OpenAI and Claude models | |
| 1129 | - if (version_compare($current_version, '3.0.6', '<')) { | |
| 1130 | - mxchat_migrate_deprecated_models(); | |
| 1131 | - } | |
| 1132 | - | |
| 1133 | - // 3.1.2: Convert chat transcripts table to utf8mb4 for emoji support | |
| 1134 | - if (version_compare($current_version, '3.1.2', '<')) { | |
| 1135 | - mxchat_migrate_transcripts_charset(); | |
| 1136 | - } | |
| 1137 | - | |
| 1138 | - // 3.1.7: Clean up stale shared session email/name entries | |
| 1139 | - if (version_compare($current_version, '3.1.7', '<')) { | |
| 1140 | - delete_option('mxchat_email_null'); | |
| 1141 | - delete_option('mxchat_name_null'); | |
| 1142 | - } | |
| 1143 | - | |
| 1144 | - // 3.2.3: Add embedding_model tracking columns and backfill active model | |
| 1145 | - if (version_compare($current_version, '3.2.3', '<')) { | |
| 1146 | - mxchat_add_embedding_model_columns(); | |
| 1147 | - } | |
| 1148 | - | |
| 1149 | 739 | // Run full activation to ensure everything is up to date |
| 1150 | 740 | mxchat_activate(); |
| 1151 | 741 | |
| 1152 | 742 | // Run migration functions |
| @@ -1278,59 +868,31 @@ | ||
| 1278 | 868 | function mxchat_handle_live_agent_update() { |
| 1279 | 869 | // Get the CURRENT stored version (before it gets updated) |
| 1280 | 870 | $current_version = get_option('mxchat_plugin_version', '0.0.0'); |
| 1281 | 871 | $new_version = '2.2.2'; |
| 1282 | - | |
| 872 | + | |
| 1283 | 873 | // Only run this once for the update to 2.2.2 |
| 1284 | 874 | $update_handled = get_option('mxchat_live_agent_update_2_2_2_handled', false); |
| 1285 | - | |
| 875 | + | |
| 1286 | 876 | // Check if we're upgrading TO 2.2.2 and haven't handled this yet |
| 1287 | 877 | if (version_compare($current_version, $new_version, '<') && !$update_handled) { |
| 1288 | 878 | $options = get_option('mxchat_options', array()); |
| 1289 | - | |
| 879 | + | |
| 1290 | 880 | // Check if live agent was previously enabled |
| 1291 | 881 | if (isset($options['live_agent_status']) && $options['live_agent_status'] === 'on') { |
| 1292 | 882 | // Disable live agent |
| 1293 | 883 | $options['live_agent_status'] = 'off'; |
| 1294 | 884 | update_option('mxchat_options', $options); |
| 1295 | - | |
| 885 | + | |
| 1296 | 886 | // Set flag to show the notification banner |
| 1297 | 887 | update_option('mxchat_show_live_agent_disabled_notice', true); |
| 1298 | 888 | } |
| 1299 | - | |
| 889 | + | |
| 1300 | 890 | // Mark this update as handled |
| 1301 | 891 | update_option('mxchat_live_agent_update_2_2_2_handled', true); |
| 1302 | 892 | } |
| 1303 | 893 | } |
| 1304 | 894 | |
| 1305 | -/** | |
| 1306 | - * Handle theme migration notice for version 3.0.1 | |
| 1307 | - * Shows a dismissible notice to Pro users about migrating AI-generated themes | |
| 1308 | - */ | |
| 1309 | -function mxchat_handle_theme_migration_notice() { | |
| 1310 | - // Get the CURRENT stored version (before it gets updated) | |
| 1311 | - $current_version = get_option('mxchat_plugin_version', '0.0.0'); | |
| 1312 | - $target_version = '3.0.1'; | |
| 1313 | - | |
| 1314 | - // Only run this once for the update to 3.0.1 | |
| 1315 | - $update_handled = get_option('mxchat_theme_migration_update_3_0_1_handled', false); | |
| 1316 | - | |
| 1317 | - // Check if we're upgrading TO 3.0.1 and haven't handled this yet | |
| 1318 | - if (version_compare($current_version, $target_version, '<') && !$update_handled) { | |
| 1319 | - // Check if Pro is activated - only show to Pro users | |
| 1320 | - $license_status = get_option('mxchat_license_status', 'inactive'); | |
| 1321 | - $is_pro = ($license_status === 'active'); | |
| 1322 | - | |
| 1323 | - if ($is_pro) { | |
| 1324 | - // Set flag to show the theme migration notification banner | |
| 1325 | - update_option('mxchat_show_theme_migration_notice', true); | |
| 1326 | - } | |
| 1327 | - | |
| 1328 | - // Mark this update as handled (whether Pro or not) | |
| 1329 | - update_option('mxchat_theme_migration_update_3_0_1_handled', true); | |
| 1330 | - } | |
| 1331 | -} | |
| 1332 | - | |
| 1333 | 895 | // Initialize plugin safely |
| 1334 | 896 | function mxchat_init() { |
| 1335 | 897 | // Include all class files first |
| 1336 | 898 | mxchat_include_classes(); |
| @@ -1362,17 +924,10 @@ | ||
| 1362 | 924 | // Initialize meta box class |
| 1363 | 925 | if (class_exists('MxChat_Meta_Box')) { |
| 1364 | 926 | new MxChat_Meta_Box(); |
| 1365 | 927 | } |
| 1366 | - | |
| 1367 | 928 | } |
| 1368 | - | |
| 1369 | - // Initialize content generator globally — it registers wp_head hook | |
| 1370 | - // for frontend CSS injection, plus wp_ajax_ hooks for admin. | |
| 1371 | - if (class_exists('MxChat_Content_Generator')) { | |
| 1372 | - new MxChat_Content_Generator(); | |
| 1373 | - } | |
| 1374 | - | |
| 929 | + | |
| 1375 | 930 | // Initialize public classes |
| 1376 | 931 | if (class_exists('MxChat_Public')) { |
| 1377 | 932 | $mxchat_public = new MxChat_Public(); |
| 1378 | 933 | } |
| @@ -1416,41 +971,8 @@ | ||
| 1416 | 971 | $checked = true; |
| 1417 | 972 | |
| 1418 | 973 | mxchat_migrate_pinecone_roles_add_bot_id(); |
| 1419 | 974 | mxchat_migrate_add_content_type_column(); |
| 1420 | - mxchat_migrate_add_translations_table(); | |
| 1421 | -} | |
| 1422 | - | |
| 1423 | -/** | |
| 1424 | - * Migration: Create transcript translations table (v3.0.4) | |
| 1425 | - * For users upgrading from versions before 3.0.4 | |
| 1426 | - */ | |
| 1427 | -function mxchat_migrate_add_translations_table() { | |
| 1428 | - $migration_key = 'mxchat_translations_table_created'; | |
| 1429 | - | |
| 1430 | - // Check if migration already ran | |
| 1431 | - if (get_option($migration_key)) { | |
| 1432 | - return; | |
| 1433 | - } | |
| 1434 | - | |
| 1435 | - // Create the translations table | |
| 1436 | - mxchat_create_translations_table(); | |
| 1437 | - | |
| 1438 | - // Mark migration as complete | |
| 1439 | - update_option($migration_key, '3.0.4'); | |
| 1440 | -} | |
| 1441 | - | |
| 1442 | -/** | |
| 1443 | - * Migration: Update deprecated Gemini embedding model (v3.0.5) | |
| 1444 | - * Updates gemini-embedding-exp-03-07 to gemini-embedding-001 for users who had it selected | |
| 1445 | - */ | |
| 1446 | -function mxchat_migrate_gemini_embedding_model() { | |
| 1447 | - $options = get_option('mxchat_options', array()); | |
| 1448 | - | |
| 1449 | - if (isset($options['embedding_model']) && $options['embedding_model'] === 'gemini-embedding-exp-03-07') { | |
| 1450 | - $options['embedding_model'] = 'gemini-embedding-001'; | |
| 1451 | - update_option('mxchat_options', $options); | |
| 1452 | - } | |
| 1453 | 975 | } |
| 1454 | 976 | |
| 1455 | 977 | // Register activation hook |
| 1456 | 978 | register_activation_hook(__FILE__, 'mxchat_activate'); |