REST API 文档

小部件类型

💡 云策文档标注

概述

本文档介绍了 WordPress REST API 中小部件类型的 Schema 定义和端点操作,包括字段结构和如何通过 API 检索小部件类型信息。

关键要点

  • Schema 定义了小部件类型记录的字段,如 id、name、description、is_multi 和 classname,这些字段在响应中默认包含,除非使用 _filter 参数或特定上下文限制。
  • 提供了两个 REST API 端点:GET /wp/v2/widget-types 用于检索所有小部件类型,GET /wp/v2/widget-types/ 用于检索特定小部件类型。
  • 支持 context 参数(view、embed、edit)来控制响应中字段的可见性,默认值为 view。

代码示例

GET /wp/v2/widget-types
$ curl https://example.com/wp-json/wp/v2/widget-types

GET /wp/v2/widget-types/<id>
$ curl https://example.com/wp-json/wp/v2/widget-types/<id>

📄 原文内容

Schema

The schema defines all the fields that exist within a widget type record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.

id Unique slug identifying the widget type.

JSON data type: string

Read only

Context: embed, view, edit

name Human-readable name identifying the widget type.

JSON data type: string

Read only

Context: embed, view, edit

description Description of the widget.

JSON data type: string

Context: view, edit, embed

is_multi Whether the widget supports multiple instances

JSON data type: boolean

Read only

Context: view, edit, embed

classname Class name

JSON data type: string

Read only

Context: embed, view, edit

Retrieve a Widget Type

Definition & Example Request

GET /wp/v2/widget-types

Query this endpoint to retrieve a specific widget type record.

$ curl https://example.com/wp-json/wp/v2/widget-types

Arguments

context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

Retrieve a Widget Type

Definition & Example Request

GET /wp/v2/widget-types/<id>

Query this endpoint to retrieve a specific widget type record.

$ curl https://example.com/wp-json/wp/v2/widget-types/<id>

Arguments

id The widget type id.
context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit