钩子文档

set_auth_cookie

💡 云策文档标注

概述

set_auth_cookie 是一个 WordPress 动作钩子,在设置身份验证 cookie 之前立即触发,允许开发者在 cookie 设置时执行自定义操作。

关键要点

  • 触发时机:在身份验证 cookie 设置之前立即执行。
  • 参数:包括 $auth_cookie(cookie 值)、$expire(登录宽限期到期时间)、$expiration(cookie 过期时间)、$user_id(用户 ID)、$scheme(身份验证方案)、$token(会话令牌)。
  • 相关函数:与 wp_set_auth_cookie() 函数关联,用于设置用户身份验证 cookie。
  • 版本变更:从 WordPress 4.9.0 开始添加 $token 参数。

代码示例

add_action( 'set_auth_cookie', 'my_cookie_action', 10, 5 );
function my_cookie_action( $auth_cookie, $expire, $expiration, $user_id, $scheme ) {
    // complete some action when the cookie is set.
    return;
}

📄 原文内容

Fires immediately before the authentication cookie is set.

Parameters

$auth_cookiestring
Authentication 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 authentication cookie expires as a UNIX timestamp.
Default is 14 days from now.
$user_idint
User ID.
$schemestring
Authentication scheme. Values include 'auth' or 'secure_auth'.
$tokenstring
User’s session token to use for this cookie.

Source

do_action( 'set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme, $token );

Changelog

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

User Contributed Notes