获取当前未注册用户的姓名和电子邮件,谁最近在评论表中提交了姓名和电子邮件?

时间:2012-07-15 作者:KajMagnus

在WordPress插件中,当当前用户未登录,但最近提交了评论,并在评论回复表单中指定了名称和电子邮件时,是否有任何方法可以获取该用户的名称和电子邮件?

或是名称(&A);只有在处理[用户发布的评论]的HTTP请求期间,电子邮件才可用?

(当用户未登录时WP_User 返回人wp_get_current_user() 调试时我注意到,没有包含有关用户电子邮件或姓名的信息。)

(背景:我正在编写一个评论评级插件,我想强调用户的评级,即使他/她不是注册用户。正如下面的评论所述,可能在任何情况下都需要一些cookie。我仍然有兴趣知道这个问题的答案,但是,也许我可以重用一些现有功能或其他东西)

1 个回复
最合适的回答,由SO网友:KajMagnus 整理而成

未注册用户的姓名和电子邮件可在Cookie中找到,只要他/她留下评论。Cookie的名称如下:

comment_author_3e6aea64ec43ed661a5dee3433f1e8bc
comment_author_email_3e6aea64ec43ed661a5dee3433f1e8bc
您可以这样检索它们:

sanitize_comment_cookies();
wp_get_current_commenter(); // returns comment_author,
                            //   comment_author_email, comment_author_url
它们是在这里创建的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() )
        return;

    $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, ...);
}
(我通过wp-comments-post.php 使用调试器。)

((正如上面原始问题下面的评论所提到的,这有时难道不是隐私问题吗,如果有人在公共图书馆发表评论,那么之后使用计算机的人可能会找到那些“等待验证”的评论,并且知道是谁写的,嗯))

结束

相关推荐