Discussion:
shortcode_unautop
Dobri
2013-08-21 15:40:48 UTC
Permalink
Hey WordPress Hackers,

I was struggling with shortcode_unautop not working for a while and I looked into the function to figure out what's wrong. I've created a paste bin with the code in case you don't feel like finding the function (http://pastebin.com/VDMdXxj0). My question is: is there a reason some of the "*" repetitions also have a "+" directly following? I personally have done monsters of regular expressions and never seen the combination "[whatever]*+". Am I missing something? Also, when I checked with http://regexpal.com/, removing all the extra + signs magically made the function work *exactly* as expected. Is this a bug or do I not know regex as good as I though I do?

Also, if there's nothing buggy with the function, what would be the way to make sure something like the text in the bin below renders correctly?

http://pastebin.com/7kQwdjca

Should I just remove the shorcode_unautop filter and do my own unautop? Thanks for any help with this!

~Dobri
Chris McCoy
2013-08-21 19:09:28 UTC
Permalink
http://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/


have a look at this.
Post by Dobri
Hey WordPress Hackers,
I was struggling with shortcode_unautop not working for a while and I
looked into the function to figure out what's wrong. I've created a paste
bin with the code in case you don't feel like finding the function
(http://pastebin.com/VDMdXxj0). My question is: is there a reason some of
the "*" repetitions also have a "+" directly following? I personally have
done monsters of regular expressions and never seen the combination
"[whatever]*+". Am I missing something? Also, when I checked with
http://regexpal.com/, removing all the extra + signs magically made the
function work *exactly* as expected. Is this a bug or do I not know regex
as good as I though I do?
Also, if there's nothing buggy with the function, what would be the way
to make sure something like the text in the bin below renders correctly?
http://pastebin.com/7kQwdjca
Should I just remove the shorcode_unautop filter and do my own unautop?
Thanks for any help with this!
~Dobri
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Dobri
2013-08-21 19:25:07 UTC
Permalink
Thanks but I've seen that post already. I'm actually trying to move away from a solution that moves wpautop after short codes are rendered since I've had to implement multiple workarounds for plugins that rely on regular short code rendering. I ended up just implementing my own unautop that works for my needs. Almost like this guy's new solution linked at the top with a few tweaks. I'm still open to better alternatives. I was just interested why a built-in feature of wordpress doesn't really "work." Note:

<p>[shortcode]</p>
…some content…
<p>[/shortcode]</p>

gets unautop-ed into

[shortcode]</p>
…some content…
<p>[/shortcode]

I'd say that's broken.

~Dobri
Post by Chris McCoy
http://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/
have a look at this.
Post by Dobri
Hey WordPress Hackers,
I was struggling with shortcode_unautop not working for a while and I
looked into the function to figure out what's wrong. I've created a paste
bin with the code in case you don't feel like finding the function
(http://pastebin.com/VDMdXxj0). My question is: is there a reason some of
the "*" repetitions also have a "+" directly following? I personally have
done monsters of regular expressions and never seen the combination
"[whatever]*+". Am I missing something? Also, when I checked with
http://regexpal.com/, removing all the extra + signs magically made the
function work *exactly* as expected. Is this a bug or do I not know regex
as good as I though I do?
Also, if there's nothing buggy with the function, what would be the way
to make sure something like the text in the bin below renders correctly?
http://pastebin.com/7kQwdjca
Should I just remove the shorcode_unautop filter and do my own unautop?
Thanks for any help with this!
~Dobri
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Chris McCoy
2013-08-22 00:26:37 UTC
Permalink
did you try this?

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99 );
add_filter( 'the_content', 'shortcode_unautop', 100 );



add to the bottom of your functions.php file
Post by Dobri
Thanks but I've seen that post already. I'm actually trying to move away
from a solution that moves wpautop after short codes are rendered since
I've had to implement multiple workarounds for plugins that rely on
regular short code rendering. I ended up just implementing my own unautop
that works for my needs. Almost like this guy's new solution linked at
the top with a few tweaks. I'm still open to better alternatives. I was
just interested why a built-in feature of wordpress doesn't really
<p>[shortcode]</p>
Šsome contentŠ
<p>[/shortcode]</p>
gets unautop-ed into
[shortcode]</p>
Šsome contentŠ
<p>[/shortcode]
I'd say that's broken.
~Dobri
Post by Chris McCoy
http://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/
have a look at this.
Post by Dobri
Hey WordPress Hackers,
I was struggling with shortcode_unautop not working for a while and I
looked into the function to figure out what's wrong. I've created a paste
bin with the code in case you don't feel like finding the function
(http://pastebin.com/VDMdXxj0). My question is: is there a reason some of
the "*" repetitions also have a "+" directly following? I personally have
done monsters of regular expressions and never seen the combination
"[whatever]*+". Am I missing something? Also, when I checked with
http://regexpal.com/, removing all the extra + signs magically made the
function work *exactly* as expected. Is this a bug or do I not know regex
as good as I though I do?
Also, if there's nothing buggy with the function, what would be the way
to make sure something like the text in the bin below renders correctly?
http://pastebin.com/7kQwdjca
Should I just remove the shorcode_unautop filter and do my own unautop?
Thanks for any help with this!
~Dobri
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Dobri
2013-08-22 12:49:51 UTC
Permalink
Yes, I did about a year ago, and that's exactly what I'm trying to get away from since I have plugins that rely on short codes rendering *after* the wpautop. Maybe when I have some spare time I can try working on the shortcode_unautop and offer a patch… I don't even know how solvable this issue even is though (except on a case-to-case basis).

I just noticed though that there is a hack in core for pre-wpautop short codes:

/wp-includes/class-wp-embed.php:
19 // Hack to get the [embed] shortcode to run before wpautop()
20: add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 );

Does that then make it ok to have shortcodes before and shorcodes after wpautop? If so, shouldn't that be built into core instead of being a hack? Let's say add_shortcode('name',$runnable,'before') and add_shortcode('name',$runnable,'after') where 'after' is the default value so it's backwards compatible?

~Dobri
Post by Chris McCoy
did you try this?
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99 );
add_filter( 'the_content', 'shortcode_unautop', 100 );
add to the bottom of your functions.php file
Post by Dobri
Thanks but I've seen that post already. I'm actually trying to move away
from a solution that moves wpautop after short codes are rendered since
I've had to implement multiple workarounds for plugins that rely on
regular short code rendering. I ended up just implementing my own unautop
that works for my needs. Almost like this guy's new solution linked at
the top with a few tweaks. I'm still open to better alternatives. I was
just interested why a built-in feature of wordpress doesn't really
<p>[shortcode]</p>
Šsome contentŠ
<p>[/shortcode]</p>
gets unautop-ed into
[shortcode]</p>
Šsome contentŠ
<p>[/shortcode]
I'd say that's broken.
~Dobri
Post by Chris McCoy
http://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/
have a look at this.
Post by Dobri
Hey WordPress Hackers,
I was struggling with shortcode_unautop not working for a while and I
looked into the function to figure out what's wrong. I've created a paste
bin with the code in case you don't feel like finding the function
(http://pastebin.com/VDMdXxj0). My question is: is there a reason some of
the "*" repetitions also have a "+" directly following? I personally have
done monsters of regular expressions and never seen the combination
"[whatever]*+". Am I missing something? Also, when I checked with
http://regexpal.com/, removing all the extra + signs magically made the
function work *exactly* as expected. Is this a bug or do I not know regex
as good as I though I do?
Also, if there's nothing buggy with the function, what would be the way
to make sure something like the text in the bin below renders correctly?
http://pastebin.com/7kQwdjca
Should I just remove the shorcode_unautop filter and do my own unautop?
Thanks for any help with this!
~Dobri
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...