Adds a star to WordPress comments (using the WP-Comment-Rating Plugin) that have more than 5 upvotes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ) {