我刚刚完成了我的第一个插件的构建,并在我的个人网站上使用各种插件对其进行了测试,没有任何错误。但是,一些用户说该插件导致他们出现以下错误:
strpos():/west/XXXXX/public_html/wp-content/plugins/bot-block/bot-plugin.php 200 行中的空针
在第 200 行我有这个:
//See if the domain that referred is in the current block url
$pos = strpos( $referrer, $site );
现在我看不出那条线有问题,所以我会给你整个功能:
//Check referrer function
function bot_block_parse()
{
//Get the options for the plugin
$options = get_option( 'bot_block' );
//See if the request was from another site
if( isset( $_SERVER['HTTP_REFERER'] ) )
{
//Split the URL into it's components
$referrer = parse_url( $_SERVER['HTTP_REFERER'] );
//Trim the components
$referrer = array_map( 'trim', $referrer );
//Get the domain name
$referrer = $referrer['host'];
//Get the block list
$list = $this->create_block_list();
//Loop through all the blocked domains
foreach( $list as $site )
{
//Trim the domain
$site = trim( $site );
//Set the prefix for domains that aren't sub domains
$prefix = 'www';
//Split domain into smaller components
$domainParts = explode( ".", $referrer );
//See if the domain that referred is in the current block url
$pos = strpos( $referrer, $site );
//See if block subdomains is checked
if( isset( $options['subdomains'] ) )
{
//Check to see if the domain was the current blocked site and if the prefix is not www
if( $pos !== false && $domainParts[0] != $prefix )
{
//Log spam
$this->log_spam( $site );
//Call the redirect function to see where to send the user
$this->bot_block_redirect();
exit;
}
}
//See if the domain was the current site blocked and the prefix is www
if( $pos !== false && $domainParts[0] == $prefix )
{
//Log spam
$this->log_spam( $site );
//Call the redirect function to see where to send the user
$this->bot_block_redirect();
exit;
}
}
}
}
如果您需要查看完整的插件代码,我已将其放在 pastebin 此处: http: //pastebin.com/gw7YbPVa
有人可以帮我解决这个问题吗?