| 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 |
'mxchat-forms' => array( |
| 31 |
'title' => __('MxChat Forms', 'mxchat'), |
| 32 |
'description' => __('Create and manage smart forms that automatically trigger during chat conversations. Build custom forms with multiple field types, collect submissions, and export data—all seamlessly integrated with MxChat\'s intent system. No coding required, just intuitive form building for enhanced chat interactions.', 'mxchat'), |
| 33 |
'license' => 'MxChat PRO', |
| 34 |
'accent' => '#fa73e6', |
| 35 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-forms/', |
| 36 |
'plugin_file' => 'mxchat-forms/mxchat-forms.php', |
| 37 |
'config_page' => 'mxchat-forms' |
| 38 |
), |
| 39 |
|
| 40 |
'mxchat-woo' => array( |
| 41 |
'title' => __('MxChat WooCommerce', 'mxchat'), |
| 42 |
'description' => __('Enhance your WooCommerce store with AI-powered chat interactions. This add-on enables intelligent product recommendations, order history retrieval, cart management, and seamless checkout assistance—fully integrated with MxChat\'s intent system.', 'mxchat'), |
| 43 |
'license' => 'MxChat PRO', |
| 44 |
'accent' => '#fa73e6', |
| 45 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-woo/', |
| 46 |
'plugin_file' => 'mxchat-woo/mxchat-woo.php', |
| 47 |
'config_page' => 'mxchat-woo' |
| 48 |
), |
| 49 |
'mxchat-theme' => array( |
| 50 |
'title' => __('MxChat Theme Customizer', 'mxchat'), |
| 51 |
'description' => __('MxChat Theme Customizer is a powerful add-on for MxChat Pro that makes it effortless to personalize your chatbot’s appearance. With an intuitive color picker, you can instantly adjust background colors, and interface elements—all with real-time previews. No coding required, just simple, live customization to match your brand’s look.', 'mxchat'), |
| 52 |
'license' => 'MxChat PRO', |
| 53 |
'accent' => '#fa73e6', |
| 54 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-theme/', |
| 55 |
'plugin_file' => 'mxchat-theme/mxchat-theme.php', |
| 56 |
'config_page' => 'mxchat-theme-settings' |
| 57 |
), |
| 58 |
'mxchat-moderation' => array( |
| 59 |
'title' => __('MxChat Moderation', 'mxchat'), |
| 60 |
'description' => __('MxChat Moderation is the ultimate add-on for MxChat, giving you full control over who interacts with your chatbot. Effortlessly block spammers, trolls, or unwanted users using IP and email-based bans—keeping your chat clean, safe, and enjoyable. Say goodbye to disruptive users and hello to a smoother, more secure chatbot experience!', 'mxchat'), |
| 61 |
'license' => 'MxChat PRO', |
| 62 |
'accent' => '#fa73e6', |
| 63 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-moderation/', |
| 64 |
'plugin_file' => 'mxchat-moderation/mx-chat-moderation.php', |
| 65 |
'config_page' => 'mx-chat-moderation' |
| 66 |
), |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Register the stylesheets for the admin area. |
| 72 |
*/ |
| 73 |
public function enqueue_styles() { |
| 74 |
$plugin_version = '2.0.4'; |
| 75 |
|
| 76 |
wp_enqueue_style( |
| 77 |
'mxchat-addons', |
| 78 |
plugin_dir_url(__FILE__) . '../css/admin-add-ons.css', |
| 79 |
array(), |
| 80 |
$plugin_version, |
| 81 |
'all' |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Check if an addon is installed and active |
| 87 |
* |
| 88 |
* @param string $plugin_file The plugin's main file path |
| 89 |
* @return array Status information |
| 90 |
*/ |
| 91 |
private function get_addon_status($plugin_file) { |
| 92 |
if (!function_exists('get_plugins')) { |
| 93 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 94 |
} |
| 95 |
|
| 96 |
$all_plugins = get_plugins(); |
| 97 |
$active_plugins = get_option('active_plugins', array()); |
| 98 |
|
| 99 |
// Find the addon by iterating through configs |
| 100 |
$config_page = ''; |
| 101 |
foreach ($this->addons_config as $slug => $addon) { |
| 102 |
if ($addon['plugin_file'] === $plugin_file) { |
| 103 |
$config_page = $addon['config_page']; |
| 104 |
break; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
if (isset($all_plugins[$plugin_file])) { |
| 109 |
if (in_array($plugin_file, $active_plugins)) { |
| 110 |
return array( |
| 111 |
'status' => 'active', |
| 112 |
'action_url' => admin_url('admin.php?page=' . $config_page), |
| 113 |
'action_text' => __('Configure', 'mxchat') |
| 114 |
); |
| 115 |
} else { |
| 116 |
return array( |
| 117 |
'status' => 'inactive', |
| 118 |
'action_url' => wp_nonce_url( |
| 119 |
admin_url('plugins.php?action=activate&plugin=' . $plugin_file), |
| 120 |
'activate-plugin_' . $plugin_file |
| 121 |
), |
| 122 |
'action_text' => __('Activate', 'mxchat') |
| 123 |
); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
return array( |
| 128 |
'status' => 'not-installed', |
| 129 |
'action_url' => '', |
| 130 |
'action_text' => __('Get Extension', 'mxchat') |
| 131 |
); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Render the Add Ons page content. |
| 136 |
*/ |
| 137 |
public function render_page() { |
| 138 |
$this->enqueue_styles(); |
| 139 |
?> |
| 140 |
<div class="wrap mxchat-addons-wrapper"> |
| 141 |
<div class="mxchat-addons-hero"> |
| 142 |
<h1 class="mxchat-main-title"> |
| 143 |
<span class="mxchat-gradient-text">Power Up</span> Your Chatbot |
| 144 |
</h1> |
| 145 |
<p class="mxchat-hero-subtitle"> |
| 146 |
<?php esc_html_e('Enhance your chatbot with premium & free extensions available through QuickDeployWP, an official distribution platform made by MxChat.', 'mxchat'); ?> |
| 147 |
</p> |
| 148 |
</div> |
| 149 |
<div class="mxchat-addons-grid"> |
| 150 |
<?php |
| 151 |
foreach ($this->addons_config as $slug => $addon) { |
| 152 |
$this->render_addon_card($slug, $addon); |
| 153 |
} |
| 154 |
?> |
| 155 |
</div> |
| 156 |
</div> |
| 157 |
<?php |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Render individual add-on card |
| 162 |
* |
| 163 |
* @param string $slug The addon slug |
| 164 |
* @param array $addon The addon configuration array |
| 165 |
*/ |
| 166 |
private function render_addon_card($slug, $addon) { |
| 167 |
$status_info = $this->get_addon_status($addon['plugin_file']); |
| 168 |
$button_url = $status_info['status'] === 'not-installed' ? $addon['url'] : $status_info['action_url']; |
| 169 |
$button_target = $status_info['status'] === 'not-installed' ? '_blank' : '_self'; |
| 170 |
?> |
| 171 |
<div class="mxchat-addon-card" style="--card-accent: <?php echo esc_attr($addon['accent']); ?>"> |
| 172 |
<div class="mxchat-addon-badge"><?php echo esc_html(ucfirst($addon['license'])); ?></div> |
| 173 |
<div class="mxchat-addon-content"> |
| 174 |
<h3 class="mxchat-addon-title"><?php echo esc_html($addon['title']); ?></h3> |
| 175 |
<p class="mxchat-addon-description"><?php echo esc_html($addon['description']); ?></p> |
| 176 |
<div class="mxchat-addon-footer"> |
| 177 |
<div class="mxchat-status-indicator <?php echo esc_attr($status_info['status']); ?>"> |
| 178 |
<?php echo esc_html(ucfirst(str_replace('-', ' ', $status_info['status']))); ?> |
| 179 |
</div> |
| 180 |
<a href="<?php echo esc_url($button_url); ?>" |
| 181 |
class="mxchat-action-button" |
| 182 |
target="<?php echo esc_attr($button_target); ?>" |
| 183 |
data-action="<?php echo esc_attr($status_info['status']); ?>"> |
| 184 |
<?php echo esc_html($status_info['action_text']); ?> |
| 185 |
</a> |
| 186 |
</div> |
| 187 |
</div> |
| 188 |
</div> |
| 189 |
<?php |
| 190 |
} |
| 191 |
} |
| 192 |
|