钩子文档

rest_index

💡 云策文档标注

概述

rest_index 过滤器用于修改 REST API 根索引数据,包括认证方案、命名空间、路由和站点信息。此过滤器在 WP_REST_Server::get_index() 中被调用,允许开发者自定义 API 根响应。

关键要点

  • 过滤器名称:rest_index
  • 参数:$response(WP_REST_Response 类型,响应数据)和 $request(WP_REST_Request 类型,请求数据)
  • 用途:过滤 REST API 根索引数据,如认证、命名空间、路由和站点详情
  • 相关函数:WP_REST_Server::get_index() 用于检索站点索引
  • 版本历史:WordPress 4.4.0 引入,6.0.0 添加 $request 参数

📄 原文内容

Filters the REST API root index data.

Description

This contains the data describing the API. This includes information about supported authentication schemes, supported namespaces, routes available on the API, and a small amount of data about the site.

Parameters

$responseWP_REST_Response
Response data.
$requestWP_REST_Request
Request data.

Source

return apply_filters( 'rest_index', $response, $request );

Changelog

Version Description
6.0.0 Added $request parameter.
4.4.0 Introduced.