wp_auth_check()
云策文档标注
概述
wp_auth_check() 是一个 WordPress 函数,用于在 Heartbeat API 中检查用户是否仍保持登录状态。它返回一个包含 'wp-auth-check' 值的响应数组,以指示登录状态。
关键要点
- 函数用途:检查用户登录状态,主要用于 Heartbeat 机制。
- 参数:接受一个数组参数 $response,作为 Heartbeat 响应。
- 返回值:返回修改后的 Heartbeat 响应数组,其中 'wp-auth-check' 值基于 is_user_logged_in() 和 $GLOBALS['login_grace_period'] 设置。
- 相关函数:依赖于 is_user_logged_in() 来判断用户是否登录。
- 版本历史:自 WordPress 3.6.0 版本引入。
代码示例
function wp_auth_check( $response ) {
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response;
}
原文内容
Checks whether a user is still logged in, for the heartbeat.
Description
Send a result that shows a log-in box if the user is no longer logged in, or if their cookie is within the grace period.
Parameters
$responsearrayrequired-
The Heartbeat response.
Source
function wp_auth_check( $response ) {
$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response;
}
Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |