| | |
| | | public function getTermDetails(WP_REST_Request $request):WP_REST_Response |
| | | { |
| | | $data = $request->get_params(); |
| | | // Collect all taxonomies being queried |
| | | $taxonomies = array_keys($data); |
| | | |
| | | // Check HTTP cache headers |
| | | $cache_check = $this->checkHeaders($request, $taxonomies); |
| | | if ($cache_check) { |
| | | return $cache_check; |
| | | } |
| | | $terms = []; |
| | | foreach ($data as $tax => $IDs) { |
| | | $args = [ |
| | |
| | | |
| | | $terms[$tax] = $this->formatTerms($args, BASE.$tax); |
| | | } |
| | | return new WP_REST_Response([ |
| | | $response = new WP_REST_Response([ |
| | | 'items' => $terms, |
| | | ]); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | |
| | | /** |
| | |
| | | $data = $request->get_params(); |
| | | $taxonomy = jvbCheckBase($data['taxonomy']); |
| | | |
| | | error_log('Term Request Data for '.$taxonomy.': '.print_r($data, true)); |
| | | // Check HTTP cache headers |
| | | $cache_check = $this->checkHeaders($request, $taxonomy); |
| | | if ($cache_check) { |
| | | error_log('Header Check failed'); |
| | | return $cache_check; |
| | | } |
| | | |
| | | if (array_key_exists('termIDs', $data)) { |
| | | $args = [ |
| | | 'taxonomy' => $taxonomy, |
| | |
| | | $key = $this->cache->generateKey($args); |
| | | $cached = $this->cache->get($key); |
| | | if ($cached) { |
| | | return new WP_REST_Response($cached); |
| | | $response = new WP_REST_Response($cached); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | |
| | | $formatted = $this->formatTerms($args, $taxonomy); |
| | |
| | | 'items' => $formatted |
| | | ]; |
| | | $this->cache->set($key, $response); |
| | | return new WP_REST_Response($response); |
| | | $response = new WP_REST_Response($response); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | if (array_key_exists('content', $data)) { |
| | | // If content_type is provided, use the specialized endpoint |
| | | $content_type = $request->get_param('content'); |
| | | global $feed_types; |
| | | if (taxIsJVBContentTax($content_type)) { |
| | | return $this->getTermsForContentType($request); |
| | | $response = $this->getTermsForContentType($request); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // If searching, handle differently |
| | | if (!empty($search)) { |
| | | return $this->handleTermSearch($request); |
| | | error_log('Handling search...'); |
| | | $response = $this->handleTermSearch($request); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | |
| | | // Get terms for current level with child count |
| | |
| | | $related = $manager->getUserTermIDs($userID, $taxonomy); |
| | | |
| | | if (empty($related)) { |
| | | return new WP_REST_Response([ |
| | | $response = new WP_REST_Response([ |
| | | 'items' => [], |
| | | 'pagination' => [ |
| | | 'page' => 1, |
| | |
| | | 'has_more' => false |
| | | ] |
| | | ]); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | |
| | | $args['include'] = $related; |
| | |
| | | $related = $manager->getRelatedTerms($ID, BASE.$request->get_param('taxonomy')); |
| | | |
| | | if (empty($related)) { |
| | | return new WP_REST_Response([ |
| | | $response = new WP_REST_Response([ |
| | | 'items' => [], |
| | | 'pagination' => [ |
| | | 'page' => 1, |
| | |
| | | 'has_more' => false |
| | | ] |
| | | ]); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | $args['tax_query'] = [ |
| | | 'taxonomy' => $taxonomy, |
| | |
| | | $args['include'] = $related_term_ids; |
| | | } else { |
| | | // No related terms found, return empty result |
| | | return new WP_REST_Response([ |
| | | $response = new WP_REST_Response([ |
| | | 'items' => [], |
| | | 'pagination' => [ |
| | | 'page' => 1, |
| | |
| | | 'has_more' => false |
| | | ] |
| | | ]); |
| | | |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | } |
| | | |
| | |
| | | $cache = $this->cache->get($key); |
| | | $cache = false; |
| | | if ($cache) { |
| | | return $cache; |
| | | $response = new WP_ReST_Response($cache); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | |
| | | $formatted_terms = $this->formatTerms($args, $taxonomy); |
| | |
| | | ]; |
| | | |
| | | $this->cache->set($key, $response); |
| | | return new WP_REST_Response($response); |
| | | $response = new WP_REST_Response($response); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | | |
| | | /** |
| | |
| | | $formatted_terms[] = [ |
| | | 'id' => $term->term_id, |
| | | 'name' => $term->name, |
| | | 'slug' => $term->slug, |
| | | 'parent' => $term->parent, |
| | | 'path' => $this->getTermPath($term->term_id, $term->name, $taxonomy), |
| | | 'hasChildren' => $has_children, |
| | | 'taxonomy' => $term->taxonomy, |
| | | 'count' => $term->count, |
| | | ]; |
| | | } |
| | | |