shortcode_unautop() in /wp-includes/formatting.php is supposed to find shortcodes in a block of text and remove wrapping paragraph tags from them.

I’ve been having issues with paragraph tags making it through this process.

Here’s the output from var_dump($pee), which I placed at the very beginning of the function, i.e., the string before being processed:

string(353) "<p>[row wrap="true"]</p>
<p>[one_half]</p>
<p>[text_block]Fusce blandit adipiscing libero, nec bibendum diam volutpat tempor.[/text_block]</p>
<p>[/one_half]</p>
<p>[one_half last="true"]</p>
<p>[text_block]Donec fermentum diam leo, ut convallis nisl tristique ut. Ut rhoncus leo vitae tempus pulvinar.[/text_block]</p>
<p>[/one_half]</p>
<p>[/row]</p>
"

All wrapped in paragraph tags, as expected.

I then put var_dump(preg_replace( $pattern, '$1', $pee )); just before the end of the function, which gives:

string(346) "[row wrap="true"]</p>
<p>[one_half]</p>
<p>[text_block]Fusce blandit adipiscing libero, nec bibendum diam volutpat tempor.[/text_block]</p>
<p>[/one_half]</p>
<p>[one_half last="true"]</p>
<p>[text_block]Donec fermentum diam leo, ut convallis nisl tristique ut. Ut rhoncus leo vitae tempus pulvinar.[/text_block]</p>
<p>[/one_half]</p>
<p>[/row]
"

All it has done is remove the opening and closing tags from the entire block, instead of each individual shortcode. I checked the value of global $shortcode_tags; and all the shortcodes in my example were in it.

Is the function broken, or am I expecting too much from it? I’m pretty sure I’m not and it is supposed to remove all the paragraph tags – but I can’t help thinking something else is going on, like unexpected space characters or something.

2 Answers
2

It seems the function is broken. The issue is in trac: https://core.trac.wordpress.org/ticket/14050

I am using this to solve the problem temporarily: https://core.trac.wordpress.org/attachment/ticket/14050/plugin.php . This code still fails some of the tests used, but it completely resolves the issue I described, so I will use it unless I find something practical that it breaks.

Leave a Reply

Your email address will not be published. Required fields are marked *