登录后重定向,Wordpress URL [英] Redirect after login, Wordpress URLs
问题描述
我正在使用以下函数在登录尝试失败后重定向用户.在functions.php中,我添加了:
I'm using the following function to redirect a user after a failed login attempt. In functions.php, I added:
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;
}
}
这行得通,但问题是我不知道如何解析?login-failed".当我将其作为 PHP 问题提出时,他们说 URL 格式错误.
This works, but the problem is I can't figure out how to parse the '?login-failed'. When I asked this as a PHP question, they said the URL is malformed.
我的网址:www.site.com/?page_id=57?login=failed
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
现在你会认为我可以改变'?'到&".当我这样做时,如果用户尝试从主页登录并失败,则会产生问题.它创建了一个 404 URL:在此服务器上找不到请求的 URL/wordpress/&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 一起使用?这样我就可以检索登录是否失败的值,如下所示:
Is there any way to correct this function so it will work with the preferred 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' );
}
?>
否则,我根本不知道如何使用该 URL.谢谢!
Otherwise, I can't figure out how to work with that URL at all. Thanks!
推荐答案
检查 ?
<?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;
}
}
?>
这篇关于登录后重定向,Wordpress URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!