rest_json_encode_options
云策文档标注
概述
rest_json_encode_options 是一个 WordPress 过滤器钩子,用于修改 REST API 响应中 JSON 编码的选项。它允许开发者在发送响应前自定义 json_encode() 的参数。
关键要点
- rest_json_encode_options 过滤器钩子用于调整 JSON 编码选项,影响 REST API 响应的输出格式。
- 该钩子接受两个参数:$options(整数,表示 JSON 编码选项)和 $request(WP_REST_Request 对象,表示当前请求)。
- 通过 apply_filters 调用,开发者可以添加自定义逻辑来修改这些选项,例如设置 JSON_PRETTY_PRINT 等标志。
- 该钩子自 WordPress 6.1.0 版本引入,主要用于 WP_REST_Server::get_json_encode_options() 方法中。
原文内容
Filters the JSON encoding options used to send the REST API response.
Parameters
$optionsint-
JSON encoding options json_encode().
$requestWP_REST_Request-
Current request object.
Source
return apply_filters( 'rest_json_encode_options', $options, $request );
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |