| 1 |
<?php |
| 2 |
/** |
| 3 |
* Single source of truth for the plugin's Free/Pro edition status. |
| 4 |
* |
| 5 |
* @package Import_Export_Menu |
| 6 |
* @since 2.2.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace ImportExportMenu; |
| 12 |
|
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
/** |
| 16 |
* Answers whether the Pro edition is present, unlocked, and currently licensed. |
| 17 |
* |
| 18 |
* Keeps every edition check in one place so the Free plugin never contains |
| 19 |
* license logic (a wp.org requirement). A separate Pro plugin supplies the real |
| 20 |
* answers by hooking the filters below; without it, every method returns false |
| 21 |
* and the plugin runs as Free. |
| 22 |
* |
| 23 |
* The three methods serve distinct purposes — do not collapse them: |
| 24 |
* |
| 25 |
* - {@see self::is_pro_active()} presence only (is the Pro plugin loaded?). |
| 26 |
* - {@see self::is_pro_unlocked()} runtime feature gate. Persistent: stays true |
| 27 |
* after a license has ever activated, even once it expires. |
| 28 |
* - {@see self::is_pro_licensed()} validity right now. For the UI badge and the |
| 29 |
* updater check — NOT a feature gate. |
| 30 |
* |
| 31 |
* @since 2.2.0 |
| 32 |
*/ |
| 33 |
final class Edition { |
| 34 |
|
| 35 |
/** |
| 36 |
* Whether the Pro plugin is loaded. |
| 37 |
* |
| 38 |
* Checks the constant only — tells presence, not entitlement. |
| 39 |
* |
| 40 |
* @return bool |
| 41 |
*/ |
| 42 |
public static function is_pro_active(): bool { |
| 43 |
return defined( 'IMPORT_EXPORT_MENU_PRO_LOADED' ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Whether a license has ever successfully activated. |
| 48 |
* |
| 49 |
* Persistent gate for Pro features: stays true even after the license |
| 50 |
* expires, so an expired license never removes access to already-unlocked |
| 51 |
* features. The Pro plugin supplies the answer via the filter. |
| 52 |
* |
| 53 |
* @return bool |
| 54 |
*/ |
| 55 |
public static function is_pro_unlocked(): bool { |
| 56 |
return self::is_pro_active() |
| 57 |
&& (bool) apply_filters( 'import_export_menu_pro_unlocked', false ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Whether the license is valid right now. |
| 62 |
* |
| 63 |
* Drives the UI badge and the updater check only — never use it to gate a |
| 64 |
* feature (use {@see self::is_pro_unlocked()} for that). The Pro plugin |
| 65 |
* supplies the answer via the filter. |
| 66 |
* |
| 67 |
* @return bool |
| 68 |
*/ |
| 69 |
public static function is_pro_licensed(): bool { |
| 70 |
return self::is_pro_active() |
| 71 |
&& (bool) apply_filters( 'import_export_menu_pro_license_valid', false ); |
| 72 |
} |
| 73 |
} |
| 74 |
|