From 3baf3d2545ba6ece6b74a64c0def59bd0774cf54 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 10 Jun 2026 16:34:12 +0000
Subject: [PATCH] =Laid the groundwork for an improved DashboardManager.php setup. Have to put it aside so I can get the dang Northeh done though.
---
inc/managers/DashboardManager.php | 43 ++++++++++++++++++++++++-------------------
1 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/inc/managers/DashboardManager.php b/inc/managers/DashboardManager.php
index 26b724f..152afc6 100644
--- a/inc/managers/DashboardManager.php
+++ b/inc/managers/DashboardManager.php
@@ -1,7 +1,7 @@
<?php
namespace JVBase\managers;
-use JVBase\forms\TaxonomySelector;
+use JetBrains\PhpStorm\NoReturn;use JVBase\forms\TaxonomySelector;
use JVBase\base\Site;
use JVBase\meta\Form;
use JVBase\registrar\Registrar;
@@ -25,11 +25,11 @@
public function __construct()
{
- $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user');
+ $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user')->user();
if (JVB_TESTING) {
$this->cache->flush();
}
- $this->cache->flush();
+
add_action('init', [$this, 'registerDashboard']);
$this->user = wp_get_current_user();
@@ -45,11 +45,12 @@
jvb_register_do_once('buildDashboard', [$this, 'activate']);
- add_filter('the_seo_framework_sitemap_exclude_ids', [$this, 'excludeDashboard'], 10, 1);
+ add_filter('the_seo_framework_sitemap_exclude_ids', [$this, 'excludeDashboard'], 8, 1);
}
- public function excludeDashboard(array $ids):array {
- $cached = $this->cache->remember(
+ public function excludeDashboard(array $IDs):array {
+ $this->cache->flush();
+ $exclude = $this->cache->remember(
'dashboardIDs',
function() {
return get_posts([
@@ -58,7 +59,11 @@
'fields' => 'ids',
]);
});
- return array_merge($ids, $cached);
+ if (!empty($exclude)) {
+ $IDs = array_merge($IDs, $exclude);
+ }
+
+ return $IDs;
}
/**
@@ -106,7 +111,7 @@
/**
* Redirect all non-admin users from wp-admin to custom dashboard
*/
- public function redirectFromAdmin()
+ public function redirectFromAdmin():void
{
// Skip if already processing a redirect
if (defined('DOING_AJAX') && DOING_AJAX) {
@@ -128,13 +133,13 @@
}
}
- protected function redirectToLogin():void
+ #[NoReturn]protected function redirectToLogin():void
{
wp_redirect(wp_login_url(get_home_url(null, '/dash')));
exit;
}
- protected function redirectToDashboard():void
+ #[NoReturn]protected function redirectToDashboard():void
{
wp_redirect(get_home_url(null, '/dash'));
exit;
@@ -186,7 +191,6 @@
if (!is_404() && !is_user_logged_in()) {
error_log('Redirecting to login - user not logged in');
$this->redirectToLogin();
- return;
}
// If logged in but doesn't have dashboard access, redirect to home
@@ -201,7 +205,6 @@
if (is_404() && (str_starts_with($wp->request, 'dash/') || $wp->request === 'dash')) {
error_log('404 on dashboard URL, redirecting to dashboard home');
$this->redirectToDashboard();
- return;
}
// For valid dashboard pages, check access permissions
@@ -390,7 +393,6 @@
$this->renderHeader();
// Pass to page handler
$constantSlug = $this->getConstantSlug($page);
-
echo apply_filters(
'jvbDashboardPage',
$this->renderPage($page),
@@ -636,7 +638,10 @@
}
}
- return $icon;
+ return match($icon) {
+ 'favourites' => 'heart',
+ default => $icon
+ };
});
}
protected function getSlug(string $slug, string $page):string
@@ -739,7 +744,7 @@
//content types
$all = array_merge(
Registrar::getRegistered('post'),
- Registrar::getFeatured('is_content', 'term')
+ Registrar::withFeature('is_content', 'term')
);
$availableContent = array_filter($pages, function($page, $key) use($all) {
return !is_numeric($key) && in_array($key, $all) && JVB()->roles()->checkRole($this->user, $key);
@@ -1086,7 +1091,7 @@
<?php
$i=1;
$content = Registrar::getRegistered('post');
- $contentTax = Registrar::getFeatured('is_content', 'term');
+ $contentTax = Registrar::withFeature('is_content', 'term');
$taxonomies = Registrar::getRegistered('term');
foreach($contentTax as $index => $tax) {
unset($taxonomies[$index]);
@@ -1279,7 +1284,7 @@
$pages[] = 'Favourites';
}
- if (!empty(Registrar::getFeatured('karma'))) {
+ if (!empty(Registrar::withFeature('karma'))) {
$pages[] = 'Karmic Score';
}
@@ -1446,7 +1451,7 @@
foreach ($roles as $role) {
$contents = Registrar::getInstance($role)?->getCreatable();
if (!empty($contents)) {
- $hasKarma = Registrar::getFeatured('karma');
+ $hasKarma = Registrar::withFeature('karma');
$remove = empty(array_intersect($contents, $hasKarma));
}
}
@@ -1507,7 +1512,7 @@
*/
protected function getRolesWithDashboard():array
{
- return Registrar::getFeatured('has_dashboard', 'user');
+ return Registrar::withFeature('has_dashboard', 'user');
}
/**
--
Gitblit v1.10.0