即使用户正确键入他们的权限,我也想返回登录错误消息。换句话说,终止登录并显示错误消息。
当我们输入错误的密码时,wordpress 会显示:
There was an error authenticating your details.
ERROR: The password you entered for the username admin is incorrect. Lost your password?
..在登录页面上。这是因为
WP_Error
返回对象。所以我好奇的问题是:
WP_Error
我自己反对,要回来吗?是数组吗? 最佳答案
您需要 Hook 到身份验证 wordpress Hook 。然后返回一个新的 WP_Error 对象以生成错误消息并重定向回登录页面。这是一个例子。
add_filter('authenticate', 'check_login_submit', 40, 3);
function check_login_submit($user, $username, $password) {
$WP_Error = new WP_Error();
$WP_Error->add('my_error', '<strong>Error</strong>: Something went wrong.');
return $WP_Error;
}
关于Wordpress 为用户登录生成 WP_Error 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16534887/