哪里在传统的登录概念中是否处理最终的真/假调用返回?
登录过程从wp-login.php
第625行附近的WordPress文件:
$user = wp_signon(\'\', $secure_cookie);
The
wp_signon()
函数来自
wp-includes/user.php
文件
/**
* Authenticate user with remember capability.
*
* The credentials is an array that has \'user_login\', \'user_password\', and
* \'remember\' indices. If the credentials is not given, then the log in form
* will be assumed and used if set.
*
* The various authentication cookies will be set by this function and will be
* set for a longer period depending on if the \'remember\' credential is set to
* true.
*
* @since 2.5.0
*
* @param array $credentials Optional. User info in order to sign on.
* @param bool $secure_cookie Optional. Whether to use secure cookie.
* @return object Either WP_Error on failure, or WP_User on success.
*/
function wp_signon( $credentials = \'\', $secure_cookie = \'\' ) {
if ( empty($credentials) ) {
if ( ! empty($_POST[\'log\']) )
$credentials[\'user_login\'] = $_POST[\'log\'];
if ( ! empty($_POST[\'pwd\']) )
$credentials[\'user_password\'] = $_POST[\'pwd\'];
if ( ! empty($_POST[\'rememberme\']) )
$credentials[\'remember\'] = $_POST[\'rememberme\'];
}
if ( !empty($credentials[\'remember\']) )
$credentials[\'remember\'] = true;
else
$credentials[\'remember\'] = false;
// TODO do we deprecate the wp_authentication action?
do_action_ref_array(\'wp_authenticate\', array(&$credentials[\'user_login\'], &$credentials[\'user_password\']));
if ( \'\' === $secure_cookie )
$secure_cookie = is_ssl();
$secure_cookie = apply_filters(\'secure_signon_cookie\', $secure_cookie, $credentials);
global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
$auth_secure_cookie = $secure_cookie;
add_filter(\'authenticate\', \'wp_authenticate_cookie\', 30, 3);
$user = wp_authenticate($credentials[\'user_login\'], $credentials[\'user_password\']);
if ( is_wp_error($user) ) {
if ( $user->get_error_codes() == array(\'empty_username\', \'empty_password\') ) {
$user = new WP_Error(\'\', \'\');
}
return $user;
}
wp_set_auth_cookie($user->ID, $credentials[\'remember\'], $secure_cookie);
do_action(\'wp_login\', $user->user_login, $user);
return $user;
}
我不是这方面的专家,但看起来你有两个选择。
1) 重写wp_authenticate()
功能位于wp-includes/pluggable.php
.
中的所有功能wp-includes/pluggable.php
, 在创建函数之前,请检查该函数是否已经存在,以便您可以在主题或插件中添加重写后的函数,它将替换默认值wp_authenticate()
作用
2) 将您的层添加到位于函数末尾附近的“wp\\u login”操作挂钩。
WordPress完成所有身份验证后,会发生“wp\\u login”操作。像这样使用它。
add_action( \'wp_login\', \'my_external_authentication\', 10, 2 );
/**
* @return object Either WP_Error on failure, or WP_User on success.
*/
function my_external_authentication( $user_login, $user ) {
// Add external authentication here.
}