57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|||
|
|
namespace AuroraAdmin\Licensing;
|
||
|
|
|
||
|
|
use AuroraAdmin\Options\Settings;
|
||
|
|
|
||
|
|
defined("ABSPATH") || exit();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Single gate every paid feature funnels through, so the free/paid split
|
||
|
|
* lives in one place instead of being re-decided in each feature's code.
|
||
|
|
*
|
||
|
|
* Today's is_active() is a placeholder: any non-empty license_key counts as
|
||
|
|
* active, with no remote validation. There's no license server yet — when
|
||
|
|
* one exists, swap is_active()'s internals for a real check (cached in a
|
||
|
|
* transient so it isn't a remote call on every admin page load); nothing
|
||
|
|
* else in the plugin needs to change, since every gated feature already
|
||
|
|
* calls into this class rather than reading the setting directly.
|
||
|
|
*/
|
||
|
|
class License
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Paid sub-apps/features, keyed by the id used to gate them, mapped to a
|
||
|
|
* human label used in upgrade prompts.
|
||
|
|
*/
|
||
|
|
const PAID_FEATURES = [
|
||
|
|
"role-editor" => "Role Editor",
|
||
|
|
"activity-log" => "Activity Log",
|
||
|
|
"database-explorer" => "Database Explorer",
|
||
|
|
"analytics" => "Analytics",
|
||
|
|
"white-label" => "White Label",
|
||
|
|
"remote-site-switcher" => "Remote Site Switcher",
|
||
|
|
];
|
||
|
|
|
||
|
|
public static function is_active()
|
||
|
|
{
|
||
|
|
$key = trim((string) Settings::get("license_key", ""));
|
||
|
|
return $key !== "";
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* True for any feature not in PAID_FEATURES (nothing to gate) or when a
|
||
|
|
* license is active; false only when the feature is paid and unlicensed.
|
||
|
|
*/
|
||
|
|
public static function is_feature_available($feature)
|
||
|
|
{
|
||
|
|
if (!isset(self::PAID_FEATURES[$feature])) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return self::is_active();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function feature_label($feature)
|
||
|
|
{
|
||
|
|
return isset(self::PAID_FEATURES[$feature]) ? self::PAID_FEATURES[$feature] : "";
|
||
|
|
}
|
||
|
|
}
|