| 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-intent-tester' => array( |
| 22 |
'title' => __('MxChat Similarity Tester', 'mxchat'), |
| 23 |
'description' => __('See exactly how your chatbot thinks. Visualize intent matches and similarity scores to optimize accuracy and understand AI decision-making. Essential for fine-tuning your responses.', 'mxchat'), |
| 24 |
'key_benefits' => array( |
| 25 |
__('Reveal top 10 knowledge matches', 'mxchat'), |
| 26 |
__('Optimize response accuracy', 'mxchat'), |
| 27 |
__('Debug AI decision patterns', 'mxchat') |
| 28 |
), |
| 29 |
'license' => 'free', |
| 30 |
'accent' => '#fa73e6', |
| 31 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-intent-tester/', |
| 32 |
'plugin_file' => 'mxchat-intent-tester/mxchat-intent-tester.php', |
| 33 |
'config_page' => 'mxchat-intent-tester' |
| 34 |
), |
| 35 |
'mxchat-pinecone' => array( |
| 36 |
'title' => __('Pinecone DB Manager (Deprecated)', 'mxchat'), |
| 37 |
'description' => __('This add-on has been sunsetted and is now included directly in the core MxChat plugin. Find Pinecone settings under the Knowledge tab in Pinecone Settings.', 'mxchat'), |
| 38 |
'key_benefits' => array( |
| 39 |
__('Now integrated into core plugin', 'mxchat'), |
| 40 |
__('Access via Knowledge tab', 'mxchat'), |
| 41 |
__('No separate installation needed', 'mxchat') |
| 42 |
), |
| 43 |
'license' => 'free', |
| 44 |
'accent' => '#fa73e6', |
| 45 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-pinecone/', |
| 46 |
'plugin_file' => 'mxchat-pinecone/pinecone-manager.php', |
| 47 |
'config_page' => 'mxchat-pinecone', |
| 48 |
'status' => 'deprecated' |
| 49 |
), |
| 50 |
'mxchat-admin-assistant' => array( |
| 51 |
'title' => __('MxChat Admin Assistant', 'mxchat'), |
| 52 |
'description' => __('Your AI powerhouse inside WordPress. Chat with multiple AI models, generate images, research the web, and boost productivity—all without leaving your dashboard.', 'mxchat'), |
| 53 |
'key_benefits' => array( |
| 54 |
__('ChatGPT-like admin interface', 'mxchat'), |
| 55 |
__('Generate images & research web', 'mxchat'), |
| 56 |
__('Searchable chat history', 'mxchat') |
| 57 |
), |
| 58 |
'license' => 'MxChat PRO', |
| 59 |
'accent' => '#fa73e6', |
| 60 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-admin-assistant/', |
| 61 |
'plugin_file' => 'mxchat-admin-chat/mxchat-admin-chat.php', |
| 62 |
'config_page' => 'mxchat-admin-chat' |
| 63 |
), |
| 64 |
'mxchat-forms' => array( |
| 65 |
'title' => __('MxChat Forms', 'mxchat'), |
| 66 |
'description' => __('Convert conversations into data collection. Create smart forms that trigger during chats, collect user information, and turn casual visitors into qualified leads.', 'mxchat'), |
| 67 |
'key_benefits' => array( |
| 68 |
__('No-code form builder', 'mxchat'), |
| 69 |
__('Intent-triggered activation', 'mxchat'), |
| 70 |
__('Export lead data easily', 'mxchat') |
| 71 |
), |
| 72 |
'license' => 'MxChat PRO', |
| 73 |
'accent' => '#fa73e6', |
| 74 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-forms/', |
| 75 |
'plugin_file' => 'mxchat-forms/mxchat-forms.php', |
| 76 |
'config_page' => 'mxchat-forms' |
| 77 |
), |
| 78 |
'mxchat-smart-recommender' => array( |
| 79 |
'title' => __('MxChat Smart Recommender', 'mxchat'), |
| 80 |
'description' => __('Turn your chatbot into a sales machine. Build personalized recommendation flows that understand user preferences and suggest perfect products or services.', 'mxchat'), |
| 81 |
'key_benefits' => array( |
| 82 |
__('Increase conversion rates', 'mxchat'), |
| 83 |
__('Custom recommendation flows', 'mxchat'), |
| 84 |
__('No coding required', 'mxchat') |
| 85 |
), |
| 86 |
'license' => 'MxChat PRO', |
| 87 |
'accent' => '#fa73e6', |
| 88 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-smart-recommender/', |
| 89 |
'plugin_file' => 'mxchat-smart-recommender/mxchat-smart-recommender.php', |
| 90 |
'config_page' => 'mxchat-smart-recommender' |
| 91 |
), |
| 92 |
'mxchat-woo' => array( |
| 93 |
'title' => __('MxChat WooCommerce', 'mxchat'), |
| 94 |
'description' => __('Boost sales with AI-powered shopping assistance. Help customers find products, manage carts, and complete purchases—all through natural conversation.', 'mxchat'), |
| 95 |
'key_benefits' => array( |
| 96 |
__('Smart product recommendations', 'mxchat'), |
| 97 |
__('Cart & checkout assistance', 'mxchat'), |
| 98 |
__('Order history access', 'mxchat') |
| 99 |
), |
| 100 |
'license' => 'MxChat PRO', |
| 101 |
'accent' => '#fa73e6', |
| 102 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-woo/', |
| 103 |
'plugin_file' => 'mxchat-woo/mxchat-woo.php', |
| 104 |
'config_page' => 'mxchat-woo' |
| 105 |
), |
| 106 |
'mxchat-theme' => array( |
| 107 |
'title' => __('MxChat Theme Customizer', 'mxchat'), |
| 108 |
'description' => __('Make your chatbot uniquely yours. Customize colors, styles, and appearance with live previews—zero coding required. Perfect for matching your brand identity.', 'mxchat'), |
| 109 |
'key_benefits' => array( |
| 110 |
__('Live preview customizer', 'mxchat'), |
| 111 |
__('Point-and-click simplicity', 'mxchat'), |
| 112 |
__('Brand-perfect styling', 'mxchat') |
| 113 |
), |
| 114 |
'license' => 'MxChat PRO', |
| 115 |
'accent' => '#fa73e6', |
| 116 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-theme/', |
| 117 |
'plugin_file' => 'mxchat-theme/mxchat-theme.php', |
| 118 |
'config_page' => 'mxchat-theme-settings' |
| 119 |
), |
| 120 |
'mxchat-perplexity' => array( |
| 121 |
'title' => __('MxChat Perplexity', 'mxchat'), |
| 122 |
'description' => __('Give your chatbot real-time knowledge. Add powerful web search capabilities so your bot can answer questions about current events and time-sensitive information.', 'mxchat'), |
| 123 |
'key_benefits' => array( |
| 124 |
__('Real-time web search', 'mxchat'), |
| 125 |
__('Intent-triggered research', 'mxchat'), |
| 126 |
__('Up-to-date information', 'mxchat') |
| 127 |
), |
| 128 |
'license' => 'MxChat PRO', |
| 129 |
'accent' => '#fa73e6', |
| 130 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-perplexity/', |
| 131 |
'plugin_file' => 'mxchat-perplexity/mxchat-perplexity.php', |
| 132 |
'config_page' => 'mxchat-perplexity' |
| 133 |
), |
| 134 |
'mxchat-moderation' => array( |
| 135 |
'title' => __('MxChat Moderation', 'mxchat'), |
| 136 |
'description' => __('Keep your chat clean and professional. Block unwanted users, filter inappropriate content, and ensure your chatbot represents your brand properly.', 'mxchat'), |
| 137 |
'key_benefits' => array( |
| 138 |
__('IP & email-based blocking', 'mxchat'), |
| 139 |
__('Content filtering', 'mxchat'), |
| 140 |
__('Spam protection', 'mxchat') |
| 141 |
), |
| 142 |
'license' => 'MxChat PRO', |
| 143 |
'accent' => '#fa73e6', |
| 144 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-moderation/', |
| 145 |
'plugin_file' => 'mxchat-moderation/mx-chat-moderation.php', |
| 146 |
'config_page' => 'mx-chat-moderation' |
| 147 |
), |
| 148 |
); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Register the stylesheets for the admin area. |
| 153 |
*/ |
| 154 |
public function enqueue_styles() { |
| 155 |
$plugin_version = '2.2.6'; |
| 156 |
|
| 157 |
wp_enqueue_style( |
| 158 |
'mxchat-addons', |
| 159 |
plugin_dir_url(__FILE__) . '../css/admin-add-ons.css', |
| 160 |
array(), |
| 161 |
$plugin_version, |
| 162 |
'all' |
| 163 |
); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Check if an addon is installed and active |
| 168 |
* |
| 169 |
* @param string $plugin_file The plugin's main file path |
| 170 |
* @return array Status information |
| 171 |
*/ |
| 172 |
private function get_addon_status($plugin_file) { |
| 173 |
if (!function_exists('get_plugins')) { |
| 174 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 175 |
} |
| 176 |
|
| 177 |
$all_plugins = get_plugins(); |
| 178 |
$active_plugins = get_option('active_plugins', array()); |
| 179 |
|
| 180 |
// Find the addon by iterating through configs |
| 181 |
$config_page = ''; |
| 182 |
foreach ($this->addons_config as $slug => $addon) { |
| 183 |
if ($addon['plugin_file'] === $plugin_file) { |
| 184 |
$config_page = $addon['config_page']; |
| 185 |
break; |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
if (isset($all_plugins[$plugin_file])) { |
| 190 |
if (in_array($plugin_file, $active_plugins)) { |
| 191 |
return array( |
| 192 |
'status' => 'active', |
| 193 |
'action_url' => admin_url('admin.php?page=' . $config_page), |
| 194 |
'action_text' => __('Configure', 'mxchat') |
| 195 |
); |
| 196 |
} else { |
| 197 |
return array( |
| 198 |
'status' => 'inactive', |
| 199 |
'action_url' => wp_nonce_url( |
| 200 |
admin_url('plugins.php?action=activate&plugin=' . $plugin_file), |
| 201 |
'activate-plugin_' . $plugin_file |
| 202 |
), |
| 203 |
'action_text' => __('Activate', 'mxchat') |
| 204 |
); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
return array( |
| 209 |
'status' => 'not-installed', |
| 210 |
'action_url' => '', |
| 211 |
'action_text' => __('Get Extension', 'mxchat') |
| 212 |
); |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Render the Add Ons page content. |
| 217 |
*/ |
| 218 |
public function render_page() { |
| 219 |
$this->enqueue_styles(); |
| 220 |
$sorted_addons = array(); |
| 221 |
|
| 222 |
// Put free add-ons first, then pro add-ons |
| 223 |
foreach ($this->addons_config as $slug => $addon) { |
| 224 |
if ($addon['license'] === 'free') { |
| 225 |
$sorted_addons[$slug] = $addon; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
foreach ($this->addons_config as $slug => $addon) { |
| 230 |
if ($addon['license'] !== 'free') { |
| 231 |
$sorted_addons[$slug] = $addon; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
?> |
| 236 |
<div class="wrap mxchat-addons-wrapper"> |
| 237 |
<div class="mxchat-addons-hero"> |
| 238 |
<h1 class="mxchat-main-title"> |
| 239 |
<span class="mxchat-gradient-text">Power Up</span> Your Chatbot |
| 240 |
</h1> |
| 241 |
<p class="mxchat-hero-subtitle"> |
| 242 |
<?php esc_html_e('Supercharge your WordPress AI chatbot with these powerful extensions. Start with our free add-ons or upgrade for premium features.', 'mxchat'); ?> |
| 243 |
</p> |
| 244 |
</div> |
| 245 |
|
| 246 |
<div class="mxchat-addons-section"> |
| 247 |
<div class="mxchat-addons-grid"> |
| 248 |
<?php foreach ($sorted_addons as $slug => $addon): ?> |
| 249 |
<?php $this->render_addon_card($slug, $addon); ?> |
| 250 |
<?php endforeach; ?> |
| 251 |
</div> |
| 252 |
</div> |
| 253 |
|
| 254 |
<div class="mxchat-cta-section"> |
| 255 |
<h2><?php esc_html_e('Ready to take your chatbot to the next level?', 'mxchat'); ?></h2> |
| 256 |
<p><?php esc_html_e('Get MxChat PRO today and access all premium extensions at one low price.', 'mxchat'); ?></p> |
| 257 |
<a href="https://mxchat.ai/" class="mxchat-cta-button" target="_blank"><?php esc_html_e('Learn More', 'mxchat'); ?></a> |
| 258 |
</div> |
| 259 |
</div> |
| 260 |
<?php |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Render individual add-on card |
| 265 |
* |
| 266 |
* @param string $slug The addon slug |
| 267 |
* @param array $addon The addon configuration array |
| 268 |
*/ |
| 269 |
private function render_addon_card($slug, $addon) { |
| 270 |
$status_info = $this->get_addon_status($addon['plugin_file']); |
| 271 |
$button_url = $status_info['status'] === 'not-installed' ? $addon['url'] : $status_info['action_url']; |
| 272 |
$button_target = $status_info['status'] === 'not-installed' ? '_blank' : '_self'; |
| 273 |
|
| 274 |
// Check if addon is deprecated |
| 275 |
$is_deprecated = isset($addon['status']) && $addon['status'] === 'deprecated'; |
| 276 |
?> |
| 277 |
<div class="mxchat-addon-card <?php echo $is_deprecated ? 'deprecated' : ''; ?>" style="--card-accent: <?php echo esc_attr($addon['accent']); ?>"> |
| 278 |
<div class="mxchat-addon-badge"> |
| 279 |
<?php if ($is_deprecated): ?> |
| 280 |
<?php esc_html_e('Deprecated', 'mxchat'); ?> |
| 281 |
<?php else: ?> |
| 282 |
<?php echo esc_html(ucfirst($addon['license'])); ?> |
| 283 |
<?php endif; ?> |
| 284 |
</div> |
| 285 |
<div class="mxchat-addon-content"> |
| 286 |
<h3 class="mxchat-addon-title"><?php echo esc_html($addon['title']); ?></h3> |
| 287 |
<p class="mxchat-addon-description"><?php echo esc_html($addon['description']); ?></p> |
| 288 |
|
| 289 |
<?php if (!empty($addon['key_benefits'])): ?> |
| 290 |
<div class="mxchat-benefits-list"> |
| 291 |
<?php foreach ($addon['key_benefits'] as $benefit): ?> |
| 292 |
<div class="mxchat-benefit-item"> |
| 293 |
<span class="mxchat-benefit-icon">✓</span> |
| 294 |
<?php echo esc_html($benefit); ?> |
| 295 |
</div> |
| 296 |
<?php endforeach; ?> |
| 297 |
</div> |
| 298 |
<?php endif; ?> |
| 299 |
|
| 300 |
<div class="mxchat-addon-footer"> |
| 301 |
<?php if ($is_deprecated): ?> |
| 302 |
<div class="mxchat-status-indicator deprecated"> |
| 303 |
<?php esc_html_e('Now Built-in', 'mxchat'); ?> |
| 304 |
</div> |
| 305 |
<a href="<?php echo esc_url(admin_url('admin.php?page=mxchat-prompts')); ?>" |
| 306 |
class="mxchat-action-button deprecated" |
| 307 |
target="_self"> |
| 308 |
<?php esc_html_e('Go to Knowledge Tab', 'mxchat'); ?> |
| 309 |
</a> |
| 310 |
<?php else: ?> |
| 311 |
<div class="mxchat-status-indicator <?php echo esc_attr($status_info['status']); ?>"> |
| 312 |
<?php echo esc_html(ucfirst(str_replace('-', ' ', $status_info['status']))); ?> |
| 313 |
</div> |
| 314 |
<a href="<?php echo esc_url($button_url); ?>" |
| 315 |
class="mxchat-action-button" |
| 316 |
target="<?php echo esc_attr($button_target); ?>" |
| 317 |
data-action="<?php echo esc_attr($status_info['status']); ?>"> |
| 318 |
<?php echo esc_html($status_info['action_text']); ?> |
| 319 |
</a> |
| 320 |
<?php endif; ?> |
| 321 |
</div> |
| 322 |
</div> |
| 323 |
</div> |
| 324 |
<?php |
| 325 |
} |
| 326 |
|
| 327 |
} |