get_comment_excerpt

The timeline below displays how wordpress function get_comment_excerpt has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the excerpt.
 *                                   Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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 = (int) _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);
    $comment_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     $comment_excerpt The comment excerpt text.
     * @param string     $comment_id      The comment ID as a numeric string.
     * @param WP_Comment $comment         The comment object.
     */
    return apply_filters('get_comment_excerpt', $comment_excerpt, $comment->comment_ID, $comment);
}

WordPress Version: 6.2

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the excerpt.
 *                                   Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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 = (int) _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 string     $comment_id The comment ID as a numeric string.
     * @param WP_Comment $comment    The comment object.
     */
    return apply_filters('get_comment_excerpt', $excerpt, $comment->comment_ID, $comment);
}

WordPress Version: 5.9

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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 = (int) _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 string     $comment_ID The comment ID as a numeric string.
     * @param WP_Comment $comment    The comment object.
     */
    return apply_filters('get_comment_excerpt', $excerpt, $comment->comment_ID, $comment);
}

WordPress Version: 5.6

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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 = (int) _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);
}

WordPress Version: .10

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 5.4

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    /* 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);
}

WordPress Version: 3.4

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 3.2

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    /* 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);
}

WordPress Version: .10

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 5.3

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    /* 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);
}

WordPress Version: 2.7

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
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);
}

WordPress Version: 2.3

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: .20

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
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);
}

WordPress Version: 2.2

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: .10

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
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);
}

WordPress Version: 5.2

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: 1.6

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 1.2

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: .10

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 0.3

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: .20

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 0.2

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: .10

/**
 * Retrieves the excerpt of the given comment.
 *
 * Returns a maximum of 20 words with an ellipsis appended if necessary.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The possibly truncated comment excerpt.
 */
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);
}

WordPress Version: 4.6

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filters the amount 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', 20);
    $use_ellipsis = count($words) > $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.
     *
     * @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);
}

WordPress Version: 4.4

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 * @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.
 *                                    Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags(str_replace(array("\n", "\r"), ' ', $comment->comment_content));
    $words = explode(' ', $comment_text);
    /**
     * Filter the amount 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', 20);
    $use_ellipsis = count($words) > $comment_excerpt_length;
    if ($use_ellipsis) {
        $words = array_slice($words, 0, $comment_excerpt_length);
    }
    $excerpt = trim(join(' ', $words));
    if ($use_ellipsis) {
        $excerpt .= '…';
    }
    /**
     * Filter 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);
}

WordPress Version: 4.1

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '…' at the end.
 * If the word count is less than 20, then no truncating is done and no '…'
 * will appear.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID ID of the comment for which to get the excerpt.
 *                        Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags($comment->comment_content);
    $blah = explode(' ', $comment_text);
    if (count($blah) > 20) {
        $k = 20;
        $use_dotdotdot = 1;
    } else {
        $k = count($blah);
        $use_dotdotdot = 0;
    }
    $excerpt = '';
    for ($i = 0; $i < $k; $i++) {
        $excerpt .= $blah[$i] . ' ';
    }
    $excerpt .= $use_dotdotdot ? '&hellip;' : '';
    /**
     * Filter 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 object $comment    The comment object.
     */
    return apply_filters('get_comment_excerpt', $excerpt, $comment_ID, $comment);
}

WordPress Version: 3.9

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '&hellip;' at the end.
 * If the word count is less than 20, then no truncating is done and no '&hellip;'
 * will appear.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID ID of the comment for which to get the excerpt.
 *                        Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags($comment->comment_content);
    $blah = explode(' ', $comment_text);
    if (count($blah) > 20) {
        $k = 20;
        $use_dotdotdot = 1;
    } else {
        $k = count($blah);
        $use_dotdotdot = 0;
    }
    $excerpt = '';
    for ($i = 0; $i < $k; $i++) {
        $excerpt .= $blah[$i] . ' ';
    }
    $excerpt .= $use_dotdotdot ? '&hellip;' : '';
    /**
     * Filter the retrieved comment excerpt.
     *
     * @since 1.5.0
     *
     * @param string $excerpt The comment excerpt text.
     */
    return apply_filters('get_comment_excerpt', $excerpt);
}

WordPress Version: 3.7

/**
 * Retrieve the excerpt of the current comment.
 *
 * Will cut each word and only output the first 20 words with '&hellip;' at the end.
 * If the word count is less than 20, then no truncating is done and no '&hellip;'
 * will appear.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID Optional. The ID of the comment for which to get the excerpt. Default current comment.
 * @return string The maybe truncated comment with 20 words or less.
 */
function get_comment_excerpt($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $comment_text = strip_tags($comment->comment_content);
    $blah = explode(' ', $comment_text);
    if (count($blah) > 20) {
        $k = 20;
        $use_dotdotdot = 1;
    } else {
        $k = count($blah);
        $use_dotdotdot = 0;
    }
    $excerpt = '';
    for ($i = 0; $i < $k; $i++) {
        $excerpt .= $blah[$i] . ' ';
    }
    $excerpt .= $use_dotdotdot ? '&hellip;' : '';
    return apply_filters('get_comment_excerpt', $excerpt);
}