Make WordPress Core

Ticket #28449: 28449-the_content-orphans-v2.patch

File 28449-the_content-orphans-v2.patch, 4.5 KB (added by dcondrey, 8 years ago)

28449-the_content-orphans-v2.patch : Filter

  • src/wp-includes/default-filters.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    9595        add_filter( $filter, 'wptexturize'   );
    9696        add_filter( $filter, 'convert_chars' );
    9797        add_filter( $filter, 'esc_html'      );
     98        add_filter( $filter, 'prevent_orphans'  );
    9899}
    99100
    100101// Format WordPress
     
    106107foreach ( array( 'single_post_title', 'single_cat_title', 'single_tag_title', 'single_month_title', 'nav_menu_attr_title', 'nav_menu_description' ) as $filter ) {
    107108        add_filter( $filter, 'wptexturize' );
    108109        add_filter( $filter, 'strip_tags'  );
     110        add_filter( $filter, 'prevent_orphans'  );
    109111}
    110112
    111113// Format text area for display.
     
    114116        add_filter( $filter, 'convert_chars'    );
    115117        add_filter( $filter, 'wpautop'          );
    116118        add_filter( $filter, 'shortcode_unautop');
     119        add_filter( $filter, 'prevent_orphans'  );
    117120}
    118121
    119122// Format for RSS
     
    124127add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
    125128
    126129// Display filters
    127 add_filter( 'the_title', 'wptexturize'   );
    128 add_filter( 'the_title', 'convert_chars' );
    129 add_filter( 'the_title', 'trim'          );
     130add_filter( 'the_title', 'wptexturize'    );
     131add_filter( 'the_title', 'convert_chars'  );
     132add_filter( 'the_title', 'trim'           );
     133add_filter( 'the_title', 'prevent_orphans');
    130134
    131135add_filter( 'the_content', 'wptexturize'        );
    132136add_filter( 'the_content', 'convert_smilies'    );
     
    134138add_filter( 'the_content', 'wpautop'            );
    135139add_filter( 'the_content', 'shortcode_unautop'  );
    136140add_filter( 'the_content', 'prepend_attachment' );
     141add_filter( 'the_content', 'prevent_orphans'    );
    137142
    138143add_filter( 'the_excerpt',     'wptexturize'      );
    139144add_filter( 'the_excerpt',     'convert_smilies'  );
    140145add_filter( 'the_excerpt',     'convert_chars'    );
    141146add_filter( 'the_excerpt',     'wpautop'          );
    142147add_filter( 'the_excerpt',     'shortcode_unautop');
     148add_filter( 'the_excerpt',     'prevent_orphans'  );
    143149add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
    144150
    145151add_filter( 'comment_text', 'wptexturize'            );
     
    148154add_filter( 'comment_text', 'force_balance_tags', 25 );
    149155add_filter( 'comment_text', 'convert_smilies',    20 );
    150156add_filter( 'comment_text', 'wpautop',            30 );
     157add_filter( 'comment_text', 'prevent_orphans'        );
    151158
    152159add_filter( 'comment_excerpt', 'convert_chars' );
     160add_filter( 'comment_excerpt', 'prevent_orphans' );
    153161
    154162add_filter( 'list_cats',         'wptexturize' );
    155163
  • src/wp-includes/formatting.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    533533}
    534534
    535535/**
     536 * Prevent orphan or widow words wrapping to new line
     537 * @param $text
     538 * @param $min Optional. Words to wrap. Default 2.
     539 * @param $special Optional. Boolean to add all UNICODE expressions of space. Array to explicitly specify chars to split on.
     540 *
     541 * @return string
     542 */
     543function prevent_orphans($text,$min,$special) {
     544        // if not specified, wrap 2 characters
     545        if ( ! $min ) $min = 2;
     546        // default = basic space, double space, en-space, em-space, mid-space, thin-space, ideographic space, horizontal tab,
     547        $space = [' ','  ',"&ensp;","&#8194;","&emsp;","&#8195;","&#8197;","&#x2005;","&thinsp;","&#8201;","&#12288;","&#x3000;","&#009;"];
     548        // if set but not explicitly specified.. add more special representations of space
     549        if ( $special == true ) $special = [ "&nbsp;","&#160;","&#xA0;","&#x0A0;","&#x00A0;","zwj","&zwnj;","&#8205;","&#8288;","&#x2060;","&#65279;","&#xfeff;","&#8203;","&#x200b;",",","&#44;","&#003;","&#004;","&#023;","&#031;","&#127;","&#173;","&shy;","&#847;","&#x34f;" ];
     550
     551        /** @var array $chars */
     552        $chars = $special ? $chars . array_merge( $space, $special ) : $space;
     553
     554        $explode = str_replace($chars, $chars[0], $text);
     555        $arr = explode($chars[0], $explode);
     556
     557        if(count($arr) >= $min) {
     558                $arr[count($arr) - 2].= '&nbsp;'.$arr[count($arr) - 1];
     559                array_pop($arr);
     560                $text = implode(' ',$arr);
     561        }
     562        return $text;
     563}
     564
     565/**
    536566 * Checks to see if a string is utf8 encoded.
    537567 *
    538568 * NOTE: This function checks for 5-Byte sequences, UTF8