REST API 文档

💡 云策文档标注

概述

本文档介绍了 WordPress 中 Sidebars 的 REST API 端点,包括其数据模式、字段定义以及如何通过 API 检索和更新侧边栏。面向开发者,用于管理侧边栏的元数据和关联的小部件。

关键要点

  • Sidebars 的 Schema 定义了多个字段,如 id、name、description、class、before_widget、after_widget、before_title、after_title、status 和 widgets,这些字段在响应中默认包含,除非使用 _filter 参数或特定上下文。
  • 所有字段均为只读(Read only),JSON 数据类型主要为字符串或数组,context 属性指定字段在 embed、view 或 edit 上下文中的可见性。
  • 提供了三个 API 端点:GET /wp/v2/sidebars 用于检索所有侧边栏,GET /wp/v2/sidebars/<id> 用于检索特定侧边栏,POST /wp/v2/sidebars/<id> 用于更新侧边栏(仅 widgets 参数可更新)。
  • 参数包括 context(默认 view,可选 embed 或 edit)和 id(用于特定侧边栏检索),更新操作仅支持 widgets 参数来修改嵌套的小部件。

📄 原文内容

Schema

The schema defines all the fields that exist within a sidebar 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 ID of sidebar.

JSON data type: string

Read only

Context: embed, view, edit

name Unique name identifying the sidebar.

JSON data type: string

Read only

Context: embed, view, edit

description Description of sidebar.

JSON data type: string

Read only

Context: embed, view, edit

class Extra CSS class to assign to the sidebar in the Widgets interface.

JSON data type: string

Read only

Context: embed, view, edit

before_widget HTML content to prepend to each widget's HTML output when assigned to this sidebar. Default is an opening list item element.

JSON data type: string

Read only

Context: embed, view, edit

after_widget HTML content to append to each widget's HTML output when assigned to this sidebar. Default is a closing list item element.

JSON data type: string

Read only

Context: embed, view, edit

before_title HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element.

JSON data type: string

Read only

Context: embed, view, edit

after_title HTML content to append to the sidebar title when displayed. Default is a closing h2 element.

JSON data type: string

Read only

Context: embed, view, edit

status Status of sidebar.

JSON data type: string

Read only

Context: embed, view, edit

One of: active, inactive

widgets Nested widgets.

JSON data type: array

Context: embed, view, edit

Retrieve a Sidebar

Definition & Example Request

GET /wp/v2/sidebars

Query this endpoint to retrieve a specific sidebar record.

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

Arguments

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

Default: view

One of: view, embed, edit

Retrieve a Sidebar

Definition & Example Request

GET /wp/v2/sidebars/<id>

Query this endpoint to retrieve a specific sidebar record.

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

Arguments

id The id of a registered sidebar
context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

Update a Sidebar

Arguments

<a href="#schema-widgets">widgets</a> Nested widgets.

Definition

POST /wp/v2/sidebars/<id>

Example Request