钩子文档

set_logged_in_cookie

💡 云策文档标注

概述

set_logged_in_cookie 是一个 WordPress 动作钩子,在用户登录认证 cookie 设置前立即触发,允许开发者自定义处理登录 cookie 相关逻辑。

关键要点

  • 触发时机:在 logged-in 认证 cookie 设置前立即执行。
  • 参数:包括 $logged_in_cookie(cookie 值)、$expire(登录宽限期过期时间)、$expiration(cookie 过期时间)、$user_id(用户 ID)、$scheme(认证方案,默认为 'logged_in')、$token(用户会话令牌)。
  • 用途:常用于自定义 cookie 处理、日志记录或安全增强。
  • 版本历史:从 WordPress 2.6.0 引入,4.9.0 版本添加了 $token 参数。

代码示例

add_action( 'set_logged_in_cookie', 'my_cookie_action', 10, 5 );
function my_cookie_action( $logged_in_cookie, $expire, $expiration, $user_id, $scheme ) {
    // 在 cookie 设置时执行某些操作。
    return;
}

📄 原文内容

Fires immediately before the logged-in authentication cookie is set.

Parameters

$logged_in_cookiestring
The logged-in cookie value.
$expireint
The time the login grace period expires as a UNIX timestamp.
Default is 12 hours past the cookie’s expiration time.
$expirationint
The time when the logged-in authentication cookie expires as a UNIX timestamp.
Default is 14 days from now.
$user_idint
User ID.
$schemestring
Authentication scheme. Default 'logged_in'.
$tokenstring
User’s session token to use for this cookie.

Source

do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in', $token );

Changelog

Version Description
4.9.0 The $token parameter was added.
2.6.0 Introduced.

User Contributed Notes