| | |
| | | {
|
| | | switch ($this->registrar->getType()) {
|
| | | case 'post':
|
| | | add_action('save_post', [$this, 'checkPostFields']);
|
| | | add_action('save_post', [$this, 'checkPostFields'], 10, 2);
|
| | | add_action('enqueue_block_editor_assets', [$this, 'enqueue']);
|
| | | break;
|
| | | case 'term':
|
| | |
| | | ? $this->determineSchema($config)
|
| | | : true;
|
| | |
|
| | | $schema = is_array($rawSchema) ? $this->schema($rawSchema) : $rawSchema;
|
| | | //Allow for null
|
| | | if ($metaType === 'object') {
|
| | | $metaType = ['object', 'null'];
|
| | | $rawSchema['type'] = ['object', 'null'];
|
| | | }
|
| | |
|
| | | $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,
|
| | | 'revisions_enabled' => true,
|
| | | ]);
|
| | | }
|
| | | }
|
| | |
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | protected function determineDefault(array $properties):array
|
| | | {
|
| | | $out = [];
|
| | | foreach ($properties as $prop => $value) {
|
| | | $out[$prop] = match ($value) {
|
| | | 'object' => [],
|
| | | default => ''
|
| | | };
|
| | | }
|
| | | return $out;
|
| | | }
|
| | | }
|