wizard
1 month ago
class-dashboard-controller.php
1 month ago
class-license-resolve-controller.php
1 month ago
class-newsletter-signup-controller.php
1 month ago
class-notice-controller.php
1 month ago
class-plugin-reset-controller.php
1 month ago
class-rewrite-check-controller.php
1 month ago
class-settings-controller.php
1 month ago
class-troubleshooting-controller.php
1 month ago
class-license-resolve-controller.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Admin\Controllers; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | use Exception; |
| 8 | use SuperbAddons\Data\Controllers\KeyController; |
| 9 | use SuperbAddons\Data\Controllers\LogController; |
| 10 | |
| 11 | class LicenseResolveController |
| 12 | { |
| 13 | const COOLDOWN_TRANSIENT = 'spbaddons_license_resolve_cooldown'; |
| 14 | const COOLDOWN_DURATION = DAY_IN_SECONDS; |
| 15 | |
| 16 | private static $attempted = false; |
| 17 | |
| 18 | /** |
| 19 | * Hook into admin_init. Called once during plugin bootstrap. |
| 20 | */ |
| 21 | public static function Initialize() |
| 22 | { |
| 23 | add_action('admin_init', array(__CLASS__, 'MaybeAutoResolve')); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Attempt automatic license resolution if a registered key has an issue |
| 28 | * and the cooldown period has elapsed. |
| 29 | */ |
| 30 | public static function MaybeAutoResolve() |
| 31 | { |
| 32 | if (self::$attempted) { |
| 33 | return; |
| 34 | } |
| 35 | self::$attempted = true; |
| 36 | |
| 37 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 38 | return; |
| 39 | } |
| 40 | if (defined('DOING_CRON') && DOING_CRON) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | if (!KeyController::HasRegisteredKey()) { |
| 45 | return; |
| 46 | } |
| 47 | if (KeyController::HasValidKey()) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | if (get_transient(self::COOLDOWN_TRANSIENT)) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | set_transient(self::COOLDOWN_TRANSIENT, 1, self::COOLDOWN_DURATION); |
| 56 | |
| 57 | try { |
| 58 | KeyController::GetUpdatedLicenseKeyInformation(); |
| 59 | if (KeyController::HasValidKey()) { |
| 60 | LogController::LogInfo('License issue resolved automatically'); |
| 61 | } |
| 62 | } catch (Exception $ex) { |
| 63 | LogController::HandleException($ex); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Clear the cooldown transient. |
| 69 | * Called when a key is manually registered or removed. |
| 70 | */ |
| 71 | public static function ClearCooldown() |
| 72 | { |
| 73 | delete_transient(self::COOLDOWN_TRANSIENT); |
| 74 | } |
| 75 | } |
| 76 |