* 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:
parent
633a6fb400
commit
415a5c60da
|
@ -57,7 +57,7 @@ if ( isset($_REQUEST['attachment_id']) && ($id = intval($_REQUEST['attachment_id
|
|||
echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
|
||||
echo '<a class="edit-attachment" href="' . esc_url( get_edit_post_link( $id ) ) . '" target="_blank">' . _x( 'Edit', 'media item' ) . '</a>';
|
||||
$title = $post->post_title ? $post->post_title : wp_basename( $post->guid ); // title shouldn't ever be empty, but use filename just in cas.e
|
||||
echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60 ) ) . '</span></div>';
|
||||
echo '<div class="filename new"><span class="title">' . esc_html( wp_html_excerpt( $title, 60, '…' ) ) . '</span></div>';
|
||||
break;
|
||||
case 2 :
|
||||
add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
|
||||
|
|
|
@ -105,7 +105,7 @@ wp_enqueue_script('admin-comments');
|
|||
enqueue_comment_hotkeys_js();
|
||||
|
||||
if ( $post_id )
|
||||
$title = sprintf(__('Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50));
|
||||
$title = sprintf( __( 'Comments on “%s”' ), wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' ) );
|
||||
else
|
||||
$title = __('Comments');
|
||||
|
||||
|
@ -143,17 +143,17 @@ require_once('./admin-header.php');
|
|||
<?php screen_icon(); ?>
|
||||
<h2><?php
|
||||
if ( $post_id )
|
||||
echo sprintf(__('Comments on “%s”'),
|
||||
sprintf('<a href="%s">%s</a>',
|
||||
get_edit_post_link($post_id),
|
||||
wp_html_excerpt(_draft_or_post_title($post_id), 50)
|
||||
echo sprintf( __( 'Comments on “%s”' ),
|
||||
sprintf( '<a href="%s">%s</a>',
|
||||
get_edit_post_link( $post_id ),
|
||||
wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' )
|
||||
)
|
||||
);
|
||||
else
|
||||
echo __('Comments');
|
||||
|
||||
if ( isset($_REQUEST['s']) && $_REQUEST['s'] )
|
||||
printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?>
|
||||
printf( '<span class="subtitle">' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '…' ) ) . '</span>' ); ?>
|
||||
</h2>
|
||||
|
||||
<?php
|
||||
|
|
|
@ -827,7 +827,7 @@ function wp_dashboard_incoming_links_output() {
|
|||
$publisher = "<strong>$publisher</strong>";
|
||||
|
||||
$content = $item->get_content();
|
||||
$content = wp_html_excerpt($content, 50) . ' …';
|
||||
$content = wp_html_excerpt( $content, 50, ' …' );
|
||||
|
||||
if ( $link )
|
||||
/* translators: incoming links feed, %1$s is other person, %3$s is content */
|
||||
|
|
|
@ -1159,7 +1159,7 @@ function get_media_item( $attachment_id, $args = null ) {
|
|||
}
|
||||
|
||||
$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
|
||||
$display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
|
||||
$display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . "</span></div>" : '';
|
||||
|
||||
$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
|
||||
$order = '';
|
||||
|
|
|
@ -515,10 +515,7 @@ function wp_nav_menu_locations_meta_box() {
|
|||
<option value="0"></option>
|
||||
<?php foreach ( $menus as $menu ) : ?>
|
||||
<option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
|
||||
value="<?php echo $menu->term_id; ?>"><?php
|
||||
$truncated_name = wp_html_excerpt( $menu->name, 40 );
|
||||
echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…';
|
||||
?></option>
|
||||
value="<?php echo $menu->term_id; ?>"><?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
|
|
|
@ -436,11 +436,7 @@ if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
|
|||
|
||||
// Generate truncated menu names
|
||||
foreach( (array) $nav_menus as $key => $_nav_menu ) {
|
||||
$_nav_menu->truncated_name = trim( wp_html_excerpt( $_nav_menu->name, 40 ) );
|
||||
if ( $_nav_menu->truncated_name != $_nav_menu->name )
|
||||
$_nav_menu->truncated_name .= '…';
|
||||
|
||||
$nav_menus[$key]->truncated_name = $_nav_menu->truncated_name;
|
||||
$nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' );
|
||||
}
|
||||
|
||||
// Retrieve menu locations
|
||||
|
@ -572,8 +568,7 @@ require_once( './admin-header.php' );
|
|||
<?php foreach ( $nav_menus as $menu ) : ?>
|
||||
<?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?>
|
||||
<option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
|
||||
<?php $truncated_name = wp_html_excerpt( $menu->name, 40 );
|
||||
echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…'; ?>
|
||||
<?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -87,8 +87,8 @@ if ( !empty($tb_url) && !empty($title) ) {
|
|||
if ( !pings_open($tb_id) )
|
||||
trackback_response(1, 'Sorry, trackbacks are closed for this item.');
|
||||
|
||||
$title = wp_html_excerpt( $title, 250 ) . '…';
|
||||
$excerpt = wp_html_excerpt( $excerpt, 252 ) . '…';
|
||||
$title = wp_html_excerpt( $title, 250, '…' );
|
||||
$excerpt = wp_html_excerpt( $excerpt, 252, '…' );
|
||||
|
||||
$comment_post_ID = (int) $tb_id;
|
||||
$comment_author = $blog_name;
|
||||
|
|
Loading…
Reference in New Issue