Make WordPress Core


Ignore:
Timestamp:
05/09/2013 12:22:02 AM (12 years ago)
Author:
SergeyBiryukov
Message:
  • Pass ellipsis as a parameter to wp_html_excerpt() instead of appending it manually.
  • Consolidate the logic to avoid appending ellipsis if the entire string is shown.
  • Show ellipsis after truncated filenames and post titles.

props solarissmoke, bpetty, SergeyBiryukov. fixes #11446.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r24207 r24214  
    22002200 * @param string $text Text to trim.
    22012201 * @param int $num_words Number of words. Default 55.
    2202  * @param string $more What to append if $text needs to be trimmed. Default '…'.
     2202 * @param string $more Optional. What to append if $text needs to be trimmed. Default '…'.
    22032203 * @return string Trimmed text.
    22042204 */
     
    31193119 * @param integer $str String to get the excerpt from.
    31203120 * @param integer $count Maximum number of characters to take.
     3121 * @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
    31213122 * @return string The excerpt.
    31223123 */
    3123 function wp_html_excerpt( $str, $count ) {
     3124function wp_html_excerpt( $str, $count, $more = null ) {
     3125    if ( null === $more )
     3126        $more = '';
    31243127    $str = wp_strip_all_tags( $str, true );
    3125     $str = mb_substr( $str, 0, $count );
     3128    $excerpt = mb_substr( $str, 0, $count );
    31263129    // remove part of an entity at the end
    3127     $str = preg_replace( '/&[^;\s]{0,6}$/', '', $str );
    3128     return $str;
     3130    $excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
     3131    if ( $str != $excerpt )
     3132        $excerpt = trim( $excerpt ) . $more;
     3133    return $excerpt;
    31293134}
    31303135
Note: See TracChangeset for help on using the changeset viewer.