From 2a2303d1dccc120dd7aa5f6b6ade0f89e0064850 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Nov 2025 07:42:23 +0000
Subject: [PATCH] =Feed block mostly good! Referrals look good to go. Ready for Madi and Heidi to approve
---
inc/managers/DashboardManager.php | 147 +++++++++++++++++++++++++------------------------
1 files changed, 75 insertions(+), 72 deletions(-)
diff --git a/inc/managers/DashboardManager.php b/inc/managers/DashboardManager.php
index 10a8a4a..69e485e 100644
--- a/inc/managers/DashboardManager.php
+++ b/inc/managers/DashboardManager.php
@@ -169,13 +169,13 @@
// For valid dashboard pages, check access permissions
if (!is_404()) {
- $page = $this->getCurrentPage();
+ $page = $this->getCurrentPageSlug();
// Dashboard home is always accessible (if authenticated)
if ($page === '' || $page === 'dash') {
return;
}
-
+ $page = $this->getCurrentPageTitle();
// Check if page exists in allowed pages
$allowedPages = $this->getUserAllowedPages();
if (!in_array($page, $allowedPages)) {
@@ -193,15 +193,16 @@
public function buildDashboard():void
{
$manageableContent = $this->getAllDashboardPages();
- foreach ($manageableContent as $key => $slug) {
- if ($slug === 'dash') {
+ foreach ($manageableContent as $slug => $page) {
+ if ($page === 'dash') {
continue;
}
+ $slug = $this->getSlug($slug, $page);
$existing = get_page_by_path($slug, OBJECT, BASE.'dash');
if ($existing) {
continue;
}
- $title = $this->getTitle($slug);
+ $title = $page;
$ID = wp_insert_post(array(
'post_title' => $title,
@@ -305,11 +306,11 @@
}
// Get current page/section
- $page = $this->getCurrentPage();
+ $page = $this->getCurrentPageTitle();
$config = $this->getConfig($page);
if(!empty($config)) {
add_filter('jvbLoadingIcon', function() use ($config) {
- return jvbIcon($config['icon']);
+ return $config['icon'];
});
}
$integrationSlugs = array_map(function($name) {
@@ -482,40 +483,13 @@
return;
}
- wp_enqueue_script('jvb-loading');
wp_enqueue_script('jvb-form');
-
- // Consolidate all dashboard settings
- wp_localize_script('jvb-loading', 'dashboardSettings', array(
- 'loadingMessages' => array(
- 'default' => 'Loading...',
- 'error' => 'Failed to load page'
- ),
- 'strings' => array(
- 'deleteConfirm' => 'Are you sure you want to delete this item?',
- 'bulkDeleteConfirm' => 'Are you sure you want to delete these items?',
- 'deleteSuccess' => 'Item(s) deleted successfully',
- 'deleteError' => 'Error deleting item(s)',
- 'saveSuccess' => 'Changes saved successfully',
- 'saveError' => 'Error saving changes',
- 'loadError' => 'Error loading content'
- ),
- 'currentUser' => array(
- 'id' => $this->user->ID,
- 'name' => $this->user->display_name,
- 'role' => array_values($this->user->roles)[0] ?? '',
- 'type' => str_replace(BASE, '', array_values($this->user->roles)[0]),
- 'city' => '', // Add if needed,
- 'artistID' => $this->userLink,
- )
- ));
-
wp_enqueue_script('jvb-selector');
wp_enqueue_script('jvb-uploader');
wp_enqueue_script('jvb-content');
wp_enqueue_script('jvb-crud');
- $page = $this->getCurrentPage();
+ $page = $this->getCurrentPageSlug();
switch ($page) {
case 'notifications':
@@ -575,7 +549,20 @@
do_action('jvbDashScripts', $page);
}
- protected function getCurrentPage():string
+ protected function getCurrentPageTitle():string
+ {
+ if (is_post_type_archive(BASE.'dash')) {
+ return 'dash';
+ }
+
+ global $post;
+ if (!$post) {
+ return '';
+ }
+
+ return $post->post_title;
+ }
+ protected function getCurrentPageSlug():string
{
if (is_post_type_archive(BASE.'dash')) {
return 'dash';
@@ -588,6 +575,29 @@
return $post->post_name;
}
+ protected function getIcon(string $slug, string $page):string
+ {
+ return $this->cache->remember('icon_'.sanitize_title($page), function() use ($slug, $page) {
+ $icon = sanitize_title($page);
+ if (!is_numeric($slug)) {
+ $config = Features::getConfig($slug);
+ if (array_key_exists('icon', $config)) {
+ $icon = $config['icon'];
+ }
+ }
+ return $icon;
+ });
+ }
+ protected function getSlug(string $slug, string $page):string
+ {
+ return $this->cache->remember('slug_'.sanitize_title($page), function() use ($slug, $page) {
+ if (!is_numeric($slug)) {
+ return $slug;
+ } else {
+ return sanitize_title($page);
+ }
+ });
+ }
protected function renderHeader():void
{
@@ -612,7 +622,7 @@
<link rel="preconnect" href="<?= get_home_url()?>"/>
<?php wp_head(); ?>
</head>
- <body class="dashboard<?= ' '.$this->getCurrentPage()?>">
+ <body class="dashboard<?= ' '.$this->getCurrentPageSlug()?>">
<?php jvbAccessibility();?>
<header>
<?php
@@ -663,28 +673,28 @@
<?= TaxonomySelector::outputSelectorModal() ?>
<nav class="dashboard-nav">
<?php
- $current_page = $this->getCurrentPage();
+ $current_page = $this->getCurrentPageSlug();
$pages = $this->getUserAllowedPages()?:[];
echo '<ul>';
- foreach ($pages as $page) {
- // Add data-page attribute for the navigator
- $active = ($current_page == $page) ? ' class="current"' : '';
- $current = ($current_page == $page) ? ' aria-current="page"' : '';
- $config = $this->getConfig($page);
- $icon = $config['icon']??$page;
- $title = ucwords(str_replace('-', ' ', $page));
+ foreach ($pages as $slug => $page) {
+ $slug = $this->getSlug($slug, $page);
+ $icon = $this->getIcon($slug, $page);
+ // Add data-page attribute for the navigator
+ $active = ($current_page == $slug) ? ' class="current"' : '';
+ $current = ($current_page == $slug) ? ' aria-current="page"' : '';
- $link = ($page === 'dash') ? '/'.$page : "/dash/$page";
+
+ $link = ($page === 'dash') ? '/'.$page : "/dash/$slug";
printf(
'<li%s><a href="%s"%s data-page="%s" data-dash title="%s">%s<span>%s</span></a></li>',
$active,
get_home_url(null, $link),
$current,
+ $slug,
$page,
- $title,
- jvbIcon($icon, ['title'=> $title]),
- $title
+ jvbIcon($icon, ['title'=> $page]),
+ $page
);
}
@@ -695,7 +705,7 @@
<?php
- do_action('jvbRenderDashboardSettings', $this->getCurrentPage());
+ do_action('jvbRenderDashboardSettings', $this->getCurrentPageSlug());
?>
<?php wp_footer(); ?>
@@ -717,7 +727,6 @@
echo '<p>Welcome back!</p>';
$pages = $this->getUserAllowedPages();
- error_log('Pages: '.print_r($pages, true));
echo '<h2>What would you like to do today?</h2>';
@@ -729,15 +738,9 @@
$title = $this->getTitle($page);
$description = $this->getDescription($page);
- $icon = $page;
- if (!is_numeric($slug)) {
- $config = Features::getConfig($slug);
- if (array_key_exists('icon', $config)) {
- $icon = $config['icon'];
- }
- } else {
- $slug = sanitize_title($page);
- }
+
+ $slug = $this->getSlug($slug, $page);
+ $icon = $this->getIcon($slug, $page);
if ($title !== '') {
echo '<li><p><a href="'.get_home_url(null, '/dash/'.$slug.'/').'"
data-page="'.$slug.'" data-dash>'.jvbIcon($icon).ucwords($title).'</a></p></li>';
@@ -1104,52 +1107,52 @@
// Add feature-dependent pages (non-config)
if (Features::forSite()->has('referrals')) {
- $pages[] = 'referrals';
+ $pages[] = 'Referrals';
}
if (Features::forMembership()->has('can_invite')) {
- $pages[] = 'invites';
+ $pages[] = 'Invites';
}
if (Features::forMembership()->has('term_approval')) {
- $pages[] = 'approvals';
+ $pages[] = 'Approvals';
}
if (Features::forMembership()->has('forum')) {
- $pages[] = 'news';
+ $pages[] = 'News';
}
if (Features::forMembership()->has('member_content')) {
- $pages[] = 'metrics';
+ $pages[] = 'Metrics';
}
if (Features::forSite()->has('favourites')) {
- $pages[] = 'favourites';
+ $pages[] = 'Favourites';
}
if (Features::anyContentHas('karma') || Features::anyTaxonomyHas('karma') || Features::anyUserHas('karma')) {
- $pages[] = 'karmic-score';
+ $pages[] = 'Karmic Score';
}
if (Features::forSite()->has('notifications')) {
- $pages[] = 'notifications';
+ $pages[] = 'Notifications';
}
if (Features::forSite()->has('support')) {
- $pages[] = 'support';
+ $pages[] = 'Support';
}
if (Features::hasAnyIntegration()) {
- $pages[] = 'integrations';
+ $pages[] = 'Integrations';
}
// Add all content types (with config keys)
foreach (JVB_CONTENT as $slug => $config) {
- $pages[$slug] = sanitize_title($config['plural']);
+ $pages[$slug] = $config['plural'];
}
foreach (JVB_TAXONOMY as $slug=>$config) {
- $pages[$slug] = sanitize_title($config['plural']);
+ $pages[$slug] = $config['plural'];
}
// Allow filtering
--
Gitblit v1.10.0