Jake Vanderwerf
2026-01-01 2bb9aaaf24b794b528e3894ee9f9c42ca6d7fe93
=FeedRoutes: extractTaxonomies added
1 files modified
56 ■■■■ changed files
inc/rest/routes/FeedRoutes.php 56 ●●●● patch | view | raw | blame | history
inc/rest/routes/FeedRoutes.php
@@ -146,33 +146,7 @@
                ];
                //Format Taxonomies
                $temp = array_filter($fields, function($field) {
                    return $field['type'] === 'taxonomy';
                });
                foreach ($temp as $key => $config) {
                    if (array_key_exists($key, $out['fields']) && $out['fields'][$key] !== '') {
                        $IDs = array_map('absint', explode(',', $out['fields'][$key]));
                        $data = [];
                        $icon = JVB_TAXONOMY[$config['taxonomy']]['icon']??jvbDefaultIcon();
                        foreach ($IDs as $ID) {
                            $term = get_term($ID, jvbCheckBase($config['taxonomy']));
                            if ($term && !is_wp_error($term)) {
                                $data[$ID] = [
                                    'id'    => $ID,
                                    'icon'  => $icon,
                                    'name'  => $term->name,
                                    'url'   => get_term_link($ID, jvbCheckBase($config['taxonomy'])),
                                ];
                                if ($this->tracker) {
                                    $data[$ID]['umami_click'] = $this->tracker->trackClick($ID, $config['taxonomy'], ['from' => $type.'_'.$postID]);
                                }
                            }
                        }
                        if (!empty($data)) {
                            $out['fields'][$key] = $data;
                        }
                    }
                }
                $out['taxonomies'] = $this->extractTaxonomies($values, $postID, $type);
                //Add images
                $imgIDs = [];
@@ -263,6 +237,8 @@
        $children = get_children(['post_parent' => $post->ID, 'orderby' => 'date', 'order' => 'ASC', 'post_status' => ['publish'], 'fields'=> 'ids']);
        array_unshift($children, $post->ID);
        $item['taxonomies'] = $this->extractTaxonomies($item['fields'], $postID, jvbNoBase($post->post_type));
        $subFields = [];
        $images = [];
        foreach ($children as $child) {
@@ -270,17 +246,37 @@
            $f = $meta->getAll($this->timelineUniqueFields);
            $f =  ['id' => $child] + $f;
            $subFields[] = $f;
            $item['taxonomies'] = array_merge($item['taxonomies'], $this->extractTaxonomies($f, $postID, jvbNoBase($post->post_type)));
            $images[$f['post_thumbnail']] = jvbImageData((int) $f['post_thumbnail']);
        }
        $item['fields']['timeline'] = $subFields;
        $item['images'] = $item['images'] + $images;
        return $item;
    }
    protected function extractTaxonomies(array $fields, int $postID, string $content):array {
        $taxonomies = [];
        foreach ($fields as $key => $value) {
            if (array_key_exists($key, JVB_TAXONOMY)) {
                $terms = array_map('absint', explode(',',$value));
                foreach($terms as $termID) {
                    $term = get_term($termID, jvbCheckBase($key));
                    if ($term && !is_wp_error($term)) {
                        $taxonomies[$key][$termID] = $this->formatTaxonomy($term, $postID, $content);
                    }
                }
            }
        }
        return $taxonomies;
    }
    protected function formatTaxonomy(WP_Term $term, int $postID, string $type)
    protected function formatTaxonomy(WP_Term|int $term, int $postID, string $type)
    {
        $cache = CacheManager::for(jvbNoBase($term->taxonomy));
        return $cache->remember(
            'feed_link_'.$term->term_id,
            function () use ($term, $postID, $type) {
        return [
            'ID' => $term->term_id,
            'title' => htmlspecialchars_decode($term->name),
@@ -290,6 +286,8 @@
            ])
        ];
    }
        );
    }
    protected function getAuthorData(WP_Post $post)
    {