能力参考
能力是 Gratis AI Agent 可以在你的 WordPress 安装中调用的原子操作。每个能力都是一个已注册的 PHP 类,会公开一个 JSON schema — agent 会在运行时读取此 schema,以了解需要哪些参数以及该能力会返回什么。
本页记录了 Gratis AI Agent v1.9.0 随附的所有能力。
自定义文章类型
这些能力用于管理通过 agent 注册的自定义文章类型(CPT)。注册信息会持久保存到 WordPress options 表中,因此即使 plugin 停用并重新启用也会保留。
register_post_type
注册一个新的自定义文章类型。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | 文章类型键(最多 20 个字符,不含大写字母,不含空格) |
singular_label | string | Yes | 人类可读的单数名称,例如 Portfolio Item |
plural_label | string | Yes | 人类可读的复数名称,例如 Portfolio Items |
public | boolean | No | 该文章类型是否可公开访问。默认 true |
supports | array | No | 要支持的功能:title、editor、thumbnail、excerpt、comments、revisions、custom-fields。默认 ["title","editor"] |
has_archive | boolean | No | 是否启用文章类型归档页面。默认 false |
menu_icon | string | No | 管理菜单图标的 Dashicons 类或 URL。默认 "dashicons-admin-post" |
rewrite_slug | string | No | 文章类型的 URL slug。默认为 slug |
示例
{
"slug": "portfolio",
"singular_label": "Portfolio Item",
"plural_label": "Portfolio Items",
"public": true,
"supports": ["title", "editor", "thumbnail"],
"has_archive": true,
"menu_icon": "dashicons-portfolio"
}
返回 { "success": true, "slug": "portfolio" }
list_post_types
返回由 agent 注册的所有自定义文章类型。
参数 — 无
返回
{
"post_types": [
{
"slug": "portfolio",
"singular_label": "Portfolio Item",
"plural_label": "Portfolio Items",
"public": true
}
]
}
delete_post_type
取消注册之前由 agent 注册的自定义文章类型。该类型的现有文章会保留在数据库中,但不再能通过该文章类型访问。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | 要移除的文章类型键 |
返回 { "success": true, "slug": "portfolio" }
自定义分类法
这些能力用于管理自定义分类法。与 CPT 一样,分类法注册信息会被持久保存。
register_taxonomy
注册一个新的自定义分类法。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | 分类法键(最多 32 个字符) |
singular_label | string | Yes | 人类可读的单数名称,例如 Project Category |
plural_label | string | Yes | 人类可读的复数名称,例如 Project Categories |
post_types | array | Yes | 此分类法应附加到的文章类型 slug |
hierarchical | boolean | No | true 表示类别样式,false 表示标签样式。默认 true |
public | boolean | No | 术语是否可公开访问。默认 true |
rewrite_slug | string | No | 分类法的 URL slug。默认为 slug |
示例
{
"slug": "project-category",
"singular_label": "Project Category",
"plural_label": "Project Categories",
"post_types": ["portfolio"],
"hierarchical": true
}
返回 { "success": true, "slug": "project-category" }
list_taxonomies
返回由 agent 注册的所有自定义分类法。
参数 — 无
返回
{
"taxonomies": [
{
"slug": "project-category",
"singular_label": "Project Category",
"post_types": ["portfolio"],
"hierarchical": true
}
]
}
delete_taxonomy
取消注册之前由 agent 注册的自定义分类法。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | 要移除的分类法键 |
返回 { "success": true, "slug": "project-category" }
设计系统
设计系统能力用于修改 WordPress 站点的视觉呈现 — 从自定义 CSS 到区块模式和站点标志。
inject_custom_css
通过 wp_add_inline_style 将 CSS 追加到站点的 <head>。CSS 存储在 gratis_ai_agent_custom_css option 中,并在 该能力重置时干净地取消入队。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
css | string | Yes | 要注入的有效 CSS |
label | string | No | 此 CSS 块的人类可读标签,用于调试日志。默认 "agent-injected" |
replace | boolean | No | 如果为 true,则替换所有先前注入的 CSS。默认 false(追加) |
示例
{
"css": ":root { --primary: #1a1a2e; --accent: #e94560; } body { font-family: 'Inter', sans-serif; }",
"label": "brand-colours",
"replace": false
}
返回 { "success": true, "bytes": 96 }
add_block_pattern
在 WordPress 模式库中注册一个可复用的区块模式。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | 模式标识符,例如 gratis/hero-dark |
title | string | Yes | 编辑器中显示的人类可读模式名称 |
content | string | Yes | 该模式的序列化区块标记(HTML) |
categories | array | No | 模式类别 slug,例如 ["featured", "hero"] |
description | string | No | 模式选择器中显示的简短描述 |
keywords | array | No | 搜索关键词 |
返回 { "success": true, "slug": "gratis/hero-dark" }
list_block_patterns
列出由 agent 注册的所有区块模式。
参数 — 无
返回
{
"patterns": [
{
"slug": "gratis/hero-dark",
"title": "Dark Hero",
"categories": ["hero"]
}
]
}
set_site_logo
将 WordPress 站点标志设置为给定的附件 ID 或远程图片 URL。提供 URL 时,图片会被下载并导入到媒体库中。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
attachment_id | integer | No | 现有媒体库附件的 ID |
url | string | No | 要导入并设置为标志的远程图片 URL |
必须提供 attachment_id 或 url 中的一个。
返回 { "success": true, "attachment_id": 42 }
apply_theme_json_preset
将命名的颜色/排版预设应用到当前启用主题的 theme.json(或 global-styles)。预设是由 Gratis AI Agent 团队维护的精选组合。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
preset | string | Yes | 预设名称,例如 minimal-dark、warm-editorial、corporate-blue |
merge | boolean | No | 如果为 true,则与现有值合并而不是替换。默认值为 false |
可用预设
| Preset | Description |
|---|---|
minimal-dark | 近黑色背景、白色文本、单一强调色 |
warm-editorial | 暖调米白背景、衬线标题、自然色系强调色 |
corporate-blue | 海军蓝与白色配色,搭配专业排版 |
vibrant-startup | 明亮渐变、圆角、现代无衬线字体 |
classic-blog | 中性灰色、舒适行高、传统布局间距 |
返回 { "success": true, "preset": "minimal-dark" }
全局样式
全局样式功能通过 WordPress Global Styles API 读取和写入 theme.json 值,影响整个站点的所有区块和模板。
get_global_styles
返回当前全局样式配置。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | No | 指向特定值的 JSON 指针,例如 /color/palette 或 /typography/fontSizes。如果省略,则返回整个对象。 |
返回 完整的全局样式对象或 path 处的值。
set_global_styles
更新全局样式配置中的一个或多个值。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | 指向要设置值的 JSON 指针,例如 /color/palette |
value | any | Yes | 新值 |
示例 — 向调色板添加一种颜色
{
"path": "/color/palette",
"value": [
{ "slug": "primary", "color": "#1a1a2e", "name": "Primary" },
{ "slug": "accent", "color": "#e94560", "name": "Accent" }
]
}
返回 { "success": true, "path": "/color/palette" }
reset_global_styles
重置所有由代理应用的全局样式更改,恢复主题默认值。
参数 — 无
返回 { "success": true }
导航菜单
导航菜单功能用于创建和管理 WordPress 导航菜单及其项目。
create_menu
创建新的 WordPress 导航菜单。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | 菜单名称,例如 Primary Navigation |
location | string | No | 要将此菜单分配到的主题位置,例如 primary |
返回 { "success": true, "menu_id": 7 }
update_menu
重命名菜单或将其重新分配到主题位置。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
menu_id | integer | Yes | 要更新的菜单 ID |
name | string | No | 新菜单名称 |
location | string | No | 要分配或重新分配的主题位置 |
返回 { "success": true, "menu_id": 7 }
add_menu_item
向现有导航菜单添加一个项目。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
menu_id | integer | Yes | 目标菜单的 ID |
type | string | Yes | 项目类型:custom、post_type 或 taxonomy |
title | string | No | 菜单项目的标签(custom 类型必填) |
url | string | No | custom 项目的 URL |
object_id | integer | No | post_type/taxonomy 项目的文章 ID 或术语 ID |
parent_id | integer | No | 用于将此项目嵌套到其下的菜单项目 ID |
position | integer | No | 菜单中从零开始的位置 |
返回 { "success": true, "item_id": 12 }
remove_menu_item
从导航菜单中移除一个项目。
参数
| Parameter | Type | Required | Description |
|---|---|---|---|
item_id | integer | Yes | 要移除的菜单项目 ID |
返回 { "success": true, "item_id": 12 }
list_menus
列出所有 WordPress 导航菜单,包括它们分配的主题位置。
参数 — 无
返回
{
"menus": [
{
"menu_id": 7,
"name": "Primary Navigation",
"location": "primary",
"item_count": 5
}
]
}