钩子文档

rest_{$this->post_type}_item_schema

💡 云策文档标注

概述

rest_{$this->post_type}_item_schema 是一个 WordPress REST API 过滤器,用于修改特定文章类型的 JSON Schema 数据。它允许开发者在获取文章模式时自定义或扩展模式定义。

关键要点

  • 这是一个动态过滤器,$this->post_type 指代控制器中的文章类型 slug,例如 post、page 或 attachment。
  • 可能的钩子名称包括 rest_post_item_schema、rest_page_item_schema 和 rest_attachment_item_schema。
  • 过滤器接收一个数组参数 $schema,包含文章的模式数据,可用于修改或添加字段。
  • 在 WP_REST_Posts_Controller::get_item_schema() 方法中使用,用于检索符合 JSON Schema 的文章模式。
  • 自 WordPress 5.4.0 版本引入。

代码示例

$schema = apply_filters( "rest_{$this->post_type}_item_schema", $schema );

📄 原文内容

Filters the post’s schema.

Description

The dynamic portion of the filter, $this->post_type, refers to the post type slug for the controller.

Possible hook names include:

  • rest_post_item_schema
  • rest_page_item_schema
  • rest_attachment_item_schema

Parameters

$schemaarray
Item schema data.

Source

$schema = apply_filters( "rest_{$this->post_type}_item_schema", $schema );

Changelog

Version Description
5.4.0 Introduced.