Jake Vanderwerf
2026-09-18 a6413da67a4579866f0fd0323ddb23a7b6b9654a
inc/registrar/helpers/AddCustomFields.php
@@ -23,7 +23,7 @@
   {
      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':
@@ -92,19 +92,24 @@
            ? $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,
         ]);
      }
   }
@@ -284,4 +289,16 @@
   {
   }
   protected function determineDefault(array $properties):array
   {
      $out = [];
      foreach ($properties as $prop => $value) {
         $out[$prop] = match ($value) {
            'object' => [],
            default     => ''
         };
      }
      return $out;
   }
}