当验证码不正确时,我想在 wp-login 表单上显示错误消息。我正在使用“login_redirect”和“login_errors”过滤器。这是我的代码。
add_filter( 'login_redirect', 'captcha_login_check', 10, 3);
add_filter( 'login_errors', 'captcha_login_post' );
function captcha_login_check($username, $password)
{
if (isset($_POST["security_check"]))
{
$code = str_decrypt($_POST["security_check"]);
if (!( empty($code)) && !($code == $_POST['security_code'] ) && ($password == false))
{
function captcha_login_post($error)
{
return $error."<p><span style='color:red'>Error, the Security Code does not match. Please Try Again.</span><br></p>";
}
}
else if(!( empty($code)) && !($code == $_POST['security_code'] ) && ($password == true))
{
$url = get_site_url().'/wp-login.php';
header('Location:'.$url);
echo "<p><span style='color:red'>Error, the Security Code does not match. Please Try Again.</span><br></p>";
}
else
{
$url = get_site_url().'/wp-admin';
header('Location:'.$url);
}
}
}