<?php
/**
 * Plugin Name:       DrezSync: Calendar Booking for Gravity Forms
 * Plugin URI:        https://www.allydrez.com/drezsync
 * Description:       Turn any Gravity Form into a booking form that stays in sync with Google Calendar. Blocks times that are already taken and writes each new booking to your calendar.
 * Version:           1.6.8
 * Requires at least: 6.0
 * Requires PHP:      7.4
 * Author:            Ally Drez
 * Author URI:        https://www.allydrez.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       drezsync
 * Domain Path:       /languages
 *
 * @package DrezSync
 */

defined( 'ABSPATH' ) || exit;

if ( function_exists( 'drezsync_fs' ) ) {
	/*
	 * The other DrezSync build is already running.
	 *
	 * Free installs to drezsync/ and Pro to drezsync-pro/, so during an upgrade
	 * both sit on the site at once and WordPress loads each one's main file.
	 * Booting a second time would redeclare every class and take the site down,
	 * so this copy does exactly one thing: tell the live Freemius instance where
	 * it lives, then stand down. Knowing both locations is what lets Freemius
	 * deactivate the free build and hand the site over to Pro.
	 *
	 * Everything else lives in the else branch, which is the "nobody got here
	 * first, so I am the one that boots" path.
	 */
	$drezsync_is_premium_build = false;

	drezsync_fs()->set_basename( $drezsync_is_premium_build, __FILE__ );
} else {

	define( 'DREZSYNC_VERSION', '1.6.8' );
	define( 'DREZSYNC_FILE', __FILE__ );
	define( 'DREZSYNC_DIR', plugin_dir_path( __FILE__ ) );
	define( 'DREZSYNC_URL', plugin_dir_url( __FILE__ ) );
	define( 'DREZSYNC_MIN_GF_VERSION', '2.5' );

	// Public URL of the "connect Google Calendar" tutorial in the Ally Drez KB.
	// Update this to the final published page URL.
	define( 'DREZSYNC_KB_CONNECT_URL', 'https://www.allydrez.com/drezsync-api-connection/' );

	// Public URL for the DrezSync Pro upsell.
	define( 'DREZSYNC_PRO_URL', 'https://www.allydrez.com/drezsync/' );

	// Freemius bootstrap: loads the licensing SDK and bridges it to the
	// drezsync_is_pro gate. This is what defines drezsync_fs(), so it is also
	// what the check at the top of this file is looking for.
	require_once DREZSYNC_DIR . 'includes/freemius.php';

	require_once DREZSYNC_DIR . 'includes/class-license.php';
	require_once DREZSYNC_DIR . 'includes/class-drezsync.php';

	// A real top-level admin page so Freemius has a page to attach its account and
	// upgrade screens to (DrezSync is a Gravity Forms add-on with no page of its own).
	if ( is_admin() ) {
		require_once DREZSYNC_DIR . 'includes/admin/class-admin-menu.php';
	}

	// Register with Gravity Forms at the right moment — gform_loaded fires only
	// when Gravity Forms is active, which is the reliable time to register an add-on.
	add_action( 'gform_loaded', array( 'DrezSync', 'instance' ), 5 );

	// Let the admin know if Gravity Forms isn't active.
	add_action( 'admin_notices', array( 'DrezSync', 'maybe_dependency_notice' ) );
}
