[oik] plugins.com

WordPress plugins and themes

  • Home
  • 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

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 51 of 51
    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

    Called by

    1 to 3 of 3
    • bw_autop() – Implement [bw_autop] shortcode
    • oik_css_oik_loaded() – Implement "oik_loaded" action for oik-css
    • Tests_oik_css::test_bw_better_autop() – Unit test of bw_better_autop()

    Invoked by

      Calls

        Call hooks

        1 to 1 of 1
        • run_wptexturize – filter
        Function name: bw_better_autop
        Plugin ref: oik-css
        Version: 2.3.1
        Sourcefile: oik-css.php
        File ref: oik-css.php
        Deprecated?: No
        API Letters: A,B

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

      Information

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

      Recent plugin updates

      oik-weight-zone-shipping v0.2.13 oik-weight-zone-shipping v0.2.13 has been tested with WooCommerce 10.1.2 and WordPress 6.8.2 ...
      SB Children Block v1.3.0 Upgrade to SB Children Block v1.3.0 for support for PHP 8.3 and PHP 8.4  ...
      oik v4.15.3 Update to oik v4.15.3 for a couple of security fixes. Tested with WordPress 6.8.2 ...
      oik-privacy-policy v1.4.9 Update to oik-privacy-policy v1.4.9 for a security fix. Tested with WordPress 6.8.2 and PHP 8.3 and PHP 8.4 ...
      oik-nivo-slider v1.17.0 oik-nivo-slider v1.17.0 introduces the Nivo slider block - oik-nivo-slider/nivo. ...

      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-2025. All rights reserved.


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

      WordPress version: 6.8.3

      Gutenberg version: 21.7.0

      PHP version: 8.2.29