REST API 文档

💡 云策文档标注

概述

本文档描述了 WordPress REST API 中插件(Plugins)端点的数据结构和操作。核心内容包括插件记录的 Schema 定义,以及通过 GET、POST、DELETE 等方法对插件进行检索、创建、更新和删除的 API 接口。

关键要点

  • 插件 Schema 定义了多个字段,如 plugin(插件文件)、status(激活状态)、name(插件名称)、version(版本号)等,每个字段包含 JSON 数据类型、只读属性、上下文和可选值。
  • API 端点支持通过 GET /wp/v2/plugins 检索插件列表,GET /wp/v2/plugins/<plugin> 检索特定插件,POST /wp/v2/plugins 创建插件,POST /wp/v2/plugins/<plugin> 更新插件状态,以及 DELETE /wp/v2/plugins/<plugin> 删除插件。
  • 请求参数包括 context(上下文,如 view、embed、edit)、search(搜索字符串)、status(插件状态过滤)和 slug(插件目录 slug),用于控制响应内容和操作行为。

代码示例

// 检索插件列表
$ curl https://example.com/wp-json/wp/v2/plugins

// 删除特定插件
$ curl -X DELETE https://example.com/wp-json/wp/v2/plugins/<plugin>?)

📄 原文内容

Schema

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

plugin The plugin file.

JSON data type: string

Read only

Context: view, edit, embed

status The plugin activation status.

JSON data type: string

Context: view, edit, embed

One of: inactive, active

name The plugin name.

JSON data type: string

Read only

Context: view, edit, embed

plugin_uri The plugin's website address.

JSON data type: string,
Format: uri

Read only

Context: view, edit

author The plugin author.

JSON data type: object

Read only

Context: view, edit

author_uri Plugin author's website address.

JSON data type: string,
Format: uri

Read only

Context: view, edit

description The plugin description.

JSON data type: object

Read only

Context: view, edit

version The plugin version number.

JSON data type: string

Read only

Context: view, edit

network_only Whether the plugin can only be activated network-wide.

JSON data type: boolean

Read only

Context: view, edit, embed

requires_wp Minimum required version of WordPress.

JSON data type: string

Read only

Context: view, edit, embed

requires_php Minimum required version of PHP.

JSON data type: string

Read only

Context: view, edit, embed

textdomain The plugin's text domain.

JSON data type: string

Read only

Context: view, edit

Retrieve a Plugin

Definition & Example Request

GET /wp/v2/plugins

Query this endpoint to retrieve a specific plugin record.

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

Arguments

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

Default: view

One of: view, embed, edit

search Limit results to those matching a string.
status Limits results to plugins with the given status.

Create a Plugin

Arguments

<a href="#schema-slug">slug</a> WordPress.org plugin directory slug.

Required: 1

<a href="#schema-status">status</a> The plugin activation status.

Default: inactive

One of: inactive, active

Definition

POST /wp/v2/plugins

Retrieve a Plugin

Definition & Example Request

GET /wp/v2/plugins/<plugin>?)

Query this endpoint to retrieve a specific plugin record.

$ curl https://example.com/wp-json/wp/v2/plugins/<plugin>?)

Arguments

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

Default: view

One of: view, embed, edit

plugin

Update a Plugin

Arguments

<a href="#schema-context">context</a> Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

<a href="#schema-plugin">plugin</a>
<a href="#schema-status">status</a> The plugin activation status.
One of: inactive, active

Definition

POST /wp/v2/plugins/<plugin>?)

Example Request

Delete a Plugin

Arguments

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

Default: view

One of: view, embed, edit

plugin

Definition

DELETE /wp/v2/plugins/<plugin>?)

Example Request

$ curl -X DELETE https://example.com/wp-json/wp/v2/plugins/<plugin>?)