<?php
/**
* Plugin Name:  Order Feedback for WooCommerce
* Description:  Adds a feedback form on thank you and order details page.
* Version:      1.0
* Author:       WPVibes
* Author URI:   https://wpvibes.com
* License:      GPLv3
* License URI:  https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain:  order-feedback-woo
* Domain Path:  languages
*/

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

    define('WPVOFW_VERSION', '1.0');
    define('WPVOFW_MIN_PHP', '7.4');
    define('WPVOFW_MIN_WP', '5.6');
    define('WPVOFW_FILE', __FILE__);
    define('WPVOFW_BASE', plugin_basename(WPVOFW_FILE));
    define('WPVOFW_PATH', plugin_dir_path(WPVOFW_FILE));
    define('WPVOFW_URL', plugin_dir_url(WPVOFW_FILE));
    define('WPVOFW_MIN',( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min');
}
// check if woocommerce is active
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    // add admin notice
    add_action('admin_notices', function(){
        ?>
        <div class="notice notice-error is-dismissible">
		<p><?php echo esc_html__( 'Order Feedback for WooCommerce requires WooCommerce to be installed and active.', 'order-feedback-woo' ); ?></p>
        </div>
        <?php
    });
}else{
    
    $active_plugins = get_option( 'active_plugins' );
    // get current file path
    $current_file_path = __FILE__;
    $is_pro = false;
    $php_version = phpversion();

    $free_plugin_path = 'order-feedback-woo/order-feedback-woo.php';
    $pro_plugin_path = 'order-feedback-woo-pro/order-feedback-woo.php';

    if(strpos($current_file_path, $pro_plugin_path) !== false){
        $is_pro = true;
        if($is_pro){
            // free is also active, unset it so that it won't be loaded
            if(in_array($free_plugin_path, $active_plugins)){
                require_once( ABSPATH . 'wp-admin/includes/plugin.php' );

                deactivate_plugins($free_plugin_path);
                // add a admin notice
                add_action( 'admin_notices', function(){
                    ?>
                    <div class="notice notice-error is-dismissible">
                        <p><?php _e( 'Order Feedback for WooCommerce (Free) cannot be activated along with Pro version as it is not needed', 'order-feedback-woo' ); ?></p>
                    </div>
                    <?php
                });
            }
        }
    }
    add_action( 'plugins_loaded', function(){
        $active_plugins = get_option( 'active_plugins' );
        $current_file_path = __FILE__;
        $is_pro = false;

        $free_plugin_path = 'order-feedback-woo/order-feedback-woo.php';
        $pro_plugin_path = 'order-feedback-woo-pro/order-feedback-woo.php';

        if(strpos($current_file_path, $pro_plugin_path) !== false){
            $is_pro = true;
            
            require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
            require_once plugin_dir_path( __FILE__ ) . 'includes/init.php';

            WPVOFW\DbTables::wpvofw_plugin_activated();
        }else{ 
            if(in_array($pro_plugin_path, $active_plugins)){
                
            }else{	
                require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
                require_once plugin_dir_path( __FILE__ ) . 'includes/init.php';

                WPVOFW\DbTables::wpvofw_plugin_activated();
            }
        }
    });    
}







