views:

115

answers:

1

Whats the best practice for getting a commenter's email address from the cookie (this is for a WordPress plugin)? Part of my plugin relies on having an email address and I'd like to try to get it even if they are not logged in by checking for the existence of a comment cookie (which should be there if they've made a comment in the last year and haven't cleared cookies).

According to http://codex.wordpress.org/WordPress_Cookies a comment_author_email cookie is created but is hashed. Is there a built in function to get the value for this or do I need to write that myself?

To be clear: I may need to get this at any time, not just when making a comment so I need to get it from the cookie rather than a comment object which may or may not exist.

+2  A: 

You should be able to do the following:

if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) {
    $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH];
    echo 'Comment Author Email: '.$$comment_author_email;
}

Sources:

Daniel Vassallo