Maison >php教程 >php手册 >允许老用户发表纯英文评论

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

WBOY
WBOYoriginal
2016-06-06 20:09:291313parcourir

Allow people who have commets approved to submit a non-Chinese comment. No miscarriage of justice any more. 允许"曾在本站发表过评论且通过了审核"的用户发表纯英文评论 , 妈妈再也不用担心我的误判. 灵感来自于wordpress默认讨论选项中的"评论者先前

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: xiaohudie
    * 2013-05-20
    */
function butterfly_en($comment) {
	$pattern = '/[一-龥]/u';  
	$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.');
	} 
} 
add_filter('preprocess_comment', 'butterfly_en'); 

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn