本文档详细介绍了 WordPress REST API 中 Widgets 端点的数据结构和操作。核心内容包括 Widget 记录的字段定义(Schema)以及通过 REST API 进行检索、创建、更新和删除 Widget 的方法。
GET /wp/v2/widgets
$ curl https://example.com/wp-json/wp/v2/widgets
GET /wp/v2/widgets/<id>
$ curl https://example.com/wp-json/wp/v2/widgets/<id>
DELETE /wp/v2/widgets/<id>
$ curl -X DELETE https://example.com/wp-json/wp/v2/widgets/<id> The schema defines all the fields that exist within a widget 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 identifier for the widget.
JSON data type: string Context: |
id_base
|
The type of the widget. Corresponds to ID in widget-types endpoint.
JSON data type: string Context: |
sidebar
|
The sidebar the widget belongs to.
JSON data type: string Context: |
rendered
|
HTML representation of the widget.
JSON data type: string Read only Context: |
rendered_form
|
HTML representation of the widget admin form.
JSON data type: string Read only Context: |
instance
|
Instance settings of the widget, if supported.
JSON data type: object Context: |
form_data
|
URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.
JSON data type: string Context: |
GET /wp/v2/widgets
Query this endpoint to retrieve a specific widget record.
$ curl https://example.com/wp-json/wp/v2/widgets
context
|
Scope under which the request is made; determines fields present in response.
Default: One of: |
sidebar
|
The sidebar to return widgets for. |
<a href="#schema-id">id</a>
|
Unique identifier for the widget. |
<a href="#schema-id_base">id_base</a>
|
The type of the widget. Corresponds to ID in widget-types endpoint. |
<a href="#schema-sidebar">sidebar</a>
|
The sidebar the widget belongs to.
Required: 1
Default: |
<a href="#schema-instance">instance</a>
|
Instance settings of the widget, if supported. |
<a href="#schema-form_data">form_data</a>
|
URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. |
POST /wp/v2/widgets
GET /wp/v2/widgets/<id>
Query this endpoint to retrieve a specific widget record.
$ curl https://example.com/wp-json/wp/v2/widgets/<id>
context
|
Scope under which the request is made; determines fields present in response.
Default: One of: |
<a href="#schema-id">id</a>
|
Unique identifier for the widget. |
<a href="#schema-id_base">id_base</a>
|
The type of the widget. Corresponds to ID in widget-types endpoint. |
<a href="#schema-sidebar">sidebar</a>
|
The sidebar the widget belongs to. |
<a href="#schema-instance">instance</a>
|
Instance settings of the widget, if supported. |
<a href="#schema-form_data">form_data</a>
|
URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only. |
POST /wp/v2/widgets/<id>
force
|
Whether to force removal of the widget, or move it to the inactive sidebar. |
DELETE /wp/v2/widgets/<id>
$ curl -X DELETE https://example.com/wp-json/wp/v2/widgets/<id>