From within a WordPress plugin, is there any way to get the name and email of the current user, when s/he is not logged in, but has recently submitted a comment, and specified name and email in the comment reply form?

Or is the name & email only available during the HTTP request in which [the comment posted by the user] is being processed?

(When the the user is not logged in, the WP_User returned by wp_get_current_user() contains no info on the user's email or name, I've noticed when debugging.)

(Background: I'm writing a comment rating plugin, and I'd like to highlight the user's ratings, even if s/he isn't a registered user. As mentioned in the comments below, perhaps some cookie will be needed in any case. I'm still interested in knowing the answer to this question however, perhaps I could reuse some existing functionality or something)

  • I think you could probably set some kind of cookie, however users might not like still being half logged in to your site after they log out.
    – fdsa
    Commented Jul 15, 2012 at 2:18
  • How are they authenticated to comment?
    – fdsa
    Commented Jul 15, 2012 at 2:36
  • @fdsa re: authentication: they probably specify name + email (or log in, if they are registered users).
    – KajMagnus
    Commented Jul 15, 2012 at 2:38
  • @fdsa Yes a cookie would probably be needed regardless, in case [someone who has not commented before (so name+email is unknown)] submits a comment rating. Then I'd still like that user to have his/her rating highlighted
    – KajMagnus
    Commented Jul 15, 2012 at 2:40
  • @fdsa "however users might not like still being half logged in" — that's a good point. What if they don't realize that the system highlights their ratings, because of a cookie, and then they leaves the computer. What if it's in a public library — then someone else could find out how they've rated other's comments.
    – KajMagnus
    Commented Jul 15, 2012 at 2:44

1 Answer 1


An unregistered user's name and email are available in cookies, once s/he has left a comment. The cookies are named like:


You can retrieve them like so:

wp_get_current_commenter(); // returns comment_author,
                            //   comment_author_email, comment_author_url

They're created here in comment.php:

 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 * @param object $comment Comment object.
 * @param object $user Comment author's object.
 * @since 3.4.0
function wp_set_comment_cookies($comment, $user) {
    if ( $user->exists() )

    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, ...);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, ...);
    setcookie('comment_author_url_' . COOKIEHASH, ...);

(I found out by stepping through wp-comments-post.php with a debugger.)

((As mentioned in the comments below the original question above, couldn't this sometimes be a privacy issue, if someone posts a comment in a public library — then the one who uses the computer afterwards might find those comments that are "waiting for authentication", and know who wrote them, hmm))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.