| | |
| | |
|
| | | $schema = is_array($rawSchema) ? $this->schema($rawSchema) : $rawSchema;
|
| | |
|
| | | $default = $config['type'] === 'repeater' ?
|
| | | $this->determineDefault($schema['schema']['properties']??[]) :
|
| | | $config['default'] ?? MetaTypeManager::getType($config['type'])['default'] ?? '';
|
| | |
|
| | | register_post_meta($this->registrar->getBased(), jvbCheckBase($name), [
|
| | | 'single' => true,
|
| | | 'type' => $metaType,
|
| | | 'default' => $config['default'] ?? MetaTypeManager::getType($config['type'])['default'] ?? '',
|
| | | 'default' => $default,
|
| | | 'sanitize_callback' => fn($value) => (Sanitizer::sanitize($value, $config)),
|
| | | 'auth_callback' => fn($allowed, $key, $postID) => current_user_can('edit_post', $postID),
|
| | | 'show_in_rest' => $schema,
|
| | |
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | protected function determineDefault(array $properties):array
|
| | | {
|
| | | $out = [];
|
| | | foreach ($properties as $prop => $value) {
|
| | | $out[$prop] = match ($value) {
|
| | | 'object' => [],
|
| | | default => ''
|
| | | };
|
| | | }
|
| | | return $out;
|
| | | }
|
| | | }
|