From d7e7d248cbe41cd7a9ef9c2fb022b6c4831f99a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 31 May 2026 15:22:56 +0000
Subject: [PATCH] =jakevan complete
---
inc/utility/Image.php | 48 +++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/inc/utility/Image.php b/inc/utility/Image.php
index df5c2f3..6c7f41d 100644
--- a/inc/utility/Image.php
+++ b/inc/utility/Image.php
@@ -21,6 +21,7 @@
$this->imgData = Cache::for('imageData')->connect('post');
if (JVB_TESTING) {
$this->cache->flush();
+ $this->imgData->flush();
}
}
@@ -72,8 +73,17 @@
if ($addLink) {
if (!$postSlug) {
- global $post;
- $postSlug = $post->post_name;
+ if (is_singular()) {
+ global $post;
+ $postSlug = $post->post_name;
+ }else if (is_tax()) {
+ $tax = get_queried_object();
+ $postSlug = jvbNoBase($tax->taxonomy);
+ }elseif (is_post_type_archive()) {
+ $obj = get_queried_object();
+ $postSlug = jvbNoBase($obj->post_type);
+ }
+
}
$full = wp_get_attachment_image_src($ID, 'full');
@@ -86,7 +96,7 @@
$postSlug,
$postSlug,
$imgSlug,
- $full[0]
+ $full[0]??''
);
// Add gallery attributes to img tag
@@ -144,4 +154,36 @@
}
);
}
+
+ public static function getData(int $imgID):array
+ {
+ return (new Image)->getImageData($imgID);
+ }
+
+ public static function gallery(string $ids, ?string $type = null):string
+ {
+ $ids = explode(',', $ids);
+ $inner = implode('', array_map(function ($ID) {
+ $caption = wp_get_attachment_caption($ID);
+ if (!empty($caption)) {
+ $caption = sprintf('<figcaption>%s</figcaption', $caption);
+ }
+ return sprintf(
+ '<li><figure>%s%s</figure></li>',
+ self::image($ID),
+ $caption
+ );
+ }, $ids));
+ return sprintf(
+ '<ul class="gallery%s">%s</ul>',
+ $type? ' '.$type : '',
+ $inner
+ );
+ }
+
+ public static function image(int $id, string $start = 'tiny', string $replace = 'large', bool $addLink = true, ?string $postSlug = null):string
+ {
+ return (new Image)->formatImage($id, $start, $replace, $addLink, $postSlug);
+ }
+
}
--
Gitblit v1.10.0