PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.0.0
MxChat – AI Chatbot & Content Generation for WordPress v2.0.0
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 / includes / class-mxchat-addons.php

class-mxchat-addons.php in MxChat – AI Chatbot & Content Generation for WordPress 2.0.0, at includes/class-mxchat-addons.php

154 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality for the Add Ons page.
4 *
5 * @package MxChat
6 * @subpackage MxChat/admin
7 */
8 class MxChat_Addons {
9 /**
10 * Store add-on configuration data
11 *
12 * @var array
13 */
14 private $addons_config;
15
16 /**
17 * Initialize the class and set its properties.
18 */
19 public function __construct() {
20 $this->addons_config = array(
21 'mxchat-pinecone' => array(
22 'title' => __('Pinecone DB Manager', 'mxchat'),
23 'description' => __('Seamlessly manage your vectorized content in Pinecone\'s vector database directly from your WordPress dashboard. This integration provides an efficient alternative to the default WordPress database storage.', 'mxchat'),
24 'license' => 'free',
25 'accent' => '#fa73e6',
26 'url' => 'https://quickdeploywp.com/plugin/mxchat-pinecone/',
27 'plugin_file' => 'mxchat-pinecone/pinecone-manager.php',
28 'config_page' => 'mxchat-pinecone'
29 ),
30 );
31 }
32
33 /**
34 * Register the stylesheets for the admin area.
35 */
36 public function enqueue_styles() {
37 $plugin_version = '2.0.0';
38
39 wp_enqueue_style(
40 'mxchat-addons',
41 plugin_dir_url(__FILE__) . '../css/admin-add-ons.css',
42 array(),
43 $plugin_version,
44 'all'
45 );
46 }
47
48 /**
49 * Check if an addon is installed and active
50 *
51 * @param string $plugin_file The plugin's main file path
52 * @return array Status information
53 */
54 private function get_addon_status($plugin_file) {
55 if (!function_exists('get_plugins')) {
56 require_once ABSPATH . 'wp-admin/includes/plugin.php';
57 }
58
59 $all_plugins = get_plugins();
60 $active_plugins = get_option('active_plugins', array());
61
62 // Find the addon by iterating through configs
63 $config_page = '';
64 foreach ($this->addons_config as $slug => $addon) {
65 if ($addon['plugin_file'] === $plugin_file) {
66 $config_page = $addon['config_page'];
67 break;
68 }
69 }
70
71 if (isset($all_plugins[$plugin_file])) {
72 if (in_array($plugin_file, $active_plugins)) {
73 return array(
74 'status' => 'active',
75 'action_url' => admin_url('admin.php?page=' . $config_page),
76 'action_text' => __('Configure', 'mxchat')
77 );
78 } else {
79 return array(
80 'status' => 'inactive',
81 'action_url' => wp_nonce_url(
82 admin_url('plugins.php?action=activate&plugin=' . $plugin_file),
83 'activate-plugin_' . $plugin_file
84 ),
85 'action_text' => __('Activate', 'mxchat')
86 );
87 }
88 }
89
90 return array(
91 'status' => 'not-installed',
92 'action_url' => '',
93 'action_text' => __('Get Extension', 'mxchat')
94 );
95 }
96
97 /**
98 * Render the Add Ons page content.
99 */
100 public function render_page() {
101 $this->enqueue_styles();
102 ?>
103 <div class="wrap mxchat-addons-wrapper">
104 <div class="mxchat-addons-hero">
105 <h1 class="mxchat-main-title">
106 <span class="mxchat-gradient-text">Power Up</span> Your Chatbot
107 </h1>
108 <p class="mxchat-hero-subtitle">
109 <?php esc_html_e('Enhance your chatbot with premium & free extensions available through QuickDeployWP, an official distribution platform made by MxChat.', 'mxchat'); ?>
110 </p>
111 </div>
112 <div class="mxchat-addons-grid">
113 <?php
114 foreach ($this->addons_config as $slug => $addon) {
115 $this->render_addon_card($slug, $addon);
116 }
117 ?>
118 </div>
119 </div>
120 <?php
121 }
122
123 /**
124 * Render individual add-on card
125 *
126 * @param string $slug The addon slug
127 * @param array $addon The addon configuration array
128 */
129 private function render_addon_card($slug, $addon) {
130 $status_info = $this->get_addon_status($addon['plugin_file']);
131 $button_url = $status_info['status'] === 'not-installed' ? $addon['url'] : $status_info['action_url'];
132 $button_target = $status_info['status'] === 'not-installed' ? '_blank' : '_self';
133 ?>
134 <div class="mxchat-addon-card" style="--card-accent: <?php echo esc_attr($addon['accent']); ?>">
135 <div class="mxchat-addon-badge"><?php echo esc_html(ucfirst($addon['license'])); ?></div>
136 <div class="mxchat-addon-content">
137 <h3 class="mxchat-addon-title"><?php echo esc_html($addon['title']); ?></h3>
138 <p class="mxchat-addon-description"><?php echo esc_html($addon['description']); ?></p>
139 <div class="mxchat-addon-footer">
140 <div class="mxchat-status-indicator <?php echo esc_attr($status_info['status']); ?>">
141 <?php echo esc_html(ucfirst(str_replace('-', ' ', $status_info['status']))); ?>
142 </div>
143 <a href="<?php echo esc_url($button_url); ?>"
144 class="mxchat-action-button"
145 target="<?php echo esc_attr($button_target); ?>"
146 data-action="<?php echo esc_attr($status_info['status']); ?>">
147 <?php echo esc_html($status_info['action_text']); ?>
148 </a>
149 </div>
150 </div>
151 </div>
152 <?php
153 }
154 }