INCLUDE_DATA

WordPress Plugin: Rate Your Comments (Comment Karma)


Comment Karma not working for you?

Since a large number of people are both successful and in need of assistance, I can’t and don’t have enough time to help everyone. If you’re willing to pay a small donation for me to install or modify the plugin on your blog use the contact form. You may also email th3rub3x|@|gmail[dot]com (same as paypal).


After searching Google for a few minutes for a comment karma/rating plugin for WordPress I was amazed I couldn’t find one. So I read through WordPress documentation for a bit, and dug in.

Comment Karma 1.1 Release
Fixed:
*Security issue.
*Hovering over the images gives you a mouse cursor now.

Comment Karma 2.0 Release
Fixed:
*Security issue.
*Better MySql queries and table indexing to increase performance.
*Allows you to see how many times a comment has been modded up, down, and the total.
*No longer displays to negative signs when a comment is below zero.

*When upgrading to 2.0 your existing comment karma count will be lost due to the new database structure. This is because it’s now tracking both up and down votes, and before it was just adding and subtracting from one number.

What is it
This is a plugin for WordPress blogs that allows users to rate or moderate other users comments. You can click thumbs up or down, and it will give them a positive or negative number. Basically the exact same thing you’ll find on Digg or Slashdot.

Issues
Currently there are no known issues, it works like a charm. If you’re using WP-Cache or similar the icons will not show up gray, nor will the numbers be updated if you reload the page until the page expires. However if a user votes again it will throw them an error. I’ve worked around this by setting the cache for 120 seconds. That way the server doesn’t get hammered with SQL queries, but you still see the comments being moderated in almost real time.

If you’re having trouble installing 2.0 from 1.1, try deactivating the plugin, deleting the files and reupload them. Proceed to PHPMyAdmin and drop the ck_karma table. (Sorry, it’s the only way). Then enable the plugin and use it as you normally would.

Installation

Unzip the folder you downloaded, and upload the whole thing in to your plugins directory. You’ll need to edit your header file, and add:

<script type=”text/javascript” src=”http://domain/wp-content/plugins/ck-karma/ck-karma.js”>
</script>

I added mine directly under the head tag. Next depending on your theme you need to edit your comments theme file. You need to add ck_display_karma(); in your comment’s for each loop. Look for “foreach ($comments as $comment)”. You can insert it in that loop. Mine happens to be here:

<?php if (comment_subscription_status()) { echo ” (subscribed to comments) “; } ck_display_karma(); ?>

Lastly enable it via plugins page. That should install all the needed tables.

Questions? Comments? Bugs?
If you have questions about installing or using it you can post a comment on this post. This is so people having the same issues can easily get the fix. If you’re willing to pay a small donation for me to install or modify the plugin in any way use the contact form. You may also email th3rub3x|@|gmail[dot]com (same as paypal).

Download
Comment Karma 2.0
Comment Karma 1.1

Thanks to
Bawked - Wrote the ajax, and debugged the PHP.


Hey even a few dollars helps!

Enjoy - Rub3X and Bawked!

