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

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