From f859e64a57c624ff2daa2b21355f65a49fd4807d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 29 Aug 2026 03:09:12 +0000
Subject: [PATCH] =Some more tweaks. Mostly on the MenuBlock and adding the Meta.php to WooCommerce Products
---
inc/managers/DirectoryManager.php | 69 +++++++++++++++++++++-------------
1 files changed, 42 insertions(+), 27 deletions(-)
diff --git a/inc/managers/DirectoryManager.php b/inc/managers/DirectoryManager.php
index 1d5c15a..4f46e0f 100644
--- a/inc/managers/DirectoryManager.php
+++ b/inc/managers/DirectoryManager.php
@@ -5,6 +5,8 @@
exit;
}
+use JVBase\Instance;
+use JVBase\integrations\services\Umami;
use JVBase\registrar\Registrar;
use JVBase\base\Site;
use WP_Block;
@@ -12,6 +14,7 @@
class DirectoryManager
{
+ use Instance;
protected array $directories;
protected array $directoryPageIDs;
protected array $directoryList;
@@ -20,7 +23,7 @@
protected static string $slug = BASE.'for_type_slug';
protected Cache $cache;
- public function __construct($perPage = 100)
+ private function __construct($perPage = 100)
{
$this->directories = $this->getDirectories();
if (empty($this->directories)) {
@@ -28,19 +31,22 @@
}
$this->perPage = $perPage;
$this->cache = Cache::for('directory', WEEK_IN_SECONDS);
- $this->cache->connect('post', true)
- ->connect('taxonomy', true)
- ->connect('user', true);
- if (JVB_TESTING) {
- $this->cache->flush();
- }
+
jvb_register_do_once('buildDirectories', [$this, 'activate']);
add_action('init', [$this, 'registerDirectories']);
- add_filter('render_block', [$this, 'renderBlock'], 998, 3);
+ add_filter('pre_render_block', [$this, 'renderBlock'], 20, 3);
+ add_action('save_post', [$this, 'flushCache']);
+ add_action('edit_terms', [$this, 'flushCache']);
}
+ public function flushPostCache(int $postID):void
+ {
+ //TODO: We can probably use a bit more finesse here.
+ $this->cache->flush();
+ }
+
public function registerDirectories():void
{
@@ -85,25 +91,26 @@
public function getDirectories():array
{
$directories = get_option(BASE.'directories');
+
if (!$directories) {
$directories = [];
//content
- $content = Registrar::getFeatured('show_directory', 'post');
+ $content = Registrar::withFeature('show_directory', 'post');
if(!empty($content)) {
foreach ($content as $key) {
$directories[$key] = 'content';
}
}
- $taxonomies = Registrar::getFeatured('show_directory', 'term');
+ $taxonomies = Registrar::withFeature('show_directory', 'term');
if(!empty($taxonomies)) {
foreach ($taxonomies as $key) {
$directories[$key] = 'taxonomy';
}
}
- $users = Registrar::getFeatured('show_directory', 'user');
+ $users = Registrar::withFeature('show_directory', 'user');
if(!empty($users)) {
foreach ($users as $key) {
$directories[$key] = 'user';
@@ -134,7 +141,7 @@
$title = $config['title'];
//Bail early if we've already created the page
$existing = new WP_Query([
- 'post_type' => BASE.'dash',
+ 'post_type' => BASE.'directory',
'name' => sanitize_title($title),
'posts_per_page' => 1,
]);
@@ -228,7 +235,6 @@
// ];
// }
// }
-
if (!empty($created)) {
update_option(BASE.'directory_ids', $created);
}
@@ -240,6 +246,7 @@
protected function buildDirectoryList():array
{
$saved = get_option(BASE.'directory_list', []);
+
if (empty($saved)) {
$all = new WP_Query([
'post_type' => BASE.'directory',
@@ -324,7 +331,7 @@
string $name = '',
string $url = '',
string $ID = '',
- $extra = false
+ ?array $extra = null
):array {
if ($name == '') {
$name = get_the_title();
@@ -373,7 +380,7 @@
$config = Registrar::getInstance($slug);
$aOpen = '<a href="'.$directory['url'].'" title="See our list of '.$directory['title'].'">';
$aClose = '</a>';
- $cache .= '<li class="directory col start">
+ $cache .= '<li class="directory col left">
'. $aOpen.jvbIcon($config->getIcon() !== '' ? $config->getIcon() :'list-dashes').$directory['title'].$aClose;
if (!empty($directory['description'])) {
$cache .= '<div class="description">';
@@ -412,7 +419,7 @@
);
if ($current !== '' && array_key_exists($current, $this->directories())) {
$open = ($open) ? ' open' : '';
- $cache = '<details'.$open.'><summary class="row btw">Other '.$this->referAs(true).':</summary>'.
+ $cache = '<details'.$open.'><summary class="row x-btw">Other '.$this->referAs(true).':</summary>'.
str_replace('id="'.$current.'"', 'id="'.$current.'" class="current"', $cache)
.'</details>';
}
@@ -437,12 +444,20 @@
return $this->cache->remember(
$cacheKey,
function() use ($slug, $type, $registrar, $config, $paged) {
- $out = '<h1>' . $this->directoryTitle($registrar) . '</h1>';
+
+ $out = '<h1>' . $config['title'] . '</h1>';
$out .= '<div class="description">';
foreach ($config['description'] ?? [] as $p) {
$out .= '<p>' . $p . '</p>';
}
$out .= '</div>';
+ $link = match($registrar->getType()) {
+ 'post' => get_post_type_archive_link($registrar->getBased()),
+ 'term' => false,
+ 'user' => get_post_type_archive_link($registrar->getProfile()->getBased()),
+ default => false,
+ };
+ $out .= $link ? '<ul class="buttons"><li><a href="'.$link.'">See All</a></li></ul>' : '';
$out .= $this->renderIndex($slug);
$list = [];
@@ -465,7 +480,7 @@
$get = new WP_Query($args);
- $hasExtra = $registrar->hasFeature('directory_extra');
+ $hasExtra = !empty($config['directory_extra']??[]);
if ($get->have_posts()) {
while ( $get->have_posts() ) {
$get->the_post();
@@ -613,7 +628,7 @@
$children =$this->renderListChunk($taxonomy, $term->term_id);
$out .= '<li>';
if ($children !== '') {
- $out .= '<details class="term"><summary class="row btw"><a href="'.get_term_link($term->term_id, $term->taxonomy).'" title="See more '.html_entity_decode($term->name).'">'.$term->name.'</a></summary>';
+ $out .= '<details class="term"><summary class="row x-btw"><a href="'.get_term_link($term->term_id, $term->taxonomy).'" title="See more '.html_entity_decode($term->name).'">'.$term->name.'</a></summary>';
$out .= $children;
$out .= '</details>';
} else {
@@ -664,26 +679,27 @@
public function renderLettersList(array $list, string $type):string
{
- $umami = JVB()->connect('umami');
+ $umami = Umami::getInstance();
$out = '<ul class="list-none">';
foreach ($list as $letter => $items) {
- $out .= '<li id="starts-with-'.$letter.'" class="row a-start btw nowrap"><h3>'.strtoupper($letter).'</h3><ul>';
+ $out .= '<li id="starts-with-'.$letter.'" class="row top x-btw nowrap"><h3>'.strtoupper($letter).'</h3><ul>';
foreach ($items as $item) {
$extra = '';
if (!empty($item['extra'])) {
- $extra = '<span>';
+ $extra = '<ul class="term-list row">';
foreach ($item['extra'] as $ext) {
+ $icon = Registrar::getInstance($ext['type'])->getIcon();
$umamiType = ($ext['type'] === BASE.'shop') ? 'click_shop' : 'click_taxonomy';
- $extra .= '<a href="'.$ext['url'].'"'.$umami->trackContentClick($item['id'],$umamiType, ['source_type' => 'directory']).'>'.$ext['name'].'</a>';
+ $extra .= '<li><a href="'.$ext['url'].'"'.$umami->trackContentClick($item['id'],$umamiType, ['source_type' => 'directory']).'>'.jvbIcon($icon).$ext['name'].'</a></li>';
}
- $extra .= '</span>';
+ $extra .= '</ul>';
}
$item_html = apply_filters('jvb_directory_render_item', '', $item, $type, $extra);
if (empty($item_html)) {
- $item_html = '<li class="row btw">
+ $item_html = '<li class="row x-btw">
<a href="'.$item['url'].'" title="More about '.$item['name'].'">
'.$item['name'].'</a>'.$extra.'
</li>';
@@ -697,7 +713,7 @@
return $out;
}
- public function renderBlock(string $content, array $block, WP_Block $instance)
+ public function renderBlock(?string $content, array $block, ?WP_Block $instance)
{
if (!is_post_type_archive(BASE.'directory') && !is_singular(BASE.'directory')) {
return $content;
@@ -706,7 +722,6 @@
return $content;
}
- error_log('Still working on directory manager...');
// For archive page
if (is_post_type_archive(BASE.'directory') && $block['blockName'] === 'core/group') {
return ($block['attrs']['tagName']??'' === 'main') ? '<main>'.$this->renderArchive().'</main>' : $content;
--
Gitblit v1.10.0