| 1 |
<?php |
| 2 |
|
| 3 |
// allow-no-test-found: covered by tests/SetupWizardTest.php through setup wizard form submission entry points. |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Reads and persists setup wizard state. |
| 11 |
*/ |
| 12 |
class ABJ_404_Solution_SetupWizardOptionStore { |
| 13 |
|
| 14 |
public const OPTION_NAME = 'abj404_setup_completed'; |
| 15 |
|
| 16 |
/** |
| 17 |
* Return true when the setup wizard has already been completed. |
| 18 |
* |
| 19 |
* @return bool |
| 20 |
*/ |
| 21 |
public static function isComplete(): bool { |
| 22 |
$completed = get_option(self::OPTION_NAME, ''); |
| 23 |
return !empty($completed); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Persist today's setup completion marker. |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public static function markCompleteToday(): void { |
| 32 |
update_option(self::OPTION_NAME, gmdate('Y-m-d', abj_clock()->now())); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Return the currently persisted plugin options. |
| 37 |
* |
| 38 |
* @return array<string,mixed> |
| 39 |
*/ |
| 40 |
public static function loadPluginOptions(): array { |
| 41 |
$optionsRepository = abj_service('options_repository'); |
| 42 |
$options = $optionsRepository->getOptions(); |
| 43 |
return is_array($options) ? $options : array(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Return the site administrator email used by setup decisions. |
| 48 |
*/ |
| 49 |
public static function adminEmail(): string { |
| 50 |
$adminEmail = get_option('admin_email'); |
| 51 |
return is_string($adminEmail) ? $adminEmail : ''; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Persist plugin options already derived by the setup policy. |
| 56 |
* |
| 57 |
* @param array<string,mixed> $options |
| 58 |
*/ |
| 59 |
public static function savePluginOptions(array $options): void { |
| 60 |
abj_service('options_repository')->updateOptions($options); |
| 61 |
} |
| 62 |
} |
| 63 |
|