Home > CMS Tutorial > WordPress > body text

How to prohibit WordPress comments from specifying content in English

藏色散人
Release: 2020-01-04 10:11:29
Original
2421 people have browsed it

How to prohibit WordPress comments from specifying content in English

How to disable comments in WordPress that contain specific content in English?

The example in this article describes how WordPress prohibits comments on specified content in English. Share it with everyone for your reference. The specific analysis is as follows:

Recommendation: "wordpress tutorial"

The first thing to filter out in WordPress comments is all-English spam. This is simple. We only need to check whether the Chinese characters are included. Sometimes we want some sensitive words not to be submitted. All we need is a simple filtering function.

Many friends may find that there is a lot of English garbage discussion content , here is a function, the code is as follows:

The code is as follows:

<?php 
function scp_comment_post( $incoming_comment ) { 
$pattern = &#39;/[一-?]/u&#39;; 
// 禁止全英文评论 
if(!preg_match($pattern, $incoming_comment[&#39;comment_content&#39;])) { 
wp_die( "You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience! 您的评论中必须包含汉字!" ); 
} 
return( $incoming_comment ); 
} 
?>
Copy after login

The following code prohibits comments from containing

The code is as follows:

function lianyue_comment_post( $incoming_comment ) { 
$http = &#39;/[href="|rel="nofollow"|http://|</a>]/u&#39;; 
if(preg_match($http, $incoming_comment[&#39;comment_content&#39;])) { 
wp_die( "万恶的发贴机!" ); 
} 
return( $incoming_comment ); 
} 
add_filter(&#39;preprocess_comment&#39;, &#39;lianyue_comment_post&#39;);
Copy after login

I hope this article will be helpful to everyone’s WordPress website building.

The above is the detailed content of How to prohibit WordPress comments from specifying content in English. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template