# mxchat-basic/2.0.0/includes/class-mxchat-addons.php

MxChat – AI Chatbot &amp; Content Generation for WordPress, version 2.0.0. 154 lines.

- Page: https://pluginprobe.com/plugins/mxchat-basic/2.0.0/code/includes/class-mxchat-addons.php
- Raw: https://pluginprobe.com/plugins/mxchat-basic/2.0.0/raw/includes/class-mxchat-addons.php
- Modified: 2025-02-06T03:44:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/mxchat-basic/2.0.0/code/includes/class-mxchat-addons.php#L10-L20`.

```php
<?php
/**
 * The admin-specific functionality for the Add Ons page.
 *
 * @package    MxChat
 * @subpackage MxChat/admin
 */
class MxChat_Addons {
    /**
     * Store add-on configuration data
     *
     * @var array
     */
    private $addons_config;

    /**
     * Initialize the class and set its properties.
     */
    public function __construct() {
        $this->addons_config = array(
            'mxchat-pinecone' => array(
                'title' => __('Pinecone DB Manager', 'mxchat'),
                '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'),
                'license' => 'free',
                'accent' => '#fa73e6',
                'url' => 'https://quickdeploywp.com/plugin/mxchat-pinecone/',
                'plugin_file' => 'mxchat-pinecone/pinecone-manager.php',
                'config_page' => 'mxchat-pinecone'
            ),
        );
    }

    /**
     * Register the stylesheets for the admin area.
     */
    public function enqueue_styles() {
        $plugin_version = '2.0.0';
        
        wp_enqueue_style(
            'mxchat-addons',
            plugin_dir_url(__FILE__) . '../css/admin-add-ons.css',
            array(),
            $plugin_version,
            'all'
        );
    }

    /**
     * Check if an addon is installed and active
     *
     * @param string $plugin_file The plugin's main file path
     * @return array Status information
     */
      private function get_addon_status($plugin_file) {
    if (!function_exists('get_plugins')) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }

    $all_plugins = get_plugins();
    $active_plugins = get_option('active_plugins', array());
    
    // Find the addon by iterating through configs
    $config_page = '';
    foreach ($this->addons_config as $slug => $addon) {
        if ($addon['plugin_file'] === $plugin_file) {
            $config_page = $addon['config_page'];
            break;
        }
    }

    if (isset($all_plugins[$plugin_file])) {
        if (in_array($plugin_file, $active_plugins)) {
            return array(
                'status' => 'active',
                'action_url' => admin_url('admin.php?page=' . $config_page),
                'action_text' => __('Configure', 'mxchat')
            );
        } else {
            return array(
                'status' => 'inactive',
                'action_url' => wp_nonce_url(
                    admin_url('plugins.php?action=activate&plugin=' . $plugin_file),
                    'activate-plugin_' . $plugin_file
                ),
                'action_text' => __('Activate', 'mxchat')
            );
        }
    }

    return array(
        'status' => 'not-installed',
        'action_url' => '',
        'action_text' => __('Get Extension', 'mxchat')
    );
}

    /**
     * Render the Add Ons page content.
     */
    public function render_page() {
        $this->enqueue_styles();
        ?>
        <div class="wrap mxchat-addons-wrapper">
            <div class="mxchat-addons-hero">
                <h1 class="mxchat-main-title">
                    <span class="mxchat-gradient-text">Power Up</span> Your Chatbot
                </h1>
                <p class="mxchat-hero-subtitle">
                    <?php esc_html_e('Enhance your chatbot with premium & free extensions available through QuickDeployWP, an official distribution platform made by MxChat.', 'mxchat'); ?>
                </p>
            </div>
            <div class="mxchat-addons-grid">
                <?php 
                foreach ($this->addons_config as $slug => $addon) {
                    $this->render_addon_card($slug, $addon);
                }
                ?>
            </div>
        </div>
        <?php
    }

    /**
     * Render individual add-on card
     * 
     * @param string $slug The addon slug
     * @param array  $addon The addon configuration array
     */
    private function render_addon_card($slug, $addon) {
        $status_info = $this->get_addon_status($addon['plugin_file']);
        $button_url = $status_info['status'] === 'not-installed' ? $addon['url'] : $status_info['action_url'];
        $button_target = $status_info['status'] === 'not-installed' ? '_blank' : '_self';
        ?>
        <div class="mxchat-addon-card" style="--card-accent: <?php echo esc_attr($addon['accent']); ?>">
            <div class="mxchat-addon-badge"><?php echo esc_html(ucfirst($addon['license'])); ?></div>
            <div class="mxchat-addon-content">
                <h3 class="mxchat-addon-title"><?php echo esc_html($addon['title']); ?></h3>
                <p class="mxchat-addon-description"><?php echo esc_html($addon['description']); ?></p>
                <div class="mxchat-addon-footer">
                    <div class="mxchat-status-indicator <?php echo esc_attr($status_info['status']); ?>">
                        <?php echo esc_html(ucfirst(str_replace('-', ' ', $status_info['status']))); ?>
                    </div>
                    <a href="<?php echo esc_url($button_url); ?>" 
                       class="mxchat-action-button" 
                       target="<?php echo esc_attr($button_target); ?>"
                       data-action="<?php echo esc_attr($status_info['status']); ?>">
                        <?php echo esc_html($status_info['action_text']); ?>
                    </a>
                </div>
            </div>
        </div>
        <?php
    }
}
```
