From 07282da9671de8fb2601e9e641decb2655439ad8 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 01 Jan 2026 23:20:54 +0000
Subject: [PATCH] =FeedRoutes.php: fixed the extractTaxonomies method
---
inc/blocks/CustomBlocks.php | 459 ++++++++++++++++++++++++--------------------------------
1 files changed, 197 insertions(+), 262 deletions(-)
diff --git a/inc/blocks/CustomBlocks.php b/inc/blocks/CustomBlocks.php
index 966276f..f83b57d 100644
--- a/inc/blocks/CustomBlocks.php
+++ b/inc/blocks/CustomBlocks.php
@@ -14,16 +14,11 @@
class CustomBlocks
{
protected CacheManager $cache;
- protected CacheManager $imgCache;
public function __construct()
{
$this->cache = CacheManager::for('blocks', WEEK_IN_SECONDS);
- $this->imgCache = CacheManager::for('images', WEEK_IN_SECONDS);
-
-
add_filter('render_block', [$this, 'render'], 999, 3);
-
add_action('init', [$this, 'registerBlockStyles']);
}
@@ -75,16 +70,16 @@
$function = BASE.$method;
if (function_exists($function)) {
+ return $function($block, $content);
// return $this->cache->remember(
// $block,
// function () use ($function, $block, $content) {
// return $function($block, $content);
// }
// );
- return $function($block, $content);
} else if (method_exists($this, $method)) {
return $this->$method($block, $content);
- //TODO: Recache it
+
// return $this->cache->remember(
// $block,
// function () use ($method, $block, $content) {
@@ -100,14 +95,17 @@
'core/site-title',
'jvb/forms'
];
- if (!in_array($block['blockName'], $ignore)) {
+// if (!in_array($block['blockName'], $ignore)) {
// jvbDump('No method found for '.print_r($block['blockName'], true));
- }
+// }
}
if ($block['blockName'] === 'jvb/feed') {
// Enqueue the feed block script (it will automatically load dependencies)
$this->localize_feedblock();
}
+ if ($block['blockName'] === 'jvb/forms') {
+ wp_enqueue_style('jvb-form');
+ }
return $content;
}
@@ -127,7 +125,7 @@
*/
- protected function render_core_button(array $block):string
+ public function render_core_button(array $block):string
{
preg_match('/href="([^"]*)"/', $block['innerHTML'], $url);
preg_match('/>([^<]*)<\/a>/', $block['innerHTML'], $label);
@@ -142,6 +140,7 @@
if (str_contains($url[1], 'maps.apple.com')) {
$icon = 'apple-logo';
}
+
if ($icon !== '') {
return sprintf(
'<li%s><a href="%s" title="Find Us On %s">%s Maps</a></li>',
@@ -160,13 +159,13 @@
);
}
- protected function render_core_buttons(array $block):string
+ public function render_core_buttons(array $block):string
{
return '<ul'.$this->getClassesAndStyles($block['attrs'], ['buttons','row']).'>'.
$this->innerBlocks($block).'</ul>';
}
- protected function render_core_column(array $block):string
+ public function render_core_column(array $block):string
{
$styles = (array_key_exists('attrs', $block) &&
array_key_exists('width', $block['attrs'])) ?
@@ -177,7 +176,7 @@
$this->innerBlocks($block).'</div>';
}
- protected function render_core_columns(array $block):string
+ public function render_core_columns(array $block):string
{
return '<section'.
$this->getClassesAndStyles($block['attrs'], ['columns']).'>'.
@@ -185,11 +184,12 @@
}
//core_comment_template
- protected function render_core_group(array $block):string
+ public function render_core_group(array $block):string
{
$tag = (array_key_exists('tagName', $block['attrs'])) ? $block['attrs']['tagName'] : 'div';
+
$classes = ($tag === 'main') ?
- $this->getClassesAndStyles($block['attrs']) :
+ '' :
$this->getClassesAndStyles($block['attrs'], ['group']);
return '<'.$tag.$classes.'>'.$this->innerBlocks($block).'</'.$tag.'>';
}
@@ -197,12 +197,12 @@
//core_more
//core_nextpage
- protected function render_core_separator(array $block):string
+ public function render_core_separator(array $block):string
{
return '<hr'.$this->getClassesAndStyles($block['attrs']).'>';
}
- protected function render_core_spacer(array $block):string
+ public function render_core_spacer(array $block):string
{
return '<div'.$this->getClassesAndStyles($block['attrs'], ['spacer'], ['height:2rem']).
' aria-hidden="true"></div>';
@@ -218,7 +218,7 @@
* Media Blocks
*/
//core_audio
- protected function render_core_cover(array $block):string
+ public function render_core_cover(array $block):string
{
// Extract block attributes
@@ -241,7 +241,7 @@
if (array_key_exists('useFeaturedImage', $attrs)) {
global $post;
$ID = get_post_thumbnail_id($post->ID);
- } else {
+ } else if (array_key_exists('id', $attrs)) {
$ID = (int)$attrs['id'];
}
@@ -253,7 +253,7 @@
// Build classes and styles
unset($attrs['url']);
- $classes = $this->getClassesAndStyles($attrs, ['cover']);
+ $classes = $this->getClassesAndStyles($attrs, ['cover row']);
return '<section' . $classes . '>' .
@@ -265,14 +265,14 @@
//core_file
- protected function render_core_gallery(array $block):string
+ public function render_core_gallery(array $block):string
{
return '<ul'.$this->getClassesAndStyles($block['attrs'], ['gallery']).'>'.
$this->innerBlocks($block,'<li>', '</li>').
'</ul>';
}
- protected function render_core_image(array $block):string
+ public function render_core_image(array $block):string
{
$ID = $this->imageID('', $block);
if (!$ID) {
@@ -286,18 +286,20 @@
wp_get_attachment_caption($ID) .
'</figcaption>' :
'<figcaption>' . $title . '</figcaption>';
-
+ $size = array_key_exists('sizeSlug', $block['attrs']) ? $block['attrs']['sizeSlug'] : 'large';
return '<figure'.
$this->getClassesAndStyles($block['attrs']).'>'.
- $this->imageLink(true, $ID) .
+ $this->imageLink(true, $ID, 'tiny', $size) .
$caption.'</figure>';
}
- protected function render_core_media_text(array $block):string
+ public function render_core_media_text(array $block):string
{
$ID = $this->imageID('', $block);
- $imgLink = ($ID) ? $this->imageLink(true, $ID) : '';
+
+ $size = array_key_exists('mediaSizeSlug', $block['attrs']) ? $block['attrs']['mediaSizeSlug'] : 'large';
+ $imgLink = ($ID) ? $this->imageLink(true, $ID, 'tiny', $size) : '';
$inner = $this->innerBlocks($block);
@@ -331,7 +333,7 @@
//render_core_details
//render_core_footnotes
//render_core_classic
- protected function render_core_heading(array $block):string
+ public function render_core_heading(array $block):string
{
$level = (array_key_exists('level', $block['attrs'])) ? $block['attrs']['level'] : '2';
$content = $this->inside($block);
@@ -341,25 +343,25 @@
'</h'.$level.'>';
}
- protected function render_core_list(array $block):string
+ public function render_core_list(array $block):string
{
$tag = (array_key_exists('ordered', $block['attrs'])) ? 'ol' : 'ul';
return '<'.$tag.$this->getClassesAndStyles($block['attrs']).'>'.$this->innerBlocks($block).'</'.$tag.'>';
}
-// protected function render_core_list_item(array $block):string
+// public function render_core_list_item(array $block):string
// {
// return '<li'.$this->getClassesAndStyles($block['attrs']).'>'.$this->inside($block).'</li>';
// }
//render_core_missing
- protected function render_core_paragraph(array $block):string
+ public function render_core_paragraph(array $block):string
{
return '<p'.$this->getClassesAndStyles($block['attrs']).'>'.
$this->inside($block, 'p').
'</p>';
}
- protected function render_core_quote(array $block): string
+ public function render_core_quote(array $block): string
{
$innerHTML = $block['innerHTML'];
@@ -380,7 +382,7 @@
$citeHtml.
'</blockquote>';
}
- protected function render_core_pullquote(array $block): string
+ public function render_core_pullquote(array $block): string
{
$innerHTML = $block['innerHTML'];
@@ -412,7 +414,7 @@
//core_loginout
//core_pattern
- protected function render_core_site_logo(array $block, string $content):string
+ public function render_core_site_logo(array $block, string $content):string
{
$open = $close = '';
@@ -427,7 +429,7 @@
}
//core_site_title_tagline
- protected function render_core_site_title(array $block, string $content):string
+ public function render_core_site_title(array $block, string $content):string
{
$tag = (array_key_exists('level', $block['attrs'])) ? $block['attrs']['level'] : 1;
$tag = ($tag == 0) ? 'p' : 'h'.$tag;
@@ -469,7 +471,7 @@
/**
* Theme Navigation Blocks
*/
- protected function render_core_navigation(array $block, string $content):string
+ public function render_core_navigation(array $block, string $content):string
{
$ID = (array_key_exists('ref', $block['attrs'])) ? $block['attrs']['ref'] : false;
@@ -510,17 +512,18 @@
'</nav>'.$helpmenu;
}
- protected function render_core_navigation_link(array $block):string
+ public function render_core_navigation_link(array $block):string
{
global $wp;
$url = (str_starts_with($block['attrs']['url'],'/')) ?
home_url($block['attrs']['url']) :
$block['attrs']['url'];
$current = (home_url($wp->request.'/') == $url);
-
+ $temp = $block['attrs'];
+ unset($temp['url']);
$classes = ($current) ?
- $this->getClassesAndStyles($block['attrs'], ['current']):
- $this->getClassesAndStyles($block['attrs']);
+ $this->getClassesAndStyles($temp, ['current']):
+ $this->getClassesAndStyles($temp);
$aria = '';
if ($current) {
$aria = ' aria-current="page"';
@@ -531,7 +534,7 @@
return '<li'.$classes.'>'.$linkOpen.$block['attrs']['label'].'</a></li>';
}
- protected function render_core_navigation_submenu(array $block):string
+ public function render_core_navigation_submenu(array $block):string
{
global $wp;
$url = (str_starts_with($block['attrs']['url'],'/')) ?
@@ -539,9 +542,11 @@
$block['attrs']['url'];
$current = (home_url($wp->request) == $url);
+ $temp = $block['attrs'];
+ unset($temp['url']);
$classes = ($current) ?
- $this->getClassesAndStyles($block['attrs'], ['has-submenu', 'current']):
- $this->getClassesAndStyles($block['attrs'], ['has-submenu']);
+ $this->getClassesAndStyles($temp, ['has-submenu', 'current']):
+ $this->getClassesAndStyles($temp, ['has-submenu']);
$aria = '';
if ($current) {
@@ -599,7 +604,7 @@
//core_post_author
//core_post_author_biography
//core_post_author_name
- protected function render_core_post_content(array $block, string $content = ''):string
+ public function render_core_post_content(array $block, string $content = ''):string
{
$tag = (array_key_exists('tagName', $block['attrs'])) ?
@@ -607,30 +612,39 @@
'main';
if ($content == '') {
- return do_blocks(get_the_content(get_the_ID()));
+ global $post;
+
+ $block['innerBlocks'] = parse_blocks($post->post_content);
+ return $this->innerBlocks($block);
} else {
return $this->inside($block, $tag, $content);
}
}
//core_post_date
- protected function render_core_post_date(array $block):string
+ public function render_core_post_date(array $block):string
{
$postDate = get_the_date('c');
return '<time datetime="'.$postDate.'" itemprop="datePublished"'.$this->getClassesAndStyles($block['attrs']).'>'.get_the_date().'</time>';
}
//core_post_excerpt
- protected function render_core_post_featured_image(array $block):string
+ public function render_core_post_featured_image(array $block):string
{
global $post;
$ID = get_post_thumbnail_id($post->ID);
- return '<figure'.$this->getClassesAndStyles($block['attrs']).'>'.
- $this->image($ID).
- '</figure>';
+ $aOpen = $aClose = '';
+ if(!is_single($ID)) {
+ $aOpen = '<a href="'.get_the_permalink($post->ID).'">';
+ $aClose = '</a>';
+ }
+
+ return $aOpen.'<figure'.$this->getClassesAndStyles($block['attrs']).'>'.
+ apply_filters('jvbCoreFeaturedImage', $this->image($ID), $post->post_type).
+ '</figure>'.$aClose;
}
//core_post_navigation_link
//core_post_template
//core_post_terms
- protected function render_core_post_terms(array $block):string
+ public function render_core_post_terms(array $block):string
{
$terms = get_the_terms(get_the_ID(), $block['attrs']['term']);
$out = '';
@@ -650,7 +664,7 @@
return $out;
}
//core_post_time_to_read
- protected function render_core_post_title(array $block):string
+ public function render_core_post_title(array $block):string
{
$open = $close = '';
if (array_key_exists('isLink', $block['attrs'])) {
@@ -675,99 +689,104 @@
'</h'.$level.'>';
}
- protected function render_core_query(array $block, string $content):string
+ public function render_core_query(array $block, string $content):string
{
-// jvbDump($block);
-// $queryID = $block['attrs']['queryId'];
-// $args = [];
-// $inherit = $block['attrs']['inherit']??false;
-// if ($inherit) {
-// global $wp_query;
-// $loop = $wp_query;
-// } else {
-// foreach ($block['attrs']['query'] as $key => $value) {
-// if (empty($value)) {
-// continue;
-// }
-// switch ($key) {
-// case 'postType':
-// $args['post_type'] = $value;
-// break;
-// case 'perPage':
-// $args['posts_per_page'] = $value;
-// break;
-// case 'orderBy':
-// $args['orderby'] = $value;
-// break;
-// case 'taxQuery':
-// $taxQuery = [];
-// foreach ($value as $tax => $terms) {
-// $taxQuery[] = [
-// 'taxonomy' => $tax,
-// 'terms' => $terms
-// ];
-// }
-// if (!empty($taxQuery)) {
-// $args['tax_query'] = $taxQuery;
-// if (count($taxQuery) > 1) {
-// $args['tax_query']['relation'] = 'OR';
-// }
-// }
-// break;
-// case 'sticky':
-// if ($value === 'ignore') {
-// $args['ignore_sticky_posts'] = true;
-// } else if ($value === 'exclude'){
-// $args['post__not_in'] = get_option('sticky_posts');
-// } else if ($value === 'only') {
-// $args['include'] = get_option('sticky_posts');
-// }
-// break;
-// case 'search':
-// $args['s'] = $value;
-// break;
-// default:
-// $args[$key] = $value;
-// break;
-//
-// }
-// }
-// //Add in any args from the query string
-// $search = 'query-'.$queryID;
-// foreach ($_GET as $key => $value) {
-// if (str_contains($key, $search)) {
-// $key = str_replace($search, '', $key);
-// if ($key === 'page') {
-// $args['paged'] = (int)$value;
-// }
-// }
-// }
-// $loop = new WP_Query($args);
-// }
+ $queryID = $block['attrs']['queryId'];
+ $args = [];
+ $inherit = $block['attrs']['inherit']??false;
+ if ($inherit) {
+ global $wp_query;
+ $loop = $wp_query;
+ } else {
+ foreach ($block['attrs']['query'] as $key => $value) {
+ if (empty($value)) {
+ continue;
+ }
+ switch ($key) {
+ case 'postType':
+ if ($value === BASE.'progress'){
+ $args['post_parent'] = 0;
+ }
+ $args['post_type'] = $value;
+ break;
+ case 'perPage':
+ $args['posts_per_page'] = $value;
+ break;
+ case 'orderBy':
+ $args['orderby'] = $value;
+ break;
+ case 'taxQuery':
+ $taxQuery = [];
+ foreach ($value as $tax => $terms) {
+ $taxQuery[] = [
+ 'taxonomy' => $tax,
+ 'terms' => $terms
+ ];
+ }
+ if (!empty($taxQuery)) {
+ $args['tax_query'] = $taxQuery;
+ if (count($taxQuery) > 1) {
+ $args['tax_query']['relation'] = 'OR';
+ }
+ }
+ break;
+ case 'sticky':
+ if ($value === 'ignore') {
+ $args['ignore_sticky_posts'] = true;
+ } else if ($value === 'exclude'){
+ $args['post__not_in'] = get_option('sticky_posts');
+ } else if ($value === 'only') {
+ $args['include'] = get_option('sticky_posts');
+ }
+ break;
+ case 'search':
+ $args['s'] = $value;
+ break;
+ default:
+ $args[$key] = $value;
+ break;
-// $inner = $this->innerBlocks($block);
-// foreach ($block['innerBlocks'] as $innerBlock) {
-// switch ($innerBlock['blockName']) {
-// case 'core/post-template':
-// $inner .= '<ul class="item-grid">';
-// if ($loop->have_posts()) {
-// while($loop->have_posts()) {
-// $loop->the_post();
-// $inner .= $this->doBlocks
-// }
-// }
-// $inner .= '</ul>';
-// break;
-// }
-// }
+ }
+ }
+ //Add in any args from the query string
+ $search = 'query-'.$queryID;
+ foreach ($_GET as $key => $value) {
+ if (str_contains($key, $search)) {
+ $key = str_replace($search, '', $key);
+ if ($key === 'page') {
+ $args['paged'] = (int)$value;
+ }
+ }
+ }
+ $loop = new WP_Query($args);
+ }
+
+ $inner = '';
+
+ foreach ($block['innerBlocks'] as $innerBlock) {
+ switch ($innerBlock['blockName']) {
+ case 'core/post-template':
+ $inner .= '<section class="item-grid">';
+ if ($loop->have_posts()) {
+ while($loop->have_posts()) {
+ $loop->the_post();
+ $postType = get_post_type();
+ $inner .= '<div class="item '.jvbNoBase($postType).'">'.$this->innerBlocks($innerBlock).'</div>';
+ }
+ }
+ $inner .= '</section>';
+ break;
+
+ }
+ }
$tagName = (array_key_exists('tagName', $block['attrs'])) ? $block['attrs']['tagName'] : 'div';
- $out = '<'.$tagName.' class="loop">'.$this->innerBlocks($block).'</'.$tagName.'>';
-// if ($inherit) {
-// wp_reset_postdata();
-// }
+ $out = '<'.$tagName.' class="loop">'.$inner.'</'.$tagName.'>';
+ if ($inherit) {
+ wp_reset_postdata();
+ }
return $out;
}
@@ -778,10 +797,9 @@
//core_query_pagination_previous
//core_query_title
//core_read_more
- protected function render_core_template_part(array $block, string $content):string
+ public function render_core_template_part(array $block, string $content):string
{
- $check = ['header', 'footer'];
$isHeaderTemplate = (
(array_key_exists('slug', $block['attrs']) && str_contains(strtolower($block['attrs']['slug']), 'header')) ||
(array_key_exists('tagName', $block['attrs']) && str_contains(strtolower($block['attrs']['tagName']), 'header'))
@@ -792,7 +810,8 @@
) ? 'footer' : false;
- if ($isHeaderTemplate || $isFooterTemplate) {
+ if (($isHeaderTemplate || $isFooterTemplate)) {
+
$tag = $isHeaderTemplate ?: $isFooterTemplate ?: 'div';
$breadcrumbs = $themeSwitch = $afterHeader = $beforeHeader = $footerText= '';
@@ -806,27 +825,39 @@
$title = ($checked == '') ? 'Toggle Dark Mode' : 'Toggle Light Mode';
$showThemeSwitch = (bool)apply_filters('jvb_show_theme_switch', true);
$themeSwitch = ($showThemeSwitch) ? '<label title="'.$title.'" id="theme-switch" class="toggle-switch" for="theme-switcher">
- <input class="theme-switch row" id="theme-switcher" type="checkbox"'.$checked.' data-setting="theme" data-theme role="switch" name="dark-mode"><span class="slider">'.
+ <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>' : '';
$breadcrumbs = jvbBuildBreadcrumbs();
$afterHeader = apply_filters('jvbBelowHeader', $afterHeader);
+
if ($afterHeader !== '') {
$afterHeader = '<aside class="sub-header">'.$afterHeader.'</aside>';
}
+ $footerText = '<div class="scroll-progress"><div class="bar"></div>
+</div>';
} elseif ($isFooterTemplate) {
$beforeHeader = apply_filters('jvbBeforeFooter', '');
if ($beforeHeader !== '') {
$beforeHeader = '<section class="pre-footer">'.$beforeHeader.'</section>';
}
$footerText = jvbRandomFooterText();
- }
+ }
+// jvbDump($beforeHeader,'beforeHeader');
+// jvbDump('<'.$tag.$this->getClassesAndStyles($block['attrs']).'>','tag');
+// jvbDump($themeSwitch,'themeSwitch');
+// jvbDump($this->inside($block, $tag, $content),'inside');
+// jvbDump($footerText,'footerText');
+// jvbDump($afterHeader, 'afterheader');
+// jvbDump($breadcrumbs, 'breadcrumbs');
+
return $beforeHeader.'<'.$tag.$this->getClassesAndStyles($block['attrs']).'>'.
$themeSwitch .
- $this->inside($block, $tag, $content).
+ $this->inside($block, $tag, $content) .
$footerText.'</'.$tag.'>'.$afterHeader.$breadcrumbs;
}
+
return $content;
}
//core_term_description
@@ -845,7 +876,7 @@
//core_rss
//core_search
//core_shortcode
- protected function render_core_social_link(array $block, string $content):string
+ public function render_core_social_link(array $block, string $content):string
{
$url = $block['attrs']['url'];
$service = $block['attrs']['service'];
@@ -856,7 +887,7 @@
}
return '<li><a href="'.$url.'" target="_blank" rel="nofollow" title="Find us on '.ucfirst($service).'">'.$icon.'<span class="screen-reader-text">Find us on '.ucfirst($service).'</span></a></li>';
}
- protected function render_core_social_links(array $block, string $content):string
+ public function render_core_social_links(array $block, string $content):string
{
return '<ul class="socials">'.$this->innerBlocks($block).'</ul>';
}
@@ -870,8 +901,6 @@
protected function localize_feedblock():void
{
wp_localize_script('jvb-feed-view-script', 'feedSettings', [
- 'apiUrl' => rest_url('jvb/v1/'),
- 'nonce' => wp_create_nonce('wp_rest'),
'currentUser' => is_user_logged_in() ? [
'id' => get_current_user_id()
] : null,
@@ -921,7 +950,9 @@
$tag = (str_contains($tag, ' class')) ? strtok($tag, ' class') : $tag;
$tag = trim($tag);
}
-
+ if (!str_starts_with($o, '<'.$tag)) {
+ return $o;
+ }
$len = strlen('</'.$tag.'>');
@@ -988,30 +1019,16 @@
int $ID = 0,
string $start = 'tiny',
string $replace = 'large',
- string $postSlug = ''
+ ?string $postSlug = null
):string {
- $image = $this->image($ID, $start, $replace);
- if ($ID === 0) {
- $ID = $this->imageID($ID);
- }
- if ($postSlug==='') {
- global $post;
- $postSlug = $post->post_name;
- }
- if (!$ID) {
- return '';
- }
- $img = get_post($ID);
- if (!$img) {
- return '';
- }
- $imgSlug = $img->post_name;
- $img = '<a class="open-gallery" target="_blank" rel="nofollow" data-opens="gallery-'.$postSlug.'" data-focus="'.$postSlug.'-'.$imgSlug.'">'.$image;
+ $image = jvbFormatImage($ID, $start, $replace, true, $postSlug);
+
if ($close) {
- $img .= '</a>';
+ return $image;
}
- return $img;
+ $len = strlen('</a>');
+ return substr_replace($image, '', -$len, $len);
}
public function image(string $ID = '', string $start = 'tiny', string $replace = 'large'):string
{
@@ -1023,41 +1040,7 @@
if ($ID === 0 || $ID === false) {
return '';
}
-
- $img = wp_get_attachment_image_src($ID, $start);
- if (!$img) return '';
- $img = $img[0];
-
- $data = $this->gallerySizes($ID, $replace);
-
- $alt = get_post_meta($ID, '_wp_attachment_image_alt', true);
- $alt = ($alt=='')? '' : ' alt="'.$alt.'" ';
-
- return '<img width="100%" height="auto" src="' .
- $img . '"' .$alt . $data . ' loading="lazy" decoding="async">';
- }
- public function gallerySizes(int $ID, string $replace = 'medium'):string
- {
- if (!wp_get_attachment_image_src($ID)) {
- return '';
- }
- if ($replace == 'large') {
- return 'data-small="'.
- wp_get_attachment_image_src($ID, 'large')[0].'" data-medium="'.
- wp_get_attachment_image_src($ID, 'full')[0].'" data-full="'.
- wp_get_attachment_image_src($ID, 'full')[0].'"';
- } elseif ($replace == 'medium') {
- return 'data-small="'.
- wp_get_attachment_image_src($ID, 'large')[0].'" data-medium="'.
- wp_get_attachment_image_src($ID, 'large')[0].'" data-full="'.
- wp_get_attachment_image_src($ID, 'large')[0].'"';
- } elseif ($replace == 'thumbnail') {
- return 'data-small="'.
- wp_get_attachment_image_src($ID, 'medium')[0].'" data-medium="'.
- wp_get_attachment_image_src($ID, 'medium')[0].'" data-full="'.
- wp_get_attachment_image_src($ID, 'medium')[0].'"';
- }
- return '';
+ return jvbFormatImage($ID, $start, $replace, false);
}
public function sanitizeBlockName(array $block):string
{
@@ -1225,9 +1208,9 @@
$type = 'row';
if (array_key_exists('type', $value)) {
$type = 'col';
- if ($value['type'] === 'constrained') {
- $classes[] = 'container col';
- }
+// if ($value['type'] === 'constrained') {
+// $classes[] = 'container col';
+// }
}
if (array_key_exists('orientation', $value)) {
$type = 'col';
@@ -1753,63 +1736,15 @@
return $styles;
}
- public function getGallerySizes(int $ID, string $replace):string
- {
- if (!wp_get_attachment_image_src($ID)) {
- return '';
- }
- if (!has_image_size($replace)) {
- $replace = 'large';
- }
-
- if ($replace == 'large') {
- return 'data-small="' .
- wp_get_attachment_image_src($ID)[0] . '" data-medium="' .
- wp_get_attachment_image_src($ID, 'large')[0] . '" data-full="' .
- wp_get_attachment_image_src($ID, 'full')[0] . '"';
- } elseif ($replace == 'medium') {
- return 'data-small="'.
- wp_get_attachment_image_src($ID, 'large')[0].'" data-medium="'.
- wp_get_attachment_image_src($ID, 'large')[0].'" data-full="'.
- wp_get_attachment_image_src($ID, 'large')[0].'"';
- } elseif ($replace == 'thumbnail') {
- return 'data-small="'.
- wp_get_attachment_image_src($ID, 'medium')[0].'" data-medium="'.
- wp_get_attachment_image_src($ID, 'medium')[0].'" data-full="'.
- wp_get_attachment_image_src($ID, 'medium')[0].'"';
- }
- return '';
- }
-
public function formatImage(int $ID = 0, string $start = 'tiny', string $replace = 'large'):string
{
- if ($ID === 0) {
- $ID = $this->imageID($ID);
- }
- if ($ID === 0) {
- return '';
- }
-
- return $this->imgCache->remember(
- ['ID' => $ID, 'start' => $start, 'replace' => $replace],
- function() use ($ID, $start, $replace) {
- $img = wp_get_attachment_image_src($ID, $start);
- if (!$img) {
- return'';
- }
- $img = $img[0];
-
- $data = $this->getGallerySizes($ID, $replace);
-
-
-
- $alt = get_post_meta($ID, '_wp_attachment_image_alt', true);
- $alt = ($alt=='')? '' : ' alt="'.$alt.'" ';
- return '<img width="300px" height="300px" src="'.$img.'"'.$alt.$data.' loading="lazy" decoding="async">';
- }
- );
+ if ($ID === 0) {
+ $ID = $this->imageID($ID);
+ }
+ if ($ID === 0) {
+ return '';
+ }
+ return jvbFormatImage($ID, $start, $replace);
}
}
-
-new CustomBlocks();
--
Gitblit v1.10.0