improve setup configs
This commit is contained in:
+21
-5
@@ -12,16 +12,24 @@ if (!function_exists('dd')) {
|
||||
function dd(): never
|
||||
{
|
||||
echo '<pre>';
|
||||
array_map(function($arg) {var_dump($arg);}, func_get_args());
|
||||
array_map(function ($arg) {
|
||||
var_dump($arg);
|
||||
}, func_get_args());
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
function setup_configs(): void
|
||||
{
|
||||
$configs = [];
|
||||
$configs_dir = plugin_dir_path(__FILE__).'configs';
|
||||
foreach (glob($configs_dir.'/*.php') as $configs_file) {
|
||||
$configs[basename($configs_file, '.php')] = include $configs_file;
|
||||
}
|
||||
|
||||
define("DA_CASHED_CONFIG", [
|
||||
'da' => require plugin_dir_path(__FILE__) . 'configs/da.php',
|
||||
]);
|
||||
|
||||
define("DA_CASHED_CONFIG", $configs);
|
||||
}
|
||||
setup_configs();
|
||||
|
||||
if (!function_exists('config')) {
|
||||
function config(string $key, ?string $default = null): null|string|array
|
||||
@@ -33,3 +41,11 @@ if (!function_exists('config')) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('get_configured_option')) {
|
||||
function get_configured_option(string $key, ?string $default = null): null|string|array
|
||||
{
|
||||
return get_option(config($key), $default);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user