Jake Vanderwerf
2026-06-29 4089ba01e0881c89a72332e13bc3a80b6bddec2a
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,9 +25,13 @@
    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();
      }
        add_action('init', [$this, 'registerDashboard']);
      $this->cache->flush();
        $this->user = wp_get_current_user();
        $this->role = jvbUserRole($this->user->ID);
        $this->userLink = (int)get_user_meta($this->user->ID, BASE.'profile_link', true);
@@ -41,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([
@@ -54,7 +59,11 @@
               'fields' => 'ids',
            ]);
         });
      return array_merge($ids, $cached);
      if (!empty($exclude)) {
         $IDs = array_merge($IDs, $exclude);
      }
      return $IDs;
   }
    /**
@@ -102,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) {
@@ -124,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;
@@ -182,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
@@ -197,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
@@ -211,7 +218,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();
@@ -379,14 +386,13 @@
   }
   protected function renderDashboard(string $page):string
   {
      ob_start();
//    ob_start();
      jvbInlineStyles('nav');
      jvbInlineStyles('dash');
      jvbInlineStyles('forms');
      $this->renderHeader();
      // Pass to page handler
      $constantSlug = $this->getConstantSlug($page);
        echo apply_filters(
         'jvbDashboardPage',
         $this->renderPage($page),
@@ -395,7 +401,8 @@
      );
      $this->renderFooter();
      return ob_get_clean();
//    return ob_get_clean();
return '';
//    $integrationSlugs = array_map(function($name) {
//       return sanitize_title(str_replace('_', '-', $name));
//    }, array_keys(JVB()->getAvailableServices(false)));
@@ -631,7 +638,10 @@
            }
         }
         return $icon;
         return match($icon) {
            'favourites'   => 'heart',
            default => $icon
         };
      });
   }
   protected function getSlug(string $slug, string $page):string
@@ -677,7 +687,10 @@
         if (function_exists($function)) {
            echo $function([],'');
         } else {
            echo JVB()->blocks()->render_core_site_logo([],'');
            echo render_block( [
               'blockName' => 'core/site-logo',
               'attrs'     => [],
            ]);
         }
         ?>
@@ -701,9 +714,9 @@
      <?php
      $menu = new Navigation('sidebar');
      $menuClasses = ['col', 'a-start', 'nowrap'];
      $menuClasses = ['left'];
      $itemClasses = ['col'];
      $menu->addClass('col a-start')->hasToggle()->defaultMenuClasses($menuClasses);
      $menu->addClass('sidebar left')->hasToggle()->defaultMenuClasses($menuClasses);
      $menu->defaultItemClasses($itemClasses);
      $pages = $this->getUserAllowedPages()?:[];
      //Dashboard
@@ -731,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);
@@ -754,8 +767,11 @@
                  $itemMenu = $item->submenu($slug);
                  foreach ($taxonomies as $s) {
                     $taxRegistrar = Registrar::getInstance($s);
                     $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon())
                     if ($taxRegistrar) {
                        $itemMenu->addItem($taxRegistrar->getPlural(), $taxRegistrar->getIcon())
                        ->url($this->baseURL.'/'.$s);
                     }
                  }
               }
            }
@@ -849,6 +865,7 @@
    public function renderIndex(string $content, string $page):string
    {
      jvbDump($page);
      if ($page !== '' && $page !== 'dash') {
         return $content;
      }
@@ -914,28 +931,6 @@
        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);
@@ -999,7 +994,7 @@
    {
        ?>
        <div class="approvals container">
            <nav class="tabs row start" role="tablist">
            <nav class="tabs row left" role="tablist">
                <button type="button" class="tab active" data-tab="summary" role="tab" aria-selected="true">
                   <?= jvbDashIcon('infinity')?>All
                </button>
@@ -1071,11 +1066,11 @@
      }
      ob_start();
        ?>
        <nav class="tabs row start" role="tablist">
        <nav class="tabs row left" role="tablist">
        <?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]);
@@ -1209,6 +1204,7 @@
        echo jvbNewModal(
            'edit-modal '.$type,
         'edit-modal',
            'Edit '.ucfirst($type),
            jvbRenderForm('admin', $fields)
        );
@@ -1268,7 +1264,7 @@
            $pages[] = 'Favourites';
         }
         if (!empty(Registrar::getFeatured('karma'))) {
         if (!empty(Registrar::withFeature('karma'))) {
            $pages[] = 'Karmic Score';
         }
@@ -1327,12 +1323,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
@@ -1345,6 +1343,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;
@@ -1435,11 +1434,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':
@@ -1496,7 +1496,7 @@
    */
   protected function getRolesWithDashboard():array
   {
      return Registrar::getFeatured('has_dashboard', 'user');
      return Registrar::withFeature('has_dashboard', 'user');
   }
   /**