允许老用户发表纯英文评论

Allow people who have commets approved to submit a non-Chinese comment.
No miscarriage of justice any more.
允许"曾在本站发表过评论且通过了审核"的用户发表纯英文评论, 妈妈再也不用担心我的误判.

灵感来自于wordpress默认讨论选项中的"评论者先前须有评论通过了审核"这一项, 我在wp-includes/comments.php中找到了相关动作, 此动作在get_option('comment_whitelist')后触发, 我觉得可以用在纯英文评论上

以上是废话, 以下代码扔到functions.php

   /**
* allow old users to submit english comments
* coder:
* 2013-05-20
*/
function butterfly_en($comment) { $pattern = '/[一-龥]/u'; $ccontent = htmlspecialchars($comment['comment_content']); $cau=$comment['comment_author'] ; $cem=$comment['comment_author_email'] ; global $wpdb; $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$cau' AND comment_author_email = '$cem' and comment_approved = '1' LIMIT 1"); if( is_user_logged_in() || 1 == $ok_to_comment ){ return $comment; } elseif ( !preg_match_all($pattern, $ccontent, $match) ) { exit('sorry, please type some Chinese words like 小蝴蝶最漂亮 in your comment to pass the spam-check.'); } else{return $comment; } } add_filter('preprocess_comment', 'butterfly_en');

大家可以尽情测试, 测试方法(前提你之前在小蝴蝶评论过):
你可以成功的提交一条纯英文评论了, 不会英文的同学可以复制这一句: smallbutterfly is very beautiful
然后你可以改一下你的昵称, 然后再发一条纯英文评论试试

73 Comments

Name *

E-mail *

Website

  1. Vind

    small butterfly和little butterfly 是不一样的概念哦!

  2. 梦月酱

    papapa~

  3. 灰狼

    bigbutterfly is very beautiful

  4. SEO博客

    wo bu hui ying wen za ban a ? ni kan ming bai wo shuo sha le ma ? qin ! qi shi wo yi zhi an lian ni.

  5. 海蓝

    Can really do?看来不行

  6. LYT博客

    Nothing happened…
    对不起,为了防垃圾评论,评论内容中必须带有中文字符.

  7. figo

    在自己的主题测试不行,任何评论都禁止了……

    • 小蝴蝶

      @figo 写丢了一个参数,已经修改过来,现在你试试一定可以了

  8. ray1980

    smallbutterfly is very beautiful