您在此处引用的字符是汉(中文使用),因为它们与unicode character property \\p{Han}
.
您可以在如下插件中执行正则表达式搜索:
<?php
/**
* Plugin Name: Drop comments by chars
* Description: Delete comments which includes unicode characters of Han, Hangul and Cyrillic.
* Version: 2014.02.18
* Author: David Naber
* Licence: MIT
* Licence URI: http://opensource.org/licenses/mit-license.php
* Copyright: (c) 2014 David Naber
* @see http://wordpress.stackexchange.com/q/116973/31323
*/
/**
* check for the occurence of Han, Hangul and Cyrillic characters
*
* @param string $content
* @return bool
*/
function wpse_116973_has_unallowed_char( $content ) {
return (bool) preg_match( \'~\\p{Hangul}|\\p{Han}|\\p{Cyrillic}~u\', $content );
}
/**
* @wp-hook comment_post
* @param int $comment_ID
* @param array $approved
* @return void
*/
function wpse_116973_trash_unallowed_comments( $comment_ID, $approved ) {
$comment = get_comment( $comment_ID );
if ( ! wpse_116973_has_unallowed_char( $comment->comment_content ) )
return;
wp_trash_comment( $comment_ID );
}
add_action( \'comment_post\', \'wpse_116973_trash_unallowed_comments\', 10, 2 );
控制功能
wpse_116973_has_unallowed_char()
搜索汉语(Han)、韩语(Hangul)和俄语(Chyrillic)语言的所有字符。插件将这些注释移动到垃圾箱。
如果有人只想将其标记为垃圾邮件,请使用过滤器pre_comment_approved
像这样:
/**
* @wp-hook pre_comment_approved
* @param bool $approved
* @param array $commentdata
* @return bool|string Returns FALSE, TRUE, or \'spam\'
*/
function wpse_116973_allow_comment( $approved, $commentdata ) {
if ( wpse_116973_has_unallowed_char( $commentdata[ \'comment_content\' ] ) )
return \'spam\';
return $approved;
}
add_filter( \'pre_comment_approved\', \'wpse_116973_allow_comment\', 10, 2 );