<?php
/**
 * ADDON - POP for Paid Member Subscriptions (CozmosLabs)
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';

$bootstrap = function () {
	// Prevent init plugin in other ajax action
	if ( ! is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
		return;
	}

	if ( ! \WcElectronInvoice\Functions\isCozmoslabsPaidMemberSubscriptionsActive() ) {
		return;
	}

	$filters = array();

	if ( ! is_admin() ) {
		include_once \WooPoPCozmosLabsPMS\Plugin::getPluginDirPath( '/inc/filtersFront.php' );
	} else {
		include_once \WooPoPCozmosLabsPMS\Plugin::getPluginDirPath( '/inc/filtersAdmin.php' );
	}

	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
		include_once \WooPoPCozmosLabsPMS\Plugin::getPluginDirPath( '/inc/filters.php' );
	}

	$init = new WooPoPCozmosLabsPMS\Init( new WooPoPCozmosLabsPMS\Loader(), $filters );
	$init->init();
};

if (did_action('init')) {
	$bootstrap();
} else {
	add_action('init', $bootstrap, 9);
}
