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/rest/routes/ContentRoutes.php | 62 ++++++++++++++++--------------
1 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/inc/rest/routes/ContentRoutes.php b/inc/rest/routes/ContentRoutes.php
index 0b9cea6..7f12b55 100644
--- a/inc/rest/routes/ContentRoutes.php
+++ b/inc/rest/routes/ContentRoutes.php
@@ -5,18 +5,15 @@
use JVBase\managers\queue\executors\ContentExecutor;
use JVBase\managers\queue\TypeConfig;
use JVBase\meta\Meta;
+use JVBase\registrar\Registrar;
use JVBase\rest\PermissionHandler;
use JVBase\rest\Response;
use JVBase\rest\Rest;
-use JVBase\managers\Cache;
use JVBase\rest\Route;
-use JVBase\utility\Features;
use WP_Post;
use WP_Query;
-use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
-use Exception;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
@@ -103,11 +100,12 @@
protected function initTimelineFields(string $content): void
{
$content = jvbNoBase($content);
- if (!Features::forContent($content)->has('is_timeline')) {
+
+ $config = Registrar::getInstance($content);
+ if (!$config || !$config->hasFeature('is_timeline')) {
return;
}
- $config = Features::getConfig($content);
- $this->fields = $config['fields'];
+ $this->fields = $config->getFields();
$this->timelineSharedFields = $this->getTimelineSharedFields($content);
array_unshift($this->timelineSharedFields, 'post_thumbnail');
@@ -120,11 +118,12 @@
public function getTimelineUniqueFields(string $content): array
{
$content = jvbNoBase($content);
- if (!Features::forContent($content)->has('is_timeline')) {
+ $registrar = Registrar::getInstance($content);
+ if (!$registrar || !$registrar->hasFeature('is_timeline')) {
return [];
}
- $config = Features::getConfig($content);
- $allFields = $config['fields'];
+
+ $allFields = $registrar->getFields();
return array_keys(array_filter($allFields, function ($field) {
if (array_key_exists('for_all', $field) && $field['for_all'] === true) {
@@ -137,14 +136,12 @@
public function getTimelineSharedFields(string $content): array
{
$content = jvbNoBase($content);
- if (!Features::forContent($content)->has('is_timeline')) {
+ $registrar = Registrar::getInstance($content);
+ if (!$registrar || !$registrar->hasFeature('is_timeline')) {
return [];
}
- $config = Features::getConfig($content);
- if (!$config || empty($config)) {
- return [];
- }
- $allFields = $config['fields'] ?? [];
+
+ $allFields = $registrar->getFields()??[];
return array_keys(array_filter($allFields, function ($field) {
if (!array_key_exists('for_all', $field) || $field['for_all'] === false) {
@@ -203,6 +200,7 @@
public function getContent(WP_REST_Request $request): WP_REST_Response
{
$params = $request->get_params();
+ error_log('getContent params: '.print_r($params, true));
$user_id = $params['user'];
$post_status = $params['status'];
@@ -225,12 +223,14 @@
'post_status' => $post_status
];
//Only top level posts for timeline types
- if (Features::forContent($post_type)->has('is_timeline')) {
+ $registrar = Registrar::getInstance($post_type);
+
+ if ($registrar && $registrar->hasFeature('is_timeline')) {
$args['post_parent'] = 0;
}
//Calendar filters
- if (Features::forContent($post_type)->has('is_calendar')) {
+ if ($registrar && $registrar->hasFeature('is_calendar')) {
$args = $this->applyCalendarFilters($args, $params);
}
$taxonomies = array_filter($params, function ($param) {
@@ -281,7 +281,7 @@
$query = new WP_Query($args);
- $this->fields = jvbGetFields(str_replace('-', '_', $this->post_type));
+ $this->fields = Registrar::getFieldsFor(str_replace('-', '_', $this->post_type));
$this->taxonomies = $this->getTaxonomies($this->post_type);
$posts = array_map([$this, 'prepareItem'], $query->posts);
@@ -388,16 +388,19 @@
*/
protected function getTaxonomies(string $content): array
{
- $taxonomy_for = jvbGlobalTaxonomyFor();
- $out = [];
- foreach ($taxonomy_for as $tax => $postTypes) {
- if (in_array($content, $postTypes)) {
- $out[BASE . $tax] = [
- 'label' => JVB_CONTENT[$content]['plural'],
- 'icon' => $tax,
- ];
- }
+ $registrar = Registrar::getInstance($content);
+ if (!$registrar) {
+ return [];
}
+ $out = [];
+ foreach ($registrar->registrar->taxonomies as $tax) {
+ $taxReg = Registrar::getInstance($tax);
+ $out[jvbCheckBase($tax)] = [
+ 'label' => $taxReg->getPlural(),
+ 'icon' => $taxReg->getIcon()??jvbDefaultIcon()
+ ];
+ }
+
return $out;
}
@@ -424,7 +427,8 @@
*/
protected function prepareItem(WP_Post $post, bool $skip = false, bool $fields = true): array
{
- if (!$skip && Features::forContent($post->post_type)->has('is_timeline')) {
+ $registrar = Registrar::getInstance($post->post_type);
+ if (!$skip && $registrar && $registrar->hasFeature('is_timeline')) {
$this->initTimelineFields($post->post_type);
return $this->formatTimeline($post);
}
--
Gitblit v1.10.0