<?php
/*
    * Plugin Name: EHx Members
    * Plugin URI:  https://wordpress.org/plugins/ehx-members
    * Description: The Ehx Members plugin is a powerful tool designed to simplify and streamline the user registration process on your WordPress site. This plugin allows you to create customizable, mobile-friendly frontend registration forms with support for AJAX submissions, robust validation, and error handling. Ideal for membership websites, the plugin enables the creation of new WordPress users with specific roles, integrates seamlessly with WordPress’s user management system, and supports custom fields for collecting additional user information. 
    * 
    * Key Features:
    * - Fully customizable frontend forms. 
    * - AJAX-based form submission for a seamless user experience.
    * - Create and assign WordPress roles automatically.
    * - Support for custom fields like phone, address, and membership type.
    * - Multilingual ready, with translation support via Text Domain.
    * - Lightweight and optimized for performance.
    * - Easy to integrate into any WordPress theme.
    * 
    * Version:           1.0.0
    * Requires at least: 5.8
    * Requires PHP:      8.0
    * Author:            EH Studio
    * Author URI:        https://eh.studio
    * License:           GPLv2 or later
    * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
    * Text Domain:       ehx-members
    * Domain Path:       /languages
*/

if (!defined('ABSPATH')) {
    die('Hi there!  I\'m just a plugin, not much I can do when called directly.');
}

define('EHXME_VERSION', '1.0.0');
define('EHXME_MINIMUM_WP_VERSION', '5.8');
define('EHXME_PLUGIN_DIR', plugin_dir_path( __FILE__));
define('EHXME_PLUGIN_URL', plugin_dir_url( __FILE__));
define('EHXME_DELETE_LIMIT', 10000);

class EHxMembers
{
    /**
     * Plugin instance
     * 
     * @var EHxMembers
     */
    private static $instance;

    /**
     * Get plugin instance
     * 
     * @return EHxMembers
     */
    public static function getInstance(): EHxMembers
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Initialize the plugin
     */
    private function __construct()
    {
        // Load required dependencies
        require_once EHXME_PLUGIN_DIR . 'vendor/autoload.php';

        add_action('plugins_loaded', [$this, 'initPlugin']);
    }

    /**
     * Initialize plugin components
     */
    public function initPlugin(): void
    {
        // Initialize core components

        // Initialize components
        new \EHxMe\Classes\AdminNavMenuHandler();

        new \EHxMe\Classes\Settings();

        new \EHxMe\PostTypes\FormPostType();
        new \EHxMe\Metabox\PostContentRestriction();
        new \EHxMe\Classes\RegisterScripts();

        // Frontend components
        new \EHxMe\Shortcodes\CustomFormShortcode();
        new \EHxMe\Shortcodes\FormShortcode();

        // Initialize admin components
        if (is_admin()) {
            new \EHxMe\Classes\AdminMenuHandler();
            new \EHxMe\Classes\AdminActionHandler();
            new \EHxMe\Classes\ActivationHandler();
        }
    }
}

// Initialize the plugin
EHxMembers::getInstance();

register_activation_hook(__FILE__, [\EHxMe\Classes\ActivationHandler::class, 'handle']);
register_deactivation_hook(__FILE__, [\EHxMe\Classes\DeactivationHandler::class, 'handle']);
register_uninstall_hook(__FILE__, [\EHxMe\Classes\UninstallHandler::class, 'handle']);