2

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

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.

1

I've been reading the WordPress documentation about this function and the behaviour you are having there, is the one expected to happen.

This function clean outside of the shortcode and not inside. The regex is not checking the content of the shortcode.

EDIT:

https://developer.wordpress.org/reference/functions/shortcode_unautop/

Don’t auto-p wrap shortcodes that stand alone

Ensures that shortcodes are not wrapped in <p>...</p>.

Everything is said there.

2
  • Can you elaborate a bit more on this, may bee link and quote from the documentation. Your answer is flagged as low quality, but I'm not going to recommend deletion right now. As it stand, your answer is more that a comment. Please file an edit and add the required info to your answer. Thank you :-) – Pieter Goosen Feb 15 '15 at 6:49
  • A link would be good because the inline documentation for the function simply says "Don't auto-p wrap shortcodes that stand alone. Ensures that shortcodes are not wrapped in <p>...</p>." – EpF Feb 15 '15 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.