Plugin Directory

Changeset 1156333


Ignore:
Timestamp:
05/08/2015 04:43:08 PM (11 years ago)
Author:
bigsmoke
Message:

Incorporated Jesse Jacobsen's contrib.

Location:
wpautop-control/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wpautop-control/trunk/readme.txt

    r655413 r1156333  
    22
    33Contributors: bigsmoke
    4 Donate link: http://www.bismoke.us/donate/
     4Donate link: http://www.bigsmoke.us/donate/
    55Tags: wpautop, filter
    66Requires at least: 3.0
    7 Tested up to: 3.2.1
    8 Stable tag: 1.3
     7Tested up to: 4.2.2
     8Stable tag: 1.4
    99
    1010Adds a global setting to turn the wpautop filter on and off. It also allows you to override this default for any post by adding a wpautop custom field.
     
    2929You can set the field's value to `true`, `yes` or `on` if you do want WordPress to use its `wpautop` filter to add `<p>` and `<br>` tags for you. (Of course, this only makes sense if you've globally disabled `wpautop` in the included option screen.)
    3030
     31= How do I turn of line-end break insertions? =
     32
     33Set the field's value to '-break' to just disable the conversion of newlines to `&lt;br/&gt;` tags within paragraphs.
     34
     35
    3136== Changelog ==
     37
     38= 1.4 =
     39* Jesse Jacobson contributed a new feature, which disables only the conversion of newlines into `&lt;br/&gt;` tags within paragraphs. This is useful, for example, when writing Markdown with a text editor like Vim.
    3240
    3341= 1.3 =
  • wpautop-control/trunk/wpautop-control.php

    r367680 r1156333  
    44Plugin URI: http://blog.bigsmoke.us/tag/wpautop-control/
    55Description: This plugin allows you fine control of when and when not to enable the wpautop filter on posts.
    6 Author: Rowan Rodrik van der Molen
    7 Author URI: http://blog.bigsmoke.us/
    8 Version: 1.0
     6Author: Rowan Rodrik van der Molen, Jesse Jacobsen <jmatjac@gmail.com>.
     7Author URI: http://blog.bigsmoke.us
     8Version: 1.4
    99*/
    1010
     
    2929      <?php settings_fields('wpautop-control') ?>
    3030
    31       <p>Normally, WordPress filters your posts' content using the wpautop filter. Roughly, what this filter does is that it replaces newlines and empty lines with <tt>&lt;br /&gt;</tt> or <tt>&lt;p&gt;</tt>. The setting below lets you turn this filter on or off. (You can later override it on a post-by-post basis by setting the wpautop custom field to ‘true’ or ‘false’.)</p>
     31      <p>Normally, WordPress filters your posts' content using the wpautop filter. What this filter does is that it replaces single newlines with <tt>&lt;br /&gt;</tt> and empty lines with <tt>&lt;p&gt;</tt>. The setting below lets you turn this filter on or off. (You can later override it on a post-by-post basis by setting the wpautop custom field to ‘default’, ‘-breaks’, or ‘off’.)</p>
    3232
    3333      <table class="form-table">
     
    3535          <th scope="row">wpautop filter on by default?</th>
    3636          <td>
    37             <label><input type="radio" name="wpautop_on_by_default" value="1" <?php if ( get_option('wpautop_on_by_default') == '1' ) echo 'checked="1"' ?>> yes <small>(WordPress' default behaviour)</small></label><br />
    38             <label><input type="radio" name="wpautop_on_by_default" value="0" <?php if ( get_option('wpautop_on_by_default') == '0' ) echo 'checked="1"' ?>> no <small>(turn of WordPress' auto-formatting, except for selected posts)</small></label>
     37            <label><input type="radio" name="wpautop_by_default" value="default" <?php if ( get_option('wpautop_by_default') == 'default' ) echo 'checked="1"' ?>> default <small>(WordPress' default behaviour)</small></label><br />
     38            <label><input type="radio" name="wpautop_by_default" value="-breaks" <?php if ( get_option('wpautop_by_default') == '-breaks' ) echo 'checked="1"' ?>> -breaks <small>(turn off WordPress' line breaks)</small></label><br />
     39            <label><input type="radio" name="wpautop_by_default" value="off" <?php if ( get_option('wpautop_by_default') == 'off' ) echo 'checked="1"' ?>> off <small>(turn off WordPress' auto-formatting)</small></label>
    3940          </td>
    4041      </table>
     
    4950
    5051  function wpautop_control_settings() {
    51     register_setting('wpautop-control', 'wpautop_on_by_default', 'intval');
     52    register_setting('wpautop-control', 'wpautop_by_default');
    5253  }
    5354}
     
    6162    $post_wpautop_value = get_post_meta($post->ID, 'wpautop', true);
    6263
    63     $default_wpautop_value = intval( get_option('wpautop_on_by_default', '1') );
     64    $default_wpautop_value = get_option('wpautop_by_default', 'default');
    6465
    6566    $remove_filter = false;
    66     if ( empty($post_wpautop_value) )
    67       $remove_filter = ! $default_wpautop_value;
    68     elseif ( in_array($post_wpautop_value, array('true', 'on', 'yes')) )
    69       $remove_filter = false;
    70     elseif ( in_array($post_wpautop_value, array('false', 'off', 'no')) )
    71       $remove_filter = true;
     67    if ( empty($post_wpautop_value) || ! in_array($post_wpautop_value, array( "default", "-breaks", "off") ) )
     68      $filter_type = $default_wpautop_value;
     69    else
     70      $filter_type = $post_wpautop_value;
    7271
    73     if ( $remove_filter ) {
     72    if ( $filter_type == "default" ) {
     73        // Leave WordPress wpautop behavior in place
     74    } elseif ( $filter_type == "-breaks" ) {
     75        // Remove the wpautop filter and install our own
     76      remove_filter('the_content', 'wpautop');
     77      remove_filter('the_excerpt', 'wpautop');
     78      add_filter('the_content', function ($pee) { return wpautop($pee, false); } );
     79      add_filter('the_excerpt', function ($pee) { return wpautop($pee, false); } );
     80    } elseif ( $filter_type == "off" ) {
     81        // Remove the wpautop filter completely
    7482      remove_filter('the_content', 'wpautop');
    7583      remove_filter('the_excerpt', 'wpautop');
Note: See TracChangeset for help on using the changeset viewer.