Jake Vanderwerf
2026-05-01 48721c85ebcfa973ee81719d2467ca80e4253dc9
inc/blocks/CustomBlocks.php
@@ -3,7 +3,8 @@
use DateTime;
use DOMDocument;
use JVBase\managers\CacheManager;
use JVBase\managers\Cache;
use JVBase\managers\SEO\BreadcrumbManager;
use WP_Block;
use WP_Query;
@@ -13,12 +14,12 @@
class CustomBlocks
{
    protected CacheManager $cache;
    protected Cache $cache;
    public function __construct()
    {
        $this->cache = CacheManager::for('blocks', WEEK_IN_SECONDS);
      add_filter('render_block', [$this, 'render'], 999, 3);
        $this->cache = Cache::for('blocks', WEEK_IN_SECONDS);
      $this->cache->connect('post')->connect('taxonomy');
      add_filter('render_block', [$this, 'render'], 900, 2);
        add_action('init', [$this, 'registerBlockStyles']);
    }
@@ -64,25 +65,25 @@
        );
    }
    public function render(string $content, array $block, WP_Block $instance)
    public function render(string $content, array $block)
    {
      $blockName = $this->sanitizeBlockName($block);
        $method = 'render_'.$blockName;
      $function = BASE.$method;
      if (function_exists($function)) {
         return $function($block, $content);
//       return $this->cache->remember(
//          $block,
//          get_the_ID(),
//          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,
//          get_the_ID(),
//          function () use ($method, $block, $content) {
//             return $this->$method($block, $content);
//          }
@@ -96,14 +97,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;
    }
@@ -123,7 +127,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);
@@ -138,6 +142,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>',
@@ -156,13 +161,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'])) ?
@@ -173,7 +178,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']).'>'.
@@ -181,11 +186,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.'>';
    }
@@ -193,12 +199,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>';
@@ -214,7 +220,7 @@
     * Media Blocks
     */
    //core_audio
    protected function render_core_cover(array $block):string
    public function render_core_cover(array $block):string
    {
        // Extract block attributes
@@ -249,7 +255,7 @@
      // Build classes and styles
      unset($attrs['url']);
      $classes = $this->getClassesAndStyles($attrs, ['cover']);
      $classes = $this->getClassesAndStyles($attrs, ['cover row']);
      return '<section' . $classes . '>' .
@@ -261,14 +267,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) {
@@ -282,18 +288,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);
@@ -327,7 +335,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);
@@ -337,25 +345,25 @@
               '</h'.$level.'>';
    }
   protected function render_core_list(array $block):string
   public function render_core_list(array $block, string $content):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'];
@@ -376,7 +384,7 @@
         $citeHtml.
         '</blockquote>';
   }
   protected function render_core_pullquote(array $block): string
   public function render_core_pullquote(array $block): string
   {
      $innerHTML = $block['innerHTML'];
@@ -391,7 +399,7 @@
      if ($cite !== '') {
         $content = $this->stripTagContents('cite', $content);
      }
      $content = apply_filters('the_content', $content);
      $content = jvb_filter_content( $content);
      return '<blockquote'.$this->getClassesAndStyles($block['attrs'], ['pull']).'>'.
         $content.
@@ -408,7 +416,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 = '';
@@ -423,7 +431,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;
@@ -465,7 +473,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;
@@ -483,7 +491,7 @@
            aria-expanded="false">'.
            jvbIcon('list', ['title'=>'Toggle Menu']).
            jvbIcon('x', ['title'=>'Toggle Menu']).
            '</button>';
      '</button>';
        $class = ($toggle === '') ?
            $this->getClassesAndStyles($block['attrs'], ['mobile']) :
            $this->getClassesAndStyles($block['attrs']);
@@ -491,6 +499,7 @@
            '<nav><ul>'.jvbNotificationMenu().jvbHelpMenu().'</ul></nav>' :
            '';
      //Allows to add custom items to a menu, based on the menu name
      $helpmenu = apply_filters('jvbMenuExtraAfter', $helpmenu, get_the_title($ID));
      $main = trim(apply_filters('jvbMenuExtra', $this->innerBlocks($block), get_the_title($ID), $block));
@@ -506,17 +515,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"';
@@ -527,7 +537,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'],'/')) ?
@@ -535,9 +545,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) {
@@ -595,7 +607,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'])) ?
@@ -603,30 +615,45 @@
            'main';
        if ($content == '') {
            return do_blocks(get_the_content(get_the_ID()));
         if(is_singular()) {
            global $post;
            $block['innerBlocks'] = parse_blocks($post->post_content);
            $result = $this->innerBlocks($block);
         }else {
            $result = '';
         }
        } else {
            return $this->inside($block, $tag, $content);
            $result = $this->inside($block, $tag, $content);
        }
      return apply_filters('jvb_post_content_output', $result, $block);
    }
    //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($post->ID)) {
         $aOpen = '<a href="'.get_the_permalink($post->ID).'">';
         $aClose = '</a>';
      }
        return '<figure'.$this->getClassesAndStyles($block['attrs']).'>'.$aOpen.
               apply_filters('jvbCoreFeaturedImage', $this->image($ID), $post->post_type).
            $aClose.'</figure>';
    }
    //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 = '';
