<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** 
 *  Plugin Name: ELEX Multi Vendor Marketplace for WooCommerce
 *  Plugin URI: https://elextensions.com/plugin/multi-vendor-plugin-for-woocommerce/
 *  Description: Plugin for multiple vendors to do e-commerce and shipping.
 *  Version: 1.1.4
 *  WC requires at least: 2.6.0
 *  WC tested up to: 10.0
 *  Author: ELEXtensions
 *  Author URI: https://elextensions.com
 *  Developer: ELEXtensions
 *  Developer URI: https://elextensions.com
 *  License: GPL-2.0+
 *  License URI: https://www.gnu.org/licenses/gpl-2.0.txt
 *  Text Domain: elex-multi-vendor-for-woocommerce
 *  Requires Plugins: woocommerce
 */




// Check if woocommerce is active
$active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() ) {
	$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins' ), array() );
}
if ( ! function_exists( 'is_plugin_active' ) ) {
	include_once ABSPATH . 'wp-admin/includes/plugin.php' ;

}

// for Required functions
if ( ! function_exists( 'elex_mv_is_woocommerce_active' ) ) {
	require_once 'elex-includes/elex-mv-functions.php' ;
}
// to check woocommerce is active
if ( ! ( elex_mv_is_woocommerce_active() ) ) {
	add_action( 'admin_notices', 'elex_mv_woocommerce_activation_notice' );
	return;
}

function elex_mv_woocommerce_activation_notice() {
	?>
	<div id="message" class="error">
		<p>
			<?php 
				deactivate_plugins( plugin_basename( __FILE__ ) );
			echo( esc_attr_e( 'WooCommerce plugin must be active for ELEX Multi-Vendor to work.', 'elex-multi-vendor-for-woocommerce' ) ); 
			?>
		</p>
	</div>
	<?php
}

if ( ! defined( 'ELEX_MULTI_VENDOR_PLUGIN_VERSION' ) ) {
	define( 'ELEX_MULTI_VENDOR_PLUGIN_VERSION', '1.0.5' );
}
if ( ! defined( 'ELEX_MULTI_VENDOR_PLUGIN_PATH' ) ) {
	define( 'ELEX_MULTI_VENDOR_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'ELEX_MULTI_VENDOR_MAIN_URL_PATH' ) ) {
	define( 'ELEX_MULTI_VENDOR_MAIN_URL_PATH', plugin_dir_url( __FILE__ ) );
}

if ( ! defined( 'ELEX_MULTI_VENDOR_MAIN_FILE' ) ) {
	define( 'ELEX_MULTI_VENDOR_MAIN_FILE', __FILE__ );
}
if ( ! defined( 'ELEXMUVE_PLUGIN_FILE' ) ) {
	define( 'ELEXMUVE_PLUGIN_FILE', __FILE__ );
}
if ( ! defined( 'ELEXMUVE_PLUGIN_DIR' ) ) {
	define( 'ELEXMUVE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'ELEXMUVE_PLUGIN_URL' ) ) {
	define( 'ELEXMUVE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/includes/class-enqueue-assets.php';


$elex_multi_ven = new \Elex\MultiVendor\ElexMultiVendor();

$migration    = new \Elex\MultiVendor\Migration();
$deactivation = new \Elex\MultiVendor\Deactivate_Multivendor();


$elex_multi_ven->with_basename( plugin_basename( __FILE__ ) );

$elex_mv_assets = new Elex_MV_Assets_Loader(
	plugin_dir_url( __FILE__ ),
	ELEX_MULTI_VENDOR_PLUGIN_VERSION
);
$elex_mv_assets->init();

$elex_multi_ven->boot();

register_activation_hook( __FILE__, array( $migration, 'settlement_history_table' ) );
register_activation_hook( __FILE__, array( $migration, 'migrate_option_names' ) );
register_activation_hook( __FILE__, array( $migration, 'migrate_meta_keys' ) );

// Run migrations for existing installations that update without re-activating.
add_action( 'plugins_loaded', array( $migration, 'migrate_option_names' ) );
add_action( 'plugins_loaded', array( $migration, 'migrate_meta_keys' ) );

register_deactivation_hook( __FILE__, array( $deactivation, 'delete_vendor_pages' ) );
