在我的wordpress项目中,我为用户创建了一个前端登录,当用户输入错误的登录信息时,它必须使用url重定向登录失败的附件。下面的代码第一次执行,然后在尝试登录时连续追加到url。我如何限制它。
add_action('wp_login_failed', 'my_front_end_login_fail');
function my_front_end_login_fail($username){
// Get the reffering page, where did the post submission come from?
$referrer = $_SERVER['HTTP_REFERER'];
// if there's a valid referrer, and it's not the default log-in screen
if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
// let's append some information (login=failed) to the URL for the theme to use
wp_redirect($referrer . '&login=failed');
exit;
}
}
任何帮助都将不胜感激。
答案 0 :(得分:1)
试试这段代码
add_action('wp_login_failed', 'my_front_end_login_fail');
function my_front_end_login_fail($username){
// Get the reffering page, where did the post submission come from?
$referrer = $_SERVER['HTTP_REFERER'];
// if there's a valid referrer, and it's not the default log-in screen
if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
// let's append some information (login=failed) to the URL for the theme to use
////already not login failed append
if(!strstr($referrer,'&login=failed'))
{
wp_redirect($referrer . '&login=failed');
}
else
{
////if alreday append go to same url
wp_redirect($referrer);
}
exit;
}
}