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/InvitationsManager.php | 84 +++++++++++++++++++++++++-----------------
1 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/inc/managers/InvitationsManager.php b/inc/managers/InvitationsManager.php
index ebf3c92..088556f 100644
--- a/inc/managers/InvitationsManager.php
+++ b/inc/managers/InvitationsManager.php
@@ -4,6 +4,7 @@
use Exception;
use JVBase\managers\queue\executors\InvitationExecutor;
use JVBase\managers\queue\TypeConfig;
+use JVBase\registrar\Registrar;
use JVBase\utility\Features;
use WP_Error;
@@ -16,9 +17,11 @@
protected array $inviteConfig;
protected CustomTable $table;
protected int $expiryDays = 14;
+ protected Cache $cache;
public function __construct()
{
$this->setInviteConfig();
+ $this->cache = Cache::for('invitations');
$this->table = CustomTable::for('invitations');
add_action('init', [$this, 'registerInvitationExecutors'], 5);
@@ -86,46 +89,58 @@
*/
protected function buildInviteTypes(): array
{
- $types = [];
+ $invitable = $this->cache->remember(
+ 'invitableTypes',
+ function () {
+ $types = [];
- // Global invitations from JVB_MEMBERSHIP
- if (!empty(JVB_MEMBERSHIP['can_invite'])) {
- foreach (JVB_MEMBERSHIP['can_invite'] as $role => $canInvite) {
- $types[$role] = [
- 'can_invite' => $canInvite,
- 'to_terms' => []
- ];
- }
- }
+ // Global invitations from JVB_MEMBERSHIP
+ if (!empty(JVB_MEMBERSHIP['can_invite'])) {
+ foreach (JVB_MEMBERSHIP['can_invite'] as $role => $canInvite) {
+ $types[$role] = [
+ 'can_invite' => $canInvite,
+ 'to_terms' => []
+ ];
+ }
+ }
- // Term invitations from invitable content taxonomies
- foreach (JVB_TAXONOMY as $taxonomy => $config) {
- if (Features::forTaxonomy($taxonomy)->has('invitable') &&
- Features::forTaxonomy($taxonomy)->has('is_content') &&
- Features::forTaxonomy($taxonomy)->has('is_ownable')) {
+ // Term invitations from invitable content taxonomies
+ $invitable = Registrar::getFeatured('invitable', 'term');
+ $content = Registrar::getFeatured('is_content', 'term');
+ $ownable = Registrar::getFeatured('is_ownable', 'term');
+ $taxonomies = array_intersect($invitable, $content, $ownable);
+ if (!empty($taxonomies)) {
+ $users = Registrar::getRegistered('user');
+ }
+ foreach ($taxonomies as $taxonomy) {
+ $registrar = Registrar::getInstance($taxonomy);
- $forContent = $config['for_content'] ?? [];
- foreach ($forContent as $content) {
- // Find which user roles can create this content
- foreach (JVB_USER as $role => $userConfig) {
- $creatable = Features::forUser($role)->getCreatableContent();
- if (in_array($content, $creatable)) {
- if (!isset($types[$role])) {
- $types[$role] = [
- 'can_invite' => [],
- 'to_terms' => []
- ];
- }
- if (!in_array($taxonomy, $types[$role]['to_terms'])) {
- $types[$role]['to_terms'][] = $taxonomy;
+ foreach ($registrar->registrar->for as $content) {
+ // Find which user roles can create this content
+ foreach ($users as $user) {
+ $userRegistrar = Registrar::getInstance($user);
+
+ $creatable = $userRegistrar->getCreatable();
+ if (in_array($content, $creatable)) {
+ if (!isset($types[$role])) {
+ $types[$role] = [
+ 'can_invite' => [],
+ 'to_terms' => []
+ ];
+ }
+ if (!in_array($taxonomy, $types[$role]['to_terms'])) {
+ $types[$role]['to_terms'][] = $taxonomy;
+ }
}
}
}
}
- }
- }
- return $types;
+ return $types;
+ }
+ );
+ return $invitable;
+
}
/******************************************************************
@@ -467,8 +482,9 @@
$term = get_term($termID, BASE . $taxonomy);
if ($term && !is_wp_error($term)) {
- $config = JVB_TAXONOMY[$taxonomy] ?? [];
- $singular = $config['singular'] ?? $taxonomy;
+ $registrar = Registrar::getInstance($taxonomy);
+
+ $singular = $registrar ? $registrar->getSingular() : $taxonomy;
$termContent[] = sprintf(
"<p>%s has also invited you to join %s. You'll be automatically added to this %s when you register.</p>",
--
Gitblit v1.10.0