好的,在你的评论之后,我想我知道你在问什么了,但我不确定,所以我会尽可能地将其泛化。
WordPress使用authenticate
筛选挂钩以执行身份验证。您可以通过将自己的函数连接到此筛选器来添加其他身份验证方法。
这是身份验证函数的示例。这是一个危险而愚蠢的示例,因为它只是以用户1的身份登录,根本没有任何检查,但它显示了您需要返回什么函数来验证用户。
add_filter(\'authenticate\', \'myplugin_auth_example\', 30, 3);
function myplugin_auth_example($user, $username, $password) {
// if user is already known, return it
if ( is_a($user, \'WP_User\') ) { return $user; }
// do your authentication via whatever method here
// bottom line is that you need to get a valid WP_User object and return it
// this example just gets user number 1 from the database and uses that
// NOTE: this here is extremely dangerous and stupid, because it just logs everybody in instantly
$user = new WP_User(1);
return $user;
// if there is an error in authentication, you could do this instead
return new WP_Error( \'some_bad_auth_reason\', \'Your credentials were invalid.\' );
}