Jake Vanderwerf
2026-02-14 27fb820ae9081fb56957cf75e79eccd8a99edd52
inc/rest/routes/ContentRoutes.php
@@ -429,6 +429,7 @@
         return $this->formatTimeline($post);
      }
      $this->meta = Meta::forPost($post->ID);
      $fields = ($fields) ? $this->meta->getAll() : [];
      $data = [
         'id' => $post->ID,
         'title' => $post->post_title,
@@ -439,7 +440,7 @@
         'alt' => get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true),
         'icon' => $this->post_type,
         'taxonomies' => [],
         'fields' => ($fields) ? $this->meta->getAll() : [],
         'fields' => $fields,
         'images' => [],
      ];
@@ -474,25 +475,69 @@
      $images = [];
      $get = [];
      $fields = (empty($fields)) ? $this->fields : $fields;
      foreach ($fields as $field => $config) {
         if ($config['type'] === 'gallery' || $config['type'] === 'image' || $field === 'post_thumbnail') {
            $get[] = $field;
         }
      }
      $get = $this->getUploadFields($fields);
      if (!empty($get)) {
         $allImages = $this->meta->getAll($get);
         $actualGet = array_map(function($fieldName) {
            return (str_contains($fieldName, ':')) ? strtok($fieldName, ':') : $fieldName;
         }, $get);
         $complex = array_map(function($item) {
            return explode(':', $item);
         },array_filter($get, function($fieldName) {
            return str_contains($fieldName, ':');
         }));
         $allImages = $this->meta->getAll($actualGet);
         foreach ($allImages as $k => $imgs) {
            $temp = explode(',', $imgs);
            foreach ($temp as $img) {
               if (is_numeric($img) && !array_key_exists($img, $images)) {
                  $images[$img] = jvbImageData((int)$img);
            //It's a complex field
            if (is_array($imgs)) {
               foreach ($imgs as $row) {
                  foreach ($row as $fName => $fValue) {
                     foreach ($complex as $c) {
                        if (in_array($k, $c)) {
                           foreach ($c as $complexField) {
                              if ($complexField === $fName) {
                                 $images = $this->addImages($fValue, $images);
                              }
                           }
                        }
                     }
                  }
               }
            } else {
               $images = $this->addImages($imgs, $images);
            }
         }
      }
      return $images;
   }
   public function addImages(string $imgs, array $images):array
   {
      $temp = explode(',', $imgs);
      foreach ($temp as $img) {
         if (is_numeric($img) && !array_key_exists($img, $images)) {
            $images[$img] = jvbImageData((int)$img);
         }
      }
      return $images;
   }
   public function getUploadFields($fields):array
   {
      $get = [];
      foreach ($fields as $field => $config) {
         if (in_array($config['type'], ['group', 'repeater'])) {
            $nestedUploads = $this->getUploadFields($config['fields']);
            foreach ($nestedUploads as $nested) {
               $get[] = $field.':'.$nested;
            }
         } elseif ($config['type'] === 'upload' || $config['type'] === 'gallery' || $config['type'] === 'image' ) {
            $get[] = $field;
         }
      }
      return $get;
   }
   public function formatTimeline(WP_Post $post): array
   {