mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 19:46:21 +00:00
Comments: add a 'comment_excerpt_length'
filter to get_comment_excerpt()
.
Create the first ever unit tests for `get_comment_excerpt()`. Props dannydehaan, wonderboymusic. Fixes #27526. Built from https://develop.svn.wordpress.org/trunk@34520 git-svn-id: http://core.svn.wordpress.org/trunk@34484 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
92fb281b71
commit
169db9dbb1
@ -565,23 +565,27 @@ function comment_date( $d = '', $comment_ID = 0 ) {
|
|||||||
*/
|
*/
|
||||||
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($comment->comment_content);
|
$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
|
||||||
$blah = explode(' ', $comment_text);
|
$words = explode( ' ', $comment_text );
|
||||||
|
|
||||||
if (count($blah) > 20) {
|
/**
|
||||||
$k = 20;
|
* Filter the amount of words used in the comment excerpt.
|
||||||
$use_dotdotdot = 1;
|
*
|
||||||
} else {
|
* @since 4.4.0
|
||||||
$k = count($blah);
|
*
|
||||||
$use_dotdotdot = 0;
|
* @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 );
|
||||||
|
|
||||||
|
$use_ellipsis = count( $words ) > $comment_excerpt_length;
|
||||||
|
if ( $use_ellipsis ) {
|
||||||
|
$words = array_slice( $words, 0, $comment_excerpt_length );
|
||||||
}
|
}
|
||||||
|
|
||||||
$excerpt = '';
|
$excerpt = trim( join( ' ', $words ) );
|
||||||
for ($i=0; $i<$k; $i++) {
|
if ( $use_ellipsis ) {
|
||||||
$excerpt .= $blah[$i] . ' ';
|
$excerpt .= '…';
|
||||||
}
|
}
|
||||||
$excerpt .= ($use_dotdotdot) ? '…' : '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the retrieved comment excerpt.
|
* Filter the retrieved comment excerpt.
|
||||||
*
|
*
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-34519';
|
$wp_version = '4.4-alpha-34520';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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…
x
Reference in New Issue
Block a user