我有一个自定义登录页面,因此设置了以下重定向:
add_action(\'init\', \'my_redirect_login_page\');
add_action(\'wp_login_failed\', \'my_custom_login_failed\');
add_filter(\'authenticate\', \'my_verify_user_pass\', 1, 3);
add_action(\'wp_logout\', \'my_logout_redirect\');
function my_redirect_login_page()
{
$login_page = site_url(\'/careers/login-register/\');
$page_viewed = basename($_SERVER[\'REQUEST_URI\']);
if ($page_viewed == \'wp-login.php\' && $_SERVER[\'REQUEST_METHOD\'] == \'GET\') {
wp_redirect($login_page);
exit;
}
}
function my_custom_login_failed()
{
$uri = (isset($_POST[\'type\']) and $_POST[\'type\'] == \'admin-login\') ? \'/admin-login/\' : \'/careers/login-register/\';
$login_page = site_url($uri);
wp_redirect($login_page . \'?login=failed\');
exit;
}
function my_verify_user_pass($user, $username, $password)
{
$uri = (isset($_POST[\'type\']) and $_POST[\'type\'] == \'admin-login\') ? \'/admin-login/\' : \'/careers/login-register/\';
$login_page = site_url($uri);
if ($username == \'\' || $password == \'\') {
wp_redirect($login_page . "?login=empty");
exit;
}
}
这很有效,但我最近发现它还可以将用户重定向到
/careers/login-register/?login=empty 当他们请求新密码时。
我试图通过添加以下内容来解决此问题:
add_filter(\'lostpassword redirect\', \'my_lost_password_redirect\');
function my_lost_password_redirect()
{
$login_page = site_url();
wp_redirect($login_page . \'/?checkemail=confirm\');
exit();
}
。。。但它没有起作用。
我试着和priority 上的参数authenticate 过滤器,但它没有改变任何东西。
Edit:
我实际上找到了一种方法,例如:
function my_verify_user_pass($user, $username, $password) {
$page_viewed = $_SERVER[\'REQUEST_URI\'];
$redirect = (strpos($page_viewed, \'?checkemail=confirm\') !== false) ? false : true;
if ($redirect) {
$uri = (isset($_POST[\'type\']) and $_POST[\'type\'] == \'admin-login\') ? \'/admin-login/\' : \'/careers/login-register/\';
$login_page = site_url($uri);
if ($username == \'\' || $password == \'\') {
wp_redirect($login_page . "?login=empty");
exit;
}
}
}
然而,不确定是否有一种更标准的方法来实现它,或者一开始就不打破它——这可能吗?
有什么想法吗?