From 772462eeca3002a1d52508aeba485aab2b4742ad Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 03 Mar 2026 19:06:19 +0000
Subject: [PATCH] =MAJOR OVERHAUL. Likely should have made a new branch ages ago. Key changes: Registrar.php is the base for custom post types, taxonomies, and user roles. Replaces JVB_CONTENT, JVB_TAXONOMY, and JVB_USER constants, eliminates most of Features.php (except for JVB_SITE, JVB_MEMBERSHIP), and has built in sanitizing and validation via sub-classes. Also started a major overhaul of the Schema output. Created a shit ton of property traits and classes to help sanitize and ensure proper data for different schema types. Still a bunch to do, but better to be starting committing changes here on this other branch.

---
 inc/managers/SEO/SchemaReferenceBuilder.php |   91 ++++++++++++---------------------------------
 1 files changed, 25 insertions(+), 66 deletions(-)

diff --git a/inc/managers/SEO/SchemaReferenceBuilder.php b/inc/managers/SEO/SchemaReferenceBuilder.php
index 507adea..ed362fc 100644
--- a/inc/managers/SEO/SchemaReferenceBuilder.php
+++ b/inc/managers/SEO/SchemaReferenceBuilder.php
@@ -1,10 +1,8 @@
 <?php
 namespace JVBase\managers\SEO;
 
-use JVBase\meta\MetaManager;
-use WP_Term;
-use WP_User;
-use WP_Post;
+use JVBase\meta\Meta;
+use JVBase\registrar\Registrar;
 
 if (!defined('ABSPATH')) {
 	exit;
@@ -47,8 +45,11 @@
 		}
 
 		// Get config for templates and schema type
-		$config = self::getConfigFor($objectType, $objectId);
-		$schemaConfig = $config['seo']['schema'] ?? [];
+		$schemaConfig = [];
+		$registrar = Registrar::getInstance($objectType);
+		if ($registrar) {
+			$schemaConfig  = $registrar->getConfig('seo')['schema']??[];
+		}
 
 		// Determine schema type
 		if ($schemaType === null) {
@@ -66,9 +67,7 @@
 		}
 
 		// Create resolver for template resolution
-		$resolver = $objectType === 'post' ? new TemplateResolver($objectId,'post') :
-			($objectType === 'term' ? new TemplateResolver($objectId,'term') :
-				($objectType === 'user' ? new TemplateResolver($objectId, 'user') : null));
+		$resolver = new TemplateResolver($objectId, $objectType)??null;
 
 		// Build reference based on schema type
 		switch ($schemaType) {
@@ -137,38 +136,6 @@
 		};
 	}
 
-	/**
-	 * Get config for an object
-	 */
-	private static function getConfigFor(string $objectType, int $objectId): ?array
-	{
-		switch ($objectType) {
-			case 'post':
-				$postType = get_post_type($objectId);
-				$typeKey = str_replace(BASE, '', $postType);
-				return defined('JVB_CONTENT') && isset(JVB_CONTENT[$typeKey])
-					? JVB_CONTENT[$typeKey]
-					: null;
-
-			case 'term':
-				$term = get_term($objectId);
-				if (!$term || is_wp_error($term)) {
-					return null;
-				}
-				$typeKey = str_replace(BASE, '', $term->taxonomy);
-				return defined('JVB_TAXONOMY') && isset(JVB_TAXONOMY[$typeKey])
-					? JVB_TAXONOMY[$typeKey]
-					: null;
-
-			case 'user':
-				$role = jvbUserRole($objectId);
-				return defined('JVB_USER') && isset(JVB_USER[$role])
-					? JVB_USER[$role]
-					: null;
-		}
-
-		return null;
-	}
 
 	/**
 	 * Build just an @id reference (most minimal)
@@ -405,39 +372,31 @@
 	 */
 	private static function inferSchemaType(string $objectType, int $objectId): string
 	{
+		$default = 'Thing';
+		$registrar = false;
 		if ($objectType === 'post') {
 			$postType = get_post_type($objectId);
-			$typeKey = str_replace(BASE, '', $postType);
-
-			if (defined('JVB_CONTENT') && isset(JVB_CONTENT[$typeKey])) {
-				$config = JVB_CONTENT[$typeKey];
-				return $config['seo']['schema']['type'] ?? 'CreativeWork';
-			}
-
-			return 'CreativeWork';
-		}
-
-		if ($objectType === 'term') {
+			$registrar = Registrar::getInstance($postType));
+			$default = 'CreativeWork';
+		} else if ($objectType === 'term') {
 			$term = get_term($objectId);
 			if (!$term || is_wp_error($term)) {
 				return 'DefinedTerm';
 			}
 
-			$taxonomyKey = str_replace(BASE, '', $term->taxonomy);
-
-			if (defined('JVB_TAXONOMY') && isset(JVB_TAXONOMY[$taxonomyKey])) {
-				$config = JVB_TAXONOMY[$taxonomyKey];
-				return $config['seo']['schema']['type'] ?? 'DefinedTerm';
-			}
-
-			return 'DefinedTerm';
-		}
-
-		if ($objectType === 'user') {
+			$registrar = Registrar::getInstance($term->taxonomy));
+			$default = 'DefinedTerm';
+		} elseif ($objectType === 'user') {
 			return 'Person';
 		}
 
-		return 'Thing';
+		$type = false;
+
+		if ($registrar) {
+			$type = $registrar->getConfig('seo')['schema']['type'];
+		}
+
+		return ($type && !empty($type)) ? $type : $default;
 	}
 
 	/**
@@ -480,8 +439,8 @@
 			case 'TattooParlor':
 			case 'Organization':
 				// Add minimal location (just street address)
-				$meta = new MetaManager($objectId, $objectType);
-				$location = $meta->getValue('location');
+				$meta = new Meta($objectId, $objectType);
+				$location = $meta->get('location');
 
 				if ($location && isset($location['address'])) {
 					$reference['address'] = [

--
Gitblit v1.10.0