I18N: Allow the length of automatically generated excerpts to be localized.
This introduces three new strings that can be used to control the maximum length of automatically generated excerpts for posts, comments, and draft post previews in the dashboard. Optionally combined with the existing word count type control this allows languages which include many multibyte characters to specify more appropriate maximum excerpt lengths. Props miyauchi, birgire, johnbillion Fixes #44541 Built from https://develop.svn.wordpress.org/trunk@45505 git-svn-id: http://core.svn.wordpress.org/trunk@45316 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
eeba1c1244
commit
c9b51df3d0
|
@ -584,6 +584,9 @@ function wp_dashboard_recent_drafts( $drafts = false ) {
|
||||||
}
|
}
|
||||||
echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
|
echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
|
||||||
|
|
||||||
|
/* translators: Maximum number of words used in a preview of a draft on the dashboard. */
|
||||||
|
$draft_length = intval( _x( '10', 'draft_length' ) );
|
||||||
|
|
||||||
$drafts = array_slice( $drafts, 0, 3 );
|
$drafts = array_slice( $drafts, 0, 3 );
|
||||||
foreach ( $drafts as $draft ) {
|
foreach ( $drafts as $draft ) {
|
||||||
$url = get_edit_post_link( $draft->ID );
|
$url = get_edit_post_link( $draft->ID );
|
||||||
|
@ -592,7 +595,7 @@ function wp_dashboard_recent_drafts( $drafts = false ) {
|
||||||
/* translators: %s: post title */
|
/* translators: %s: post title */
|
||||||
echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
|
echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
|
||||||
echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( __( 'F j, Y' ), $draft ) . '</time></div>';
|
echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( __( 'F j, Y' ), $draft ) . '</time></div>';
|
||||||
if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
|
if ( $the_content = wp_trim_words( $draft->post_content, $draft_length ) ) {
|
||||||
echo '<p>' . $the_content . '</p>';
|
echo '<p>' . $the_content . '</p>';
|
||||||
}
|
}
|
||||||
echo "</li>\n";
|
echo "</li>\n";
|
||||||
|
|
|
@ -577,42 +577,35 @@ function comment_date( $d = '', $comment_ID = 0 ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the excerpt of the current comment.
|
* Retrieves the excerpt of the given comment.
|
||||||
*
|
*
|
||||||
* Will cut each word and only output the first 20 words with '…' at the end.
|
* Returns a maximum of 20 words with an ellipsis appended if necessary.
|
||||||
* If the word count is less than 20, then no truncating is done and no '…'
|
|
||||||
* will appear.
|
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
* @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
|
* @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
|
||||||
*
|
*
|
||||||
* @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt.
|
* @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt.
|
||||||
* Default current comment.
|
* Default current comment.
|
||||||
* @return string The maybe truncated comment with 20 words or less.
|
* @return string The possibly truncated comment excerpt.
|
||||||
*/
|
*/
|
||||||
function get_comment_excerpt( $comment_ID = 0 ) {
|
function get_comment_excerpt( $comment_ID = 0 ) {
|
||||||
$comment = get_comment( $comment_ID );
|
$comment = get_comment( $comment_ID );
|
||||||
$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
|
$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
|
||||||
$words = explode( ' ', $comment_text );
|
|
||||||
|
/* translators: Maximum number of words used in a comment excerpt. */
|
||||||
|
$comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the amount of words used in the comment excerpt.
|
* Filters the maximum number of words used in the comment excerpt.
|
||||||
*
|
*
|
||||||
* @since 4.4.0
|
* @since 4.4.0
|
||||||
*
|
*
|
||||||
* @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
|
* @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
|
||||||
*/
|
*/
|
||||||
$comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 );
|
$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
|
||||||
|
|
||||||
$use_ellipsis = count( $words ) > $comment_excerpt_length;
|
$excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );
|
||||||
if ( $use_ellipsis ) {
|
|
||||||
$words = array_slice( $words, 0, $comment_excerpt_length );
|
|
||||||
}
|
|
||||||
|
|
||||||
$excerpt = trim( join( ' ', $words ) );
|
|
||||||
if ( $use_ellipsis ) {
|
|
||||||
$excerpt .= '…';
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Filters the retrieved comment excerpt.
|
* Filters the retrieved comment excerpt.
|
||||||
*
|
*
|
||||||
|
|
|
@ -3680,9 +3680,7 @@ function human_time_diff( $from, $to = '' ) {
|
||||||
/**
|
/**
|
||||||
* Generates an excerpt from the content, if needed.
|
* Generates an excerpt from the content, if needed.
|
||||||
*
|
*
|
||||||
* The excerpt word amount will be 55 words and if the amount is greater than
|
* Returns a maximum of 55 words with an ellipsis appended if necessary.
|
||||||
* that, then the string ' […]' will be appended to the excerpt. If the string
|
|
||||||
* is less than 55 words, then the content will be returned as is.
|
|
||||||
*
|
*
|
||||||
* The 55 word limit can be modified by plugins/themes using the {@see 'excerpt_length'} filter
|
* The 55 word limit can be modified by plugins/themes using the {@see 'excerpt_length'} filter
|
||||||
* The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter
|
* The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter
|
||||||
|
@ -3707,14 +3705,18 @@ function wp_trim_excerpt( $text = '', $post = null ) {
|
||||||
$text = apply_filters( 'the_content', $text );
|
$text = apply_filters( 'the_content', $text );
|
||||||
$text = str_replace( ']]>', ']]>', $text );
|
$text = str_replace( ']]>', ']]>', $text );
|
||||||
|
|
||||||
|
/* translators: Maximum number of words used in a post excerpt. */
|
||||||
|
$excerpt_length = intval( _x( '55', 'excerpt_length' ) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the number of words in an excerpt.
|
* Filters the maximum number of words in a post excerpt.
|
||||||
*
|
*
|
||||||
* @since 2.7.0
|
* @since 2.7.0
|
||||||
*
|
*
|
||||||
* @param int $number The number of words. Default 55.
|
* @param int $number The maximum number of words. Default 55.
|
||||||
*/
|
*/
|
||||||
$excerpt_length = apply_filters( 'excerpt_length', 55 );
|
$excerpt_length = apply_filters( 'excerpt_length', $excerpt_length );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the string in the "more" link displayed after a trimmed excerpt.
|
* Filters the string in the "more" link displayed after a trimmed excerpt.
|
||||||
*
|
*
|
||||||
|
@ -3725,6 +3727,7 @@ function wp_trim_excerpt( $text = '', $post = null ) {
|
||||||
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
|
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' );
|
||||||
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
|
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the trimmed excerpt string.
|
* Filters the trimmed excerpt string.
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.3-alpha-45504';
|
$wp_version = '5.3-alpha-45505';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue