<?php
/**
 * Plugin Name: Clearfy Whitelable
 * Plugin URI: https://clearfy.pro/whitelabel/
 * Description: White Labels - this plugin allows you to remove the Clearfy plugin brand and add your own.
 * Author: CreativeMotion <wordpress.webraftic@gmail.com>
 * Version: 1.0.0
 * Text Domain: clearfy-whitelable
 * Domain Path: /languages/
 * Author URI: https://cm-wp.com
 */

// Выход при непосредственном доступе
if( !defined('ABSPATH') ) {
	exit;
}

if( !function_exists('wwlable_premium_load') ) {
	function wwlable_premium_load()
	{
		if( !defined('WCL_PLUGIN_ACTIVE') || defined('WCL_PLUGIN_THROW_ERROR') ) {
			return;
		}

		if( WCL_Plugin::app()->premium->is_activate() && "14364" === WCL_Plugin::app()->premium->get_license()->get_plan_id() ) {
			if( version_compare(WCL_PLUGIN_VERSION, '1.9.4', '<') ) {
				$wwlable_plugin_error_func = function () {
					$error = __("The Clearfy Whitelable component has stopped. <b>Error:</b> You need to update the Clearfy plugin to version 1.9.4 and higher!", "clearfy");
					echo '<div class="notice notice-error"><p>' . $error . '</p></div>';
				};

				add_action('admin_notices', $wwlable_plugin_error_func);
				add_action('network_admin_notices', $wwlable_plugin_error_func);

				return;
			}

			// Устанавливаем контстанту, что плагин уже используется
			define('WWLABLE_PLUGIN_ACTIVE', true);

			// Устанавливаем контстанту, что плагин уже используется
			define('WWLABLE_PLUGIN_VERSION', '1.0.0');

			// Директория плагина
			define('WWLABLE_PLUGIN_DIR', dirname(__FILE__));

			// Относительный путь к плагину
			define('WWLABLE_PLUGIN_BASE', plugin_basename(__FILE__));

			// Ссылка к директории плагина
			define('WWLABLE_PLUGIN_URL', plugins_url(null, __FILE__));

			// Global scripts
			// ---------------------------------------------------------
			try {
				require_once WWLABLE_PLUGIN_DIR . '/includes/class-branding.php';
				//new WWLABLE_Configurate(WCL_Plugin::app());
			} catch( Exception $e ) {
				// nothing
			}

			// Admin scripts
			// ---------------------------------------------------------
			if( is_admin() ) {
				//require_once(WWLABLE_PLUGIN_DIR . '/admin/boot.php');

				$admin_path = WWLABLE_PLUGIN_DIR . '/admin/pages';
				WCL_Plugin::app()->registerPage('WWLABLE_SettingsPage', $admin_path . '/class-pages-settings.php');
			}
		}
	}

	add_action('plugins_loaded', 'wwlable_premium_load', 20);

	/**.
	 * Очищает данные плагина, при удалении плагина
	 *
	 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
	 * @since  1.1.0
	 */
	function wwlable_premium_uninstall()
	{
		//global $wpdb;
		//$wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE 'wbcr_ajs_%';" );
	}

	if( defined('WCLP_PLUGIN_ACTIVE') ) {
		$wwlable_activation_file = WCLP_PLUGIN_FILE;
	} else {
		$wwlable_activation_file = __FILE__;
	}
	register_uninstall_hook($wwlable_activation_file, 'wwlable_premium_uninstall');
}
