From a9654f00c8fbc9934289d761843ddd071025013f Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 28 Aug 2026 17:20:28 +0000
Subject: [PATCH] =PHPStorm Code Inspection: fixed class reference errors (from getting rid of JVB() and replacing with direct class::getInstance; as well as general code sniffing, etc
---
inc/managers/DashboardManager.php | 127 ++++++++++++++++++++----------------------
1 files changed, 60 insertions(+), 67 deletions(-)
diff --git a/inc/managers/DashboardManager.php b/inc/managers/DashboardManager.php
index 26b724f..fc91ddf 100644
--- a/inc/managers/DashboardManager.php
+++ b/inc/managers/DashboardManager.php
@@ -1,9 +1,9 @@
<?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\integrations\ServiceMap;use JVBase\meta\Form;
use JVBase\registrar\Registrar;
use JVBase\ui\Navigation;
use WP_Error;use WP_Query;use WP_User;
@@ -17,6 +17,8 @@
*/
class DashboardManager
{
+ use ServiceMap;
+
protected WP_User $user;
protected Cache $cache;
protected string $role;
@@ -25,11 +27,9 @@
public function __construct()
{
- $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user');
- if (JVB_TESTING) {
- $this->cache->flush();
- }
- $this->cache->flush();
+ $this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->user();
+
+
add_action('init', [$this, 'registerDashboard']);
$this->user = wp_get_current_user();
@@ -45,11 +45,11 @@
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 {
+ $exclude = $this->cache->remember(
'dashboardIDs',
function() {
return get_posts([
@@ -58,7 +58,11 @@
'fields' => 'ids',
]);
});
- return array_merge($ids, $cached);
+ if (!empty($exclude)) {
+ $IDs = array_merge($IDs, $exclude);
+ }
+
+ return $IDs;
}
/**
@@ -106,7 +110,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 +132,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 +190,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 +204,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
@@ -215,7 +217,7 @@
$page = $this->getCurrentPageTitle();
// Check if page exists in allowed pages
$allowedPages = $this->getUserAllowedPages();
-
+ error_log('Allowed pages: '.print_r($allowedPages, true));
if (!in_array($page, $allowedPages)) {
error_log("User not allowed to access page: {$page}");
$this->redirectToDashboard();
@@ -294,11 +296,10 @@
*/
protected function buildIntegrationPages(int $parentID):void
{
- $integrations = JVB()->getAvailableServices(false);
-
- foreach ($integrations as $name => $integration) {
+ $integrations = $this->getAvailableServices();
+ foreach ($integrations as $service) {
+ $integration = $this->getService($service);
$title = $integration->getTitle();
-
$slug = sanitize_title($title);
$this->createDashboardPage($slug, $title, $parentID);
}
@@ -357,7 +358,7 @@
}
$integrationSlugs = array_map(function($name) {
return sanitize_title(str_replace('_', '-', $name));
- }, array_keys(JVB()->getAvailableServices(false)));
+ }, array_keys($this->getAvailableServices()));
// Check if this is an integration subpage
if (in_array($page, $integrationSlugs)) {
@@ -390,7 +391,6 @@
$this->renderHeader();
// Pass to page handler
$constantSlug = $this->getConstantSlug($page);
-
echo apply_filters(
'jvbDashboardPage',
$this->renderPage($page),
@@ -636,7 +636,10 @@
}
}
- return $icon;
+ return match($icon) {
+ 'favourites' => 'heart',
+ default => $icon
+ };
});
}
protected function getSlug(string $slug, string $page):string
@@ -739,10 +742,10 @@
//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);
+ return !is_numeric($key) && in_array($key, $all) && Roles::getInstance()()->checkRole($this->user, $key);
}, ARRAY_FILTER_USE_BOTH);
if (!empty ($availableContent)){
$content = $menu->addItem('Your Content', jvbDashIcon('book-bookmark'))
@@ -860,12 +863,13 @@
public function renderIndex(string $content, string $page):string
{
+ jvbDump($page);
if ($page !== '' && $page !== 'dash') {
return $content;
}
if (Site::has('referrals')) {
- $whatever = JVB()->referrals()->getReferralWelcomeMessage($this->user->ID);
+ $whatever = Referrals::getInstance()->getReferralWelcomeMessage($this->user->ID);
if (!empty($whatever)) {
return $whatever;
}
@@ -925,42 +929,21 @@
jvbRenderSections($this->userLink, 'post', $type);
}
- protected function renderSettings():void
- {
- wp_enqueue_script('jvb-form');
- wp_enqueue_script(
- 'jvb-bio-manager',
- JVB_URL.'assets/js/min/bioManager.min.js',
- array('jvb-client-queue', 'sortablejs', 'quill-js', 'jvb-taxonomy-selector'),
- '1.0.0',
- true
- );
- wp_localize_script('jvb-bio-manager', 'bioSettings', [
- 'type' => 'user_settings',
- ]);
- $content = apply_filters('jvbDashboardSettings', '');
- if ($content !== '') {
- echo $content;
- } else {
- jvbRenderSections($this->user->ID, 'user', jvbUserRole());
- }
-
- }
-
protected function getIntegrationsMenu():string
{
- $integrations = JVB()->getAvailableServices(false);
+ $integrations = $this->getAvailableServices();
$out = '';
if (!empty($integrations)) {
$out = '<nav class="integrations"><ul>';
$url = get_home_url(null, '/dash/integrations/');
$out .= '<li><a href="'.$url.'">'.jvbDashIcon('plugs-connected').'Integrations</a></li>';
- foreach ($integrations as $name=> $integration) {
- if (!JVB()->userCanConnect($name, $this->user->ID) || !$integration->hasDefaults()) {
+ foreach ($integrations as $service) {
+ $integration = $this->getService($service);
+ if (method_exists($integration, 'userCanConnect') && !$integration->userCanConnect($this->user->ID)) {
continue;
}
- $link = sanitize_title(str_replace('_', '-',$name));
+ $link = sanitize_title(str_replace('_', '-',$service));
$out .= '<li><a href="'.$url.$link.'">'.jvbDashIcon($integration->icon).$integration->getTitle().'</a></li>';
}
$out .= '</ul></nav>';
@@ -979,23 +962,28 @@
if ($connection !== 'integrations') {
$userID = (Site::has('has_membership')) ? $this->user->ID : null;
- $integration = JVB()->connect($connection, $userID);
-
- echo '<h1>Managing '.$integration->title.'</h1>';
- $integration->renderDefaults();
+ $integration = $this->getServiceUser($connection, $userID);
+ if (method_exists($integration, 'renderDefaults')) {
+ echo '<h1>Managing '.$integration->title.'</h1>';
+ $integration->renderDefaults();
+ }
} else {
?>
<section class="item-grid integrations">
<?php
- $all = JVB()->getAvailableServices();
- foreach ($all as $name) {
+
+ foreach ($this->getAvailableServices() as $name) {
if (current_user_can('manage_options')) {
$userID = null;
} else {
$userID = $this->user->ID;
}
-
- JVB()->connect($name, $userID)->renderConnection();
+ $integration = $this->getService($name);
+ if (method_exists($integration, 'determineUser')
+ && method_exists($integration, 'renderConnection')) {
+ $integration->determineUser();
+ $integration->renderConnection();
+ }
}
?>
</section>
@@ -1086,7 +1074,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]);
@@ -1220,6 +1208,7 @@
echo jvbNewModal(
'edit-modal '.$type,
+ 'edit-modal',
'Edit '.ucfirst($type),
jvbRenderForm('admin', $fields)
);
@@ -1279,7 +1268,7 @@
$pages[] = 'Favourites';
}
- if (!empty(Registrar::getFeatured('karma'))) {
+ if (!empty(Registrar::withFeature('karma'))) {
$pages[] = 'Karmic Score';
}
@@ -1338,12 +1327,14 @@
}
if (!$user || !$this->userHasDashboardAccess($user)) {
+ error_log('No Dashboard Access');
return [];
}
$pages = $this->cache->get($userID);
+ $pages = false;
if ($pages === false || JVB_TESTING) {
if (user_can($userID, 'manage_options')) {
// Admin gets all pages as flat array
@@ -1356,6 +1347,7 @@
$pages = $this->getAllDashboardPages();
$canSkip = user_can($userID, 'skip_moderation');
+ jvbDump($pages, 'All Pages');
foreach($pages as $key => $slug) {
//Default to Remove pages
$remove = true;
@@ -1364,7 +1356,7 @@
$membership = Site::membership();
$type = $registrar? $registrar->getType() : false;
if ($type) {
- $permission = JVB()->roles()->getPermission('edit', $key);
+ $permission = Roles::getInstance()()->getPermission('edit', $key);
}
switch ($type) {
case 'content':
@@ -1374,7 +1366,7 @@
break;
case 'taxonomy':
$registrar = Registrar::getInstance($key);
- if ($registrar && $registrar->hasFeature('is_content') && (!empty(JVB()->roles()->getOwnedTerms($userID, $key)) || !empty(JVB()->roles()->getManagedTerms($userID, $key)))){
+ if ($registrar && $registrar->hasFeature('is_content') && (!empty(Roles::getInstance()()->getOwnedTerms($userID, $key)) || !empty(Roles::getInstance()()->getManagedTerms($userID, $key)))){
$remove = false;
} else if (count(array_intersect($registrar->registrar->for, array_keys($pages))) > 0) {
$remove = false;
@@ -1446,11 +1438,12 @@
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));
}
}
break;
+ case 'Account':
case 'dash':
case 'Referrals':
case 'favourites':
@@ -1507,7 +1500,7 @@
*/
protected function getRolesWithDashboard():array
{
- return Registrar::getFeatured('has_dashboard', 'user');
+ return Registrar::withFeature('has_dashboard', 'user');
}
/**
--
Gitblit v1.10.0