<?php

/**
 * Plugin Name: Login Page Customizer and Designer
 * Plugin URI:  https://wordpress.org/plugins/login-page-customizer-and-designer/
 * Description: Customize your WordPress login page with a visual editor. Choose from free templates and customize every detail. No coding required.
 * Version:     1.0.1
 * Author:      shoiswp
 * Author URI:  https://profiles.wordpress.org/shoiswp/
 * License:     GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: login-page-customizer-and-designer
 * Domain Path: /languages
 * Requires at least: 6.2
 * Requires PHP: 7.4
 * Tested up to: 6.9
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * Freemius SDK integration.
 */
if ( !function_exists( 'lpcd_fs' ) ) {
    // Create a helper function for easy SDK access.
    function lpcd_fs() {
        global $lpcd_fs;
        if ( !isset( $lpcd_fs ) ) {
            // Activate multisite network integration.
            if ( !defined( 'WP_FS__PRODUCT_25839_MULTISITE' ) ) {
                define( 'WP_FS__PRODUCT_25839_MULTISITE', true );
            }
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
            $lpcd_fs = fs_dynamic_init( array(
                'id'               => '25839',
                'slug'             => 'login-page-customizer-and-designer',
                'type'             => 'plugin',
                'public_key'       => 'pk_8801f2392c0f0bea915a72e636d50',
                'is_premium'       => false,
                'premium_suffix'   => 'Professional',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => array(
                    'slug'       => 'lpcd-overview',
                    'first-path' => 'admin.php?page=lpcd-overview',
                    'support'    => false,
                ),
                'is_live'          => true,
            ) );
        }
        return $lpcd_fs;
    }

    // Init Freemius.
    lpcd_fs();
    // Signal that SDK was initiated.
    do_action( 'lpcd_fs_loaded' );
    // Hook uninstall cleanup to Freemius (replaces uninstall.php).
    lpcd_fs()->add_action( 'after_uninstall', 'lpcd_fs_uninstall_cleanup' );
}
/**
 * Plugin constants.
 */
define( 'LPCD_VERSION', '1.0.1' );
define( 'LPCD_SLUG', 'login-page-customizer-and-designer' );
define( 'LPCD_DIR', plugin_dir_path( __FILE__ ) );
define( 'LPCD_URL', plugin_dir_url( __FILE__ ) );
define( 'LPCD_BASENAME', plugin_basename( __FILE__ ) );
/**
 * Check if the current user has a Pro license.
 *
 * @return bool True if Pro plan is active.
 */
function lpcd_is_pro() {
    return function_exists( 'lpcd_fs' ) && lpcd_fs()->can_use_premium_code();
}

/**
 * Include required files.
 */
require_once LPCD_DIR . 'includes/class-lpcd-sanitizer.php';
require_once LPCD_DIR . 'includes/class-lpcd-settings-manager.php';
require_once LPCD_DIR . 'includes/class-lpcd-template-manager.php';
require_once LPCD_DIR . 'includes/class-lpcd-css-generator.php';
require_once LPCD_DIR . 'includes/class-lpcd-login-renderer.php';
require_once LPCD_DIR . 'admin/class-lpcd-admin.php';
require_once LPCD_DIR . 'admin/class-lpcd-rest-api.php';
require_once LPCD_DIR . 'includes/class-lpcd-url-changer.php';
/**
 * Run on plugin activation.
 */
function lpcd_activate() {
    LPCD_Template_Manager::create_tables();
    LPCD_Settings_Manager::create_tables();
    LPCD_Template_Manager::seed_free_templates();
    flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'lpcd_activate' );
/**
 * Run on plugin deactivation.
 */
function lpcd_deactivate() {
    flush_rewrite_rules();
}

register_deactivation_hook( __FILE__, 'lpcd_deactivate' );
/**
 * Initialize plugin components.
 */
function lpcd_init() {
    // Seed any missing free templates (safe to call repeatedly).
    if ( is_admin() ) {
        LPCD_Template_Manager::seed_free_templates();
    }
    new LPCD_Admin();
    new LPCD_Rest_Api();
    new LPCD_Login_Renderer();
    new LPCD_Url_Changer();
}

add_action( 'plugins_loaded', 'lpcd_init' );
/**
 * Handle uninstallation cleanup via Freemius hook.
 * This runs after the uninstall event is reported to the server.
 */
function lpcd_fs_uninstall_cleanup() {
    global $wpdb;
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}lpcd_templates" );
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}lpcd_settings" );
}
