Support » Requests and Feedback » Comments should also associate user ID if applicable

  • Okay, one thing that’s really getting me… I’d love to see Comments for articles also have an extra database field to link to a WordPress user’s user_id, if they post whilst logged in.

    In this way it is easy to see if a comment is from a registered user, or an anonymous user. It goes a bit further. I would like to be able to highlight any posts that I make on my site, but as I use my first name (Mike), an anon user can also post with that name. I do not want to disallow this, but I do want to be able to separate my posts from posts made by anon.

    A huge bonus for this could also be pulling the user’s name from the DB. At the moment the name is stored along with the comment every single time you post; If you change how your name is displayed it will not retrospectively update old names unless you manually hack the DB.

    I know there’s probably argument for “oh, but if you store the name in one table then it’s less db calls”… but I’d rather have more functionality and abstraction than flattening everything 🙂


Viewing 4 replies - 1 through 4 (of 4 total)
  • Oh wait… maybe I’ve already answered my own problem by the fact that I didn’t browse the comment structure thoroughly enough. There’s a user_id field nestled in there. Let’s see if it does what I want it to 😉

    Update: Well, for some unknown reason, WordPress stores the user_id of the logged in user… BUT THERE IS NO BUILT-IN WAY TO ACCESS THIS. You have to hack the comment functions to get it to store this extra info. Naughty WordPress! 😛

    I do believe it stores it automatically. How else would it get into the database then? I mean my userid is stored for all of my personal posts.

    I meant to say retrieve the second time. Took some messing about, but I managed to write a plugin to grab the comment author’s ID so it can be checked against the article poster’s ID.

    Messy, but it works. Still, I’d love it if WordPress had a better way of grabbing info. Rather than relying on a thousand and one functions, perhaps having a generic one which you pass the field name to would be a better option.

    Like: get_comment_field(‘user_id’); get_comment_field(‘post_id’);

    Sure, I can write one easily enough… but it would be a good thing for WordPress to do something like this at the official level because it’d simplify the template calls significantly.

    Within the comment loop:

    if ($comment->user_id) echo "Registered User";
    else echo "Guest";

    Would also be very easy to setup where if a user changes their display name in their profile, it’ll change on all of their comments too (not in the database, just on display). Can provide the code if wanted, but it’d bump up the queries by 1 per comment that’s done by a registered user at the most (possibly less).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Comments should also associate user ID if applicable’ is closed to new replies.