<?php

/**
 * Plugin Name:       BuildsByLuke Upload Vault for Gravity Forms
 * Plugin URI:        https://buildsbyluke.com/plugins/upload-vault-for-gravity-forms
 * Description:       Gravity Forms uploads are protected only by an unguessable folder name. Upload Vault shows you exactly what a leaked URL exposes and locks it down — no code.
 * Version:           1.1.1
 * Requires at least: 6.2
 * Requires PHP:      7.4
 * Author:            Luke W
 * Author URI:        https://buildsbyluke.com
 * License:           GPLv2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       buildsbyluke-upload-vault-for-gravity-forms
 *
 * Upload Vault is an independent product and is not affiliated with, endorsed
 * by, or sponsored by Rocketgenius, Inc. ("Gravity Forms").
 *
 * @package Upload_Vault
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( function_exists( 'uvgf_fs' ) ) {
    // The other build of this plugin (free/premium) is already running. Hand it
    // this file's basename so Freemius can deactivate the redundant one. The
    // `true` marks THIS as the premium copy; the Freemius free-version processor
    // flips it to `false` in the generated wp.org build.
    uvgf_fs()->set_basename( false, __FILE__ );
} else {
    if ( !function_exists( 'uvgf_fs' ) ) {
        /**
         * Freemius SDK access.
         *
         * @return Freemius
         */
        function uvgf_fs() {
            global $uvgf_fs;
            if ( !isset( $uvgf_fs ) ) {
                require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
                $uvgf_fs = fs_dynamic_init( array(
                    'id'               => '35813',
                    'slug'             => 'buildsbyluke-upload-vault-for-gravity-forms',
                    'premium_slug'     => 'buildsbyluke-upload-vault-for-gravity-forms-premium',
                    'type'             => 'plugin',
                    'public_key'       => 'pk_d3cd5c10f781e45dfff8a5fb1f0aa',
                    'is_premium'       => false,
                    'premium_suffix'   => 'Pro',
                    'has_addons'       => false,
                    'has_paid_plans'   => true,
                    'is_org_compliant' => true,
                    'trial'            => array(
                        'days'               => 14,
                        'is_require_payment' => false,
                    ),
                    'menu'             => array(
                        'slug' => 'upload-vault-for-gravity-forms',
                    ),
                    'is_live'          => true,
                ) );
            }
            return $uvgf_fs;
        }

        uvgf_fs();
        // Turn off the SDK's sticky trial notice (guideline 11 — the upsell lives
        // only on the plugin's own pages + the SDK "Upgrade" menu item).
        uvgf_fs()->add_filter( 'show_trial', '__return_false' );
        // Turn off the SDK's deactivation-feedback dialog (it posts to
        // api.freemius.com even for users who never opted in).
        uvgf_fs()->add_filter( 'show_deactivation_feedback_form', '__return_false' );
        do_action( 'uvgf_fs_loaded' );
    }
    // ------------------------------------------------------------------
    // Upload Vault's own bootstrap.
    // ------------------------------------------------------------------
    define( 'UVGF_VERSION', '1.1.1' );
    define( 'UVGF_FILE', __FILE__ );
    define( 'UVGF_DIR', plugin_dir_path( __FILE__ ) );
    define( 'UVGF_URL', plugin_dir_url( __FILE__ ) );
    define( 'UVGF_BASENAME', plugin_basename( __FILE__ ) );
    spl_autoload_register( function ( $class ) {
        if ( 0 !== strpos( $class, 'Uvgf_' ) ) {
            return;
        }
        $file = UVGF_DIR . 'includes/class-' . str_replace( '_', '-', strtolower( $class ) ) . '.php';
        if ( is_readable( $file ) ) {
            require $file;
        }
    } );
    register_activation_hook( __FILE__, array('Uvgf_Install', 'activate') );
    register_deactivation_hook( __FILE__, array('Uvgf_Install', 'deactivate') );
    /**
     * UNINSTALL. There is deliberately no uninstall.php — WordPress runs either
     * uninstall.php OR the registered uninstall hook (never both), and a present
     * uninstall.php would deregister the Freemius SDK's uninstall handling (which
     * is why the Freemius deployment processor rejects a plugin that has one).
     */
    uvgf_fs()->add_action( 'after_uninstall', array('Uvgf_Uninstall', 'run') );
    add_action( 'uninstall_' . plugin_basename( __FILE__ ), array('Uvgf_Uninstall', 'safety_net'), 100 );
    /**
     * Container accessor.
     *
     * @return Uvgf_Plugin
     */
    function uvgf() {
        return Uvgf_Plugin::instance();
    }

    /**
     * Boot. The Pro layer loads first (when this is the premium build AND a
     * licence/trial is active) so it can hook `uvgf_loaded`.
     */
    function uvgf_boot() {
        uvgf();
    }

    add_action( 'plugins_loaded', 'uvgf_boot' );
}