PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.1.4
MxChat – AI Chatbot & Content Generation for WordPress v3.1.4
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 +10 -300 3.2.93.1.4 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.9
6 + * Version: 3.1.4
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
@@ -46,51 +46,8 @@
46 46 }
47 47 add_action('init', 'mxchat_load_textdomain');
48 48
49 49 /**
50 - * One-time migration: gemini-3-pro-preview was shut down by Google on March 9, 2026.
51 - * Existing installs with the dead ID get auto-remapped to gemini-3.1-pro-preview
52 - * (Google's official migration target) the first time admin_init fires after update.
53 - */
54 -add_action('admin_init', function () {
55 - if (get_option('mxchat_gemini_3_remap_done')) {
56 - return;
57 - }
58 - $opts = get_option('mxchat_options');
59 - if (is_array($opts) && isset($opts['model']) && $opts['model'] === 'gemini-3-pro-preview') {
60 - $opts['model'] = 'gemini-3.1-pro-preview';
61 - update_option('mxchat_options', $opts);
62 - }
63 - if (is_array($opts) && isset($opts['content_model']) && $opts['content_model'] === 'gemini-3-pro-preview') {
64 - $opts['content_model'] = 'gemini-3.1-pro-preview';
65 - update_option('mxchat_options', $opts);
66 - }
67 - update_option('mxchat_gemini_3_remap_done', 1);
68 -});
69 -
70 -/**
71 - * One-time migration: the Grok 2 family was retired by xAI (grok-2, grok-2-1212,
72 - * grok-2-latest, grok-2-vision-1212 all return 400 "Model not found"). Existing
73 - * installs with the dead ID get auto-remapped to grok-4-1-fast-non-reasoning
74 - * (modern, fast, broadly available) the first time admin_init fires after update.
75 - */
76 -add_action('admin_init', function () {
77 - if (get_option('mxchat_grok_2_remap_done')) {
78 - return;
79 - }
80 - $opts = get_option('mxchat_options');
81 - if (is_array($opts) && isset($opts['model']) && $opts['model'] === 'grok-2') {
82 - $opts['model'] = 'grok-4-1-fast-non-reasoning';
83 - update_option('mxchat_options', $opts);
84 - }
85 - if (is_array($opts) && isset($opts['content_model']) && $opts['content_model'] === 'grok-2') {
86 - $opts['content_model'] = 'grok-4-1-fast-non-reasoning';
87 - update_option('mxchat_options', $opts);
88 - }
89 - update_option('mxchat_grok_2_remap_done', 1);
90 -});
91 -
92 -/**
93 50 * Exclude MxChat assets from caching plugin optimizations
94 51 *
95 52 * This prevents issues with WP Rocket, LiteSpeed Cache, Autoptimize, WP Super Cache,
96 53 * W3 Total Cache, SG Optimizer, and similar plugins that may break the chatbot by
@@ -293,61 +250,8 @@
293 250 $rejected[] = 'wp-admin/admin-ajax.php';
294 251 return $rejected;
295 252 });
296 253
297 -// ── Page-cache bypass for chat AJAX (companion to the 3.2.6 nonce-race hotfix)
298 -// Each cache plugin gets its own filter export so that visitors hitting an
299 -// edge-cached page never receive cached chat-AJAX responses. The chat send /
300 -// stream send / file upload all POST to /wp-admin/admin-ajax.php with
301 -// `action=mxchat_*`. Without these exports, a cache plugin can stale a response
302 -// and break the per-session nonce flow on the first message.
303 -
304 -// WP Rocket — `rocket_cache_reject_uri` takes a flat array of regex strings.
305 -add_filter('rocket_cache_reject_uri', function($uris) {
306 - if (!is_array($uris)) $uris = array();
307 - $uris[] = '/wp-admin/admin-ajax\.php\?action=mxchat_.*';
308 - return $uris;
309 -});
310 -
311 -// LiteSpeed Cache — `litespeed_cache_no_cache_for_request` short-circuits
312 -// caching when the request matches our chat-AJAX pattern.
313 -add_filter('litespeed_cache_no_cache_for_request', function($no_cache) {
314 - if ($no_cache) return $no_cache;
315 - if (!empty($_SERVER['REQUEST_URI']) &&
316 - strpos($_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php') !== false &&
317 - !empty($_REQUEST['action']) &&
318 - strpos((string) $_REQUEST['action'], 'mxchat_') === 0) {
319 - return true;
320 - }
321 - return $no_cache;
322 -});
323 -
324 -// W3 Total Cache — `w3tc_pgcache_request_skip_uri` flips page-cache off when
325 -// the URI matches.
326 -add_filter('w3tc_pgcache_request_skip_uri', function($skip) {
327 - if ($skip) return $skip;
328 - if (!empty($_SERVER['REQUEST_URI']) &&
329 - strpos($_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php') !== false &&
330 - !empty($_REQUEST['action']) &&
331 - strpos((string) $_REQUEST['action'], 'mxchat_') === 0) {
332 - return true;
333 - }
334 - return $skip;
335 -});
336 -
337 -// FlyingPress — `flying_press_cacheable` takes a boolean and is run per
338 -// request. Same pattern as LiteSpeed / W3TC.
339 -add_filter('flying_press_cacheable', function($cacheable) {
340 - if (!$cacheable) return $cacheable;
341 - if (!empty($_SERVER['REQUEST_URI']) &&
342 - strpos($_SERVER['REQUEST_URI'], '/wp-admin/admin-ajax.php') !== false &&
343 - !empty($_REQUEST['action']) &&
344 - strpos((string) $_REQUEST['action'], 'mxchat_') === 0) {
345 - return false;
346 - }
347 - return $cacheable;
348 -});
349 -
350 254 // Include classes with error handling
351 255 function mxchat_include_classes() {
352 256 $class_files = array(
353 257 'includes/class-mxchat-integrator.php',
@@ -358,10 +262,8 @@
358 262 'includes/class-mxchat-meta-box.php',
359 263 'includes/class-mxchat-chunker.php',
360 264 'includes/class-mxchat-word-handler.php',
361 265 'includes/class-mxchat-content-generator.php',
362 - 'includes/class-mxchat-cache-purge.php',
363 - 'includes/class-rest-api.php',
364 266 'admin/class-ajax-handler.php',
365 267 'admin/class-pinecone-manager.php',
366 268 'admin/class-knowledge-manager.php'
367 269 );
@@ -373,26 +275,8 @@
373 275 } else {
374 276 //error_log('MxChat: Missing class file - ' . $file);
375 277 }
376 278 }
377 -
378 - // Admin pages that aren't classes (procedural include).
379 - if (is_admin()) {
380 - $admin_api_page = plugin_dir_path(__FILE__) . 'includes/admin-api-page.php';
381 - if (file_exists($admin_api_page)) {
382 - require_once $admin_api_page;
383 - }
384 - // f7c7d4 renamed this file admin-dashboard-page.php → admin-onboarding-page.php.
385 - // The require MUST live here (admin bootstrap) and not just inside
386 - // mxchat_add_plugin_page() on the admin_menu hook — admin_menu does NOT
387 - // fire on admin-ajax.php requests, so the wizard's AJAX handlers
388 - // (plan-905439: mxchat_onboarding_kb_status / save_step / mark_step /
389 - // auto_graduate + the f7c7d4 dismiss handler) would never register.
390 - $admin_onboarding_page = plugin_dir_path(__FILE__) . 'includes/admin-onboarding-page.php';
391 - if (file_exists($admin_onboarding_page)) {
392 - require_once $admin_onboarding_page;
393 - }
394 - }
395 279 }
396 280
397 281 /**
398 282 * Lazy-load the PDF parser library only when needed.
@@ -724,33 +608,8 @@
724 608 update_option('mxchat_content_type_migration_version', '2.5.6');
725 609 }
726 610
727 611 /**
728 - * 3.2.4: Backfill the active embedding model option for installs that already
729 - * have KB content but no stamped model. The mismatch warning compares this
730 - * against the user's currently selected model — no per-row column needed.
731 - */
732 -function mxchat_backfill_active_embedding_model() {
733 - global $wpdb;
734 -
735 - if (get_option('mxchat_active_embedding_model', '') !== '') {
736 - return;
737 - }
738 -
739 - $kb_table = $wpdb->prefix . 'mxchat_system_prompt_content';
740 - if ($wpdb->get_var("SHOW TABLES LIKE '{$kb_table}'") !== $kb_table) {
741 - return;
742 - }
743 -
744 - $kb_count = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$kb_table}");
745 - if ($kb_count > 0) {
746 - $options = get_option('mxchat_options', array());
747 - $current_model = $options['embedding_model'] ?? 'text-embedding-ada-002';
748 - update_option('mxchat_active_embedding_model', $current_model, false);
749 - }
750 -}
751 -
752 -/**
753 612 * 2.5.2: Create queue processing tables for reliable background processing
754 613 */
755 614 function mxchat_create_queue_tables() {
756 615 global $wpdb;
@@ -822,34 +681,8 @@
822 681 dbDelta($sql);
823 682 }
824 683
825 684 /**
826 - * Create per-session satisfaction ratings table (v3.2.6)
827 - * Stores one 👍/👎 rating + optional feedback per chat session.
828 - */
829 -function mxchat_create_session_ratings_table() {
830 - global $wpdb;
831 - $charset_collate = $wpdb->get_charset_collate();
832 -
833 - $table_name = $wpdb->prefix . 'mxchat_session_ratings';
834 - $sql = "CREATE TABLE $table_name (
835 - id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
836 - session_id varchar(255) NOT NULL,
837 - bot_id varchar(50) NOT NULL DEFAULT 'default',
838 - rating_value tinyint(1) NOT NULL,
839 - rating_feedback text DEFAULT NULL,
840 - created_at datetime NOT NULL,
841 - PRIMARY KEY (id),
842 - UNIQUE KEY session_id (session_id),
843 - KEY bot_id (bot_id),
844 - KEY created_at (created_at)
845 - ) $charset_collate;";
846 -
847 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
848 - dbDelta($sql);
849 -}
850 -
851 -/**
852 685 * 2.5.2: Fix URL column size to support long URLs (especially with UTF-8 encoding)
853 686 * This fixes "url, source_url. The supplied values may be too long" errors
854 687 */
855 688 function mxchat_fix_url_column_size() {
@@ -908,9 +741,9 @@
908 741 if (in_array($current_model, $deprecated_claude_models, true)) {
909 742 $options['model'] = 'claude-opus-4-6';
910 743 $migrated = true;
911 744 $migration_message = sprintf(
912 - 'Your chatbot model has been automatically updated from %s to Claude Opus 4.6 due to Anthropic deprecating older Claude models.',
745 + __('Your chatbot model has been automatically updated from %s to Claude Opus 4.6 due to Anthropic deprecating older Claude models.', 'mxchat'),
913 746 $current_model
914 747 );
915 748 }
916 749
@@ -917,9 +750,9 @@
917 750 // Migrate deprecated Claude Haiku 3.5 to Claude Haiku 4.5
918 751 if ($current_model === 'claude-3-5-haiku-20241022') {
919 752 $options['model'] = 'claude-haiku-4-5-20251001';
920 753 $migrated = true;
921 - $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.';
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.', 'mxchat');
922 755 }
923 756
924 757 // Migrate deprecated GPT-4 series and GPT-3.5 Turbo to GPT-5.1 Chat Latest
925 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)) {
@@ -925,9 +758,9 @@
925 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)) {
926 759 $options['model'] = 'gpt-5.1-chat-latest';
927 760 $migrated = true;
928 761 $migration_message = sprintf(
929 - 'Your chatbot model has been automatically updated from %s to GPT-5.1 Chat Latest due to OpenAI deprecating older models.',
762 + __('Your chatbot model has been automatically updated from %s to GPT-5.1 Chat Latest due to OpenAI deprecating older models.', 'mxchat'),
930 763 $current_model
931 764 );
932 765 }
933 766
@@ -935,9 +768,9 @@
935 768 if (in_array($current_model, array('gpt-4o-mini', 'gpt-4.1-mini'), true)) {
936 769 $options['model'] = 'gpt-5-mini';
937 770 $migrated = true;
938 771 $migration_message = sprintf(
939 - 'Your chatbot model has been automatically updated from %s to GPT-5 Mini due to OpenAI deprecating GPT-4 series models.',
772 + __('Your chatbot model has been automatically updated from %s to GPT-5 Mini due to OpenAI deprecating GPT-4 series models.', 'mxchat'),
940 773 $current_model
941 774 );
942 775 }
943 776
@@ -1004,26 +837,13 @@
1004 837 enabled_bots LONGTEXT DEFAULT NULL,
1005 838 PRIMARY KEY (id)
1006 839 ) $charset_collate;";
1007 840
1008 - // Individual Intent Phrases Table - each phrase gets its own embedding vector
1009 - $intent_phrases_table = $wpdb->prefix . 'mxchat_intent_phrases';
1010 - $sql_intent_phrases_table = "CREATE TABLE $intent_phrases_table (
1011 - id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
1012 - intent_id BIGINT(20) UNSIGNED NOT NULL,
1013 - phrase TEXT NOT NULL,
1014 - embedding_vector LONGTEXT NOT NULL,
1015 - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
1016 - PRIMARY KEY (id),
1017 - KEY intent_id (intent_id)
1018 - ) $charset_collate;";
1019 -
1020 841 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
1021 842
1022 843 // Create other tables
1023 844 dbDelta($sql_system_prompt);
1024 845 dbDelta($sql_intents_table);
1025 - dbDelta($sql_intent_phrases_table);
1026 846
1027 847 // Create URL click tracking table
1028 848 mxchat_create_url_clicks_table();
1029 849
@@ -1035,11 +855,8 @@
1035 855
1036 856 // Create transcript translations table
1037 857 mxchat_create_translations_table();
1038 858
1039 - // Create per-session satisfaction ratings table (v3.2.6)
1040 - mxchat_create_session_ratings_table();
1041 -
1042 859 // Ensure additional columns in system prompt table
1043 860 $existing_system_columns = $wpdb->get_results("SHOW COLUMNS FROM $system_prompt_table");
1044 861 if (!empty($existing_system_columns)) {
1045 862 $existing_system_column_names = array_column($existing_system_columns, 'Field');
@@ -1082,11 +899,8 @@
1082 899
1083 900 // Run migration for existing installations
1084 901 mxchat_migrate_pinecone_roles_add_bot_id();
1085 902
1086 - // 3.2.4: Backfill active embedding model option (replaces 3.2.3 column-based tracking)
1087 - mxchat_backfill_active_embedding_model();
1088 -
1089 903 // Setup cron jobs
1090 904 mxchat_setup_cron_jobs();
1091 905
1092 906 // Update version
@@ -1121,14 +935,13 @@
1121 935 // Clear fallback flags if cron scheduling succeeded
1122 936 delete_option('mxchat_use_fallback_rate_limits');
1123 937 }
1124 938
1125 - // Schedule transcript cleanup if configured (bucket dropdown OR custom retention-days > 0)
939 + // Schedule transcript cleanup if configured
1126 940 $transcript_options = get_option('mxchat_transcripts_options', array());
1127 941 $cleanup_interval = isset($transcript_options['mxchat_auto_delete_transcripts']) ? $transcript_options['mxchat_auto_delete_transcripts'] : 'never';
1128 - $custom_retention = isset($transcript_options['mxchat_retention_days']) ? (int) $transcript_options['mxchat_retention_days'] : 0;
1129 -
1130 - if ($cleanup_interval !== 'never' || $custom_retention > 0) {
942 +
943 + if ($cleanup_interval !== 'never') {
1131 944 // Check if not already scheduled
1132 945 if (!wp_next_scheduled('mxchat_cleanup_old_transcripts')) {
1133 946 // Schedule to run daily at 3 AM
1134 947 $next_run = strtotime('tomorrow 3:00 AM');
@@ -1256,20 +1069,8 @@
1256 1069 if (version_compare($current_version, '3.1.2', '<')) {
1257 1070 mxchat_migrate_transcripts_charset();
1258 1071 }
1259 1072
1260 - // 3.1.7: Clean up stale shared session email/name entries
1261 - if (version_compare($current_version, '3.1.7', '<')) {
1262 - delete_option('mxchat_email_null');
1263 - delete_option('mxchat_name_null');
1264 - }
1265 -
1266 - // 3.2.4: Backfill active embedding model option for the warning UI
1267 - // (replaces the per-row column tracking from 3.2.3, which was reverted)
1268 - if (version_compare($current_version, '3.2.4', '<')) {
1269 - mxchat_backfill_active_embedding_model();
1270 - }
1271 -
1272 1073 // Run full activation to ensure everything is up to date
1273 1074 mxchat_activate();
1274 1075
1275 1076 // Run migration functions
@@ -1440,9 +1241,9 @@
1440 1241 // Check if we're upgrading TO 3.0.1 and haven't handled this yet
1441 1242 if (version_compare($current_version, $target_version, '<') && !$update_handled) {
1442 1243 // Check if Pro is activated - only show to Pro users
1443 1244 $license_status = get_option('mxchat_license_status', 'inactive');
1444 - $is_pro = ($license_status === 'active');
1245 + $is_pro = ($license_status === 'active' || $license_status === esc_html__('active', 'mxchat'));
1445 1246
1446 1247 if ($is_pro) {
1447 1248 // Set flag to show the theme migration notification banner
1448 1249 update_option('mxchat_show_theme_migration_notice', true);
@@ -1494,23 +1295,8 @@
1494 1295 if (class_exists('MxChat_Content_Generator')) {
1495 1296 new MxChat_Content_Generator();
1496 1297 }
1497 1298
1498 - // Initialize cache purge globally — settings writes can happen on any
1499 - // request type (admin screens, admin-ajax autosave, wp-cli), and the
1500 - // deferred-purge cron event fires on front-end requests.
1501 - if (class_exists('MxChat_Cache_Purge')) {
1502 - MxChat_Cache_Purge::init();
1503 - }
1504 -
1505 - // Initialize REST API globally — endpoints must be registered on
1506 - // every request (admin and frontend) so they're reachable via /wp-json/.
1507 - // Endpoints are auth-gated and locked until the site owner generates
1508 - // a token in MxChat → API Access.
1509 - if (class_exists('MxChat_Rest_Api')) {
1510 - new MxChat_Rest_Api();
1511 - }
1512 -
1513 1299 // Initialize public classes
1514 1300 if (class_exists('MxChat_Public')) {
1515 1301 $mxchat_public = new MxChat_Public();
1516 1302 }
@@ -1555,25 +1341,11 @@
1555 1341
1556 1342 mxchat_migrate_pinecone_roles_add_bot_id();
1557 1343 mxchat_migrate_add_content_type_column();
1558 1344 mxchat_migrate_add_translations_table();
1559 - mxchat_migrate_add_session_ratings_table();
1560 1345 }
1561 1346
1562 1347 /**
1563 - * Migration: Create per-session satisfaction ratings table (v3.2.6)
1564 - * For users upgrading from versions before 3.2.6
1565 - */
1566 -function mxchat_migrate_add_session_ratings_table() {
1567 - $migration_key = 'mxchat_session_ratings_table_created';
1568 - if (get_option($migration_key)) {
1569 - return;
1570 - }
1571 - mxchat_create_session_ratings_table();
1572 - update_option($migration_key, '3.2.6');
1573 -}
1574 -
1575 -/**
1576 1348 * Migration: Create transcript translations table (v3.0.4)
1577 1349 * For users upgrading from versions before 3.0.4
1578 1350 */
1579 1351 function mxchat_migrate_add_translations_table() {
@@ -1616,67 +1388,5 @@
1616 1388 return $schedules;
1617 1389 });
1618 1390
1619 1391 // Register deactivation hook
1620 -register_deactivation_hook(__FILE__, 'mxchat_deactivate');
1621 -
1622 -/**
1623 - * Per-session satisfaction rating: AJAX save handler (v3.2.6).
1624 - * Records one 👍/👎 + optional feedback per chat session. The UNIQUE KEY on
1625 - * session_id makes this naturally idempotent — only the first rating per
1626 - * session is stored; duplicate POSTs are silent no-ops.
1627 - */
1628 -function mxchat_save_session_rating() {
1629 - global $wpdb;
1630 -
1631 - $session_id = isset($_POST['session_id']) ? sanitize_text_field(wp_unslash($_POST['session_id'])) : '';
1632 - $bot_id = isset($_POST['bot_id']) ? sanitize_text_field(wp_unslash($_POST['bot_id'])) : 'default';
1633 - $rating_raw = isset($_POST['rating']) ? (int) $_POST['rating'] : 0;
1634 - $feedback = isset($_POST['feedback']) ? sanitize_textarea_field(wp_unslash($_POST['feedback'])) : '';
1635 -
1636 - if ($session_id === '' || ($rating_raw !== 1 && $rating_raw !== -1)) {
1637 - wp_send_json_error(array('message' => 'invalid_input'), 400);
1638 - }
1639 -
1640 - if (strlen($feedback) > 1000) {
1641 - $feedback = substr($feedback, 0, 1000);
1642 - }
1643 -
1644 - $table_name = $wpdb->prefix . 'mxchat_session_ratings';
1645 - $existing = $wpdb->get_var($wpdb->prepare(
1646 - "SELECT id FROM $table_name WHERE session_id = %s LIMIT 1",
1647 - $session_id
1648 - ));
1649 -
1650 - if ($existing) {
1651 - if ($feedback !== '') {
1652 - $wpdb->update(
1653 - $table_name,
1654 - array('rating_feedback' => $feedback),
1655 - array('id' => (int) $existing),
1656 - array('%s'),
1657 - array('%d')
1658 - );
1659 - }
1660 - wp_send_json_success(array('updated' => true));
1661 - }
1662 -
1663 - $inserted = $wpdb->insert(
1664 - $table_name,
1665 - array(
1666 - 'session_id' => $session_id,
1667 - 'bot_id' => $bot_id !== '' ? $bot_id : 'default',
1668 - 'rating_value' => $rating_raw,
1669 - 'rating_feedback' => $feedback !== '' ? $feedback : null,
1670 - 'created_at' => current_time('mysql'),
1671 - ),
1672 - array('%s', '%s', '%d', '%s', '%s')
1673 - );
1674 -
1675 - if ($inserted === false) {
1676 - wp_send_json_error(array('message' => 'db_insert_failed'), 500);
1677 - }
1678 -
1679 - wp_send_json_success(array('saved' => true));
1680 -}
1681 -add_action('wp_ajax_mxchat_save_rating', 'mxchat_save_session_rating');
1682 -add_action('wp_ajax_nopriv_mxchat_save_rating', 'mxchat_save_session_rating');
1392 +register_deactivation_hook(__FILE__, 'mxchat_deactivate');