Mark Comments by Current User

To highlight comments of the currenly logged-in user, add this plugin:

<?php
/*
Plugin Name: Comment Class for Logged-In User
Plugin URI: n/a
Description: add the comment_class .comment-author-logged-in for the comments of logged-in users.
Version: 1.0
Author: alchymyth
Author URI: http://transformationpowertools.com
License: GPL2
*/

add_filter( 'comment_class', 'comment_class_logged_in_user' );

function comment_class_logged_in_user( $classes ) {
	global $comment;
	if ( $comment->user_id > 0 && is_user_logged_in() ) {  
		global $current_user; get_currentuserinfo(); 
		$logged_in_user = $current_user->ID;  
		if( $comment->user_id == $logged_in_user ) $classes[] = 'comment-author-logged-in';
	}
return $classes;
}

//  requires formatting of the css class: 
//  .comment-author-logged-in { }
?>

Add a file with the above code into the /wp-content/plugins folder; activate the plugin under ‘appearance – plugins – installed plugins’; and add a corresponding style to the stylesheet of the currently used theme.

The code compares the comment author’s ID with the ID of the logged-in user, and adds the class .comment-author-logged-in to the ‘comment_class’ output.

Leave a Reply

Your email address will not be published. Required fields are marked *