Jake Vanderwerf
5 days ago 0dfe1d8afafc59c4a5559c498342668d5a58d6ef
inc/meta/Meta.php
@@ -89,17 +89,17 @@
    * Constructor
   ***************************************************************/
   public function __construct(int|string|null $id, string $type)
   public function __construct(int|string|null $id, string $type, array $fields = [])
   {
      $this->validator = new Validator();
      $this->sanitizer = new Sanitizer();
      $this->typeManager = new MetaTypeManager();
      $this->type = $type;
      $this->ID = $id;
      $this->buildData($id, $type);
      $this->buildData($id, $type, $fields);
   }
   protected function buildData(int|string|null $id, string $type):void
   protected function buildData(int|string|null $id, string $type, array $fields):void
   {
      $this->wpObject = match($type) {
         'post'   => get_post($id),
@@ -115,10 +115,9 @@
         default => null
      };
      $registrar = !is_null($this->slug) ? Registrar::getInstance($this->slug) : false;
      $fields = $registrar ? $registrar->getFields() : [];
      $fields = $registrar ? $registrar->getFields() : $fields;
      if ($this->type == 'option') {
         $options = Options::getInstance();
         $fields = $options->getFields();
@@ -133,15 +132,18 @@
         $meta = [];
      }
      $meta = array_map(fn($value) => maybe_unserialize($value[0]), $meta);
      $this->fields = [];
      foreach ($fields as $fieldName => $config) {
         $fieldName = jvbNoBase($fieldName);
         if ($this->type === 'option') {
            $value = get_option(BASE . $fieldName, $config['default'] ?? '');
         } else if ($this->wpObject && property_exists($this->wpObject, $fieldName)) {
         } else if (
            $this->wpObject && property_exists($this->wpObject, $fieldName)
            || $type === 'user' && $this->wpObject && property_exists($this->wpObject->data, $fieldName)) {
            $config['wp'] = true;
            $value = $this->wpObject->$fieldName;
         } else if (in_array($fieldName, $this->defaults)) {
         }  else if (in_array($fieldName, $this->defaults)) {
            $config['wp'] = true;
            switch ($fieldName) {
               case 'post_thumbnail':
@@ -252,11 +254,6 @@
         $this->save();
      }
      if ($this->type === 'option') {
         error_log('Value saved for: '.$name.': '.print_r($value, true));
      }
      return $this;
   }
@@ -372,12 +369,6 @@
         foreach ($custom as $field) {
            if ($this->type === 'option') {
               $result = update_option(BASE.$field->name, $field->value);
               if ($result) {
                  error_log('Option '.$field->name.' updated');
               } else {
                  error_log('Option '.$field->name.' not updated');
               }
               error_log('Update option '.$field->name.' result: '.print_r($result, true));
            } else {
               $result = $function($this->ID, BASE.$field->name, $field->value);
            }
@@ -450,7 +441,6 @@
   protected function setByPath(string $path, mixed $value): self
   {
      error_log('Setting by path: '.$path.', with value: '.print_r($value, true));
      $parts = explode(':', $path, 3);
      if (count($parts) !== 3) {
         return $this;