@@ -636,7 +663,7 @@
               $out .= '<li>'.$block['attrs']['prefix'].'</li>';
            }
            foreach($terms as $term) {
               $out .= '<li><a href="'.get_term_link($term).'" rel="tag">'.$term->name.'</a></li>';
               $out .= '<li><a href="'.get_term_link($term).'" rel="tag">'.html_entity_decode($term->name).'</a></li>';
            }
         if (array_key_exists('suffix', $block['attrs'])) {
            $out .= '<li>'.$block['attrs']['suffix'].'</li>';
@@ -646,7 +673,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'])) {
@@ -671,99 +698,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;
   }
@@ -774,7 +806,7 @@
    //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
    {
      $isHeaderTemplate = (
@@ -788,6 +820,7 @@
        if (($isHeaderTemplate || $isFooterTemplate)) {
         $innerContent = $content;
         $tag = $isHeaderTemplate ?: $isFooterTemplate ?: 'div';
@@ -802,15 +835,18 @@
                $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();
                $breadcrumbs = BreadcrumbManager::getInstance()->renderNavigation();
            $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 !== '') {
@@ -818,17 +854,12 @@
            }
               $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']).'>'.
            $content = $beforeHeader.'<'.$tag.$this->getClassesAndStyles($block['attrs']).'>'.
                   $themeSwitch .
               $this->inside($block, $tag, $content) .
               $this->inside($block, false, $innerContent).
//             $this->innerBlocks($block).
//             $innerContent.
                   $footerText.'</'.$tag.'>'.$afterHeader.$breadcrumbs;
        }
@@ -850,7 +881,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'];
@@ -861,7 +892,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>';
   }
@@ -896,51 +927,46 @@
    {
      $content = '';
      foreach ($block['innerBlocks'] as $b) {
         $method = 'render_'.$this->sanitizeBlockName($b);
         $function = BASE.$method;
         $content .= $before;
         if (function_exists($function)) {
            $content .= $function($b, '');
         } else if (method_exists($this, $method)) {
            $content .= $this->$method($b, '');
         } else {
            $content .= render_block($b);
         }
         $content .= $after;
         $content .= $this->render('', $b);
      }
      return $content;
    }
    public function inside(array $block, mixed $tag = false, mixed $o = false):string
    {
        if (!$o) {
            $o = trim($block['innerHTML']);
        }
        if (!$tag) {
            //check to see if there was one dynamically set first
            $tag = (array_key_exists('tagName', $block['attrs'])) ? $block['attrs']['tagName'] : '';
            $tag = ($tag == '') ? str_replace('<', '', strtok($o, '>')) : '';
            $tag = (str_contains($tag, ' class')) ? strtok($tag, ' class') : $tag;
            $tag = trim($tag);
        }
      if (!str_starts_with($o, '<'.$tag)) {
   public function inside(array $block, mixed $tag = false, mixed $o = false): string
   {
      if (!$o) {
         $o = trim($block['innerHTML']);
      }
      $dom = new \DOMDocument();
      @$dom->loadHTML('<?xml encoding="utf-8"?>' . $o, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
      // Find the real outermost element
      $root = null;
      foreach ($dom->childNodes as $node) {
         if ($node->nodeType === XML_ELEMENT_NODE) {
            $root = $node;
            break;
         }
      }
      if (!$root) {
         return $o;
      }
        $len = strlen('</'.$tag.'>');
      // Only enforce tag match if explicitly provided
      if ($tag && strtolower($root->nodeName) !== strtolower($tag)) {
         return $o;
      }
        return substr_replace(
            str_replace(
                strtok($o, '>').'>',
                ' ',
                $o
            ),
            '',
            -$len,
            $len
        );
    }
      $inner = '';
      foreach ($root->childNodes as $child) {
         $inner .= $dom->saveHTML($child);
      }
      return trim($inner);
   }
   /**
    * Extract content from a specific nested element
@@ -1139,11 +1165,9 @@
                $classes[] = $class;
            }
        }
        $classes =  array_filter($classes, function ($class) {
            return $class!=='' && !str_starts_with($class, 'wp');
        });
        return $classes;
      return array_filter($classes, function ($class) {
         return $class!=='' && !str_starts_with($class, 'wp');
      });
    }
    protected function getClass(string $key, string|bool|array|int $value, array $attrs):string|array
    {
@@ -1182,9 +1206,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';
@@ -1722,5 +1746,3 @@
    }
}
new CustomBlocks();