auth_cookie_valid
云策文档标注
概述
auth_cookie_valid 是一个 WordPress 动作钩子,在身份验证 cookie 被验证后触发。它允许开发者在 cookie 验证后执行自定义操作,例如记录日志或更新用户会话状态。
关键要点
- 触发时机:当身份验证 cookie 通过验证时立即触发。
- 参数:接收两个参数:$cookie_elements(包含用户名、过期时间、令牌、HMAC 和方案等 cookie 组件的数组)和 $user(WP_User 对象)。
- 用途:常用于扩展身份验证流程,如添加自定义日志记录或会话管理。
- 相关函数:与 wp_validate_auth_cookie() 函数关联,该函数负责验证 cookie。
- 版本历史:自 WordPress 2.7.0 版本引入。
代码示例
do_action( 'auth_cookie_valid', $cookie_elements, $user );
原文内容
Fires once an authentication cookie has been validated.
Parameters
$cookie_elementsstring[]-
Authentication cookie components.
usernamestringUser’s username.expirationstringThe time the cookie expires as a UNIX timestamp.tokenstringUser’s session token used.hmacstringThe security hash for the cookie.schemestringThe cookie scheme to use.
$userWP_User-
User object.
Source
do_action( 'auth_cookie_valid', $cookie_elements, $user );
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |