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

127 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 support for OpenAI, X.AI, and Claude models. Includes features like custom knowledge submission, chat transcripts, and seamless integration with WooCommerce. Perfect for blogs, business sites, e-commerce platforms, and more, offering real-time intelligent interactions with advanced AI models.
5 * Version: 1.1.9
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
24 function mxchat_activate() {
25 global $wpdb;
26
27 // Chat Transcripts Table
28 $chat_transcripts_table = $wpdb->prefix . 'mxchat_chat_transcripts';
29 $sql_chat_transcripts = "CREATE TABLE $chat_transcripts_table (
30 id mediumint(9) NOT NULL AUTO_INCREMENT,
31 user_id mediumint(9) DEFAULT 0,
32 session_id varchar(255) NOT NULL,
33 role varchar(255) NOT NULL,
34 message text NOT NULL,
35 timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
36 PRIMARY KEY (id)
37 );";
38
39 // System Prompt Content Table
40 $system_prompt_table = $wpdb->prefix . 'mxchat_system_prompt_content';
41 $sql_system_prompt = "CREATE TABLE $system_prompt_table (
42 id mediumint(9) NOT NULL AUTO_INCREMENT,
43 url varchar(255) NOT NULL,
44 article_content longtext NOT NULL,
45 embedding_vector longtext,
46 timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
47 PRIMARY KEY (id)
48 );";
49
50 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
51
52 // Create or update the chat transcripts table
53 dbDelta($sql_chat_transcripts);
54
55 // Create or update the system prompt content table
56 dbDelta($sql_system_prompt);
57
58 // Ensure 'embedding_vector' column exists in the 'system_prompt_content' table
59 $column_exists = $wpdb->get_results($wpdb->prepare(
60 "SHOW COLUMNS FROM {$system_prompt_table} LIKE %s",
61 'embedding_vector'
62 ));
63 if (empty($column_exists)) {
64 $wpdb->query(
65 "ALTER TABLE {$system_prompt_table} ADD COLUMN embedding_vector longtext"
66 );
67 }
68
69 // Ensure 'source_url' column exists in the 'system_prompt_content' table
70 $source_url_exists = $wpdb->get_results($wpdb->prepare(
71 "SHOW COLUMNS FROM {$system_prompt_table} LIKE %s",
72 'source_url'
73 ));
74 if (empty($source_url_exists)) {
75 $wpdb->query(
76 "ALTER TABLE {$system_prompt_table} ADD COLUMN source_url VARCHAR(255) DEFAULT NULL"
77 );
78 }
79
80 // Ensure 'user_identifier' and 'user_email' columns exist in the 'chat_transcripts' table
81 $user_identifier_exists = $wpdb->get_results($wpdb->prepare(
82 "SHOW COLUMNS FROM {$chat_transcripts_table} LIKE %s",
83 'user_identifier'
84 ));
85 if (empty($user_identifier_exists)) {
86 $wpdb->query(
87 "ALTER TABLE {$chat_transcripts_table} ADD COLUMN user_identifier VARCHAR(255)"
88 );
89 }
90
91 $user_email_exists = $wpdb->get_results($wpdb->prepare(
92 "SHOW COLUMNS FROM {$chat_transcripts_table} LIKE %s",
93 'user_email'
94 ));
95 if (empty($user_email_exists)) {
96 $wpdb->query(
97 "ALTER TABLE {$chat_transcripts_table} ADD COLUMN user_email VARCHAR(255)"
98 );
99 }
100
101 // Update the version number in the database
102 update_option('mxchat_plugin_version', '1.1.8');
103 }
104
105 function mxchat_check_for_update() {
106 $current_version = get_option('mxchat_plugin_version');
107 $plugin_version = '1.1.8';
108
109 if ($current_version !== $plugin_version) {
110 mxchat_activate(); // Run the activation script which includes database migrations
111 update_option('mxchat_plugin_version', $plugin_version); // Update to the latest version
112 }
113 }
114
115 // Run the update check function on every request
116 add_action('plugins_loaded', 'mxchat_check_for_update');
117
118 // Register activation hook
119 register_activation_hook(__FILE__, 'mxchat_activate');
120
121 // Instantiate classes
122 if (is_admin()) {
123 $mxchat_admin = new MxChat_Admin();
124 }
125 $mxchat_public = new MxChat_Public();
126 $mxchat_integrator = new MxChat_Integrator();
127