Skip to content

Instantly share code, notes, and snippets.

@code-flow
Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save code-flow/8950977 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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