WordPress.org

Ready to get started?Download WordPress

Forums

How to: determine if a comment's user has an account (7 posts)

  1. Galyn
    Member
    Posted 5 years ago #

    I'm trying to figure out how to determine if a person who posts a comment has an account. Once I have the code for that, I'll be able to color code their comments differently than people who don't have an account.

  2. ClaytonJames
    Member
    Posted 5 years ago #

    Is anything here useful?

    http://codex.wordpress.org/Function_Reference/is_user_logged_in

    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:

    http://wordpress.org/support/topic/243349?replies=3#post-984707

    I hope something helps. What a great question!

  3. Galyn
    Member
    Posted 5 years ago #

    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.

  4. Galyn
    Member
    Posted 5 years ago #

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

    http://infinitegames.com/sacred-2-the-new-co-op-hotness/

    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.

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    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.

  6. Galyn
    Member
    Posted 5 years ago #

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

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic