You appear to be a bot. Output may be restricted
Description
Improve wpautop and shortcode_unautop processingThe purpose of this function is to defer wpautop filter processing until AFTER shortcodes are expanded By default the wpautop() filter is called at priority 10 and shortcode_unautop() is also called at priority 10 (see wp-include/default-filters.php ) do_shortcode() is called at priority 11 ( see wp-includes/shortcodes.php ) In certain circumstances wpautop() can really mess up the HTML that's generated by shortcodes such as [bw_css] since it will convert new line characters to <br /> tags I applied the suggestion from link http://stackoverflow.com/questions/5940854/disable-automatic-formatting-inside-wordpress-shortcodes but that caused WooCommerce's [add_to_cart] shortcode to fail since it created new line characters during the expansion which were then converted to unwanted paragraph end and start tags. I tried moving shortcode_unautop as well but that didn't help. A pragmatic solution for [add_to_cart] was to alter the WooCommerce code so that it doesn't create unnecessary new lines. That worked BUT the wpautop() processing still had problems with textarea tags with embedded new line characters. So the latest solution ( 2013/09/03) is to disable both wpautop() and shortcode_unautop(). and replace wpautop() by bw_wpautop() where newlines are NOT converted to breaks, performed AFTER shortcode expansion.
- /03/26 – And that still doesn't work when block tags (e.g div) are embedded within non-block tags ( e.g. a )
- /07/03 – Nor does it work when they are embedded within h3 tags!
- /08/26 – To allow DIY-oik shortcodes to work nicely the latest solution is that we initially disable wpautop processing and allow it to be re-introduced by using the [bw_autop] shortcode.
- $autop
- ( bool ) optional – true if you want the bw_wpautop() filter to be run after shortcode expansion false if you want it to be removed again.
Usage
bw_better_autop( $autop );
Parameters
Returns
voidSource
File name: oik-css/oik-css.phpLines:
function bw_better_autop( $autop=false ) { remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_content', 'shortcode_unautop' ); remove_filter( 'the_content', 'wptexturize' ); remove_filter( 'the_content', 'gutenberg_wpautop', 8 ); //remove_filter( 'the_content', 'do_blocks', 9 ); if ( !function_exists( "do_shortcode_earlier" ) ) { oik_require( "includes/shortcodes-earlier.php", "oik-css" ); } oik_require( "includes/oik-filters.inc" ); bw_replace_filter( "the_content", "do_shortcode", 11, "do_shortcode_earlier" ); //add_filter( 'the_content', 'bw_tracef', 99 ); if ( $autop ) { add_filter( 'the_content', 'bw_wpautop', 99); } else { remove_filter( 'the_content', 'bw_wpautop', 99 ); } //add_filter( 'the_content', 'bw_tracef', 100 ); //add_filter( 'the_content', 'shortcode_unautop',100 ); add_filter( 'no_texturize_shortcodes', "bw_no_texturize_shortcodes" ); //add_filter( 'the_content', "bw_pre_texturize" ); /** * Filter whether to skip running wptexturize(). * * Passing false to the filter will effectively short-circuit wptexturize(). * returning the original text passed to the function instead. * * The filter runs only once, the first time wptexturize() is called. * * @since 4.0.0 * * @see wptexturize() * * @param bool $run_texturize Whether to short-circuit wptexturize(). */ $run_texturize = true; $run_texturize = apply_filters( 'run_wptexturize', $run_texturize ); if ( $run_texturize ) { if ( !function_exists( "wptexturize_blocks" ) ) { oik_require( "includes/formatting-later.php", "oik-css" ); } add_filter( 'the_content', "wptexturize_blocks", 98 ); //add_filter( 'option_blogname', 'oik_css_pesky_shortcodes'); //add_filter( 'oembed_response_data') } }View on GitHub View on Trac