Here are some WordPress Comments Related Snippets

Here are some Comments Related Snippets:

1. close the ability to comment globaly

function closeCommentsGlobaly($data) { return false; }
add_filter('comments_number', 'closeCommentsGlobaly');
add_filter('comments_open', 'closeCommentsGlobaly');

2. Give admin a different Css Class for he’s comments

if (1 == $comment->user_id)
echo 'siteadmin'; // pick your class here

3. a really cool rich with data list of comments – gr8 for custom locked page

$comments = get_comments( array(
    'number'    => 10, // how many comments
    'status'    => 'approve' // type of comments
) );

foreach($comments as $eachComment){

// collect the data and assign it
$commentID = comment_ID;
$commentAuthorEmail = $eachComment->comment_author_email;
$commentPostId = $eachComment->comment_post_ID;
$commentPostTitle = get_the_title( $commentPostId );
$commentPostUrl = get_permalink( $commentPostId );
$comment_sidebarnumber = get_comments_number( $commentPostId );

global $wpdb;
$userCommentCount = $wpdb->get_var('SELECT COUNT('.$commentID.') FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . $commentAuthorEmail . '"');

    echo    '<div style="border: 1px solid #ccc; padding: 10px;">';
    echo    '<ul style="margin: 0px;">';
    echo    '<li>Name: '. $eachComment->comment_author .'</li>';
    echo    '<li>Commented about: <a href="'.$commentPostUrl.'">'. $commentPostTitle .'</a></li>';
    echo    '<li>Commented On: '. $eachComment->comment_date .'</li>';
    echo    '<li>Commneter Site: '. $eachComment->comment_author_email .'</</li>';
    echo    '<li>Commenter Email: '. $eachComment->comment_author_email .'</</li>';
    echo    '<li>This Commenter'. $eachComment->comment_author .' Commented '. $userCommentCount .' on your site</</li>';
    echo    '</ul>';
    echo    '<p style="padding: 10px;"><strong>'. $eachComment->comment_author .' wrote</strong>: '. $eachComment->comment_content .'</p>';
    echo    '</div>';

}

You may also like...

Leave a Reply

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