admin管理员组文章数量:1122846
Once in a while, I get comments like these:
苍天有眼啊,让我在有生之年得以观得如此精彩绝伦的帖子。
They are absolutely useless to me. I don't even know if it's Chinese / Japanese / Korean / ...
How can I tell WordPress to automatically delete (not just spam) those messages?
Once in a while, I get comments like these:
苍天有眼啊,让我在有生之年得以观得如此精彩绝伦的帖子。
They are absolutely useless to me. I don't even know if it's Chinese / Japanese / Korean / ...
How can I tell WordPress to automatically delete (not just spam) those messages?
Share Improve this question asked Oct 7, 2013 at 9:47 Martin ThomaMartin Thoma 20010 bronze badges3 Answers
Reset to default 2Those characters you quoted here are Han (used by Chinese language), as they matched by the unicode character property \p{Han}
.
You can perform a regular expression search in a plugin like so:
<?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 );
The control function wpse_116973_has_unallowed_char()
searches for all characters of Chinese (Han), Korean(Hangul) and Russian (Chyrillic) languages. The plugin move those comments to trash.
If someone just want to mark them as spam, use the filter pre_comment_approved
like this:
/**
* @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 );
You can use the built in black list function in Dashboard > Settings > Discussion http://www.example.com/wp-admin/options-discussion.php
, add a few characters from the alphabet you want to exclude and it won't bother you again...I guess.
The proper solution is here: How To Automatically Trash Non-English Comments In WordPress
It will work for Russian, Chinese, or any other language.
本文标签: spamHow can I automatically delete comments that contain chineserussian signs
版权声明:本文标题:spam - How can I automatically delete comments that contain chineserussian signs? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298146a1930166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论