wp_validate_logged_in_cookie()
来源评论:
/**
* Validates the logged-in cookie.
*
* Checks the logged-in cookie if the previous auth cookie could not be
* validated and parsed.
*
* This is a callback for the {@see \'determine_current_user\'} filter, rather than API.
*
* @since 3.9.0
*
* @param int|bool $user_id The user ID (or false) as received from the
* determine_current_user filter.
* @return int|false User ID if validated, false otherwise. If a user ID from
* an earlier filter callback is received, that value is returned.
*/
它是过滤器挂钩的默认回调函数
determine_current_user
专用函数使用
_wp_get_current_user()
还有一些插件。
其默认用法如wp中所定义,包括/默认过滤器。php第371行:
add_filter( \'determine_current_user\', \'wp_validate_logged_in_cookie\', 20 );
_wp_get_current_user()
\'s过滤器的使用line 2523 of wp-includes/user.php:
/**
* Filters the current user.
*
* The default filters use this to determine the current user from the
* request\'s cookies, if available.
*
* Returning a value of false will effectively short-circuit setting
* the current user.
*
* @since 3.9.0
*
* @param int|bool $user_id User ID if one has been determined, false otherwise.
*/
$user_id = apply_filters( \'determine_current_user\', false );
在此用法中
wp_validate_logged_in_cookie()
已传递参数
false
, 因此会被迫逃跑
wp_validate_auth_cookie()
如果有一块饼干,而我们在前端。
wp_validate_auth_cookie()
如果cookie有效,则返回用户id。
的完整来源_wp_get_current_user()
, 查看上面引用的内容apply_filters()
上下文中的行。请注意,如果没有向其返回用户id,则用户id设置为无效0
并立即返回;表示没有登录用户。
function _wp_get_current_user() {
global $current_user;
if ( ! empty( $current_user ) ) {
if ( $current_user instanceof WP_User ) {
return $current_user;
}
// Upgrade stdClass to WP_User
if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
$cur_id = $current_user->ID;
$current_user = null;
wp_set_current_user( $cur_id );
return $current_user;
}
// $current_user has a junk value. Force to WP_User with ID 0.
$current_user = null;
wp_set_current_user( 0 );
return $current_user;
}
if ( defined(\'XMLRPC_REQUEST\') && XMLRPC_REQUEST ) {
wp_set_current_user( 0 );
return $current_user;
}
/**
* Filters the current user.
*
* The default filters use this to determine the current user from the
* request\'s cookies, if available.
*
* Returning a value of false will effectively short-circuit setting
* the current user.
*
* @since 3.9.0
*
* @param int|bool $user_id User ID if one has been determined, false otherwise.
*/
$user_id = apply_filters( \'determine_current_user\', false );
if ( ! $user_id ) {
wp_set_current_user( 0 );
return $current_user;
}
wp_set_current_user( $user_id );
return $current_user;
}