<?php
	/**
	 *
	 * @link              https://emoxie.com
	 * @since             1.0.0
	 * @package           Expandable_Paywall
	 *
	 * @wordpress-plugin
	 * Plugin Name: Expandable Paywall
	 * Plugin URI: https://pramadillo.com/plugins/expandble-paywall
	 * Description: A simple paywall solution with integration with several third party providers for authentication.
	 * Version: 2.1.10
	 * Author: E-Moxie
	 * Author URI: https://emoxie.com
	 * License: GPL-2.0+
	 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
	 * Text Domain: expandable-paywall
	 * Domain Path: /languages
	 */

	use Emoxie\Expandable_Paywall\Expandable_Paywall;
	use Emoxie\Expandable_Paywall\Expandable_Paywall_Activator;
	use Emoxie\Expandable_Paywall\Expandable_Paywall_Deactivator;

	if ( ! defined( 'WPINC' ) ) {
		die;
	}

	const EXPANDABLE_PAYWALL_VERSION = '2.1.10';
	const EXPANDABLE_PAYWALL_SLUG    = 'expandable-paywall';
	const EXPANDABLE_PAYWALL_NAME    = 'Expandable Paywall';
	define( 'EXPANDABLE_PAYWALL_TEMPLATE_PATH', trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) );  // 'expandable-paywall/'
	define( 'EXPANDABLE_PAYWALL_PATH', plugin_dir_path( __FILE__ ) ); //'/app/public/wp-content/plugins/expandable-paywall/'
	define( 'EXPANDABLE_PAYWALL_URL', plugin_dir_url( __FILE__ ) ); //'http://expandable-paywall.local/wp-content/plugins/expandable-paywall/'
	define( 'EXPANDABLE_PAYWALL_BASENAME', plugin_basename( __FILE__ ) ); //'expandable-paywall/expandable-paywall.php'

	if ( function_exists( 'expandable_paywall_core_freemius' ) ) {
		expandable_paywall_core_freemius()->set_basename( true, __FILE__ );
	} else {
		if ( ! function_exists( 'expandable_paywall_core_freemius' ) ) {

			function expandable_paywall_core_freemius() {
				global $expandable_paywall_core_freemius;

				if ( ! isset( $expandable_paywall_core_freemius ) ) {
					// Activate multisite network integration.
					if ( ! defined( 'WP_FS__PRODUCT_5104_MULTISITE' ) ) {
						define( 'WP_FS__PRODUCT_5104_MULTISITE', true );
					}

					// Include Freemius SDK.
					require_once EXPANDABLE_PAYWALL_PATH . 'vendor/freemius/wordpress-sdk/start.php';

					try {
						$expandable_paywall_core_freemius = fs_dynamic_init( array(
							'id'                  => '5104',
							'slug'                => 'expandable-paywall',
							'type'                => 'plugin',
							'public_key'          => 'pk_11bf7a846ef7628a4db07e7362697',
							'is_premium'          => false,
							'has_addons'          => true,
							'has_paid_plans'      => false,
							'menu'                => array(
								'slug'           => 'expandable-paywall',
								'contact'        => false,
								'support'        => false,
							),
						) );
					} catch ( Freemius_Exception $e ) {
						$button = '<a href="' . esc_attr( network_admin_url( 'plugins.php' )) . '" rel="nofollow ugc">Return to Plugins</a>';
						deactivate_plugins( EXPANDABLE_PAYWALL_BASENAME );
						wp_die( 'Expandable Paywall - ' . esc_html( $e->getMessage() ) . ' - ' . $button );
					}
				}

				return $expandable_paywall_core_freemius;
			}
		}

		require EXPANDABLE_PAYWALL_PATH . 'vendor/autoload.php';


		function activate_expandable_paywall() {
			require_once EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall-activator.php';
			Expandable_Paywall_Activator::activate();
		}

		function deactivate_expandable_paywall() {
			require_once EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall-deactivator.php';
			Expandable_Paywall_Deactivator::deactivate();
		}

		register_activation_hook( __FILE__, 'activate_expandable_paywall' );
		register_deactivation_hook( __FILE__, 'deactivate_expandable_paywall' );

		require EXPANDABLE_PAYWALL_PATH . 'includes/class-expandable-paywall.php';

		function run_expandable_paywall() {
			expandable_paywall_core_freemius();
			do_action( 'expandable_paywall_core_freemius_loaded' );
			expandable_paywall_core_freemius()->add_filter( 'plugin_icon', function () {
				return EXPANDABLE_PAYWALL_PATH . '/admin/img/icon.png';
			} );
			$plugin = new Expandable_Paywall();
			$plugin->run();
		}

		run_expandable_paywall();
	}