Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds a star to WordPress comments (using the WP-Comment-Rating Plugin) that have more than 5 upvotes.
<?php
/*
Plugin Name: Add stars to comments
Description: Adds stars to comments when comment gets 10 up-votes
*/
add_filter( 'wpbcr_output_elements', 'my_wpbcr_output_elements', 10, 2 );
function my_wpbcr_output_elements( $elements, $comment ) {
$rating = isset( $comment->comment_wpbcr_rating ) ? intval( $comment->comment_wpbcr_rating ) : intval( get_comment_meta( $comment->comment_ID, 'wpbcr_rating', true ) );
if ( $rating >= 5 ) {
$elements[] = ' <span class="wpbcr-icon wpbcr-icon-star"></span>';
}
return $elements;
}
@code-flow

This comment has been minimized.

Copy link
Owner Author

@code-flow code-flow commented Feb 12, 2014

Name this file maybe my-add-stars-to-comments.php and put it into the /wp-contents/plugins/ folder. Then activate it from the plugins menu in your administration panel.

If you want to show your own image replace the span-element (line 14) maybe to this:

$elements[] = ' <img src="http://url-to-your-image.com" alt="stars" />';

If you want to show the star when upvotes are more than 10, replace line 13 with:

if ( $rating >= 10 ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.