{"id":18900115,"date":"2026-05-05T23:30:15","date_gmt":"2026-05-05T23:30:15","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/shortcode-recursion-bug\/"},"modified":"2026-05-05T23:30:55","modified_gmt":"2026-05-05T23:30:55","slug":"shortcode-recursion-bug","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/shortcode-recursion-bug\/","title":{"rendered":"Shortcode Recursion Bug"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hey!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just a friendly developer reviewing the code here \ud83d\ude42<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I think I found a recursion issue (I&#8217;ll be honest, I haven&#8217;t installed it just yet). It looks like you have some code in place to prevent the same shortcode from running, but I don&#8217;t see anything in place for preventing multi-step recursion. Also, I think the code that&#8217;s there would fail to save it after rendering a different sub-shortcode.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">More specifically, here&#8217;s the code I&#8217;m seeing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        \/\/ Prevent same shortcode nested loop<br \/>        if( self::$current_shortcode == $shortcode&#091; 'name' ] ){<br \/>            return '';<br \/>        }<br \/>        self::$current_shortcode = $shortcode&#091; 'name' ];<br \/><br \/>...<br \/><br \/>        self::$current_shortcode = false;<br \/><br \/>        return $sc_content;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You probably actually want to make <code>self::$current_shortcode<\/code> an array that you push to\/pop from, and then do an <code>in_array()<\/code> check, rather than using a single value. Otherwise, if shortcode A contains B, and shortcode B contains A, this wouldn&#8217;t catch the recursion. The <code>= false<\/code> here also fails to restore the previous value. So, if shortcode A contains shortcode B followed by shortcode A, <code>self::$current_shortcode<\/code> is <code>false<\/code> by the time the nested A is reached.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for your work though! I&#8217;ll probably install this soon! (Albeit, I&#8217;ll just be careful with recursive shortcodes \ud83d\ude09 )<\/p>\n","protected":false},"template":"","class_list":["post-18900115","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18900115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18900115\/revisions"}],"predecessor-version":[{"id":18900117,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18900115\/revisions\/18900117"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18900115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}