Support » Themes and Templates » How to: determine if a comment’s user has an account

How to: determine if a comment’s user has an account

Viewing 6 replies - 1 through 6 (of 6 total)
  • Is anything here useful?


    My thinking is along the lines of leaving non-logged in user comments the default colors, and maybe giving logged in users another color, or an un-obtrusive identifying tag of some sort. but I have no idea what type of conditional statements would need to follow.

    Maybe another option would be fine tuning it with something like the references in this thread:


    I hope something helps. What a great question!

    The trick is that comment users are treated so much differently than Posts users, which is definitely understandable. I just wish that the two were a *little* more alike.

    If a user is logged in and posts a comment, it actually records their user id, so I could code to check against the user id, if it’s greater than 0, it’s a person with an account. The problem with that is if a person with an account happens to post without signing in, it records them as having a user id of 0, even if the email addresses are the same. (Which, bothers me, sorta, because it can allow people who aren’t that user to post comments as them as long as they know their email address, admittedly, the comment still has to be approved, but it just seems to be a big hole in security.)

    There is a function: email_exists() that would solve the problem, but it is only live on the user and registration pages.

    So for now, until some things change, I think the solution is to check and see if the user id of the comment is greater than 0, and just make sure all my users know to log in BEFORE posting comments.

    Ok, so here’s a link on my website with an example of what I’m doing…


    and here’s the code:

    <?php if($comment->user_id == 0) {echo "<span style='background:gray; color:#FFF;'>Non iG Comment</span>" ; } ?>

    I also have it in other places to give the grey text color and grey border background.

    This link also shows a test comment, where I, as a registered user with an account, have entered a comment without logging in, using the same email address that I am registered with. I’ve approved the test comment, and of I was allowing gravatars to non-iG comments, it would show the same avatar as the original post. However, because I did not sign in, it has set the user_id in the $comment variable to 0. It would be nice if, when approving a comment, wordpress checked to see if the email was the same, then asked the approver if it is the same as X user, if the approver says yes, it assigns that user’s id to user_id in the comments record.

    If you’re using the new 2.7 theme stuff (specifically, the comment_class() function) in your theme, then it adds a “byuser” class to the comment for any/all logged in users. This can be used for styling.

    I haven’t seen much on the new 2.7 theme stuff, I’ll have to do some research on that.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to: determine if a comment’s user has an account’ is closed to new replies.