rest_send_nocache_headers
云策文档标注
概述
rest_send_nocache_headers 是一个 WordPress REST API 过滤器,用于控制是否在 REST API 请求中发送 no-cache 头。它允许开发者基于条件(如用户登录状态)动态调整缓存行为。
关键要点
- 过滤器名称:rest_send_nocache_headers
- 参数:一个布尔值,决定是否发送 no-cache 头
- 默认行为:基于 is_user_logged_in() 返回结果,通常为已登录用户发送 no-cache 头
- 应用场景:在 WP_REST_Server::serve_request() 方法中调用,用于处理 REST API 请求
- 版本历史:从 WordPress 4.4.0 引入,6.3.2 版本有相关代码块移动
代码示例
$send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
原文内容
Filters whether to send no-cache headers on a REST API request.
Parameters
$rest_send_nocache_headersbool-
Whether to send no-cache headers.
Source
$send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
Changelog
| Version | Description |
|---|---|
| 6.3.2 | Moved the block to catch the filter added on rest_cookie_check_errors() from wp-includes/rest-api.php. |
| 4.4.0 | Introduced. |