From 46d681c6b825d21b3f698d793c4e630c687d90ad Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 21 May 2026 21:41:53 +0000
Subject: [PATCH] =Major CustomBlocks.php overhaul, expanding block support and customization from the editor. theme.json should now be updated on new themes to set brand colours, etc. Also note: major change to .col vs .row alignment: simplifying it to .top .bottom vs the confusion of the differences for .col/.row .start and .a-start
---
inc/managers/DashboardManager.php | 186 ++++++++++++++++++++++------------------------
1 files changed, 90 insertions(+), 96 deletions(-)
diff --git a/inc/managers/DashboardManager.php b/inc/managers/DashboardManager.php
index 68f7fe3..36eaff2 100644
--- a/inc/managers/DashboardManager.php
+++ b/inc/managers/DashboardManager.php
@@ -6,7 +6,7 @@
use JVBase\meta\Form;
use JVBase\registrar\Registrar;
use JVBase\ui\Navigation;
-use WP_User;
+use WP_Error;use WP_Query;use WP_User;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
@@ -27,13 +27,10 @@
{
$this->cache = Cache::for('dashboard', WEEK_IN_SECONDS)->connect('user');
add_action('init', [$this, 'registerDashboard']);
- if (!$this->isRegistered()) {
- add_action('init', [$this, 'buildDashboard']);
- }
- $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.'link', true);
+ $this->userLink = (int)get_user_meta($this->user->ID, BASE.'profile_link', true);
$this->baseURL = get_home_url(null, '/dash');
add_action('template_redirect', [$this, 'handleRedirects']);
@@ -42,6 +39,8 @@
add_action('wp_enqueue_scripts', [$this, 'dashboardScripts'], 50);
add_filter('jvbDashboardPage', [$this, 'renderIndex'], 10, 2);
+ jvb_register_do_once('buildDashboard', [$this, 'activate']);
+
add_filter('the_seo_framework_sitemap_exclude_ids', [$this, 'excludeDashboard'], 10, 1);
}
@@ -224,34 +223,65 @@
* Ensures the necessary pages are created
* @return void
*/
- public function buildDashboard():void
+ public function activate():void
{
$manageableContent = $this->getAllDashboardPages();
+ error_log('[DashboardManager]::buildDashboard Manageable Content: '.print_r($manageableContent, true));
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;
+
+ $ID = $this->createDashboardPage($slug, $page);
+
+
+ $registrar = Registrar::getInstance($slug);
+ if ($registrar) {
+ $create = [
+ 'new_' => 'Create New ',
+ 'edit_' => 'Edit '
+ ];
+ $parentID = (int)$ID;
+ foreach ($create as $s => $t) {
+ $s .= $slug;
+ $t .= $page;
+ $this->createDashboardPage($s, $t, $parentID);
+ }
}
- $title = $page;
-
- $ID = wp_insert_post(array(
- 'post_title' => $title,
- 'post_name' => $slug,
- 'post_type' => BASE.'dash',
- 'post_status' => 'publish',
- ));
-
- if ($title === 'Integrations') {
+ if ($page === 'Integrations') {
$this->buildIntegrationPages($ID);
}
}
- update_option(BASE.'dashboard_registered', true);
- remove_action('init', [$this, 'buildDashboard']);
}
+ public function createDashboardPage(string $slug, string $page, int $parentID = 0):int|WP_Error
+ {
+ if (is_numeric($slug)) {
+ $slug = $this->getSlug($slug, $page);
+ }
+
+ $existing = new WP_Query([
+ 'post_type' => BASE.'dash',
+ 'name' => $slug,
+ 'fields' => 'ids',
+ 'posts_per_page' => 1,
+ ]);
+
+ if ($existing->have_posts()) {
+ return $existing->posts[0];
+ }
+
+
+ $args = [
+ 'post_title' => $page,
+ 'post_name' => $slug,
+ 'post_type' => BASE.'dash',
+ 'post_status' => 'publish',
+ ];
+ if ($parentID > 0) {
+ $args['post_parent'] = $parentID;
+ }
+ return wp_insert_post($args);
+ }
/**
* Build integration sub-pages
@@ -264,27 +294,9 @@
foreach ($integrations as $name => $integration) {
$title = $integration->getTitle();
+
$slug = sanitize_title($title);
-
- // Check if integration page already exists
- $existing = get_posts([
- 'post_type' => BASE.'dash',
- 'name' => $slug,
- 'post_parent' => $parentID,
- 'posts_per_page' => 1,
- ]);
-
- if (!empty($existing)) {
- continue; // Skip if exists
- }
-
- wp_insert_post([
- 'post_title' => $title,
- 'post_name' => $slug,
- 'post_type' => BASE.'dash',
- 'post_status' => 'publish',
- 'post_parent' => $parentID
- ]);
+ $this->createDashboardPage($slug, $title, $parentID);
}
}
@@ -318,14 +330,6 @@
return $description;
}
- /**
- * Checks if we've already created the need pages
- * @return bool
- */
- protected function isRegistered():bool
- {
- return get_option(BASE.'dashboard_registered', false);
- }
/**
* Hacking into the template_include to set our custom templates and protections
@@ -647,7 +651,7 @@
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
- <title><?= (array_key_exists('dashboard_title', JVB_SITE)) ? JVB_SITE['dashboard_title'] : 'Dashboard | '.get_bloginfo('name') ?></title>
+ <title><?= Site::dashboardTitle()??'Dashboard | '.get_bloginfo('name') ?></title>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
@@ -667,41 +671,27 @@
<body class="dashboard<?= ' '.$this->getCurrentPageSlug()?>">
<?php jvbAccessibility();?>
<header>
- <?php
- $checked = (is_user_logged_in() && current_user_can('prefers_dark_theme', true)) ? ' checked' : '';
- $title = ($checked == '') ? 'Toggle Dark Mode' : 'Toggle Light Mode';
- echo '<label title="'.$title.'" id="theme-switch" class="toggle-switch" for="theme-switcher">
- <input class="theme-switch row" id="theme-switcher" name="theme-switcher" type="checkbox"'.$checked.' data-setting="theme" data-theme role="switch" name="dark-mode" aria-label="Toggle dark mode"><span class="slider">'.
- jvbIcon('sun-dim', ['title'=> 'Light Mode']).
- jvbIcon('moon', ['title'=>'Dark Mode']).
- '</span></label>';
- ?>
- <p class="title">
- <a href="<?= get_home_url(); ?>" rel="home" title="Back to Site">
- <?php
- $icon = (int) get_option( 'site_icon' );
- $out = '';
- if ($icon > 0) {
- $url = wp_get_attachment_image_url( $icon);
- if ($url) {
- $out = '<img src="'.$url.'">';
- }
- }
- if ($out == '') {
- $out =jvbIcon('house');
- }
- ?><?= $out ?>
- </a>
- </p>
+ <?= jvbDarkModeToggle() ?>
+ <?php
+ $function = BASE.'render_core_site_logo';
+ if (function_exists($function)) {
+ echo $function([],'');
+ } else {
+ echo render_block( [
+ 'blockName' => 'core/site-logo',
+ 'attrs' => [],
+ ]);
+ }
+ ?>
- <nav>
- <ul>
- <?= jvbNotificationMenu() ?>
- <?= jvbHelpMenu() ?>
- <li><a href="<?=wp_logout_url(get_home_url())?>" title="Logout"><?=jvbIcon('sign-out')?></a></li>
- </ul>
- </nav>
- </header>
+ <nav>
+ <ul>
+ <?= jvbNotificationMenu() ?>
+ <?= jvbHelpMenu() ?>
+ <li><a href="<?=wp_logout_url(get_home_url())?>" title="Logout"><?=jvbIcon('sign-out')?></a></li>
+ </ul>
+ </nav>
+ </header>
<main><section class="replace">
<?php
@@ -714,9 +704,9 @@
<?php
$menu = new Navigation('sidebar');
- $menuClasses = ['col', 'a-start', 'nowrap'];
+ $menuClasses = ['col', 'left', 'nowrap'];
$itemClasses = ['col'];
- $menu->addClass('col a-start')->hasToggle()->defaultMenuClasses($menuClasses);
+ $menu->addClass('col left')->hasToggle()->defaultMenuClasses($menuClasses);
$menu->defaultItemClasses($itemClasses);
$pages = $this->getUserAllowedPages()?:[];
//Dashboard
@@ -767,8 +757,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);
+ }
+
}
}
}
@@ -876,7 +869,7 @@
ob_start();
$name = ($this->user->first_name !== '') ? $this->user->first_name : $this->user->display_name;
- echo '<h1 style="text-transform:none;margin-top:2em!important;">Hey '.$name.'</h1>';
+ echo '<h1>Hey '.$name.'</h1>';
echo '<p>Welcome back!</p>';
$pages = $this->getUserAllowedPages();
@@ -1012,18 +1005,18 @@
{
?>
<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">
- <h2><?= jvbDashIcon('infinity')?>All</h2>
+ <?= jvbDashIcon('infinity')?>All
</button>
<button type="button" class="tab" data-tab="artists" role="tab" aria-selected="false">
- <h2><?= jvbDashIcon('users-three')?>Artists</h2>
+ <?= jvbDashIcon('users-three')?>Artists
</button>
<button type="button" class="tab" data-tab="terms" role="tab" aria-selected="false">
- <h2><?= jvbDashIcon('hash')?>Terms</h2>
+ <?= jvbDashIcon('hash')?>Terms
</button>
<button type="button" class="tab" data-tab="yours" role="tab" aria-selected="false">
- <h2><?= jvbDashIcon('user')?>Yours</h2>
+ <?= jvbDashIcon('user')?>Yours
</button>
</nav>
</div>
@@ -1084,7 +1077,7 @@
}
ob_start();
?>
- <nav class="tabs row start" role="tablist">
+ <nav class="tabs row left" role="tablist">
<?php
$i=1;
$content = Registrar::getRegistered('post');
@@ -1363,6 +1356,7 @@
$remove = true;
if (!is_numeric($key)) {
$registrar = Registrar::getInstance($key);
+ $membership = Site::membership();
$type = $registrar? $registrar->getType() : false;
if ($type) {
$permission = JVB()->roles()->getPermission('edit', $key);
--
Gitblit v1.10.0