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/meta/Form.php |   91 ++++++++++++++++++++++-----------------------
 1 files changed, 45 insertions(+), 46 deletions(-)

diff --git a/inc/meta/Form.php b/inc/meta/Form.php
index 1d3db3f..57bdd85 100644
--- a/inc/meta/Form.php
+++ b/inc/meta/Form.php
@@ -2,6 +2,7 @@
 namespace JVBase\meta;
 
 use DateTime;
+use JVBase\registrar\Registrar;
 
 if (!defined('ABSPATH')) {
 	exit;
@@ -674,16 +675,9 @@
 			$content = $config['content'];
 
 			$config['data']['content'] = $content;
-			$plural =
-				JVB_CONTENT[$content]['plural']
-				?? JVB_TAXONOMY[$content]['plural']
-				?? JVB_USER[$content]['plural']
-				?? str_replace('_', ' ', $content) . 's';
-
-			$singular = JVB_CONTENT[$content]['singular']
-				?? JVB_TAXONOMY[$content]['singular']
-				?? JVB_USER[$content]['singular']
-				?? str_replace('_', ' ',$config['content']);
+			$registrar = Registrar::getInstance($content);
+			$plural = $registrar->getPlural()??str_replace('_', ' ', $content).'s';
+			$singular = $registrar->getSingular()??str_replace('_', ' ', $content);
 		}
 		if ($config['limit'] > 0) {
 			$config['data']['max-files'] = $config['limit'];
@@ -1185,12 +1179,11 @@
 			'type'		=> $config['subtype'],
 		], $config);
 
-		$icon = match ($config['subtype']) {
-			'taxonomy' => JVB_TAXONOMY[$config['taxonomy']]['icon'] ?? jvbDefaultIcon(),
-			'content' => JVB_CONTENT[$config['content']]['icon'] ?? jvbDefaultIcon(),
-			'user' => JVB_USER[$config['role']]['icon'] ?? 'user',
-			default => jvbDefaultIcon(),
-		};
+		$registrar = Registrar::getInstance($config['subtype']);
+		$icon = jvbDefaultIcon();
+		if ($registrar){
+			$icon = $registrar->getIcon()??jvbDefaultIcon();
+		}
 
 		$containerId = sprintf('%s-%s-selector', $name, $config['subtype']);
 
@@ -1228,45 +1221,48 @@
 
 		protected static function getPlural(array $config):array
 		{
+			$single = $plural = '';
 			switch ($config['subtype']) {
 				case 'taxonomy':
-					if (array_key_exists($config['taxonomy'], JVB_TAXONOMY)) {
-						$single = JVB_TAXONOMY[$config['taxonomy']]['singular'];
-						$plural = JVB_TAXONOMY[$config['taxonomy']]['plural'];
+					$registrar = Registrar::getInstance($config['taxonomy']);
+					if ($registrar) {
+						$single = $registrar->getSingular();
+						$plural = $registrar->getPlural();
 					} else {
 						$taxonomy = get_taxonomy($config['taxonomy']);
-						if (!$taxonomy) {
-							return [];
+						if ($taxonomy) {
+							$single = $taxonomy->labels->singular_name;
+							$plural = $taxonomy->labels->name;
 						}
-						$single = $taxonomy->labels->singular_name;
-						$plural = $taxonomy->labels->name;
 					}
 					break;
 				case 'content':
-					if (array_key_exists($config['content'], JVB_CONTENT)) {
-						$single = JVB_CONTENT[$config['content']]['singular'];
-						$plural = JVB_CONTENT[$config['content']]['plural'];
+					$registrar = Registrar::getInstance($config['content']);
+					if ($registrar) {
+						$single = $registrar->getSingular();
+						$plural = $registrar->getPlural();
 					} else {
 						$postType = get_post_type_object($config['content']);
-						if (!$postType) {
-							return '';
+						if ($postType) {
+							$single = $postType->labels->singular_name;
+							$plural = $postType->labels->name;
 						}
-						$single = $postType->labels->singular_name;
-						$plural = $postType->labels->name;
+
 					}
 					break;
 
 				case 'user':
-					if (array_key_exists($config['user'], JVB_USER)) {
-						$single = JVB_USER[$config['user']]['singular'];
-						$plural = JVB_USER[$config['user']]['plural'];
+					$registrar = Registrar::getInstance($config['user']);
+
+					if ($registrar) {
+						$single = $registrar->getSingular();
+						$plural = $registrar->getPlural();
 					} else {
 						$user = get_role($config['user']);
-						if (!$user) {
-							return '';
+						if ($user) {
+							$single = 'User';
+							$plural = 'Users';
 						}
-						$single = 'User';
-						$plural = 'Users';
 					}
 					break;
 			}
@@ -1277,9 +1273,10 @@
 		{
 			switch ($config['subtype']) {
 				case 'taxonomy':
-					if (array_key_exists($config['taxonomy'], JVB_TAXONOMY)) {
-						$single = JVB_TAXONOMY[$config['taxonomy']]['singular'];
-						$plural = JVB_TAXONOMY[$config['taxonomy']]['plural'];
+					$registrar = Registrar::getInstance($config['taxonomy']);
+					if ($registrar) {
+						$single = $registrar->getSingular();
+						$plural = $registrar->getPlural();
 					} else {
 						$taxonomy = get_taxonomy($config['taxonomy']);
 						if (!$taxonomy) {
@@ -1296,9 +1293,10 @@
 					);
 					break;
 				case 'content':
-					if (array_key_exists($config['content'], JVB_CONTENT)) {
-						$single = JVB_CONTENT[$config['content']]['singular'];
-						$plural = JVB_CONTENT[$config['content']]['plural'];
+					$registrar = Registrar::getInstance($config['content']);
+					if ($registrar) {
+						$single = $registrar->getSingular();
+						$plural = $registrar->getPlural();
 					} else {
 						$postType = get_post_type_object($config['content']);
 						if (!$postType) {
@@ -1316,9 +1314,10 @@
 					break;
 
 				case 'user':
-					if (array_key_exists($config['user'], JVB_USER)) {
-						$single = JVB_USER[$config['user']]['singular'];
-						$plural = JVB_USER[$config['user']]['plural'];
+					$registrar = Registrar::getInstance($config['user']);
+					if ($registrar){
+						$single = $registrar->getSingular();
+						$plural = $registrar->getPlural();
 					} else {
 						$user = get_role($config['user']);
 						if (!$user) {

--
Gitblit v1.10.0