| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Early settings and path helpers used during plugin boot. |
| 8 |
* |
| 9 |
* abj404_getUploadsDir() resolves the plugin's temp upload directory and is |
| 10 |
* needed before any Loader.php initialization that might touch |
| 11 |
* Logging/SynchronizationUtils. abj404_get_settings_options() is the |
| 12 |
* centralized, container-aware read of the abj404_settings option and is the |
| 13 |
* plugin-root fallback boundary for raw settings reads. |
| 14 |
* |
| 15 |
* Both are required early (before Loader.php) because boot-time code paths call |
| 16 |
* them before the service container is fully available. |
| 17 |
*/ |
| 18 |
// allow-no-test-found: boot-time global settings/path helpers required before Loader.php and the service container; no same-named unit file. abj404_get_settings_options (the raw-settings boundary) is exercised in OptionsRepositoryMigrationContractTest::testBootstrapRawSettingsReadsStayIsolatedToHelper. |
| 19 |
|
| 20 |
// Used by multiple classes during early admin initialization (e.g. upgrade/migration paths). |
| 21 |
// This must be defined before any Loader.php initialization that might touch Logging/SynchronizationUtils. |
| 22 |
if (!function_exists('abj404_getUploadsDir')) { |
| 23 |
/** @return string */ |
| 24 |
function abj404_getUploadsDir() { |
| 25 |
$uploadsDirArray = wp_upload_dir(null, false); |
| 26 |
$uploadsDir = $uploadsDirArray['basedir']; |
| 27 |
$uploadsDir .= DIRECTORY_SEPARATOR . 'temp_' . ABJ404_PP . DIRECTORY_SEPARATOR; |
| 28 |
return $uploadsDir; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
if (!function_exists('abj404_get_settings_options')) { |
| 33 |
/** |
| 34 |
* Centralized settings read so call sites don't repeat option-shape checks. |
| 35 |
* This is the plugin-root fallback boundary for raw abj404_settings reads: |
| 36 |
* ordinary callers must use this helper or options_repository. |
| 37 |
* |
| 38 |
* @return array<string, mixed> |
| 39 |
*/ |
| 40 |
function abj404_get_settings_options() { |
| 41 |
if (function_exists('abj_service_optional')) { |
| 42 |
$optionsRepository = abj_service_optional('options_repository'); |
| 43 |
if (is_object($optionsRepository) && method_exists($optionsRepository, 'getOptions')) { |
| 44 |
try { |
| 45 |
$options = $optionsRepository->getOptions(true); |
| 46 |
if (is_array($options)) { |
| 47 |
$normalizedOptions = array(); |
| 48 |
foreach ($options as $key => $value) { |
| 49 |
if (is_string($key)) { |
| 50 |
$normalizedOptions[$key] = $value; |
| 51 |
} |
| 52 |
} |
| 53 |
return $normalizedOptions; |
| 54 |
} |
| 55 |
if (function_exists('abj404_logRuntimeWarning')) { |
| 56 |
abj404_logRuntimeWarning('options_repository->getOptions(true) returned ' . gettype($options) . '; falling back to raw bootstrap option read'); |
| 57 |
} |
| 58 |
} catch (\Throwable $e) { |
| 59 |
if (function_exists('abj404_logRuntimeWarning')) { |
| 60 |
abj404_logRuntimeWarning('options_repository->getOptions(true) failed while reading settings options; falling back to raw bootstrap option read', $e); |
| 61 |
} else { |
| 62 |
abj404_logPhpFallback( |
| 63 |
'early-boot', |
| 64 |
'options_repository->getOptions(true) failed while reading settings options; falling back to raw bootstrap option read (' . $e->getMessage() . ')' |
| 65 |
); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
$options = function_exists('get_option') ? get_option('abj404_settings') : false; |
| 71 |
if (!is_array($options)) { |
| 72 |
return array(); |
| 73 |
} |
| 74 |
$normalizedOptions = array(); |
| 75 |
foreach ($options as $key => $value) { |
| 76 |
if (is_string($key)) { |
| 77 |
$normalizedOptions[$key] = $value; |
| 78 |
} |
| 79 |
} |
| 80 |
return $normalizedOptions; |
| 81 |
} |
| 82 |
} |
| 83 |
|