Home > Article > CMS Tutorial > 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 = '/[一-?]/u'; // 禁止全英文评论 if(!preg_match($pattern, $incoming_comment['comment_content'])) { wp_die( "You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience! 您的评论中必须包含汉字!" ); } return( $incoming_comment ); } ?>