Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Outerbridge

    (@outerbridge)

    We’re not aware of a way of getting the number of nested layers that you have. For reference, our plugin implements the “do_shortcode” functionality as per this part of the codex:

    https://codex.www.ads-software.com/Shortcode_API#Nested_Shortcodes

    Please let us know if you find a way to get the max-depth info!

    Cheers,

    ^Mike

    Thread Starter Amit Kvint

    (@webifish)

    Hi Mike,

    Thanks.

    I did not find the way but I am on it, I think the best approach is to try end get the regex and then try to put it into a recursive PHP function, something along these lines –

    <?php
    function do_shortcode($content) {
        global $shortcode_tags;
    
        if (empty($shortcode_tags) || !is_array($shortcode_tags))
            return $content;
    
        $pattern = get_shortcode_regex();
        return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
    }
        $elements = parse($pattern);
    
        if (count($elements) > 0) {
            echo "Elements found: <b>".count($elements)."</b><br />";
    
            foreach ($elements as $element) {
                echo "<p>Tpl node: <pre>".htmlentities($element->node)."</pre>
                Tagname: <tt>".$element->tagname."</tt><br />
                Attributes: <tt>".$element->attributes."</tt><br />
                Omittag: <tt>".($element->omittag ? 'true' : 'false')."</tt><br />
                Inner HTML: <pre>".htmlentities($element->inner_html)."</pre></p>";
            }
        }
    ?>

    I’d most appreciate your remarks,
    Cheers,
    Amit

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get max depth of nested shortcodes’ is closed to new replies.