* 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.

git-svn-id: http://core.svn.wordpress.org/trunk@24214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2013-05-09 00:22:02 +00:00
parent 633a6fb400
commit 415a5c60da
11 changed files with 27 additions and 34 deletions

View File

@@ -229,9 +229,7 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) {
$blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );
}
$title = wp_html_excerpt( $blogname, 40 );
if ( $title != $blogname )
$title = trim( $title ) . '…';
$title = wp_html_excerpt( $blogname, 40, '…' );
$wp_admin_bar->add_menu( array(
'id' => 'site-name',

View File

@@ -897,9 +897,7 @@ final class WP_Customize_Manager {
if ( $menus ) {
$choices = array( 0 => __( '— Select —' ) );
foreach ( $menus as $menu ) {
$truncated_name = wp_html_excerpt( $menu->name, 40 );
$truncated_name = ( $truncated_name == $menu->name ) ? $menu->name : trim( $truncated_name ) . '…';
$choices[ $menu->term_id ] = $truncated_name;
$choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '…' );
}
foreach ( $locations as $location => $description ) {

View File

@@ -1753,7 +1753,7 @@ function do_trackbacks($post_id) {
else
$excerpt = apply_filters('the_excerpt', $post->post_excerpt);
$excerpt = str_replace(']]>', ']]>', $excerpt);
$excerpt = wp_html_excerpt($excerpt, 252) . '…';
$excerpt = wp_html_excerpt($excerpt, 252, '…');
$post_title = apply_filters('the_title', $post->post_title, $post->ID);
$post_title = strip_tags($post_title);

View File

@@ -2199,7 +2199,7 @@ function wp_trim_excerpt($text = '') {
*
* @param string $text Text to trim.
* @param int $num_words Number of words. Default 55.
* @param string $more What to append if $text needs to be trimmed. Default '…'.
* @param string $more Optional. What to append if $text needs to be trimmed. Default '…'.
* @return string Trimmed text.
*/
function wp_trim_words( $text, $num_words = 55, $more = null ) {
@@ -3118,14 +3118,19 @@ function wp_sprintf_l($pattern, $args) {
*
* @param integer $str String to get the excerpt from.
* @param integer $count Maximum number of characters to take.
* @param string $more Optional. What to append if $str needs to be trimmed. Defaults to empty string.
* @return string The excerpt.
*/
function wp_html_excerpt( $str, $count ) {
function wp_html_excerpt( $str, $count, $more = null ) {
if ( null === $more )
$more = '';
$str = wp_strip_all_tags( $str, true );
$str = mb_substr( $str, 0, $count );
$excerpt = mb_substr( $str, 0, $count );
// remove part of an entity at the end
$str = preg_replace( '/&[^;\s]{0,6}$/', '', $str );
return $str;
$excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
if ( $str != $excerpt )
$excerpt = trim( $excerpt ) . $more;
return $excerpt;
}
/**