<?php

/**
 * Plugin Name: Parkstatic
 * Plugin URI: https://parkstatic.site/
 * Description: Serve a static front-end on your WordPress domain while keeping wp-admin on WordPress. Includes a bundled demo site and tools to manage your title, favicon, and metadata.
 * Version: 1.0.0
 * Requires at least: 6.0
 * Requires PHP: 7.4
 * Author: Parkstatic
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: parkstatic
 *
 * @package Parkstatic
 */
declare (strict_types = 1);
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( !function_exists( 'parkstatic_is_free_plugin_file' ) ) {
    /**
     * @return bool
     */
    function parkstatic_is_free_plugin_file() : bool {
        return 'parkstatic/parkstatic.php' === plugin_basename( __FILE__ );
    }

}
if ( !function_exists( 'parkstatic_premium_plugin_is_active' ) ) {
    /**
     * @return bool
     */
    function parkstatic_premium_plugin_is_active() : bool {
        $premium_basenames = array('parkstatic_pro/parkstatic.php', 'parkstatic-premium/parkstatic.php');
        $active = get_option( 'active_plugins', array() );
        if ( !is_array( $active ) ) {
            return false;
        }
        foreach ( $premium_basenames as $basename ) {
            if ( !in_array( $basename, $active, true ) ) {
                continue;
            }
            if ( file_exists( WP_PLUGIN_DIR . '/' . $basename ) ) {
                return true;
            }
        }
        return false;
    }

}
// WordPress loads parkstatic/ before parkstatic_pro/ alphabetically. Bail out
// before Freemius init so the premium copy owns SDK filters and redirects.
if ( parkstatic_is_free_plugin_file() && parkstatic_premium_plugin_is_active() ) {
    return;
}
if ( !function_exists( 'parkstatic_register_premium_freemius_admin_routes__premium_only' ) ) {
}
if ( !function_exists( 'parkstatic_fs' ) ) {
    // Create a helper function for easy SDK access.
    function parkstatic_fs() {
        global $parkstatic_fs;
        if ( !isset( $parkstatic_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
            $parkstatic_fs = fs_dynamic_init( array(
                'id'               => '31647',
                'slug'             => 'parkstatic',
                'premium_slug'     => 'parkstatic_pro',
                'type'             => 'plugin',
                'public_key'       => 'pk_b3151e78db4e3d9ea5594bbbbe3a8',
                'is_premium'       => false,
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'anonymous_mode'   => true,
                'menu'             => array(
                    'slug'        => 'parkstatic-settings',
                    'parent'      => array(
                        'slug' => 'parkstatic-deploy',
                    ),
                    'support'     => false,
                    'account'     => false,
                    'contact'     => false,
                    'pricing'     => false,
                    'affiliation' => false,
                ),
                'is_live'          => true,
            ) );
        }
        return $parkstatic_fs;
    }

    // Init Freemius.
    parkstatic_fs();
    // Signal that SDK was initiated.
    do_action( 'parkstatic_fs_loaded' );
    // Don't auto-redirect new activations to the Freemius opt-in screen; the
    // plugin sends freshly activated sites to the Deploy onboarding wizard.
    parkstatic_fs()->add_filter( 'redirect_on_activation', '__return_false' );
    if ( function_exists( 'parkstatic_register_premium_freemius_admin_routes__premium_only' ) ) {
        parkstatic_register_premium_freemius_admin_routes__premium_only();
    }
}
// WordPress can include the main plugin file more than once when switching
// between free and premium builds (duplicate active_plugins entries, etc.).
if ( defined( 'PARKSTATIC_BOOTSTRAPPED' ) ) {
    return;
}
if ( !defined( 'PARKSTATIC_VERSION' ) ) {
    define( 'PARKSTATIC_VERSION', '1.0.0' );
}
/**
 * Where the "Upgrade Now" button on the Deploy screen sends the user: the
 * Freemius-hosted checkout for the Pro plan.
 */
if ( !defined( 'PARKSTATIC_CHECKOUT_URL' ) ) {
    define( 'PARKSTATIC_CHECKOUT_URL', 'https://checkout.freemius.com/plugin/31647/plan/52581/' );
}
/**
 * Where the "Find out more" button on the Deploy screen sends the user.
 */
if ( !defined( 'PARKSTATIC_PRO_URL' ) ) {
    define( 'PARKSTATIC_PRO_URL', 'https://parkstatic.site/' );
}
if ( !defined( 'PARKSTATIC_PLUGIN_FILE' ) ) {
    define( 'PARKSTATIC_PLUGIN_FILE', __FILE__ );
}
if ( !defined( 'PARKSTATIC_PLUGIN_DIR' ) ) {
    define( 'PARKSTATIC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
define( 'PARKSTATIC_BOOTSTRAPPED', true );
require_once PARKSTATIC_PLUGIN_DIR . 'includes/class-storage.php';
require_once PARKSTATIC_PLUGIN_DIR . 'includes/class-plugin.php';
Parkstatic_Plugin::instance();
if ( function_exists( 'parkstatic_register_premium_freemius_admin_routes__premium_only' ) ) {
    parkstatic_register_premium_freemius_admin_routes__premium_only();
}
if ( !function_exists( 'parkstatic_uninstall_cleanup' ) ) {
    /**
     * Removes Parkstatic files, options, and transients on plugin deletion.
     *
     * Runs through Freemius' "after_uninstall" hook instead of an uninstall.php
     * file. Freemius disallows uninstall.php because its presence prevents the
     * uninstall event (and user feedback) from being reported to the server.
     */
    function parkstatic_uninstall_cleanup() {
        require_once PARKSTATIC_PLUGIN_DIR . 'includes/class-storage.php';
        require_once PARKSTATIC_PLUGIN_DIR . 'includes/class-uninstaller.php';
        Parkstatic_Uninstaller::run();
    }

}
parkstatic_fs()->add_action( 'after_uninstall', 'parkstatic_uninstall_cleanup' );