<?php
/**
 * Plugin Name: SaveTo Wishlist Lite for WooCommerce
 * Plugin URI: https://savetowishlist.com/
 * Description: The best wishlist plugin for WooCommerce.
 * Version: 1.0.7
 * Author: Rymera Web Co
 * Author URI: https://rymera.com.au
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Requires at least: 5.8
 * Tested up to: 7.0
 * WC requires at least: 4.0
 * WC tested up to: 10.2
 * Requires Plugins: woocommerce
 *
 * Text Domain: saveto-wishlist-lite-for-woocommerce
 * Domain Path: /languages/
 *
 * @package SaveToWishlist
 * @category Core
 * @author Rymera Web Co
 */

namespace SaveToWishlist;

use SaveToWishlist\Classes\SaveToWishlist;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! function_exists( 'is_plugin_active' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

// Load and initialise plugin constants.
// Required explicitly because the autoloader is not yet registered at this point.
require_once plugin_dir_path( __FILE__ ) . 'Classes/Constants.php';
\SaveToWishlist\Classes\Constants::define( __FILE__ );

/**
 * Register plugin autoloader.
 *
 * @since 1.0
 *
 * @param $class_name string Name of the class to load.
 */
spl_autoload_register(
    function ( $class_name ) {
        if ( strpos( $class_name, 'SaveToWishlist\\' ) === 0 ) { // Only do autoload for our plugin files.
            $class_file = str_replace( array( '\\', 'SaveToWishlist' . DIRECTORY_SEPARATOR ), array( DIRECTORY_SEPARATOR, '' ), $class_name ) . '.php';
            require_once plugin_dir_path( __FILE__ ) . $class_file;
        }
    }
);

if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
    add_action(
        'admin_notices',
        function () {
            echo '<div class="notice notice-error"><p>SaveTo Wishlist requires WooCommerce to be installed and active.</p></div>';
        }
    );
} else {
    // Declare HPOS compatibility.
    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 );
        }
        }
    );

    // Register activation and deactivation hooks.
    register_activation_hook( __FILE__, array( 'SaveToWishlist\\Classes\\Activate', 'activate' ) );
    register_deactivation_hook( __FILE__, array( 'SaveToWishlist\\Classes\\Deactivate', 'deactivate' ) );

    /**
     * Load the plugin.
     */
    add_action( 'setup_theme', array( SaveToWishlist::instance(), 'boot' ), 100 );
}
