Find out which moderator approved comment?

Is there any way to find out what moderators have approved a comment, and then display that information on the front-end?

e.g.

John says: “This is a great article”
– Approved by Admin1

1
1

To record the moderator that approves the comment:

function wpse_comment_moderator_log( $comment ) {
    global $current_user;
    get_currentuserinfo();

    update_comment_meta( $comment->comment_ID, 'approved_by', $current_user->user_login );
}
add_action( 'comment_unapproved_to_approved', 'wpse_comment_moderator_log' );

To display it after the comment text:

function wpse_display_moderator( $comment_text, $comment ) {
    $approved_by = get_comment_meta( $comment->comment_ID, 'approved_by', true );
    if ( $approved_by ) {
        $comment_text .= " - Approved by $approved_by";
    }
    return $comment_text;
}
add_filter( 'comment_text', 'wpse_display_moderator', 99, 2 );

Leave a Comment