ADD CHAT LINK TO COMMENTS

The following snippet of code will allow you to place a contact link button after the comment text, to permit current user to easily navigate to chat with the comment author.

The button will also include an unread count if this user has unread messages from the comment author

Add the following code to your child theme’s functions file (functions.php) or with a custom plugin:

add_filter("comment_text", function( $text, $comment = null ) {
    global $current_user;
    if ( empty( $current_user->ID ) || !class_exists('BM\Includes\Core\Loader') ) return $text;
    $comment->user_id = (int) $comment->user_id;
    if ( !empty($comment->user_id) && $comment->user_id !== $current_user->ID ) {
        $user = get_userdata( $comment->user_id );
        if ( empty( $user->ID ) ) return $text;
        $count = (int) do_shortcode( "[bm-chat-unread-count recipient={$user->ID}]" ); // unread count
        $text .= sprintf(
            '<p><a href="%s" title="Contact %s" class="btn btn-primary">Send Me a Message!%s</a></p>',
            do_shortcode( "[bm-chat-link recipient={$user->ID}]" ), // chat link
            $user->display_name, // contact name
            $count ? " (+{$count})" : '' // add unread count if any
        );
    }
    return $text;
}, 10, 2);

Preview

blog-messages-comment-preview