| | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | | use JVBase\meta\MetaManager; |
| | | |
| | | use JVBase\meta\Form; |
| | | use JVBase\meta\Meta; |
| | | |
| | | class OptionsRegistry |
| | | { |
| | |
| | | */ |
| | | public function registerOptions(): void |
| | | { |
| | | $meta = new MetaManager(null, 'options'); |
| | | $meta = Meta::forOptions('options'); |
| | | foreach ($this->fields as $field_name => $field) { |
| | | if (in_array($field_name, ['common', 'fields'])) { |
| | | continue; |
| | |
| | | |
| | | // Add default value if not exists |
| | | if (get_option($option_name) === false) { |
| | | add_option($option_name, $field['default'] ?? $meta->getDefaultValue($field['type'])); |
| | | add_option($option_name, $field['default'] ??''); |
| | | } |
| | | |
| | | // |
| | |
| | | $name = $args['name']; |
| | | $value = get_option(BASE . $name); |
| | | |
| | | // Use MetaForm to render if available |
| | | if (class_exists('\JVBase\meta\MetaForm')) { |
| | | $form = new \JVBase\meta\MetaForm(); |
| | | echo $form->renderField($name, $field, $value); |
| | | } |
| | | echo Form::render($name, $value, $field); |
| | | } |
| | | |
| | | private function getFieldType(string $type): string |
| | |
| | | default => 'string' |
| | | }; |
| | | } |
| | | |
| | | private function getSanitizeCallback(array $field): callable |
| | | { |
| | | return function($value) use ($field) { |
| | | $manager = new \JVBase\meta\MetaManager(); |
| | | return $manager->sanitizeField($value, $field); |
| | | }; |
| | | } |
| | | } |