From d38d825e3484d822ea3c1f0fb1df37ecf386b18a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 04 Jan 2026 19:54:16 +0000
Subject: [PATCH] =TaxonomyCreator.js debugging

---
 inc/managers/SEO/BreadcrumbManager.php |   92 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 74 insertions(+), 18 deletions(-)

diff --git a/inc/managers/SEO/BreadcrumbManager.php b/inc/managers/SEO/BreadcrumbManager.php
index 529dd76..32e91a6 100644
--- a/inc/managers/SEO/BreadcrumbManager.php
+++ b/inc/managers/SEO/BreadcrumbManager.php
@@ -24,6 +24,7 @@
 	private function __construct()
 	{
 		$this->cache = CacheManager::for('breadcrumbs', MONTH_IN_SECONDS)->connectTo('all');
+//		$this->cache->clear();
 	}
 
 	public static function getInstance(): self
@@ -45,14 +46,30 @@
 			return [];
 		}
 
-		$key = get_queried_object_id() ?: 'home';
-		$crumbs = $this->cache->get($key);
+		switch (true) {
+			case is_singular():
+				$key = get_queried_object_id();
+				break;
+			case is_post_type_archive():
+				$obj = get_queried_object();
+				$key = $obj->name;
+				break;
+			case is_tax():
+				$obj = get_queried_object();
+				$key = $obj->taxonomy;
+				break;
+			default:
+				$key = 'home';
+				break;
+		}
 
+		$crumbs = $this->cache->get($key);
 		if ($crumbs !== false) {
 			return $crumbs;
 		}
 
 		$crumbs = $this->buildCrumbs();
+		$crumbs = apply_filters('jvbBreadcrumbs',$crumbs);
 		$this->cache->set($key, $crumbs);
 
 		return $crumbs;
@@ -73,12 +90,12 @@
 		];
 
 		$obj = get_queried_object();
-
 		if (is_tax()) {
 			$crumbs = $this->addTaxonomyCrumbs($crumbs, $obj);
 		} elseif (is_singular()) {
 			$crumbs = $this->addArchiveCrumbs($crumbs, $obj);
-			$crumbs = $this->addSingularCrumbs($crumbs, $obj);
+			$hierarchy = $this->addSingularCrumbs($crumbs, $obj);
+			$crumbs = $crumbs + $hierarchy;
 		} elseif (is_post_type_archive() && !is_post_type_archive(BASE.'dash')) {
 			$crumbs = $this->addArchiveCrumbs($crumbs, $obj);
 		}
@@ -109,7 +126,7 @@
 
 		// Add directory if exists
 		if (Features::forTaxonomy($tax)->has('directory')) {
-			$directory = jvbDirectories($tax);
+			$directory = JVB()->directories()?->directories($tax);
 			$crumbs[] = [
 				'name' => $directory['title'],
 				'url'  => $directory['url']
@@ -128,23 +145,26 @@
 	private function addSingularCrumbs(array $crumbs, WP_Post $post): array
 	{
 		// Add directory if exists
-		$directory = jvbDirectories(jvbNoBase($post->post_type));
-		if (!empty($directory)) {
-			$crumbs[] = [
-				'name' => $directory['title'],
-				'url'  => $directory['url']
-			];
+		$content = jvbNoBase($post->post_type);
+		if(Features::forContent($content)->has('show_directory')) {
+			$directory = JVB()->directories()->getDirectoryList()[$content]??[];
+			if (!empty($directory)) {
+				$crumbs[] = [
+					'name'	=> $directory['title'],
+					'url'	=>$directory['url']
+				];
+			}
 		}
 
 		// Handle directory posts specially
-		if (jvbIsDirectory()) {
+		if (JVB()->directories()->isDirectory()) {
 			$pos = jvbGetDirectoryInfo();
 			if (!empty($pos)) {
 				// Special case for map
 				if ($pos['title'] == 'Map') {
 					$crumbs[] = [
 						'name' => 'Tattoo Shops',
-						'url'  => jvbDirectories(BASE.'shop')['url']
+						'url'  => JVB()->directories()?->directories(BASE.'shop')['url']
 					];
 				}
 
@@ -154,6 +174,10 @@
 				];
 			}
 		} else {
+			$name = jvbNoBase($post->post_type);
+			if (Features::forContent($name)->has('addCrumb')) {
+				$this->addTaxToCrumbs($crumbs, JVB_CONTENT[$name]['addCrumb']);
+			}
 			// Add post hierarchy
 			$crumbs = array_merge($crumbs, $this->buildPostHierarchy($post));
 		}
@@ -166,12 +190,18 @@
 	 */
 	private function addArchiveCrumbs(array $crumbs, object $obj): array
 	{
-		$type = is_singular() ? $obj->post_type : $obj -> name;
+		$type = is_singular() ? $obj->post_type : $obj->name;
 		$name = jvbNoBase($type);
-		if (array_key_exists($name, JVB_CONTENT)) {
+
+		if (Features::forSite()->has('is_directory') && $name === 'directory') {
+			$crumbs[] = [
+				'name'	=> 'Directory',
+				'url'	=> get_post_type_archive_link($type)
+			];
+		} elseif ((is_post_type_archive() || !Features::forContent($name)->has('show_directory')) && array_key_exists($name, JVB_CONTENT)) {
 			$crumbs[] = [
 				'name' => JVB_CONTENT[$name]['breadcrumb'] ?? JVB_CONTENT[$name]['plural'],
-				'url'  => get_post_type_archive_link($type),
+				'url'  => get_post_type_archive_link($type)
 			];
 		}
 
@@ -241,6 +271,7 @@
 		$out .= '<ol itemscope itemtype="https://schema.org/BreadcrumbList">';
 
 		$position = 1;
+		$total = count($crumbs);
 		foreach ($crumbs as $crumb) {
 			$label = '<span itemprop="name">' . strtolower($crumb['name']) . '</span>';
 
@@ -253,8 +284,7 @@
 
 			// Add link if URL exists and not current page
 			if ($crumb['url'] !== false) {
-				$isCurrent = isset($crumb['id']) && $crumb['id'] === get_queried_object_id();
-				if (!$isCurrent) {
+				if ($total !== $position) {
 					$aOpen = '<a itemprop="item" href="' . esc_url($crumb['url']) . '" title="' . esc_attr($crumb['name']) . '">';
 					$aClose = '</a>';
 				}
@@ -324,4 +354,30 @@
 			$this->cache->clear();
 		}
 	}
+
+	public function addTaxToCrumbs(array $crumbs, string $taxonomy):array
+	{
+		$ID = get_the_ID();
+		$taxonomy = jvbCheckBase($taxonomy);
+		$terms = get_the_terms($ID, $taxonomy);
+		if ($terms && !is_wp_error($terms)) {
+			$term = $terms[0];
+			$ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy');
+			$ancestors = array_reverse($ancestors);
+			foreach ($ancestors as $ancestor) {
+				$aTerm = get_term($ancestor, $taxonomy);
+				if ($aTerm && !is_wp_error($aTerm)) {
+					$crumbs[] = [
+						'name' => $aTerm->name,
+						'url'   => get_term_link($ancestor, $taxonomy)
+					];
+				}
+			}
+			$crumbs[] = [
+				'name' => $term->name,
+				'url'   => get_term_link($term, $taxonomy)
+			];
+		}
+		return $crumbs;
+	}
 }

--
Gitblit v1.10.0