[英]Redirect after login, Wordpress URLs
I'm using the following function to redirect a user after a failed login attempt. 登录失败后,我使用以下功能重定向用户。 In functions.php, I added: 在functions.php中,我添加了:
add_action( 'wp_login_failed', 'inline_login_fail' );
function inline_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER'];
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
if ( !strstr($referrer,'?login=failed') ) { // don’t append twice
wp_redirect( $referrer . '?login=failed' );
} else {
wp_redirect( $referrer );
}
exit;
}
}
This works, but the problem is I can't figure out how to parse the '?login-failed'. 这可行,但是问题是我不知道如何解析“?login-failed”。 When I asked this as a PHP question, they said the URL is malformed. 当我将其作为PHP问题问时,他们说URL格式错误。
My URL: www.site.com/?page_id=57?login=failed 我的网址:www.site.com/?page_id=57?login=failed
Preferred URL: www.site.com/?page_id=57&login=failed 首选网址:www.site.com/?page_id=57&login=failed
Now you would think I could just change the '?' 现在您会认为我可以更改“?” to '&'. 至 '&'。 When I do this, it creates an issue if the user is trying to login from the home page and fails. 当我这样做时,如果用户尝试从主页登录并失败,则会产生问题。 It creates a URL which is a 404: "The requested URL /wordpress/&login=failed was not found on this server." 它创建的URL是404:“在此服务器上找不到请求的URL / wordpress /&login = failed”。
Is there any way to correct this function so it will work with the preferred URL? 有什么方法可以纠正此功能,以便它可以与首选URL一起使用吗? That's so I can retrieve the value of whether login has failed, like this: 这样一来,我可以检索是否登录失败的值,如下所示:
<?php
if(isset($_GET['login']) === true and $_GET['login'] === 'failed')
{
get_template_part( 'login', 'failed' );
} else {
get_template_part( 'login', 'form' );
}
?>
Otherwise, I can't figure out how to work with that URL at all. 否则,我根本无法弄清楚如何使用该URL。 Thanks! 谢谢!
check for ?
检查?
<?php
function inline_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER'];
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
if ( !strstr($referrer,'login=failed') ) { // don’t append twice
if(!strstr($referrer, '?')){
wp_redirect( $referrer . '?login=failed' );
} else {
wp_redirect( $referrer . '&login=failed' );
}
} else {
wp_redirect( $referrer );
}
exit;
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.