• Hi All,
    I’d like to work on a plugin that allows me to offer the rating of posts to registered users.
    Ideally, I’d like registered users to only be able to rate a post 0 or 1 times. ie, I’d rather users didn’t inflate or deflate ratings by voting multiple times.
    The mechanism I have in mind is relatively simple — store in a table the post id, user id and rating whenever a registered user rates a post, and skip displaying the ‘rate it’ link if the table contains a rating for the user in question on the post in question.
    My question is, is there a global variable I can check to work out:
    – if the person requesting the page is logged in
    – what their user id is, if they are?
    Any help appreciated!
    Much warmth,
    planetthoughtful

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter planetthoughtful

    (@planetthoughtful)

    Hi podz,
    Thanks for this, but I’m not trying to work out how many users are online, but if the page is being requested by a logged-in user.
    I’m aware, for example of a global variable $user_level, which I check in one of my own plugins to see if I should display an ‘edit this’ link next to my footnotes.
    I guess I could experiment with the availability of a $user_id variable, but was hoping someone could confirm or deny its existence up front.
    But thanks, again, all the same!
    Much warmth,
    planetthoughtful

    Thread Starter planetthoughtful

    (@planetthoughtful)

    Sigh. Doesn’t matter. Should have just tried a search using ‘$user_id’. Doing so has demonstrated that it does exist and I should be able to use it for my plugin.
    * shakes head at self *
    Much warmth,
    planetthoughtful

    Thread Starter planetthoughtful

    (@planetthoughtful)

    Okay, I have a variation on the above issue.
    I want to pass a link to a page of my own which will insert some values into a database.
    On that page I want to be able to verify that the information in GET string matches the information WordPress makes available about the current user. In particular, I want to make sure people aren’t ‘spoofing’ other users when registering ratings on posts, since they will only be able to rate each post once on their own login.
    I can’t for the life of me find how to make $user_login / $user_ID etc available to my page. The population of these variables doesn’t appear to be encapsulated in any one function.
    So, can anyone either point me at an include / function I may be overlooking, or help me mirror the population of those variables in my own function, to be used in my page?
    Any help appreciated!
    Much warmth,
    planetthoughtful

    Thread Starter planetthoughtful

    (@planetthoughtful)

    Laugh. Okay, never mind again.
    Figured out that the key to this is generating the cookiehash (ie md5 of site url – see What is the cookiehash?), by which I can retrieve the logged-in user’s user name, which I can use to verify that the id in the GET string matches the logged-in user’s details.
    In fact, thinking about it, I should be able to do away with passing the ID in the GET string at all, now I can retrieve the user name.
    Returning you to your regular broadcasting…
    Much warmth,
    Murray

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Determining if current visitor has logged in?’ is closed to new replies.