<?php
/**
 * Plugin Name: PureDash Cleaner
 * Description: Clean up your WordPress admin interface by hiding annoying elements with a click. Enhanced Edition.
 * Version: 1.2.8
 * Tested up to: 7.0
 * Author: Rahajason
 * Text Domain: puredash-cleaner
 * Domain Path: /languages
 * License: GPLv2 or later
 * CLI Command: puredash-cleaner
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Global Constants
define( 'PUREDASH_VERSION', '1.2.8' );
define( 'PUREDASH_PATH', plugin_dir_path( __FILE__ ) );
define( 'PUREDASH_URL', plugin_dir_url( __FILE__ ) );

// Freemius Integration
if ( ! function_exists( 'puredash_fs' ) ) {
	/**
	 * Create a helper function for easy SDK access.
	 *
	 * @return \Freemius
	 */
	function puredash_fs() {
		global $puredash_fs;

		if ( ! isset( $puredash_fs ) ) {
			// Include Freemius SDK.
			if ( ! function_exists( 'fs_dynamic_init' ) ) {
				require PUREDASH_PATH . 'vendor/freemius/wordpress-sdk/start.php';
			}

			$puredash_fs = fs_dynamic_init(
				array(
					'id'               => '24028',
					'slug'             => 'puredash-cleaner',
					'type'             => 'plugin',
					'public_key'       => 'pk_0b6090f420c69ba42edc2d2b24ac7',
					'is_premium'       => false,
					'is_org_compliant' => true,
					'has_addons'       => false,
					'has_paid_plans'   => false,
					'menu'             => array(
						'slug'       => 'puredash-cleaner',
						'first-path' => 'options-general.php?page=puredash-cleaner',
						'support'    => false,
					),
				)
			);

			// Register uninstall cleanup.
			$puredash_fs->add_action( 'after_uninstall', 'puredash_fs_uninstall_cleanup' );
		}

		return $puredash_fs;
	}

	/**
	 * Cleanup function called by Freemius after uninstall.
	 */
	function puredash_fs_uninstall_cleanup() {
		delete_option( 'puredash-cleaner_blacklist' );
		delete_option( 'puredash-cleaner_schema_version' );
		delete_option( 'puredash-cleaner_white_label' );
	}

	// Init Freemius.
	puredash_fs();
	// Signal that skipped custom initialization.
	do_action( 'puredash_fs_loaded' );
}
if ( ! defined( 'PUREDASH_DEBUG' ) ) {
	define( 'PUREDASH_DEBUG', false );
}

// Define main file for hooks
if ( ! defined( 'PUREDASH_FILE' ) ) {
	define( 'PUREDASH_FILE', __FILE__ );
}

// Autoloader (Primitive but effective since we have a fixed structure)
spl_autoload_register(
	function ( $class_name ) {
		$prefix   = 'PureDash\\';
		$base_dir = PUREDASH_PATH . 'includes/';

		$len = strlen( $prefix );
		if ( strncmp( $prefix, $class_name, $len ) !== 0 ) {
			return;
		}

		$relative_class = substr( $class_name, $len );
		// WP Class Naming: underscores to hyphens, lowercase
		$filename = 'class-' . strtolower( str_replace( '_', '-', $relative_class ) ) . '.php';
		$file     = $base_dir . $filename;

		if ( file_exists( $file ) ) {
			require $file;
		}
	}
);

// Require Main Class
require_once PUREDASH_PATH . 'includes/class-puredash-cleaner.php';

/**
 * Returns the main instance of puredash_cleaner.
 *
 * @return PureDash_Cleaner
 */
function puredash_cleaner() {
	return \PureDash\PureDash_Cleaner::get_instance();
}
// Kickoff
puredash_cleaner();
