• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

[oik] plugins.com

WordPress plugins and themes

  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

bw_better_autop() – Improve wpautop and shortcode_unautop processing

You appear to be a bot. Output may be restricted

Description

Improve wpautop and shortcode_unautop processing

The 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.

  1. /03/26 – And that still doesn't work when block tags (e.g div) are embedded within non-block tags ( e.g. a )
  2. /07/03 – Nor does it work when they are embedded within h3 tags!
  1. /08/26 – To allow DIY-oik shortcodes to work nicely the latest solution is that we initially disable wpautop processing
  2. and allow it to be re-introduced by using the [bw_autop] shortcode.

    Usage

    bw_better_autop( $autop );

    Parameters

    $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.

    Returns

    void

    Source

    File name: oik-css/oik-css.php
    Lines:
    1 to 52 of 52
    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')
        remove_filter( 'the_excerpt', 'wpautop');
      }
    }
     
     View on GitHub View on Trac

Published: June 10, 2013 | Last updated: December 18, 2017

Primary Sidebar

Information

Function name: bw_better_autop
Plugin ref: oik-css
Version: 2.4.0
Sourcefile: oik-css.php
File ref: oik-css.php
Deprecated?: No
API Letters: A,B

Recent plugin updates

oik-fields v1.55.1
oik-fields v1.55.1 oik-fields v1.55.1 has been tested with WordPress 7.1. ...
oik v4.16.0
oik v4.16.0 Upgrade to oik v4.16.0 for many accessibility (a11y) improvements for both the front end and admin areas, plus a security fix. ...
oik-fields v1.55.0
oik-fields v1.55.0 Upgrade to oik-fields v1.55.0 for accessibility improvements to the featured image virtual field. ...
oik-css v2.4.0
oik-css v2.4.0 Upgrade to oik-css v2.4.0 for accessibility improvements for Low Color Contrast errors. ...
oik-unloader v0.4.0
oik-unloader v0.4.0 Update to oik-unloader v0.4.0 for improved accessibility of the active-plugins shortcode. Tested with WordPress 6.9 and PHP 8.4 ...

Footer

Plugins

  • All Plugins
  • oik base plugin
  • FREE oik plugins
  • WordPress plugins
  • Premium oik plugins

Themes

  • FREE themes
  • Bespoke themes
  • Premium themes

Blocks

  • All Blocks
  • Block examples
  • About Blocks

Shortcodes

  • All Shortcodes
  • Shortcode examples
  • About Shortcodes

Reference

  • About APIs
  • All APIs
  • All Classes
  • All Files
  • All Hooks

Support

  • Contact
  • Cookies policy
  • Get API key
  • Privacy
  • Request support
  • Sitemap
  • Stay informed
  • Terms and Conditions
oik-plugins
Email: oikplug@oik-plugins.com

Weight shipping plugins

Find out which cart weight shipping plugin you need for your WooCommerce site.
Which cart weight based plugin do I need?

Site:  www.oik-plugins.com
© Copyright oik-plugins 2011-2026. All rights reserved.


Website designed and developed by Herb Miller of Bobbing Wide
Proudly powered by WordPress and oik-plugins

WordPress version: 7.1.2

Gutenberg version: 24.0.0

PHP version: 8.2.35