<?php
/**
 * Plugin Name: RedFox Tab Manager
 * Plugin URI: https://www.redfoxwp.com/plugin/redfox-tab-manager/
 * Version: 1.0.3
 * Description: Create stunning WooCommerce product tabs with unlimited content possibilities! Use any Gutenberg blocks - videos, galleries, forms, testimonials, pricing tables, and more. Transform boring product pages into conversion powerhouses that sell like crazy!
 * Author: RedFox WP
 * Author URI: https://www.redfoxwp.com
 * Text Domain: redfox-tab-manager
 * Requires at least: 6.8
 * Requires PHP: 7.2
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Requires Plugins: woocommerce
 *
 * @package RedFoxWP\RedFoxTabManager
 * @since 1.0.0
 */

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

// Plugin constants.
define( 'REDFOX_TAB_MANAGER_VERSION', '1.0.3' );
define( 'REDFOX_TAB_MANAGER_PLUGIN_FILE', __FILE__ );
define( 'REDFOX_TAB_MANAGER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'REDFOX_TAB_MANAGER_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'REDFOX_TAB_MANAGER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

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

// Load required classes in correct order.
require_once REDFOX_TAB_MANAGER_PLUGIN_DIR . 'includes/abstracts/class-abstract-singleton.php';
require_once REDFOX_TAB_MANAGER_PLUGIN_DIR . 'includes/abstracts/class-abstract-api-endpoint.php';
require_once REDFOX_TAB_MANAGER_PLUGIN_DIR . 'includes/class-plugin.php';

/**
 * Initialize the RedFox Tab Manager plugin.
 *
 * @since 1.0.0
 * @access public
 * @return void
 */
function redfox_tab_manager_init() {
	// Initialize the main plugin singleton instance.
	\RedFoxWP\RedFoxTabManager\Plugin::get_instance();
}

// Hook into WordPress plugins_loaded action to initialize the plugin.
add_action( 'plugins_loaded', 'redfox_tab_manager_init' );

if ( ! function_exists( 'redfox_tab_manager_fs' ) ) {
	/**
	 * Initialize Freemius.
	 *
	 * @since 1.0.3
	 * @return \Freemius
	 */
	function redfox_tab_manager_fs() {
		global $redfox_tab_manager_fs;

		if ( ! isset( $redfox_tab_manager_fs ) ) {

			$redfox_tab_manager_fs = fs_dynamic_init(
				array(
					'id'               => '21687',
					'slug'             => 'redfox-tab-manager',
					'type'             => 'plugin',
					'public_key'       => 'pk_70e9887df3b9b828fe2ad31ccedfb',
					'is_premium'       => false,
					'has_addons'       => false,
					'has_paid_plans'   => false,
					'is_org_compliant' => true,
					'menu'             => array(
						'slug'       => 'redfox-tab-manager',
						'first-path' => 'admin.php?page=redfox-tab-manager',
						'account'    => false,
						'contact'    => false,
						'support'    => false,
						'parent'     => array(
							'slug' => 'redfox-wp',
						),
					),
				)
			);
		}

		return $redfox_tab_manager_fs;
	}

	// Init Freemius.
	redfox_tab_manager_fs();
	// Signal that SDK was initiated.
	do_action( 'redfox_tab_manager_fs_loaded' );

	/**
	 * Get the settings URL for the plugin.
	 *
	 * @since 1.0.4
	 * @return string The settings URL.
	 */
	function redfox_tab_manager_fs_settings_url() {
		return admin_url( 'admin.php?page=redfox-tab-manager' );
	}

	redfox_tab_manager_fs()->add_filter( 'connect_url', 'redfox_tab_manager_fs_settings_url' );
	redfox_tab_manager_fs()->add_filter( 'after_skip_url', 'redfox_tab_manager_fs_settings_url' );
	redfox_tab_manager_fs()->add_filter( 'after_connect_url', 'redfox_tab_manager_fs_settings_url' );
	redfox_tab_manager_fs()->add_filter( 'after_pending_connect_url', 'redfox_tab_manager_fs_settings_url' );
}

/**
 * Plugin activation hook for RedFox Tab Manager.
 *
 * Checks user capability and flushes rewrite rules.
 *
 * @since 1.0.0
 * @access public
 * @return void
 */
function redfox_tab_manager_activate() {
	// Ensure the current user can activate plugins.
	if ( ! current_user_can( 'activate_plugins' ) ) {
		return;
	}

	// Flush rewrite rules to register custom post types and endpoints.
	flush_rewrite_rules();
}
// Register plugin activation hook.
register_activation_hook( __FILE__, 'redfox_tab_manager_activate' );

/**
 * Plugin deactivation hook for RedFox Tab Manager.
 *
 * Flushes rewrite rules.
 *
 * @since 1.0.0
 * @access public
 * @return void
 */
function redfox_tab_manager_deactivate() {
	// Ensure the current user can activate plugins.
	if ( ! current_user_can( 'activate_plugins' ) ) {
		return;
	}

	// Flush rewrite rules to clean up custom post types and endpoints.
	flush_rewrite_rules();
}
// Register plugin deactivation hook.
register_deactivation_hook( __FILE__, 'redfox_tab_manager_deactivate' );
