From 2127b1bdd73ecd2423e443992da4b442f5a3c1a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 04 Feb 2026 21:19:25 +0000
Subject: [PATCH] =Major overhaul of MetaManager.php -> Meta.php and RestRouteManager.php -> Rest.php. Seems to work for JakeVan

---
 inc/registry/TaxonomyRegistrar.php |   64 ++++++++++++-------------------
 1 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/inc/registry/TaxonomyRegistrar.php b/inc/registry/TaxonomyRegistrar.php
index bd0c049..448d917 100644
--- a/inc/registry/TaxonomyRegistrar.php
+++ b/inc/registry/TaxonomyRegistrar.php
@@ -1,12 +1,8 @@
 <?php
 namespace JVBase\registry;
 
-use JVBase\meta\MetaManager;
-use JVBase\meta\MetaRegistry;
-use JVBase\managers\CacheManager;
-use JVBase\utility\Checker;
-use Exception;
-use WP_Error;
+use JVBase\meta\Meta;
+use JVBase\meta\Registry;
 if (!defined('ABSPATH')) {
 	exit;
 }
@@ -31,7 +27,6 @@
 		if ($this->config['is_content'] ?? false) {
 			$this->setupContentTaxonomyHooks();
 		}
-		$this->registerHooks();
 	}
 
 	public function register(): void
@@ -55,12 +50,32 @@
 		$post_types = array_map(fn($type) => BASE . $type, $this->config['for_content'] ?? []);
 		register_taxonomy($this->taxonomy, $post_types, $args);
 
+		$this->maybeAddRewriteRule($args['rewrite']);
 		if (!empty($this->fields)) {
-			$meta_registry = new MetaRegistry($this->fields, $this->slug, 'term');
+			$meta_registry = new Registry($this->fields, $this->slug, 'term');
 			$meta_registry->registerMetaFields();
 		}
 	}
 
+	/**
+	 * Add custom rewrite rule for hierarchical taxonomy slugs (e.g., post-type/by/taxonomy-slug)
+	 */
+	protected function maybeAddRewriteRule(array $rewrite_config): void
+	{
+		$slug = $rewrite_config['slug'] ?? $this->slug;
+
+		// Only add custom rule if slug contains slashes (hierarchical path)
+		if (!str_contains($slug, '/')) {
+			return;
+		}
+
+		add_rewrite_rule(
+			"^{$slug}/([^/]+)/?$",
+			'index.php?' . $this->taxonomy . '=$matches[1]',
+			'top'
+		);
+	}
+
     private function buildLabels(string $singular, string $plural): array
     {
         return [
@@ -197,13 +212,13 @@
         // Prepare data for insertion/update
         $data = [
             'term_id' => $term_id,
-            'name' => $term->name,
+            'name' => html_entity_decode($term->name),
             'slug' => $term->slug,
             'updated_at' => current_time('mysql')
         ];
 
         // Get meta manager for this term
-        $meta = new MetaManager($term_id, 'term');
+        $meta = Meta::forTerm($term_id);
 		$values = $meta->getAll(array_keys($custom_fields));
 
         // Process each custom field
@@ -326,33 +341,4 @@
     {
         return jvbContentTaxonomiesTableFields($this->slug)['fields'] ?? [];
     }
-
-	protected function registerHooks():void
-	{
-		$actions = ['created_term', 'edited_term', 'delete_term'];
-		$taxonomy = $this->taxonomy;
-		foreach ($actions as $action) {
-			add_action($action, function($term_id, $tt_id, $tax) use ($taxonomy, $action) {
-				if ($tax !== $taxonomy) return;
-
-				$term = get_term($term_id, $tax);
-				jvbUpdateCacheTimestamp('term', $term);
-
-				// Clear taxonomy cache
-				CacheManager::invalidateGroup($taxonomy);
-				CacheManager::invalidateGroup('terms');
-				CacheManager::invalidateGroup('termCheck');
-
-				// Clear cache for associated content types
-				$checker = Checker::getInstance();
-				$content_types = $checker->getContentForTaxonomy($taxonomy);
-
-				foreach ($content_types as $content_type) {
-					CacheManager::invalidateGroup($content_type);
-				}
-
-				do_action("jvb_taxonomy_cache_invalidated_{$taxonomy}", $term, $action);
-			}, 10, 3);
-		}
-	}
 }

--
Gitblit v1.10.0