From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
inc/blocks/FAQBlock.php | 71 +++++++++++++++++++++--------------
1 files changed, 43 insertions(+), 28 deletions(-)
diff --git a/inc/blocks/FAQBlock.php b/inc/blocks/FAQBlock.php
index d16032a..c43133c 100644
--- a/inc/blocks/FAQBlock.php
+++ b/inc/blocks/FAQBlock.php
@@ -2,14 +2,21 @@
namespace JVBase\blocks;
use JVBase\managers\Cache;
+use JVBase\registrar\Registrar;
use WP_Block;
use WP_Query;
-
+if (!defined('ABSPATH')) {
+ exit;
+}
class FAQBlock {
- protected Cache $cache;
+// protected Cache $cache;
+ protected string $postType;
+ protected string $section;
+ protected string $slug;
+ protected bool $isDirectory;
public function __construct()
{
- $this->cache = Cache::for('faq_block', WEEK_IN_SECONDS)->connect('post', true)->connect('taxonomy', true);
+// $this->cache = Cache::for('faq_block', 'post', WEEK_IN_SECONDS);
add_action('init', [ $this, 'registerBlock' ]);
add_action('enqueue_block_editor_assets', [$this, 'localizeData']);
}
@@ -25,12 +32,14 @@
'render_callback' => [$this, 'render'],
]
);
-//
-// // Localize script data for the editor
-// add_action('enqueue_block_editor_assets', [$this, 'enqueue_editor_assets']);
-//
-// // Enqueue frontend scripts
-// add_action('wp_enqueue_scripts', [$this, 'enqueue_frontend_assets']);
+
+
+ $faq = array_values(Registrar::withFeature('is_faq','post'));
+ $registrar = Registrar::getInstance($faq[0]);
+ $this->section = array_map('jvbCheckBase', $registrar->registrar->taxonomies)[0];
+ $this->postType = $registrar->getBased();
+ $this->slug = $registrar->getSlug();
+ $this->isDirectory = $registrar->hasFeature('show_directory');
}
/**
@@ -70,12 +79,11 @@
public function localizeData(): void
{
// Get all sections
- $section_taxonomy = BASE . 'section';
$sections_data = $this->cache->remember(
'sections',
function() {
$sections = get_terms([
- 'taxonomy' => BASE.'section',
+ 'taxonomy' => $this->section,
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
@@ -102,8 +110,8 @@
'jvb-faq-editor-script',
'jvbFaq',
[
- 'sectionTaxonomy' => $section_taxonomy,
- 'faqPostType' => BASE . 'faq',
+ 'sectionTaxonomy' => $this->section,
+ 'faqPostType' => $this->postType,
'sections' => $sections_data,
]
);
@@ -129,10 +137,6 @@
* @param string $content Block content
* @param WP_Block $block Block instance
*/
-// Get BASE constant
- $base = defined('BASE') ? BASE : '';
- $faq_post_type = $base . 'faq';
- $section_taxonomy = $base . 'section';
// Get block attributes
$section_order = $attributes['sectionOrder'] ?? [];
@@ -140,7 +144,7 @@
$collapse_by_default = $attributes['collapseByDefault'] ?? false;
// Determine if we're on a taxonomy archive or main FAQ archive
- $is_tax_archive = is_tax($section_taxonomy);
+ $is_tax_archive = is_tax($this->section);
$current_term = null;
if ($is_tax_archive) {
@@ -150,7 +154,7 @@
} else {
// Build query args based on context
$query_args = [
- 'post_type' => $faq_post_type,
+ 'post_type' => $this->postType,
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'menu_order title',
@@ -162,10 +166,10 @@
if (!$faq_query->have_posts()) {
- echo '<div class="faq-block faq-block--empty">';
- echo '<p>' . esc_html__('No FAQs found.', 'jvb') . '</p>';
- echo '</div>';
- return;
+ return sprintf(
+ '<div class="faq-block empty"><p>%s</p></div>',
+ esc_html__('No FAQs found.', 'jvb')
+ );
}
// Organize FAQs by section
@@ -175,7 +179,7 @@
$faq_query->the_post();
$post_id = get_the_ID();
- $terms = get_the_terms($post_id, $section_taxonomy);
+ $terms = get_the_terms($post_id, $this->section);
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
@@ -251,14 +255,25 @@
if (!empty($section_order)) {
$nav = '<nav id="faq"><h2>Sections:</h2><ol>';
foreach ($section_order as $term_id) {
- $term = get_term($term_id, $section_taxonomy);
+ $term = get_term($term_id, $this->section);
if ($term && !is_wp_error($term)) {
$url = (!$is_tax_archive) ? "#{$term->slug}" : get_term_link($term);
$nav .= '<li><a href="'.$url.'">'.html_entity_decode($term->name).'</a></li>';
}
}
- $seeAll = ($is_tax_archive) ? '<p><a href="'.get_post_type_archive_link(BASE.'faq').'">'.__('See All FAQs', 'jvb').'</a></p>' : '';
- $nav .= '</ol>'.$seeAll.'</nav>';
+ $buttons = '';
+ if ($this->isDirectory) {
+ $directory = DirectoryManager::getInstance()->directories($this->slug);
+ $url = $directory['url']??'';
+ if (!empty($url)) {
+ $buttons .= '<li><a href="'.$url.'">'.__('See Alphabetical List', 'jvb').'</a></li>';
+ }
+ }
+ if (is_tax()) {
+ $buttons .= '<li><a href="'.get_home_url(null, '/faq/').'">'.__('See All FAQs', 'jvb').'</a></li>';
+ }
+ $buttons = empty($buttons) ? '' : '<ul class="buttons">'.$buttons.'</ul>';
+ $nav .= '</ol>'.$buttons.'</nav>';
}
?>
@@ -280,7 +295,7 @@
?>
<details class="faq"<?= !$collapse_by_default ? ' open' : '' ?>>
<summary><h3><b>Q</b> <?= esc_html($faq['title']) ?></h3></summary>
- <?= apply_filters('the_content', $faq['content']) ?>
+ <?= jvb_filter_content( $faq['content']) ?>
<a class="button" href="<?= $faq['url'] ?>" title="Learn More about <?=$faq['title']?>">Learn More</a>
</details>
<?php endforeach; ?>
--
Gitblit v1.10.0