From a58a2e7ca4700d3e23341fde767060a4c2c704a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 30 Aug 2026 21:04:37 +0000
Subject: [PATCH] =Minor tweaks to MenuBlock.php
---
inc/blocks/MenuBlock.php | 45 +++++++++++++++++++++++++++++++++++++++------
1 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/inc/blocks/MenuBlock.php b/inc/blocks/MenuBlock.php
index 66edde2..264e41e 100644
--- a/inc/blocks/MenuBlock.php
+++ b/inc/blocks/MenuBlock.php
@@ -32,7 +32,6 @@
public function __construct()
{
$this->cache = Cache::for('menu', 'post', WEEK_IN_SECONDS);
- $this->cache->flush();
if (Site::hasIntegration('square')) {
$this->base = '_square_';
} else if (Site::hasIntegration('helcim')) {
@@ -40,6 +39,7 @@
}
add_action('init', [ $this, 'registerBlock' ]);
add_action('save_post', [$this, 'flushCache'], 10, 2);
+ add_action('wp_footer', [$this, 'renderGallery']);
}
public function flushCache(int $postID, WP_Post $post):void
@@ -212,7 +212,7 @@
$excerpt = get_the_excerpt($ID);
$isVariable = !empty($fields['variations']??[]);
- $priceRange = $fields['price'];
+ $priceRange = jvbCurrency($fields['price']);
if ($isVariable) {
$prices = array_map('floatval', array_column($fields['variations'], 'price'));
$min = min($prices);
@@ -229,16 +229,40 @@
// jvbDump($product->get_image_id(), 'product image');
// jvbDump($product->get_gallery_image_ids(), 'Gallery images');
if ($fields['post_title'] === 'Breakfast Poutine') {
- jvbDump($ID);
- jvbDump($fields);
+// jvbDump($ID);
+// jvbDump($fields);
}
+ $gallery = '';
+ if (!empty($fields['gallery_image_ids'])) {
+ $gallery = implode(array_map(function($id) use ($fields){
+ $id = absint($id);
+ $caption = wp_get_attachment_caption($id);
+ return sprintf(
+ '<figure>%s<figcaption>%s</figcaption></figure>',
+ jvbFormatImage($id,'tiny','medium',true,'menu'),
+ empty($caption) ? $fields['post_title'] : $caption
+ );
+ }, $fields['gallery_image_ids']));
+ }
+
+ $caption = '';
+ if (!empty($fields['image_id'])) {
+ $caption = wp_get_attachment_caption((int)$fields['image_id']);
+ $caption = empty($caption) ? $fields['post_title'] : $caption;
+ }
+
+
$out = sprintf(
'<div id="%s" class="menu-item%s" data-section="%s" data-label="%s" data-id="%s">
<div class="header row x-btw">
- <h3>%s</h3>
- <p class="price">%s</p>
+ <figure>%s<figcaption>%s</figcaption></figure>
+ <div class="text row x-btw">
+ <h3>%s</h3>
+ <p class="price">%s</p>
+ </div>
</div>
+ <div class="gallery row%s">%s</div>
<div class="description">%s</div>
<div class="info col right">',
sanitize_title($fields['post_title']),
@@ -246,8 +270,12 @@
$slug,
$fields['post_title'],
$ID,
+ !empty($fields['image_id']) ? jvbFormatImage((int)$fields['image_id'],'tiny','medium',true,'menu') : '',
+ $caption,
$fields['post_title'],
$priceRange,
+ empty($gallery) ? '' : ' has',
+ $gallery,
$excerpt
);
@@ -465,4 +493,9 @@
}
echo jvbOnThisPage(array_keys($this->details));
}
+
+ public function renderGallery():void
+ {
+ jvbRenderGallery();
+ }
}
--
Gitblit v1.10.0