Jake Vanderwerf
2026-09-13 1aa7c404dae63c9518468fe9b579fad819f8d871
inc/meta/Meta.php
@@ -1,6 +1,7 @@
<?php
namespace JVBase\meta;
use JVBase\base\options;
use JVBase\managers\Cache;
use JVBase\registrar\Registrar;
@@ -25,6 +26,7 @@
    * @var array of Registrar's defined fields, if any
    */
   protected static array $registrars = [];
   protected static ?options $options = null;
   /**
    * @var array Field values, stored in memory
    */
@@ -60,6 +62,9 @@
            self::$registrars[$this->content] = $registrar->getFields();
         }
      }
      if ($this->objectType === 'options' && !isset(self::$options)) {
         self::$options = options::getInstance();
      }
      if ($this->objectType === 'post' && function_exists('wc_get_product') && in_array($this->content, ['product', 'product_variation'], true)) {
         $this->product = wc_get_product($this->ID) ?: null;
@@ -81,6 +86,9 @@
            'user'   => get_user_meta($this->ID),
            default  => []
         };
         $this->fields = array_map(fn($values) => is_array($values) ? $values[0] : $values, $this->fields);
         $this->fields = array_combine(
            array_map('jvbNoBase', array_keys($this->fields)),
            $this->fields
@@ -210,10 +218,13 @@
   public function set(string $name, mixed $value): bool {
      $field = $this->getFieldConfig($name);
      if ($field) {
         if ($field['type']??'' === 'repeater' && str_contains($name, ':')) {
            return $this->setByPath($name, $value);
         } elseif ($field['type']??'' === 'group' && str_contains($name, '|')) {
            return $this->setGroup($name, $value);
         if (array_key_exists('type', $field)) {
            if ($field['type'] === 'repeater' && str_contains($name, ':')) {
               $this->log('Setting by path in set');
               return $this->setByPath($name, $value);
            } elseif ($field['type'] === 'group' && str_contains($name, '|')) {
               return $this->setGroup($name, $value);
            }
         }
         if (!self::$validator->validate($value, $field)) {
@@ -407,7 +418,7 @@
    * WOOCOMMERCE PRODUCT SPECIFIC
   **************************************************************/
   protected function isProductField(string $name): bool {
      return method_exists($this->product, 'get_'.$name) || method_exists($this->product, 'set_'.$name);
      return $name === 'variations' || method_exists($this->product, 'get_'.$name) || method_exists($this->product, 'set_'.$name);
   }
   protected function getProductField(string $name): mixed {
@@ -422,7 +433,7 @@
         $variations = $this->product->get_children();
         $out = [];
         foreach ($variations as $v) {
            $out[] = self::forPost($v)->getAll();
            $out[] = array_merge(['id' => $v], self::forPost($v)->getAll());
         }
         return $out;
      }
@@ -442,8 +453,14 @@
      return [
         'price',
         'sku',
         'sale',
         'sale_price',
         'regular_price',
         'date_on_sale_from',
         'date_on_sale_to',
         'max_purchase_quantity',
         'min_purchase_quantity',
         'short_description',
         'description',
         'image_id',
         'gallery_image_ids',
         'stock',
@@ -505,9 +522,13 @@
   }
   protected function setByPath(string $path, mixed $value):bool
   {
      if (!str_contains($path, ':')) {
         $this->log('setByPath called without appropriate string (:)');
         return $this->set($path, $value);
      }
      $parts = explode(':', $path, 3);
      if (count($parts) !== 3) {
         $this->log('Could not set value by path');
         $this->log('Could not set value by path: '.$path.', with value: '.print_r($value, true));
         return false;
      }
      [$repeaterName, $rowIndex, $subField] = $parts;
@@ -536,6 +557,10 @@
   protected function setGroup(string $name, mixed $value):bool
   {
      if (!str_contains($name, '|')) {
         $this->log('setGroup called without appropriate key (|)');
         return $this->set($name, $value);
      }
      [$parent, $child] = explode('|', $name, 2);
      $this->clearCache();
      return $this->group($parent)->set($child, $value);
@@ -571,13 +596,18 @@
   protected function hasRegistrar():bool
   {
      return array_key_exists($this->content, self::$registrars);
      return !is_null($this->content) && array_key_exists($this->content, self::$registrars);
   }
   public function getFieldConfig(string $name): ?array {
      if ($this->objectType === 'options') return $this->getOptionsConfig($name);
      if (!$this->hasRegistrar()) return null;
      return self::$registrars[$this->content][$name] ?? null;
   }
      protected function getOptionsConfig(string $name):?array
      {
         return self::$options->getConfig($name);
      }
   protected function getCoreDefault(string $name):string
   {