| 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 |
* Persists setup wizard completion and setup-derived option changes. |
| 11 |
*/ |
| 12 |
class ABJ_404_Solution_SetupWizardOptionStore { |
| 13 |
|
| 14 |
/** |
| 15 |
* Return true when the setup wizard has already been completed. |
| 16 |
* |
| 17 |
* @return bool |
| 18 |
*/ |
| 19 |
public static function isComplete(): bool { |
| 20 |
$completed = get_option(ABJ_404_Solution_SetupWizard::OPTION_NAME, ''); |
| 21 |
return !empty($completed); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Persist today's setup completion marker. |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public static function markCompleteToday(): void { |
| 30 |
update_option(ABJ_404_Solution_SetupWizard::OPTION_NAME, gmdate('Y-m-d', abj_clock()->now())); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Persist plugin options derived from validated setup answers. |
| 35 |
* |
| 36 |
* @param array{q1:string,q2:string,q3:string} $answers Validated setup answers. |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public static function saveAnswers(array $answers): void { |
| 40 |
$optionsRepository = abj_service('options_repository'); |
| 41 |
$options = $optionsRepository->getOptions(); |
| 42 |
if (!is_array($options)) { |
| 43 |
$options = array(); |
| 44 |
} |
| 45 |
|
| 46 |
$adminEmail = get_option('admin_email'); |
| 47 |
$options = ABJ_404_Solution_SetupWizardAnswerPolicy::applyToOptions( |
| 48 |
$options, |
| 49 |
$answers, |
| 50 |
is_string($adminEmail) ? $adminEmail : '' |
| 51 |
); |
| 52 |
|
| 53 |
$optionsRepository->updateOptions($options); |
| 54 |
} |
| 55 |
} |
| 56 |
|