<?php
/**
 * Plugin Name: Email Customizer for WooCommerce - Spark Editor
 * Plugin URI: https://sparkeditor.com/
 * Description: Create awesome transactional emails with a drag and drop email builder.
 * Version: 1.1.4
 * Author: emaileditorplus
 * Slug: email-editor-plus
 * Text Domain: email-editor-plus
 * Domain Path: /i18n/languages/
 * License: GPLv2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 * Contributors: emaileditorplus
 * Requires at least: 6.0
 * WC requires at least: 6.6
 * WC tested up to: 10.8
 */

use Automattic\WooCommerce\Utilities\FeaturesUtil;
use EDPW\Core\Helpers\Plugin;
use EDPW\Core\Router;
use EDPW\Core\Setup;

defined( 'ABSPATH' ) || exit;

add_action( 'before_woocommerce_init', function () {
	if ( class_exists( FeaturesUtil::class ) ) {
		FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__ );
	}
} );

if ( ! function_exists( 'edpwIsProActive' ) ) {
	function edpwIsProActive() {
		$active_plugins = get_option( 'active_plugins', [] );
		if ( is_multisite() ) {
			$active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', [] ) ) );
		}

		return in_array( 'email-editor-plus-pro/email-editor-plus-pro.php', $active_plugins, false );
	}
}

if ( edpwIsProActive() ) {
	return;
}
/**
 * Plugin constants
 */
defined( 'EDPW_PLUGIN_NAME' ) or define( 'EDPW_PLUGIN_NAME', 'Spark Email Editor' );
defined( 'EDPW_PLUGIN_VERSION' ) or define( 'EDPW_PLUGIN_VERSION', '1.1.4' );
defined( 'EDPW_MINIMUM_PHP_VERSION' ) or define( 'EDPW_MINIMUM_PHP_VERSION', '7.4.0' );
defined( 'EDPW_MINIMUM_WP_VERSION' ) or define( 'EDPW_MINIMUM_WP_VERSION', '6.0' );
defined( 'EDPW_MINIMUM_WC_VERSION' ) or define( 'EDPW_MINIMUM_WC_VERSION', '6.6' );
defined( 'EDPW_PLUGIN_SLUG' ) or define( 'EDPW_PLUGIN_SLUG', 'email-editor-plus' );
defined( 'EDPW_PLUGIN_PATH' ) or define( 'EDPW_PLUGIN_PATH', __DIR__ . '/' );
defined( 'EDPW_PLUGIN_URL' ) or define( 'EDPW_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
defined( 'EDPW_PLUGIN_FILE' ) or define( 'EDPW_PLUGIN_FILE', __FILE__ );
defined( 'EDPW_PLUGIN_PREFIX' ) or define( 'EDPW_PLUGIN_PREFIX', 'edpw' );
defined( 'EDPW_BASE_FILE' ) or define( 'EDPW_BASE_FILE', plugin_basename( __FILE__ ) );
defined( 'EDPW_PLUGIN_LANGUAGE' ) or define( 'EDPW_PLUGIN_LANGUAGE', get_locale() );

if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
	return;
}
if ( ! class_exists( 'EDPW\Core\Helpers\Plugin' ) ) {
// Autoload the vendor
	require __DIR__ . '/vendor/autoload.php';
}

//Init the router
if ( class_exists( Router::class ) ) {
	Setup::init(); // init setup
	if ( Plugin::checkDependencies() ) {
		Router::init();
		do_action( 'edpw_spark_editor_loaded' );
		$edpw_add_on_list = apply_filters( 'edpw_add_on_init', [] );
		foreach ( $edpw_add_on_list as $edpw_app_path ) {
			if ( file_exists( $edpw_app_path ) ) {
				include $edpw_app_path;
			}
		}
	}
}
