Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
1  
This kind of data is not saved natively. So you will need to start capturing and storing such info first. –  Rarst Jun 29 '11 at 18:59
    
sigh I thought so alright. I really need to get myself a developer :( Thanks for the help Rarst! –  James Jun 29 '11 at 19:08
1  
@Rarst would we be talking hooking into something like: add_action('comment_unapproved_to_approved', 'comment_approved'); –  MartinJJ Jun 29 '11 at 20:32
    
@Martin no idea, hadn't looked at code. There are multiple ways that comments are dealt with (admin, notification emails, XML-RPC) and I am not sure how hookable all of it is. –  Rarst Jun 29 '11 at 20:46
add comment

1 Answer

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 );
share|improve this answer
2  
+1 @Hameedullah, i was just building the display function for my effort.. comforting to know for a learner like myself that my record function is almost exact to yours so i was on the right track.... –  MartinJJ Jun 29 '11 at 21:29
2  
Glad we both are on right track, as I am myself still a learner. –  Hameedullah Khan Jun 29 '11 at 21:35
add comment

protected by toscho Jul 4 '12 at 11:55

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.