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

106 lines 3.6 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.5
6 * Author: Maxwell Runion
7 * License: GPLv2 or later
8 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
9 */
10
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly.
13 }
14
15 // Include classes
16 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-integrator.php';
17 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-admin.php';
18 require_once plugin_dir_path(__FILE__) . 'includes/class-mxchat-public.php';
19
20 function mxchat_activate() {
21 global $wpdb;
22
23 // Chat Transcripts Table
24 $chat_transcripts_table = $wpdb->prefix . 'mxchat_chat_transcripts';
25 $sql_chat_transcripts = "CREATE TABLE $chat_transcripts_table (
26 id mediumint(9) NOT NULL AUTO_INCREMENT,
27 user_id mediumint(9) DEFAULT 0,
28 session_id varchar(255) NOT NULL,
29 role varchar(255) NOT NULL,
30 message text NOT NULL,
31 timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
32 PRIMARY KEY (id)
33 );";
34
35 // System Prompt Content Table
36 $system_prompt_table = $wpdb->prefix . 'mxchat_system_prompt_content';
37 $sql_system_prompt = "CREATE TABLE $system_prompt_table (
38 id mediumint(9) NOT NULL AUTO_INCREMENT,
39 url varchar(255) NOT NULL,
40 article_content longtext NOT NULL,
41 embedding_vector longtext,
42 timestamp timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
43 PRIMARY KEY (id)
44 );";
45
46 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
47
48 // Create or update the chat transcripts table
49 dbDelta($sql_chat_transcripts);
50
51 // Create or update the system prompt content table
52 dbDelta($sql_system_prompt);
53
54 // Ensure 'embedding_vector' column exists in the 'system_prompt_content' table
55 $column_exists = $wpdb->get_results($wpdb->prepare(
56 "SHOW COLUMNS FROM %s LIKE %s",
57 $system_prompt_table,
58 'embedding_vector'
59 ));
60 if (empty($column_exists)) {
61 $wpdb->query($wpdb->prepare(
62 "ALTER TABLE %s ADD COLUMN embedding_vector longtext",
63 $system_prompt_table
64 ));
65 }
66
67 // Ensure 'source_url' column exists in the 'system_prompt_content' table
68 $source_url_exists = $wpdb->get_results($wpdb->prepare(
69 "SHOW COLUMNS FROM %s LIKE %s",
70 $system_prompt_table,
71 'source_url'
72 ));
73 if (empty($source_url_exists)) {
74 $wpdb->query($wpdb->prepare(
75 "ALTER TABLE %s ADD COLUMN source_url VARCHAR(255) DEFAULT NULL",
76 $system_prompt_table
77 ));
78 }
79
80 // Update the version number in the database
81 update_option('mxchat_plugin_version', '1.0.4');
82 }
83
84 function mxchat_check_for_update() {
85 $current_version = get_option('mxchat_plugin_version');
86 $plugin_version = '1.0.4';
87
88 if ($current_version !== $plugin_version) {
89 mxchat_activate(); // Run the activation script which includes database migrations
90 update_option('mxchat_plugin_version', $plugin_version); // Update to the latest version
91 }
92 }
93
94 // Run the update check function on every request
95 add_action('plugins_loaded', 'mxchat_check_for_update');
96
97 // Register activation hook
98 register_activation_hook(__FILE__, 'mxchat_activate');
99
100 // Instantiate classes
101 if (is_admin()) {
102 $mxchat_admin = new MxChat_Admin();
103 }
104 $mxchat_public = new MxChat_Public();
105 $mxchat_integrator = new MxChat_Integrator();
106