get_comment_excerpt()
get_comment_excerpt( int|WP_Comment $comment_ID ) 检索给定注…
get_comment_excerpt( int|WP_Comment $comment_ID )
检索给定注释的摘录。
Retrieves the excerpt of the given comment.
目录锚点:#说明#参数#返回#源码
说明(Description)
返回最多20个单词,必要时附加省略号。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $comment_ID | (int | WP_Comment) | 必需 | WP_Comment或要获取摘录的注释的ID。默认当前注释。 |
返回(Return)
(string)可能被截断的注释摘录。
源码(Source)
function get_comment_excerpt( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( ! post_password_required( $comment->comment_post_ID ) ) {
$comment_text = strip_tags( str_replace( array( "n", "r" ), ' ', $comment->comment_content ) );
} else {
$comment_text = __( 'Password protected' );
}
/* translators: Maximum number of words used in a comment excerpt. */
$comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) );
/**
* Filters the maximum number of words used in the comment excerpt.
*
* @since 4.4.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', $comment_excerpt_length );
$excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );
/**
* Filters the retrieved comment excerpt.
*
* @since 1.5.0
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
* @param string $excerpt The comment excerpt text.
* @param int $comment_ID The comment ID.
* @param WP_Comment $comment The comment object.
*/
return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
}
| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 4.4.0 | wp-includes/comment-template.php:596 | 1 function | 6 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!