send_auth_cookies
云策文档标注
概述
send_auth_cookies 是一个 WordPress 过滤器钩子,用于控制是否向客户端发送身份验证 cookies。它允许开发者基于特定条件阻止 cookies 的发送,常用于自定义登录流程或安全增强。
关键要点
- 这是一个过滤器钩子,默认返回 true 以发送 auth cookies。
- 接受多个参数,包括 $send(布尔值,是否发送 cookies)、$expire(登录宽限期到期时间)、$expiration(登录 cookie 过期时间)、$user_id(用户 ID)、$scheme(认证方案)和 $token(会话令牌)。
- 在 WordPress 6.2.0 版本中新增了 $expire、$expiration、$user_id、$scheme 和 $token 参数,增强了灵活性。
- 与 wp_set_auth_cookie() 和 wp_clear_auth_cookie() 函数相关,用于设置和清除身份验证 cookies。
代码示例
if ( ! apply_filters( 'send_auth_cookies', true, $expire, $expiration, $user_id, $scheme, $token ) ) {
// 阻止发送 auth cookies 的逻辑
}注意事项
- 参数 $expire、$expiration、$user_id、$scheme 和 $token 在清除 cookies 时可能为零或空字符串,需在代码中处理这些边界情况。
- 使用此钩子时,应确保不影响核心登录功能,避免意外阻止合法用户的身份验证。
原文内容
Allows preventing auth cookies from actually being sent to the client.
Parameters
$sendbool-
Whether to send auth cookies to the client. Default true.
$expireint-
The time the login grace period expires as a UNIX timestamp.
Default is 12 hours past the cookie’s expiration time. Zero when clearing cookies. $expirationint-
The time when the logged-in authentication cookie expires as a UNIX timestamp.
Default is 14 days from now. Zero when clearing cookies. $user_idint-
User ID. Zero when clearing cookies.
$schemestring-
Authentication scheme. Values include
'auth'or'secure_auth'.
Empty string when clearing cookies. $tokenstring-
User’s session token to use for this cookie. Empty string when clearing cookies.
Source
if ( ! apply_filters( 'send_auth_cookies', true, $expire, $expiration, $user_id, $scheme, $token ) ) {