<?php
/**
 * Plugin Name: WooCommerce Product Tabs Pro
 * Plugin URI: https://barn2.com/wordpress-plugins/woocommerce-product-tabs/
 * Description: WooCommerce Product Tabs Pro for WooCommerce. Add unlimited custom tabs with options of seleting products title,  categories, tags and can add icon.
 * Version: 1.1.2
 * Author: Barn2 Plugins
 * Author URI: https://barn2.com/
 * License: GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain: woocommerce-product-tabs
 * Domain Path: /languages
 * WC requires at least:  6.5
 * WC tested up to: 8.0.1
 * Update URI: https://barn2.com/wordpress-plugins/woocommerce-product-tabs/
 *
 * @package Woocommerce_Product_Tabs
 */

namespace Barn2\Plugin\WC_Product_Tabs_Pro;

use Freemius;

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

// Define.
define( 'WOOCOMMERCE_PRODUCT_TABS_VERSION', '1.1.2' );
define( 'WOOCOMMERCE_PRODUCT_TABS_NAME', 'Woocommerce Product Tabs' );
define( 'WOOCOMMERCE_PRODUCT_TABS_SLUG', 'woocommerce-product-tabs' );
define( 'WOOCOMMERCE_PRODUCT_TABS_FREEMIUS_ID', '8712' );
define( 'WOOCOMMERCE_PRODUCT_TABS_BASENAME', basename( dirname( __FILE__ ) ) );
define( 'WOOCOMMERCE_PRODUCT_TABS_DIR', rtrim( plugin_dir_path( __FILE__ ), '/' ) );
define( 'WOOCOMMERCE_PRODUCT_TABS_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
define( 'WOOCOMMERCE_PRODUCT_TABS_POST_TYPE_TAB', 'woo_product_tab' );

if ( ! defined( 'WP_WELCOME_DIR' ) ) {
	define( 'WP_WELCOME_DIR', WOOCOMMERCE_PRODUCT_TABS_DIR . '/vendor/ernilambar/wp-welcome' );
}

if ( ! defined( 'WP_WELCOME_URL' ) ) {
	define( 'WP_WELCOME_URL', WOOCOMMERCE_PRODUCT_TABS_URL . '/vendor/ernilambar/wp-welcome' );
}

/**
 * Check if WooCommerce is active.
 */
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
	add_action( 'admin_notices', 'Barn2\Plugin\WC_Product_Tabs_Pro\wpt_admin_notice_woo_inactive' );
	return;
}

/**
 * Check if free version is active.
 */
if ( in_array( 'woocommerce-product-tabs/woocommerce-product-tabs.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
	add_action( 'admin_notices', 'Barn2\Plugin\WC_Product_Tabs_Pro\wpt_admin_notice_free_active' );
	return;
}

// Init autoload.
if ( file_exists( WOOCOMMERCE_PRODUCT_TABS_DIR . '/vendor/autoload.php' ) ) {
	require_once WOOCOMMERCE_PRODUCT_TABS_DIR . '/vendor/autoload.php';
	require_once WOOCOMMERCE_PRODUCT_TABS_DIR . '/vendor/ernilambar/wp-welcome/init.php';
}

/**
 * The code that runs during plugin activation.
 */
require_once plugin_dir_path( __FILE__ ) . 'src/Admin/Activator.php';

/**
 * The code that runs during plugin deactivation.
 */
require_once plugin_dir_path( __FILE__ ) . 'src/Admin/Deactivator.php';

/** This action is documented in src/class-woocommerce-product-tabs-activator.php */
register_activation_hook( __FILE__, array( 'Barn2\Plugin\WC_Product_Tabs_Pro\Admin\Activator', 'activate' ) );

/** This action is documented in src/class-woocommerce-product-tabs-deactivator.php */
register_deactivation_hook( __FILE__, array( 'Barn2\Plugin\WC_Product_Tabs_Pro\Admin\Deactivator', 'deactivate' ) );

function wpt_admin_notice_woo_inactive() {
	$message = sprintf( esc_html__( '%1$s is not active. Please activate it.', 'woocommerce-product-tabs' ), 'WooCommerce' );
	printf( '<div class="notice notice-warning"><p>%1$s</p></div>', $message );
}

function wpt_admin_notice_free_active() {
	$message = sprintf( esc_html__( '%1$s is still active. Please deactivate it first to use pro version.', 'woocommerce-product-tabs' ), 'WooCommerce Product Tabs' );
	printf( '<div class="notice notice-warning"><p>%1$s</p></div>', $message );
}

const PLUGIN_VERSION = '1.1.0';
const PLUGIN_FILE    = __FILE__;

// Include autoloader.
require_once __DIR__ . '/vendor/autoload.php';

/**
 * Helper function to access the shared plugin instance.
 *
 * @return Barn2\Plugin\WC_Product_Tabs_Pro
 */
function wta() {
	return Plugin_Factory::create( PLUGIN_FILE, PLUGIN_VERSION );
}

// Load the plugin.
wta()->register();



