<?php

/**
 * Plugin Name: WPStack Sandbox Manager
 * Plugin URI:  https://wpstack.online/
 * Description: Creates isolated, disposable WordPress Multisite demos. Built by WP Stack Online.
 * Version:     0.3.2
 * Author:      Aditya Bhimrajka
 * Author URI:  https://wpstack.online/
 * Text Domain: wpstack-sandbox
 * License:     GPL-2.0-or-later
 * Network:     true
 *
 */
declare (strict_types = 1);
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/*
 * Freemius deactivates a second edition when the free and paid packages are
 * installed together. Do not remove this guard: it prevents both editions
 * from booting in the same request.
 */
if ( function_exists( 'wsm_fs' ) ) {
    wsm_fs()->set_basename( false, __FILE__ );
    return;
}
if ( !function_exists( 'wsm_fs' ) ) {
    function wsm_fs() {
        global $wsm_fs;
        if ( !isset( $wsm_fs ) ) {
            if ( !defined( 'WP_FS__PRODUCT_35851_MULTISITE' ) ) {
                define( 'WP_FS__PRODUCT_35851_MULTISITE', true );
            }
            require_once __DIR__ . '/vendor/freemius/start.php';
            $wsm_fs = fs_dynamic_init( [
                'id'               => '35851',
                'slug'             => 'wpstack-sandbox-manager',
                'type'             => 'plugin',
                'public_key'       => 'pk_2123ae266422eb08a756a336688aa',
                'is_premium'       => false,
                'premium_suffix'   => 'Pro',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => [
                    'slug'    => 'wpstack-sandboxes',
                    'support' => false,
                    'network' => true,
                ],
                'is_live'          => true,
            ] );
        }
        return $wsm_fs;
    }

    wsm_fs();
    do_action( 'wsm_fs_loaded' );
}
define( 'WPSTACK_SANDBOX_VERSION', '0.3.2' );
define( 'WPSTACK_SANDBOX_FILE', __FILE__ );
define( 'WPSTACK_SANDBOX_DIR', plugin_dir_path( __FILE__ ) );
define( 'WPSTACK_SANDBOX_URL', plugin_dir_url( __FILE__ ) );
spl_autoload_register( static function ( string $class ) : void {
    $prefix = 'WPStack\\Sandbox\\';
    if ( !str_starts_with( $class, $prefix ) ) {
        return;
    }
    $relative = substr( $class, strlen( $prefix ) );
    $file = WPSTACK_SANDBOX_DIR . 'src/' . str_replace( '\\', '/', $relative ) . '.php';
    if ( is_readable( $file ) ) {
        require_once $file;
    }
} );
register_activation_hook( __FILE__, [\WPStack\Sandbox\WordPress\Installer::class, 'activate'] );
register_deactivation_hook( __FILE__, [\WPStack\Sandbox\WordPress\Installer::class, 'deactivate'] );
add_action( 'plugins_loaded', static function () : void {
    if ( !is_multisite() ) {
        return;
    }
    \WPStack\Sandbox\WordPress\Installer::maybeUpgrade();
    ( new \WPStack\Sandbox\WordPress\SandboxPlugin() )->boot();
} );