Make WordPress Core

Changeset 24214


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.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/async-upload.php

    r22915 r24214  
    5858            echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
    5959            $title = $post->post_title ? $post->post_title : wp_basename( $post->guid ); // title shouldn't ever be empty, but use filename just in cas.e
    60             echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60 ) ) . '</span></div>';
     60            echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ) . '</span></div>';
    6161            break;
    6262        case 2 :
  • trunk/wp-admin/edit-comments.php

    r23578 r24214  
    106106
    107107if ( $post_id )
    108     $title = sprintf(__('Comments on &#8220;%s&#8221;'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
     108    $title = sprintf( __( 'Comments on &#8220;%s&#8221;' ), wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' ) );
    109109else
    110110    $title = __('Comments');
     
    144144<h2><?php
    145145if ( $post_id )
    146     echo sprintf(__('Comments on &#8220;%s&#8221;'),
    147         sprintf('<a href="%s">%s</a>',
    148             get_edit_post_link($post_id),
    149             wp_html_excerpt(_draft_or_post_title($post_id), 50)
     146    echo sprintf( __( 'Comments on &#8220;%s&#8221;' ),
     147        sprintf( '<a href="%s">%s</a>',
     148            get_edit_post_link( $post_id ),
     149            wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' )
    150150        )
    151151    );
     
    154154
    155155if ( isset($_REQUEST['s']) && $_REQUEST['s'] )
    156     printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?>
     156    printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '&hellip;' ) ) . '</span>' ); ?>
    157157</h2>
    158158
  • trunk/wp-admin/includes/dashboard.php

    r24212 r24214  
    828828
    829829        $content = $item->get_content();
    830         $content = wp_html_excerpt($content, 50) . ' &hellip;';
     830        $content = wp_html_excerpt( $content, 50, ' &hellip;' );
    831831
    832832        if ( $link )
  • trunk/wp-admin/includes/media.php

    r24187 r24214  
    11601160
    11611161    $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
    1162     $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
     1162    $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . "</span></div>" : '';
    11631163
    11641164    $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
  • trunk/wp-admin/includes/nav-menu.php

    r24185 r24214  
    516516                    <?php foreach ( $menus as $menu ) : ?>
    517517                    <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
    518                         value="<?php echo $menu->term_id; ?>"><?php
    519                         $truncated_name = wp_html_excerpt( $menu->name, 40 );
    520                         echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '&hellip;';
    521                     ?></option>
     518                        value="<?php echo $menu->term_id; ?>"><?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?></option>
    522519                    <?php endforeach; ?>
    523520                </select>
  • trunk/wp-admin/nav-menus.php

    r24183 r24214  
    437437// Generate truncated menu names
    438438foreach( (array) $nav_menus as $key => $_nav_menu ) {
    439     $_nav_menu->truncated_name = trim( wp_html_excerpt( $_nav_menu->name, 40 ) );
    440     if ( $_nav_menu->truncated_name != $_nav_menu->name )
    441         $_nav_menu->truncated_name .= '&hellip;';
    442 
    443     $nav_menus[$key]->truncated_name = $_nav_menu->truncated_name;
     439    $nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
    444440}
    445441
     
    573569                                    <?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?>
    574570                                    <option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
    575                                         <?php $truncated_name = wp_html_excerpt( $menu->name, 40 );
    576                                         echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '&hellip;'; ?>
     571                                        <?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
    577572                                    </option>
    578573                                <?php endforeach; ?>
  • trunk/wp-includes/admin-bar.php

    r23512 r24214  
    230230    }
    231231
    232     $title = wp_html_excerpt( $blogname, 40 );
    233     if ( $title != $blogname )
    234         $title = trim( $title ) . '&hellip;';
     232    $title = wp_html_excerpt( $blogname, 40, '&hellip;' );
    235233
    236234    $wp_admin_bar->add_menu( array(
  • trunk/wp-includes/class-wp-customize-manager.php

    r23591 r24214  
    898898            $choices = array( 0 => __( '&mdash; Select &mdash;' ) );
    899899            foreach ( $menus as $menu ) {
    900                 $truncated_name = wp_html_excerpt( $menu->name, 40 );
    901                 $truncated_name = ( $truncated_name == $menu->name ) ? $menu->name : trim( $truncated_name ) . '&hellip;';
    902                 $choices[ $menu->term_id ] = $truncated_name;
     900                $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
    903901            }
    904902
  • trunk/wp-includes/comment.php

    r24207 r24214  
    17541754        $excerpt = apply_filters('the_excerpt', $post->post_excerpt);
    17551755    $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
    1756     $excerpt = wp_html_excerpt($excerpt, 252) . '&#8230;';
     1756    $excerpt = wp_html_excerpt($excerpt, 252, '&#8230;');
    17571757
    17581758    $post_title = apply_filters('the_title', $post->post_title, $post->ID);
  • 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 '&hellip;'.
     2202 * @param string $more Optional. What to append if $text needs to be trimmed. Default '&hellip;'.
    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
  • trunk/wp-trackback.php

    r24207 r24214  
    8888        trackback_response(1, 'Sorry, trackbacks are closed for this item.');
    8989
    90     $title =  wp_html_excerpt( $title, 250 ) . '&#8230;';
    91     $excerpt = wp_html_excerpt( $excerpt, 252 ) . '&#8230;';
     90    $title =  wp_html_excerpt( $title, 250, '&#8230;' );
     91    $excerpt = wp_html_excerpt( $excerpt, 252, '&#8230;' );
    9292
    9393    $comment_post_ID = (int) $tb_id;
Note: See TracChangeset for help on using the changeset viewer.