PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 1.6.2
MxChat – AI Chatbot & Content Generation for WordPress v1.6.2
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
mxchat-basic / mxchat-basic.php

mxchat-basic.php in MxChat – AI Chatbot & Content Generation for WordPress 1.6.2, at mxchat-basic.php

159 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: MxChat
4 * Description: AI chatbot for WordPress with OpenAI, Claude, xAI, live agent transfer, PDF uploads, WooCommerce, and training on website data.
5 * Version: 1.6.2
6 * Author: MxChat
7 * Author URI: https://mxchat.ai
8 * License: GPLv2 or later
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if (!defined('ABSPATH')) {
13 exit; // Exit if accessed directly.
14 }
15
16 // Include classes
17 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-integrator.php';
18 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-admin.php';
19 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-public.php';
20 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-utils.php';
21 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-user.php';
22 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-woocommerce.php';
23 require_once plugin_dir_path(__FILE__) . 'includes/pdf-parser/alt_autoload.php';
24 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-word-handler.php';
25
26 function mxchat_activate() {
27 global $wpdb;
28 $charset_collate = $wpdb->get_charset_collate();
29
30 // Chat Transcripts Table
31 $chat_transcripts_table = $wpdb->prefix . 'mxchat_chat_transcripts';
32 $sql_chat_transcripts = "CREATE TABLE $chat_transcripts_table (
33 id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
34 user_id MEDIUMINT(9) DEFAULT 0,
35 session_id VARCHAR(255) NOT NULL,
36 role VARCHAR(255) NOT NULL,
37 message TEXT NOT NULL,
38 user_email VARCHAR(255) DEFAULT NULL,
39 timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
40 PRIMARY KEY (id)
41 ) $charset_collate;";
42
43 // System Prompt Content Table
44 $system_prompt_table = $wpdb->prefix . 'mxchat_system_prompt_content';
45 $sql_system_prompt = "CREATE TABLE $system_prompt_table (
46 id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
47 url VARCHAR(255) NOT NULL,
48 article_content LONGTEXT NOT NULL,
49 embedding_vector LONGTEXT,
50 source_url VARCHAR(255) DEFAULT NULL,
51 timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
52 PRIMARY KEY (id)
53 ) $charset_collate;";
54
55 // Intents Table
56 $intents_table = $wpdb->prefix . 'mxchat_intents';
57 $sql_intents_table = "CREATE TABLE $intents_table (
58 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
59 intent_label VARCHAR(255) NOT NULL,
60 phrases TEXT NOT NULL,
61 embedding_vector LONGTEXT NOT NULL,
62 callback_function VARCHAR(255) NOT NULL,
63 similarity_threshold FLOAT DEFAULT 0.85,
64 PRIMARY KEY (id)
65 ) $charset_collate;";
66
67 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
68
69 // Create or update tables
70 dbDelta($sql_chat_transcripts);
71 dbDelta($sql_system_prompt);
72 dbDelta($sql_intents_table);
73
74 // Ensure additional columns in `mxchat_chat_transcripts`
75 mxchat_add_missing_columns($chat_transcripts_table, 'user_identifier', 'VARCHAR(255)');
76 mxchat_add_missing_columns($chat_transcripts_table, 'user_email', 'VARCHAR(255) DEFAULT NULL');
77
78 // Ensure additional columns in `mxchat_system_prompt_content`
79 mxchat_add_missing_columns($system_prompt_table, 'embedding_vector', 'LONGTEXT');
80 mxchat_add_missing_columns($system_prompt_table, 'source_url', 'VARCHAR(255) DEFAULT NULL');
81
82 // Set default thresholds for existing intents
83 $wpdb->query("UPDATE {$intents_table} SET similarity_threshold = 0.85 WHERE similarity_threshold IS NULL");
84
85 // Update plugin version in the database
86 update_option('mxchat_plugin_version', '1.6.2');
87 }
88
89
90 function mxchat_add_missing_columns($table, $column_name, $column_type) {
91 global $wpdb;
92 $column_exists = $wpdb->get_results($wpdb->prepare("SHOW COLUMNS FROM $table LIKE %s", $column_name));
93 if (empty($column_exists)) {
94 $wpdb->query("ALTER TABLE $table ADD COLUMN $column_name $column_type");
95 }
96 }
97
98 function mxchat_check_for_update() {
99 $current_version = get_option('mxchat_plugin_version');
100 $plugin_version = '1.6.2'; // Update with your latest version
101
102 if ($current_version !== $plugin_version) {
103 mxchat_activate(); // Run the activation script to apply schema changes
104 mxchat_migrate_live_agent_status(); // Add migration for live agent status
105 update_option('mxchat_plugin_version', $plugin_version); // Update the version
106 }
107 }
108
109 function mxchat_migrate_live_agent_status() {
110 $options = get_option('mxchat_options', []);
111
112 // Check if live_agent_status exists
113 if (isset($options['live_agent_status'])) {
114 $current_status = $options['live_agent_status'];
115 $needs_update = false;
116
117 // Convert to new format if needed
118 if ($current_status === 'online') {
119 $options['live_agent_status'] = 'on';
120 $needs_update = true;
121 } else if ($current_status === 'offline') {
122 $options['live_agent_status'] = 'off';
123 $needs_update = true;
124 } else if (!in_array($current_status, ['on', 'off'])) {
125 // Default to off for any unexpected values
126 $options['live_agent_status'] = 'off';
127 $needs_update = true;
128 }
129
130 // Only update if needed
131 if ($needs_update) {
132 update_option('mxchat_options', $options);
133 }
134 } else {
135 // If status doesn't exist, set default to off
136 $options['live_agent_status'] = 'off';
137 update_option('mxchat_options', $options);
138 }
139 }
140
141
142 // Run the update check function on every request
143 add_action('plugins_loaded', 'mxchat_check_for_update');
144
145 // Register activation hook
146 register_activation_hook(__FILE__, 'mxchat_activate');
147
148 add_action('init', function() {
149 add_action('mxchat_process_pdf_pages', array('MxChat_Admin', 'process_pdf_pages_cron'), 10, 5);
150 add_action('mxchat_process_sitemap_urls', array('MxChat_Admin', 'process_sitemap_urls_cron'), 10, 5);
151 });
152
153 // Instantiate classes
154 if (is_admin()) {
155 $mxchat_admin = new MxChat_Admin();
156 }
157 $mxchat_public = new MxChat_Public();
158 $mxchat_integrator = new MxChat_Integrator();
159