refactor: complete ‘Reference Container’ settings group
This commit is contained in:
parent
a6aa8e7fe2
commit
9b4aa7ba9f
13 changed files with 1521 additions and 989 deletions
|
@ -57,10 +57,20 @@ abstract class SettingsSection {
|
|||
|
||||
protected abstract function load_dependencies(): void;
|
||||
|
||||
public function load_options_group(): void {
|
||||
$options_group = get_option($this->options_group_slug);
|
||||
|
||||
if (!! $options_group) {
|
||||
foreach ($options_group as $setting_key => $setting_value) {
|
||||
$this->set_setting_value($setting_key, $setting_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add_settings_section(): void {
|
||||
add_settings_section(
|
||||
$this->section_slug,
|
||||
$this->title,
|
||||
__( $this->title, 'footnotes'),
|
||||
array($this, 'setting_section_callback'),
|
||||
'footnotes'
|
||||
);
|
||||
|
@ -93,4 +103,38 @@ abstract class SettingsSection {
|
|||
public function get_settings_group(string $group_id) {
|
||||
return $this->settings_groups[$group_id];
|
||||
}
|
||||
|
||||
public function get_setting(string $setting_key): ?Setting {
|
||||
foreach ($this->settings_groups as $settings_group) {
|
||||
$setting = $settings_group->get_setting($setting_key);
|
||||
|
||||
if ($setting) return $setting;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_options(): array {
|
||||
$options = array();
|
||||
|
||||
foreach ($this->settings_groups as $settings_group) {
|
||||
$options = array_merge($options, $settings_group->get_options());
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function get_setting_value(string $setting_key) {
|
||||
$setting = $this->get_setting($setting_key);
|
||||
|
||||
if (! $setting) return null;
|
||||
else return $setting->value ?? $setting->default_value ?? trigger_error("No default value found for ".$setting_key.".", E_USER_ERROR);
|
||||
}
|
||||
|
||||
public function set_setting_value(string $setting_key, $value): ?bool {
|
||||
$setting = $this->get_setting($setting_key);
|
||||
|
||||
if (! $setting) return null;
|
||||
else return $setting->set_value($value);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue