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/helpers/dashboard.php | 112 +++++++++----------------------------------------------
1 files changed, 19 insertions(+), 93 deletions(-)
diff --git a/inc/helpers/dashboard.php b/inc/helpers/dashboard.php
index e9a32b4..06f574b 100644
--- a/inc/helpers/dashboard.php
+++ b/inc/helpers/dashboard.php
@@ -1,5 +1,7 @@
<?php
+use JVBase\registrar\Registrar;
+
if (!defined('ABSPATH')) {
exit;
}
@@ -60,91 +62,12 @@
array_map(function ($role) {
return BASE.$role;
},
- jvbRolesWithDashboard())
+ Registrar::getFeatured('has_dashboard', 'user'))
)
)>0;
}
-/**
- * The basis for the dashboard navigation
- * @return array
- */
-function jvbGetUserDashboardPages():array
-{
- if (!isOurPeople() && !current_user_can('manage_options')) {
- return [];
- }
- $user = wp_get_current_user();
- $pages = get_transient('jvb_'.$user->ID.'_dashboard_pages');
- $pages = false;
- if (!$pages) {
- $pages = ['dash'];
- $roles = array_intersect(
- jvbRolesWithDashboard(),
- array_map(function ($role) {
- return jvbNoBase($role);
- },
- $user->roles)
- );
- $content = [];
-
- foreach ($roles as $role) {
- $content = array_unique(array_merge(jvbRolePages($role), $content));
- }
- error_log('Content: '.print_r($content, true));
- foreach ($content as $c) {
-
- $permission = JVB_CONTENT[$c]['plural']??$c.'s';
- if (current_user_can('edit_'.$permission)) {
- $pages[] = $c;
- }
- }
-
-
- if (jvbCheck('can_invite', JVB_MEMBERSHIP) && jvbUserIsVerified()) {
- $pages[] = 'invites';
- }
- if (jvbCheck('term_approval', JVB_MEMBERSHIP) && jvbUserIsVerified()) {
- $pages[] = 'approvals';
- }
- if (jvbSiteHasTermContent()) {
- $terms = array_filter(JVB_TAXONOMY, function ($tax) {
- return jvbCheck('is_content', $tax);
- });
- foreach ($terms as $term => $config) {
- if (current_user_can('manage_'.$term)) {
- $pages[] = $config['plural'];
- }
- }
- }
-
- if (jvbSiteHasIntegrations()) {
- //TODO: Check that user has integrations enabled
- $pages[] = 'integrations';
- }
- if (jvbSiteHasForum() &&
- (empty(JVB_MEMBERSHIP['member_only']??[]) || array_intersect(JVB_MEMBERSHIP['member_only'], $roles) > 0)) {
- $pages[] = 'news';
- }
-
- if (jvbCheck('member_content', JVB_MEMBERSHIP) && jvbUserCanCreate()) {
- $pages[] = 'metrics';
- }
-
- if (jvbCheck('favourites', JVB_SITE)) {
- $pages[] = 'favourites';
- }
-
- if (jvbSiteHasSupport()) {
- $pages[] = 'support';
- }
- $pages = apply_filters('jvbUserDashboardPages', $pages, $user->roles);
- set_transient('jvb_'.$user->ID.'_dashboard_pages', $pages, WEEK_IN_SECONDS);
- }
-
- return $pages;
-}
/**
@@ -167,25 +90,28 @@
}
$role = jvbUserRole((int) $link);
- $config = JVB_USER[$role];
- foreach ($config['can_create'] as $type) {
- if (is_array($type)) {
- $types = array_unique(array_merge($types, array_values($type)[0]));
- } else {
- $types[] = $type;
- }
- }
+ $registrar = Registrar::getInstance($role);
+ if ($registrar && !empty($registrar->getCreatable())){
+ foreach ($registrar->getCreatable() as $type) {
+ if (is_array($type)) {
+ $types = array_unique(array_merge($types, array_values($type)[0]));
+ } else {
+ $types[] = $type;
+ }
+ }
+ }
+
$temp = [];
foreach ($types as $t) {
- $permission = JVB_CONTENT[$t]['plural']??$t.'s';
- if (user_can($link, 'edit_'.$permission)){
+ $permission = JVB()->roles()->getPermission('edit',$t);
+ if (user_can($link, $permission)){
$temp[] = $t;
}
}
- global $jvb_feed;
- $types = array_filter($temp, function ($type) use ($jvb_feed) {
- return array_key_exists($type, $jvb_feed);
+ $types = Registrar::getFeatured('show_feed');
+ $types = array_filter($temp, function ($type) use ($types) {
+ return in_array($type, $types);
});
update_post_meta($postID, BASE.'content_types', $types);
--
Gitblit v1.10.0