<?php
/**
 * Plugin Name:       Event Monster
 * Plugin URI:        https://awplife.com/wordpress-plugins/event-monster-premium/
 * Description:       A free event management plugin for WordPress. Create and manage events with ease. Upgrade to Pro for payment gateways, tickets, coupons, and more!
 * Version:           2.1.1
 * Author:            A WP Life
 * Author URI:        https://awplife.com/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       event-monster
 * Domain Path:       /languages
 * Requires at least: 6.0
 * Tested up to:      7.0
 * Requires PHP:      7.4
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

/**
 * -------------------------------------------------------------------------
 * Define Core Constants
 * -------------------------------------------------------------------------
 * These are the only constants that should be defined globally.
 */
define( 'EM_FREE_VERSION', '2.1.1' );
define( 'EM_FREE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'EM_FREE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'EM_FREE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
if (!defined('EM_IS_PRO')) {
	define( 'EM_IS_PRO', false );
}


/**
 * -------------------------------------------------------------------------
 * Register Activation & Deactivation Hooks
 * -------------------------------------------------------------------------
 * This handles what happens when the user clicks "Activate" or "Deactivate".
 * All logic is delegated to dedicated classes.
 */
/**
 * Prevent activation if Event Monster Premium is already active.
 */
function activate_Event_Monster_Free_free() {
	if ( is_plugin_active( 'event-monster-premium/event-monster-premium.php' ) ) {
		wp_die(
			esc_html__( 'Event Monster (Free) cannot be activated while Event Monster Premium is active. Please deactivate the Premium version first.', 'event-monster' ),
			esc_html__( 'Plugin Activation Error', 'event-monster' ),
			array( 'back_link' => true )
		);
	}
	require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-activator.php';
	Event_Monster_Free_Activator::activate();
}

function deactivate_Event_Monster_Free_free() {
	require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-deactivator.php';
	Event_Monster_Free_Deactivator::deactivate();
}

register_activation_hook( __FILE__, 'activate_Event_Monster_Free_free' );
register_deactivation_hook( __FILE__, 'deactivate_Event_Monster_Free_free' );


/**
 * -------------------------------------------------------------------------
 * Load and Run the Core Plugin
 * -------------------------------------------------------------------------
 * This is the main entry point. We load the main class and tell it to run,
 * which will set up all the hooks, shortcodes, and admin pages.
 */
require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-main.php';

// Include shortcodes class
require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-shortcodes.php';

// Include frontend renderer class
require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-frontend-renderer.php';

// Include calendar class
require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-calendar.php';

// Include updater class (handles migrations and update notices)
require_once EM_FREE_PLUGIN_DIR . 'includes/class-event-monster-updater.php';

/**
 * Begins execution of the plugin.
 */
function run_Event_Monster_Free_free() {
	// Bail if Pro version is active to prevent conflicts.
	$active_plugins = (array) get_option('active_plugins', array());
	if (is_multisite()) {
		$active_plugins = array_merge($active_plugins, array_keys((array) get_site_option('active_sitewide_plugins', array())));
	}
	
	if (in_array('event-monster-premium/event-monster-premium.php', $active_plugins) || defined('EM_IS_PRO') && EM_IS_PRO === true) {
		return;
	}
	$plugin = new Event_Monster_Free_Main();
	$plugin->run();
}

run_Event_Monster_Free_free();
