<?php

/**
 *
 * @since             1.0.0
 * @package           Mds_Product_Bulk_Editor_For_Woocommerce
 *
 * @wordpress-plugin
 * Plugin Name:       Product Bulk Editor for WooCommerce
 * Description:       Allow easy and fast product edition and creation
 * Version:           1.12.0
 * Author:            MDS
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       mds-product-bulk-editor-for-woocommerce
 * Domain Path:       /languages
 * Requires at least: 5.4
 * Requires PHP:      7.3
 * Requires Plugins:  woocommerce
 */

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

/**
 * Currently plugin version
 */
define( 'MDSPBE_VERSION', '1.12.0' );

/**
 * Plugin path
 */
define( 'MDSPBE_PATH', plugin_dir_path( __FILE__ ) );

/**
 * Plugin name
 */
define( 'MDSPBE_NAME', 'MDS Product Bulk Editor' );

/**
 * 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-mds-product-bulk-editor-for-woocommerce.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 mdspbe_run_mds_product_bulk_editor() {

	$plugin = new MDSPBE();
	$plugin->run();

}
//mdspbe_run_mds_product_bulk_editor();



/**
 * Check if WooCommerce is active
 */
function mdspbe_is_woocommerce_active() {
    // Get the active plugins for the current site
    $active_plugins = get_site_option( 'active_sitewide_plugins', [] );
    
    if ( isset( $active_plugins['woocommerce/woocommerce.php'] ) ) {
        // WooCommerce is active network-wide
        return true;
    }

    // Check if WooCommerce is active on the current site
    $current_site_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', [] ) );
    return in_array( 'woocommerce/woocommerce.php', $current_site_plugins );
}



if ( mdspbe_is_woocommerce_active() ) {
    mdspbe_run_mds_product_bulk_editor();
} else {
    // WooCommerce is not active, so display an error message
    add_action( 'admin_notices', 'mdspbe_woocommerce_required' );
    function mdspbe_woocommerce_required() {
        echo '<div class="error"><p>' . esc_html( MDSPBE_NAME ) . ' requires the WooCommerce plugin to work. Please install and activate it.</p></div>';
    }
}