<?php

/**
 * The plugin bootstrap file
 *
 * This file is read by WordPress to generate the plugin information in the plugin
 * admin area. This file also includes all of the dependencies used by the plugin,
 * registers the activation and deactivation functions, and defines a function
 * that starts the plugin.
 *
 * @link              https://profile.fraxzon.com
 * @since             1.0.0
 * @package           Ffl_Dealers
 *
 * @wordpress-plugin
 * Plugin Name:       FF Dealers
 * Plugin URI:        https://fraxzon.com
 * Description:       Product is delivered through the issuance of a Federal Firearms License (FFL).
 * Author:            shafiq
 * Author URI:        https://profile.fraxzon.com/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       ffl-dealers
 * Domain Path:       /languages
 * Version:           2.0.2
 * Requires at least: 5.8
 * Tested up to: 6.5.5
 * Requires PHP: 7.4
 */

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

if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || ( is_multisite() && in_array( 'woocommerce/woocommerce.php', array_flip( get_site_option( 'active_sitewide_plugins' ) ) ) ) ) {
/**
 * Currently plugin version.
 * Start at version 1.0.0 and use SemVer - https://semver.org
 * Rename this for your plugin and update it as you release new versions.
 */

function define_fll_dealers() {
		define_fll_dealers_constants( 'FFL_DEALERS_VERSION', '1.0.0' );
		define_fll_dealers_constants( 'FFL_DEALERS_FILE', __FILE__ );
		define_fll_dealers_constants( 'FFL_DEALERS_BASE', plugin_basename( FFL_DEALERS_FILE));
		define_fll_dealers_constants( 'FFL_DEALERS_PATH', plugin_dir_path( FFL_DEALERS_FILE) );
		define_fll_dealers_constants( 'FFL_DEALERS_DIR_URL', plugin_dir_url( FFL_DEALERS_FILE ) );
		define_fll_dealers_constants( 'FFL_DEALERS_ADMIN_POST_URL', admin_url('admin-post.php'));
}
function define_fll_dealers_constants( $key, $value ) {
		if ( ! defined( $key ) ) {
			define( $key, $value );
		}
}
/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-ffl-dealers-activator.php
 */
function activate_ffl_dealers() {
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-ffl-dealers-activator.php';
	FFL_Dealers_Activator::activate();
}

/**
 * The code that runs during plugin deactivation.
 * This action is documented in includes/class-ffl-dealers-deactivator.php
 */
function deactivate_ffl_dealers() {
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-ffl-dealers-deactivator.php';
	Ffl_Dealers_Deactivator::deactivate();
}
/**
 * The setting page link from plugin page.
 */
function ffl_dealers_plugin_settings($links) {
	$links['settings'] = '<a href="admin.php?page=ffl-settings">Settings</a>';
	$links['supports'] 	= '<a href="mailto:shafiq6171@gmail.com" target="_blank">Supports</a>';
	$links['donate'] 	= '<a href="https://www.buymeacoffee.com/shafiq6171Y" target="_blank">Donate</a>';
	return $links;
}

register_activation_hook( __FILE__, 'activate_ffl_dealers' );
register_deactivation_hook( __FILE__, 'deactivate_ffl_dealers' );
add_filter("plugin_action_links_" . plugin_basename( __FILE__), 'ffl_dealers_plugin_settings');
/**
 * The core plugin class that is used to define internationalization,
 * admin-specific hooks, and public-facing site hooks.
 */
require plugin_dir_path( __FILE__ ) . 'includes/class-ffl-dealers.php';

/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function run_ffl_dealers() {
	define_fll_dealers();
	$ffl_dealers = new FFL_Dealers();
	$ffl_dealers->run();
	$GLOBALS['ffl_dealers_obj'] = $ffl_dealers;
	$GLOBALS['ffl_dealers_notices'] = false;
}
add_action( 'woocommerce_init' , 'run_ffl_dealers');

} else {
    add_action('admin_notices', 'ffl_dealers_install_error_notice');
    function ffl_dealers_install_error_notice(){
        global $current_screen;
        if($current_screen->parent_base == 'plugins'){
              echo '<div class="error"><p>FFL Dealers '.__(' requires WooCommerce to be activated in order to work. Please install and activate <a href="'.admin_url('plugin-install.php?tab=search&type=term&s=WooCommerce').'" target="_blank">WooCommerce</a> first.', 'ffl-dealers').'</p></div>';
        }
    }
    include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    if(is_plugin_active(plugin_basename( __FILE__))){
            deactivate_plugins(plugin_basename( __FILE__));
    }
    if ( isset( $_GET['activate'] ) ){
		 unset( $_GET['activate'] );
	}
}