<?php

/**
 * Plugin Name:       BuildsByLuke SEO Flight Recorder
 * Plugin URI:        https://buildsbyluke.com/plugins/seo-flight-recorder
 * Description:       Records your pages' SEO-critical output — titles, meta, robots, canonicals, schema, Open Graph — and tells you what changed, when, and which update did it.
 * Version:           1.0.2
 * 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-seo-flight-recorder
 * Domain Path:       /languages
 *
 * @package SEO_Flight_Recorder
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( function_exists( 'sfrec_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, and
    // stop here: nothing below must run twice. The `true` marks THIS as the
    // premium copy (this is the premium source); the Freemius free-version
    // processor flips it to `false` in the generated wp.org build.
    sfrec_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( 'sfrec_fs' ) ) {
        /**
         * Freemius SDK access.
         *
         * @return Freemius
         */
        function sfrec_fs() {
            global $sfrec_fs;
            if ( !isset( $sfrec_fs ) ) {
                // Include Freemius SDK.
                require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
                $sfrec_fs = fs_dynamic_init( array(
                    'id'               => '35810',
                    'slug'             => 'buildsbyluke-seo-flight-recorder',
                    'premium_slug'     => 'buildsbyluke-seo-flight-recorder-premium',
                    'type'             => 'plugin',
                    'public_key'       => 'pk_1d7ed81f67800f86fc6100843c583',
                    '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' => 'seo-flight-recorder',
                    ),
                    'is_live'          => true,
                ) );
            }
            return $sfrec_fs;
        }

        // Init Freemius.
        sfrec_fs();
        /**
         * Turn the SDK's trial-promotion notice off.
         *
         * Left on, the SDK raises a sticky notice on EVERY admin screen 24 hours
         * after activation and again every 30 days. Guideline 11 asks for upgrade
         * prompts to be "limited in scope and used sparingly, be that contextually
         * or only on the plugin's setting page" — so this plugin's upsell lives in
         * exactly two places a person chooses to open: its own Flight Log page,
         * and the SDK's clearly-labelled "Upgrade" item under its own menu.
         * `show_trial` is the SDK's own documented opt-out.
         */
        sfrec_fs()->add_filter( 'show_trial', '__return_false' );
        /**
         * Turn the SDK's deactivation-feedback dialog off.
         *
         * Left on, deactivating opens a "quick feedback" modal whose submission is
         * posted to api.freemius.com — including by users who never opted in. The
         * readme promises Freemius is contacted only in the click-through
         * situations it lists, and this dialog would be an extra one.
         * Deactivation should be one click, not a survey.
         */
        sfrec_fs()->add_filter( 'show_deactivation_feedback_form', '__return_false' );
        // Signal that SDK was initiated.
        do_action( 'sfrec_fs_loaded' );
    }
    // ------------------------------------------------------------------
    // SEO Flight Recorder's own bootstrap.
    // ------------------------------------------------------------------
    define( 'SFREC_VERSION', '1.0.2' );
    define( 'SFREC_FILE', __FILE__ );
    define( 'SFREC_DIR', plugin_dir_path( __FILE__ ) );
    define( 'SFREC_URL', plugin_dir_url( __FILE__ ) );
    define( 'SFREC_BASENAME', plugin_basename( __FILE__ ) );
    spl_autoload_register( function ( $class ) {
        if ( 0 !== strpos( $class, 'SFRec_' ) ) {
            return;
        }
        $file = SFREC_DIR . 'includes/class-' . str_replace( '_', '-', strtolower( $class ) ) . '.php';
        if ( is_readable( $file ) ) {
            require $file;
        }
    } );
    register_activation_hook( __FILE__, array('SFRec_Install', 'activate') );
    register_deactivation_hook( __FILE__, array('SFRec_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.
     * Cleanup lives in SFRec_Uninstall: the SDK's `after_uninstall` action is the
     * sanctioned path, and the core `uninstall_{basename}` registration below is
     * the safety net for when the SDK instance cannot be resolved (it no-ops if
     * the SDK path already ran).
     */
    sfrec_fs()->add_action( 'after_uninstall', array('SFRec_Uninstall', 'run') );
    add_action( 'uninstall_' . plugin_basename( __FILE__ ), array('SFRec_Uninstall', 'safety_net'), 100 );
    /**
     * Container accessor.
     *
     * @return SFRec_Plugin
     */
    function sfrec() {
        return SFRec_Plugin::instance();
    }

    /**
     * Boot. The Pro layer loads first (when this is the premium build AND a
     * licence/trial is active) so it can hook `sfrec_loaded`, which the container
     * fires at the end of its own boot.
     */
    function sfrec_boot() {
        sfrec();
    }

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