How to hide a Fivestar field in a comment when the user didn't vote? The comments on my articles have a Fivestar field called 'Stars', but rating nodes isn't always required (see: How to hide rating field when adding comment to own node?). When the user didn't rate the node on which he/she is reacting, 0 stars (not saved in the database) are now being displayed in his/her comment, but I don't really like that.



How can I hide the stars when the user didn't vote?



Edit: I'm trying to find a workaround with flags. I've created a flag called 'Reaction on own' and a rule that flags a comment when the comment's author equals the author of the commented node. In my case, it's sufficient that the 'Stars' field isn't displayed when a comment is flagged with 'Reaction on own'. This is the code of my custom module:

function hiderating_comment_view($comment) {
  $flag = flag_get_flag('reaction_on_own');
  if ($flag-&gt;is_flagged($comment-&gt;cid)){
    unset($comment-&gt;field_stars);
  }
}


Unfortunately, this isn't working. What's going wrong?



Note: In fact, the edit above isn't entirely true in my case, because 'zero' stars appear when a user reacts on his/her article or when the user has commented before. I've provided an answer for both cases.
You could try an approach like this (untested) but may work

/**
 * Implements hook_comment_view
 */
function hiderating_comment_view($comment) {
  if($flag = flag_get_flag('reaction_on_own')){
    // Debug comment to find field to hide, check dblog / watchdog
    debug($comment);
    if (!$flag-&gt;is_flagged($comment-&gt;cid)){
      unset($comment-&gt;field_stars);
    }
  }
}