<?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://wpgenie.org
 * @since             1.0.0
 * @package           Mysterx - Mystery Boxes for WooCommerce
 *
 * @wordpress-plugin
 * Plugin Name:       Mysterx - Mystery Boxes for WooCommerce
 * Plugin URI:        https://wpgenie.org
 * Description:       Addon that implements custom product type "Mystery box" which enables you to offer and sell loot boxes within your WooCommerce store.
 * Version:           1.0.2
 * Author:            wpgenie
 * Author URI:        https://wpgenie.org/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       mysterx-mystery-boxes-for-woocommerce
 * Domain Path:       /languages
 *
 * WC requires at least: 4.0
 * WC tested up to: 11.0
 * Requires Plugins: woocommerce
 */
// If this file is called directly, abort.
if ( !defined( 'WPINC' ) ) {
    die;
}
global $wpdb;
define( 'MYSTERX_VERSION', '1.0.2' );
define( 'MYSTERX_FILE', __FILE__ );
define( 'MYSTERX_DIR', plugin_dir_path( __FILE__ ) );
define( 'MYSTERX_URL', plugin_dir_url( __FILE__ ) );
define( 'MYSTERX_TBL_ITEMS', $wpdb->prefix . 'mysterx_items' );
define( 'MYSTERX_TBL_LOG', $wpdb->prefix . 'mysterx_log' );
define( 'MYSTERX_TBL_OPEN_LOG', $wpdb->prefix . 'mysterx_open_log' );
if ( !function_exists( 'mysterx_fs' ) ) {
    /**
     * Create a helper function for easy SDK access.
     *
     * @return object Freemius SDK instance.
     */
    function mysterx_fs() {
        global $mysterx_fs;
        if ( !isset( $mysterx_fs ) ) {
            // Include Freemius SDK.
            require_once __DIR__ . '/vendor/freemius/start.php';
            $mysterx_fs = fs_dynamic_init( array(
                'id'               => '23321',
                'slug'             => 'mysterx-mystery-boxes-for-woocommerce',
                'type'             => 'plugin',
                'public_key'       => 'pk_699101b58e105584920315c892020',
                'is_premium'       => false,
                'premium_suffix'   => 'Professional',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => array(
                    'slug'       => 'mysterx',
                    'first-path' => 'admin.php?page=mysterx-settings',
                    'support'    => false,
                    'contact'    => false,
                ),
                'is_live'          => true,
            ) );
        }
        return $mysterx_fs;
    }

    // Init Freemius.
    mysterx_fs();
    if ( is_admin() ) {
        mysterx_fs()->add_filter( 'is_show_go_pro_menu', '__return_true' );
        mysterx_fs()->add_filter( 'menu_go_pro_label', function () {
            return '<span style="color:#f39c12; font-weight:bold;">Go Pro</span>';
        } );
    }
    // Signal that SDK was initiated.
    do_action( 'mysterx_fs_loaded' );
}
/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-mysterx-activator.php
 */
function activate_mysterx() {
    require_once plugin_dir_path( __FILE__ ) . 'includes/class-mysterx-activator.php';
    Mysterx_Activator::activate();
}

/**
 * The code that runs during plugin deactivation.
 * This action is documented in includes/class-mysterx-deactivator.php
 */
function deactivate_mysterx() {
    require_once plugin_dir_path( __FILE__ ) . 'includes/class-mysterx-deactivator.php';
    Mysterx_Deactivator::deactivate();
}

register_activation_hook( __FILE__, 'activate_mysterx' );
register_deactivation_hook( __FILE__, 'deactivate_mysterx' );
/**
 * 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-mysterx.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_mysterx() {
    $plugin = new Mysterx();
    $plugin->run();
}

add_action( 'woocommerce_init', 'run_mysterx', 90 );
add_action( 'before_woocommerce_init', function () {
    if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    }
} );