PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 1.5.2
MxChat – AI Chatbot & Content Generation for WordPress v1.5.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.5.2, at mxchat-basic.php

120 lines 4.7 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.5.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
25 function mxchat_activate() {
26 global $wpdb;
27 $charset_collate = $wpdb->get_charset_collate();
28
29 // Chat Transcripts Table
30 $chat_transcripts_table = $wpdb->prefix . 'mxchat_chat_transcripts';
31 $sql_chat_transcripts = "CREATE TABLE $chat_transcripts_table (
32 id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
33 user_id MEDIUMINT(9) DEFAULT 0,
34 session_id VARCHAR(255) NOT NULL,
35 role VARCHAR(255) NOT NULL,
36 message TEXT NOT NULL,
37 timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
38 PRIMARY KEY (id)
39 ) $charset_collate;";
40
41 // System Prompt Content Table
42 $system_prompt_table = $wpdb->prefix . 'mxchat_system_prompt_content';
43 $sql_system_prompt = "CREATE TABLE $system_prompt_table (
44 id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
45 url VARCHAR(255) NOT NULL,
46 article_content LONGTEXT NOT NULL,
47 embedding_vector LONGTEXT,
48 source_url VARCHAR(255) DEFAULT NULL,
49 timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
50 PRIMARY KEY (id)
51 ) $charset_collate;";
52
53 // Intents Table
54 $intents_table = $wpdb->prefix . 'mxchat_intents';
55 $sql_intents_table = "CREATE TABLE $intents_table (
56 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
57 intent_label VARCHAR(255) NOT NULL,
58 phrases TEXT NOT NULL,
59 embedding_vector LONGTEXT NOT NULL,
60 callback_function VARCHAR(255) NOT NULL,
61 similarity_threshold FLOAT DEFAULT 0.85,
62 PRIMARY KEY (id)
63 ) $charset_collate;";
64
65 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
66
67 // Create or update tables
68 dbDelta($sql_chat_transcripts);
69 dbDelta($sql_system_prompt);
70 dbDelta($sql_intents_table);
71
72 // Ensure additional columns in `mxchat_system_prompt_content` and `mxchat_chat_transcripts`
73 mxchat_add_missing_columns($system_prompt_table, 'embedding_vector', 'LONGTEXT');
74 mxchat_add_missing_columns($system_prompt_table, 'source_url', 'VARCHAR(255) DEFAULT NULL');
75 mxchat_add_missing_columns($chat_transcripts_table, 'user_identifier', 'VARCHAR(255)');
76 mxchat_add_missing_columns($chat_transcripts_table, 'user_email', 'VARCHAR(255)');
77
78 // Set default thresholds for existing intents
79 $wpdb->query("UPDATE {$intents_table} SET similarity_threshold = 0.85 WHERE similarity_threshold IS NULL");
80
81 // Update plugin version in the database
82 update_option('mxchat_plugin_version', '1.5.2');
83 }
84
85 function mxchat_add_missing_columns($table, $column_name, $column_type) {
86 global $wpdb;
87 $column_exists = $wpdb->get_results($wpdb->prepare("SHOW COLUMNS FROM $table LIKE %s", $column_name));
88 if (empty($column_exists)) {
89 $wpdb->query("ALTER TABLE $table ADD COLUMN $column_name $column_type");
90 }
91 }
92
93 function mxchat_check_for_update() {
94 $current_version = get_option('mxchat_plugin_version');
95 $plugin_version = '1.5.2';
96
97 if ($current_version !== $plugin_version) {
98 mxchat_activate(); // Run the activation script which includes database migrations
99 update_option('mxchat_plugin_version', $plugin_version); // Update to the latest version
100 }
101 }
102
103 // Run the update check function on every request
104 add_action('plugins_loaded', 'mxchat_check_for_update');
105
106 // Register activation hook
107 register_activation_hook(__FILE__, 'mxchat_activate');
108
109 add_action('init', function() {
110 add_action('mxchat_process_pdf_pages', array('MxChat_Admin', 'process_pdf_pages_cron'), 10, 5);
111 add_action('mxchat_process_sitemap_urls', array('MxChat_Admin', 'process_sitemap_urls_cron'), 10, 5);
112 });
113
114 // Instantiate classes
115 if (is_admin()) {
116 $mxchat_admin = new MxChat_Admin();
117 }
118 $mxchat_public = new MxChat_Public();
119 $mxchat_integrator = new MxChat_Integrator();
120