Jake Vanderwerf
2025-11-23 d7dbe7fee362d587dfc334135d9581b6216a4295
inc/managers/DashboardManager.php
@@ -169,7 +169,7 @@
      // 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') {
@@ -178,7 +178,7 @@
         // Check if page exists in allowed pages
         $allowedPages = $this->getUserAllowedPages();
         if (!in_array($page, $allowedPages)) {
         if (!array_key_exists($page, $allowedPages)) {
            error_log("User not allowed to access page: {$page}");
            $this->redirectToDashboard();
            return;
@@ -193,15 +193,17 @@
    public function buildDashboard():void
    {
        $manageableContent = $this->getAllDashboardPages();
        foreach ($manageableContent as $key => $slug) {
         if ($slug === 'dash') {
        foreach ($manageableContent as $slug => $page) {
         if ($page === 'dash') {
            continue;
         }
         $existing = get_page_by_path($slug, OBJECT, BASE.'dash');
         if ($existing) {
            continue;
         }
            $title = $this->getTitle($slug);
            $title = $page;
         $slug = $this->getSlug($slug, $page);
            $ID = wp_insert_post(array(
                'post_title'    => $title,
@@ -305,11 +307,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) {
@@ -515,7 +517,7 @@
      wp_enqueue_script('jvb-content');
      wp_enqueue_script('jvb-crud');
      $page = $this->getCurrentPage();
      $page = $this->getCurrentPageSlug();
            switch ($page) {
                case 'notifications':
@@ -575,7 +577,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 +603,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 +650,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 +701,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 +733,7 @@
      <?php
        do_action('jvbRenderDashboardSettings', $this->getCurrentPage());
        do_action('jvbRenderDashboardSettings', $this->getCurrentPageSlug());
      ?>
        <?php wp_footer(); ?>
@@ -717,7 +755,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 +766,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 +1135,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