我建议首先禁止垃圾邮件用户。
但最重要的是,我不知道Search Meter插件的性能。使用Google Analytics或StatCounter等免费工具,您可以验证搜索是否真的发生过。
解决方法
由于您有搜索发生时的准确时间戳,您还可以获取用户的身份,例如IP地址。任何像Google Analytics或StatCounter这样的免费工具都可以帮助您实现这一点。
在维基百科中,为了禁止坏用户,我们有时会屏蔽用户的IP地址。
插件
<?php
/**
* Plugin Name: WPSE Restrict Unwanted Users
* Author: 22728
* Version: 1.0.0
*/
/**
* Get the user\'s IP address
*
* For the prohibition of multiple vote count on Star Rating, we are grabbing the
* user\'s IP address and storing it to database for the time we want to restrict
* the user into voting again.
*
* @author Barış Ünver
* @link http://code.tutsplus.com/articles/creating-a-simple-contact-form-for-simple-needs--wp-27893
*
* @return string IP address, formatted.
*/
function wpse_306059_22728_get_the_ip() {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
return $_SERVER["HTTP_X_FORWARDED_FOR"];
}
elseif (isset($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
}
else {
return $_SERVER["REMOTE_ADDR"];
}
}
/**
* Restrict the user and display a message.
*
* @see wpse_306059_22728_get_the_ip()
* @see wp_die()
*
* @return void
*/
function wpse_306059_22728_restrict_user() {
// Get the list of blocked IP address in comma separated string.
$black_list = \'0.0.0.0, 1.1.1.1, ::1\'; // use get_option(\'your_spam_user_block_list\')
// make it an array
$block_array = explode(\',\', $black_list);
$block_array = array_map(\'trim\', $block_array); // remove the spaces
// get current user\'s IP address
$current_user_ip = wpse_306059_22728_get_the_ip();
// Restrict the user
if( in_array($current_user_ip, $block_array) ) {
$message = \'<h3>\'. __(\'Access Restricted\', \'wpse-restrict-unwanted-users\') .\'</h3>\';
$message .= \'<p>\'. __( \'It seems the IP address you are using is spamming us. We are sorry for your inconvenience, but your access to the site is restricted.\', \'wpse-restrict-unwanted-users\' ) .\'</p>\';
$message .= \'<p>\'. sprintf(
__( \'If the message seems wrong to you, please contact us by emailing at: <strong>%s</strong>\', \'wpse-restrict-unwanted-users\' ),
antispambot( \'[email protected]\' )
) .\'</p>\';
wp_die(
$message, // message
__( \'Access Restricted\', \'wpse-restrict-unwanted-users\' ) // page title
);
}
}
add_action( \'wp\', \'wpse_306059_22728_restrict_user\' );
NOTE在第44行,我将列入黑名单的IP地址硬编码。最好使用
WordPress\' Options API 并使用文本区域输入受限制的IP地址,并将其保存到
options
表,然后使用
get_option()
获取变量中的值。
Be Aware
使用IP地址阻止用户也有自己的注意事项。如果IP地址不是专用的,则下一个使用相同IP的真实用户将被阻止。
在这种情况下,可以执行临时阻止操作。您可以不断添加/删除IP地址以查看性能的任何改进。但如果你不在乎,没关系。