24 Responses to “WordPress Plugin: Rate Your Comments (Comment Karma)”

  1. Rub3X Says:

    This is a test comment, so you can see the ratings. Enjoy!

  2. Ian Harris Says:

    Hello. I wonder how hard it would be to rank the comments according to their rating? So poor comments get buried and good comments rise to the top. I guess it would be difficult?

  3. Raj Says:

    Hi,

    I have activated this on my new site; keepreadingus.com [using wp v2.0.5], but the voting images are always grayed out. Why is this so?

    Does the plugin take into account the IP of the machine fromw hich the commpent is posted from?

    Or is this some kind of error that needs to be fixed. I even tried logging out and checked, but they ares till grayedout.

    Thanks for any help.

  4. josh Says:

    Hey, great plugin. I’m wondering if there is a function to get the highest rated comment for a post? So when I display a link to a post I can also include some, if not all of the highest rated comment. Any thoughts? Also, and I think you may be adding this to the new build, but I’d like to sort the comments from highest to lowest for a particular post. Thanks again!

  5. Jason Says:

    Is there anyway to make this so it does not check IP’s per rating. I am in college and many of my sites visitors are from my college, which only has one external IP address due to the way the network is setup. Thus only one person can make a rating on the posts, and all others are blocked from doing it.

    Thanks

  6. Alex Bailey Says:

    [quote comment="7559"]Is there anyway to make this so it does not check IP’s per rating. I am in college and many of my sites visitors are from my college, which only has one external IP address due to the way the network is setup. Thus only one person can make a rating on the posts, and all others are blocked from doing it.

    Thanks[/quote]

    Comment out this line

    $ck_ips = $row['ck_ips'] . getenv(”REMOTE_ADDR”);

    In ck-processkarma.php. A comment is // in front of the line by the way. Everyone will be able to vote unlimited amounts of times if you do this.

  7. James Says:

    How hard would it be to modify this seemingly very cool plugin to allow the readers to rate the posts as well as the comments?

    And will there be any way of “easily” administering the images used for up.png and down.png? Having that feature in the options section (I’ll assume there is one) would be sort of cool.

    Thanks.

  8. Bawked Says:

    coderweb.n...%201.2.zip <- small fix

  9. Alex Schleber Says:

    Hi,

    I was wondering how the “bury” is actually implemented, since I couldn’t find anything about it in your plugin code.

    As a quick hack, I added a function to ckarma.php:

    function get_cmt_karma($id) {
    global $ckarma;
    $karma = $ckarma->getKarma($id);
    return $karma;
    }

    that I then call in my comments (foreach) loop right at the top:

    $karma = get_cmt_karma(get_comment_id());
    if ($karma < -9) continue;

    So we skip over “buried” comments with ratings of -10 or less; set your own threshold here.

    Then you can also use this as a qualifier when writing the comment header info to turn off e.g. a DoFollow link for a spammy comment.

    Anyway, hope someone finds this useful, I would still be interested if there was some sort of implementation of the “bury” that I overlooked.

    I too am working on a way to get the top comment for a post, easiest would likely be to add a field ck_post_id to the table and save this on “insert”. Else it’s going to have to be a pretty messy (and slower) join of the wp_comments and wp_ckTbl_ tables.

    Thanks for the great plugin.

  10. Alex Schleber Says:

    Here is the example code for the DoFollow link suppression on spammy comments (note that the threshold for this would be set to lower than for “bury”

    if (get_comment_author_url() && ($karma > -5)) {
    display comment_author() inside of comment_url() link …
    } else {
    display comment_author() only
    }

  11. wrongling Says:

    Thanks for the extra code snippets everyone - this plugin has so much potential. How difficult would it be to highlight every comment rated above a certain threshold with a css style? (ie every comment rated +20 or above gets a colored background to highlight it, or an icon, gold star, etc).

  12. Alex Schleber Says:

    I finally got around to creating the function to return the top-rated comment
    for a given post:

    function get_top_comment($postId) {
    global $wpdb;
    $sql = “SELECT comment_ID, comment_date, comment_author, comment_author_url, comment_content, SUM(ckTbl_rating) AS ratings_total
    FROM wp_ckTbl_commentMain, wp_comments
    WHERE ckTbl_comment_id = comment_ID
    AND comment_post_ID = $postId
    GROUP BY ckTbl_comment_id
    ORDER BY ratings_total DESC, comment_date ASC;”; // the date is the tie-braker, earlier comment wins

    $comments = $wpdb->get_results($sql);
    $topcmt = $comments[0]; // take the top-most one, we have sorted for it to be the top comment
    if (!$topcmt->comment_ID) $topcmt=0; // if it’s not set, return 0
    return $topcmt;
    }

    in ckarma.php:

    function get_top_comment($postId) {
    global $ckarma;
    $topcmt = $ckarma->get_top_comment($postId);
    return $topcmt;
    }

    then use

    $topcmt = get_top_comment(get_the_ID());

    $topcmt->comment_author

    and so forth in e.g. the while(have_posts()) loop in your index.php to do stuff with the top comment, or place elsewhere in your templates or custom widgets.

    Watch this function in action on my blog:

    businessmi...dhacks.com
    (top comment excerpt with DoFollow link displayed if present for every post on the index page)

    Best - Alex

  13. KC Says:

    When I installed it first time, the images were grayed out. Turns out I did not create sub directories (images and RCS) in plugins directory while uploading to the server. Make sure you follow the directory structure in the zip file

  14. MikeonTV Says:

    Why is it that the newest version is not the same template as what we have in this discussion?

    I would like to have the two vote buttons and then the tallied number next to it rather than how many up votes next to the thumb up and how many downs next to the thumb down. Can you specify how to do this?

  15. Sally Says:

    When I installed it first time, the images were grayed out. Turns out I did not create sub directories (images and RCS) in plugins directory while uploading to the server. Make sure you follow the directory structure in the zip file

    - I’m getting the same problem as Raj did. I have the folders “images” and “RCS”, but inside the ck-karma directory, not inside its parent (which is plugin) dir.

    Why? Is it because I’m testing it locally (localhost/127.0.0.1)? :P If so, what should I do to fix the problem?

  16. SPiHC Says:

    I’ve noticed a few different people ask if it would be possible to sort the comments by current rank.

    I was wondering if it’d be possible to take Alex Schleber’s addition there and modify it into a top 10 / top 5 listing?

    Cheers,
    SPiHC

  17. drew3000 Says:

    Got it to show up with a little tinkering (plus my theme’s calls are different from the usual) but it’s not really allowing people to actually vote. It just shows up. The curser ctivates when hovering over but when you click thumbs up or down, nothing changes. Anyone have anything similar?

  18. MitchMoore Says:

    Any help available… I installed the plugin as directed. Everything shows up and it seems to be fine, but when I try to vote up or down it doesn’t do anything?

    Even the ones for the comments on this page wont let me vote… I get an error msg on this page, but nothing on mine.

    I just upgraded to WP version 2.6.5 anyone have an ideas or suggestions? THX!!

  19. magic Says:

    everything is possible. btw, alexes method is for karma 1 and to the old database structure. Also the first function would be enough. You could also take alexes mathod and have it return the comments so you could loop through that and have the comments sorted by most rated etc.

  20. Peter Says:

    How can this be integrated into Wordpress 2.7 comments ?

    As there is no “foreach” anymore.

    Thanks.

  21. Michael Says:

    Hey, I got a problem, nothing big, just annoying: If someone rates a comment the space between the icon and the current score disappears and everything right to the icon slips a few pixels to the left. Has anyone an idea how to avoid that?

    Thanks, Michael

  22. Voucher Codes Says:

    Many thanks for this superb plugin.

    Will be interested to learn the compatibility with 2.7 though.

    Is there anyway i can call a list of the most voted comments?

  23. Bawked Says:

    holy shit my inbox still gets hit by this…… i might tweak it to work with 2.7 for those out there.

  24. Peter Says:

    Any advance in making it work with 2.7 or 2.8 that its coming out ?

    Thanks.

Leave a Reply