Please don’t use addslashes to escape things for SQL (it’s potentially dangerous), use $wpdb->prepare("SQL with %s placeholders", $string)
. It will put the data into the placeholder’s … place and take care of escaping, giving you SQL that is safe to execute.
Anyway. Your question is how to give them a different background color based on the comment count?
Why not keep it simple and change
return $author_name .' | <span class="wpdiscuz-comment-count">'.$comment_text.'</span>';
to
$bgcolor="#CCCCCC"; // default
if($count > 800) $bgcolor="#FF00FF";
if($count > 500) $bgcolor="#00FFFF";
if($count > 250) $bgcolor="#FFFF00";
if($count > 100) $bgcolor="#800000";
return $author_name . ' | <span class="wpdiscuz-comment-count" style="background-color: ' . $bgcolor . ';">' . $comment_text . '</span>';
Or have I completely missed the point and failed to understand what you are trying to do?
To manipulate the left part of a comment, you can go for something like
add_filter('wpdiscuz_after_label', 'my_badgeCount', 10, 2);
function my_badgeCount($html, $comment) {
global $wpdb;
$count = $wpdb->get_var( $wpdb->prepare('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments . ' WHERE comment_author_email = %s', $comment->comment_author_email) );
if($count > 9) return $html . '<img src="https://wordpress.stackexchange.com/wp-content/uploads/badge-great.png" alt="great user" />';
if($count > 6) return $html . '<img src="/wp-content/uploads/badge-good.png" alt="good user" />';
if($count > 3) return $html . '<img src="/wp-content/uploads/badge-ok.png" alt="ok user" />';
return $html;
}
You’ll have to adapt the conditions and images, obviously. Also note the $wpdb->prepare() use. Not only is it safer, I find it much easier to read, too.