wp_refresh_heartbeat_nonces()
云策文档标注
概述
wp_refresh_heartbeat_nonces() 函数用于在 Heartbeat 响应中更新 Heartbeat 和 REST API 的 nonce,确保安全性和时效性。
关键要点
- 函数接收一个 Heartbeat 响应数组作为参数,并返回更新后的响应数组。
- 通过 wp_create_nonce() 生成新的 'wp_rest' 和 'heartbeat-nonce' nonce,分别赋值给响应数组的 'rest_nonce' 和 'heartbeat_nonce' 键。
- 此函数自 WordPress 5.0.0 版本引入,是 Heartbeat API 的一部分。
代码示例
function wp_refresh_heartbeat_nonces( $response ) {
// Refresh the Rest API nonce.
$response['rest_nonce'] = wp_create_nonce( 'wp_rest' );
// Refresh the Heartbeat nonce.
$response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' );
return $response;
}
原文内容
Adds the latest Heartbeat and REST API nonce to the Heartbeat response.
Parameters
$responsearrayrequired-
The Heartbeat response.
Source
function wp_refresh_heartbeat_nonces( $response ) {
// Refresh the Rest API nonce.
$response['rest_nonce'] = wp_create_nonce( 'wp_rest' );
// Refresh the Heartbeat nonce.
$response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' );
return $response;
}
Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |