如果我們的WordPress有開啟允許評論功能的話,你會發(fā)現(xiàn)會有各種的國內(nèi)國外的軟件群發(fā)評論的。所以我們有些時候直接禁止評論,如果有需要聯(lián)絡(luò)的直接社交軟件聯(lián)絡(luò)。我們也要知道國內(nèi)的非企業(yè)網(wǎng)站或者交互允許的是不允許開通評論的。
這里有幾個有用的代碼能夠禁止 WordPress被非人工的評論。
禁止評論包含網(wǎng)址:
//禁止評論中有鏈接 function wp_comment_post( $incoming_comment ) { $http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u'; if(preg_match($http, $incoming_comment['comment_content'])) { err( "禁止發(fā)鏈接地址!" ); } return( $incoming_comment ); } add_filter('preprocess_comment', 'wp_comment_post');
評論內(nèi)容必須有中文:
這樣可以防止海外的群發(fā)軟件。
// 評論必須有中文 function wp_refused_spam_comments($comment_data) { $pattern = '/[一-龥]/u'; $jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u'; if (!preg_match($pattern, $comment_data['comment_content'])) { err(__('評論中需要有一個漢字!')); } if (preg_match($jpattern, $comment_data['comment_content'])) { err(__('不能有日文!')); } return ($comment_data); } add_filter('preprocess_comment', 'wp_refused_spam_comments');
是不是還不錯?
評論