<?php

/**
 * Plugin Name: Player Transfers for SportsPress
 * Description: Manage player transfers for SportsPress.
 * Version: 1.4.1
 * Author: savvasha
 * Author URI: https://profiles.wordpress.org/savvasha/
 * Text Domain: player-transfers-for-sportspress
 * Domain Path: /languages
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * 
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
    // Exit if accessed directly
}
if ( function_exists( 'ptfs_fs' ) ) {
    ptfs_fs()->set_basename( false, __FILE__ );
} else {
    /**
     * DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE
     * `function_exists` CALL ABOVE TO PROPERLY WORK.
     */
    if ( !function_exists( 'ptfs_fs' ) ) {
        // Create a helper function for easy SDK access.
        function ptfs_fs() {
            global $ptfs_fs;
            if ( !isset( $ptfs_fs ) ) {
                // Include Freemius SDK.
                require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
                $ptfs_fs = fs_dynamic_init( array(
                    'id'               => '17893',
                    'slug'             => 'player-transfers-for-sportspress',
                    'type'             => 'plugin',
                    'public_key'       => 'pk_685c26192de113e50d15f8e56fbbf',
                    'is_premium'       => false,
                    'premium_suffix'   => 'Premium',
                    'has_addons'       => false,
                    'has_paid_plans'   => true,
                    'menu'             => array(
                        'slug' => 'edit.php?post_type=ptfs_player_transfer',
                    ),
                    'is_live'          => true,
                    'is_org_compliant' => true,
                ) );
            }
            return $ptfs_fs;
        }

        // Init Freemius.
        ptfs_fs();
        // Signal that SDK was initiated.
        do_action( 'ptfs_fs_loaded' );
    }
    /**
     * Define constants
     */
    if ( !defined( 'PTFS_VERSION' ) ) {
        define( 'PTFS_VERSION', '1.4.1' );
    }
    if ( !defined( 'PTFS_URL' ) ) {
        define( 'PTFS_URL', plugin_dir_url( __FILE__ ) );
    }
    if ( !defined( 'PTFS_DIR' ) ) {
        define( 'PTFS_DIR', plugin_dir_path( __FILE__ ) );
    }
    /**
     * Include the TGM_Plugin_Activation class.
     */
    require_once PTFS_DIR . 'includes/libraries/class-tgm-plugin-activation.php';
    /**
     * Register the required plugins for this plugin.
     * 
     * This function is hooked into `tgmpa_register`, which is fired on the WP `init` action on priority 10.
     */
    function ptfs_register_required_plugins() {
        /*
         * Array of plugin arrays. Required keys are name and slug.
         * If the source is NOT from the .org repo, then source is also required.
         */
        $plugins = array(array(
            'name'        => 'SportsPress',
            'slug'        => 'sportspress',
            'required'    => true,
            'is_callable' => 'SP',
        ), array(
            'name'        => 'Meta Box',
            'slug'        => 'meta-box',
            'required'    => true,
            'is_callable' => 'rwmb_meta',
        ));
        /*
         * Array of configuration settings. Amend each line as needed.
         */
        $config = array(
            'id'           => 'player-transfers-for-sportspress',
            'default_path' => '',
            'menu'         => 'tgmpa-install-plugins',
            'parent_slug'  => 'plugins.php',
            'capability'   => 'manage_options',
            'has_notices'  => true,
            'dismissable'  => true,
            'dismiss_msg'  => '',
            'is_automatic' => true,
            'message'      => '',
            'strings'      => array(
                'notice_can_install_required' => _n_noop( 'Player Transfers for SportsPress requires the following plugin: %1$s.', 'Player Transfers for SportsPress requires the following plugins: %1$s.', 'player-transfers-for-sportspress' ),
                'notice_ask_to_update'        => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with Player Transfers for SportsPress: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with Player Transfers for SportsPress: %1$s.', 'player-transfers-for-sportspress' ),
            ),
        );
        tgmpa( $plugins, $config );
    }

    add_action( 'tgmpa_register', 'ptfs_register_required_plugins' );
    /**
     * Include required files and initialize the plugin.
     * 
     * This section loads the custom post type for player transfers and sets up
     * activation/deactivation hooks. The plugin functionality is only initialized
     * when the required plugins (SportsPress and Meta Box) are active.
     */
    require_once PTFS_DIR . 'includes/class-cpt-player-transfers.php';
    add_action( 'plugins_loaded', function () {
        PTFS_Player_Transfers::init();
    } );
    // Register activation and deactivation hooks
    register_activation_hook( __FILE__, ['PTFS_Player_Transfers', 'activate'] );
    register_deactivation_hook( __FILE__, ['PTFS_Player_Transfers', 'deactivate'] );
    // Initialize the plugin after all plugins are loaded
    add_action( 'init', function () {
        if ( function_exists( 'SP' ) && function_exists( 'rwmb_meta' ) ) {
            // Include required files
            require_once PTFS_DIR . 'includes/class-metaboxes.php';
            require_once PTFS_DIR . 'includes/class-shortcode.php';
            require_once PTFS_DIR . 'includes/class-frontend-assets.php';
            PTFS_Metaboxes::init();
            PTFS_Shortcode::init();
            PTFS_Frontend_Assets::init();
        }
    } );
}