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

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