跳到主要内容

能力参考

能力是 Gratis AI Agent 可以在你的 WordPress 安装中调用的原子操作。每个能力都是一个已注册的 PHP 类,会公开一个 JSON schema — agent 会在运行时读取此 schema,以了解需要哪些参数以及该能力会返回什么。

本页记录了 Gratis AI Agent v1.9.0 随附的所有能力。


自定义文章类型

这些能力用于管理通过 agent 注册的自定义文章类型(CPT)。注册信息会持久保存到 WordPress options 表中,因此即使 plugin 停用并重新启用也会保留。

register_post_type

注册一个新的自定义文章类型。

参数

ParameterTypeRequiredDescription
slugstringYes文章类型键(最多 20 个字符,不含大写字母,不含空格)
singular_labelstringYes人类可读的单数名称,例如 Portfolio Item
plural_labelstringYes人类可读的复数名称,例如 Portfolio Items
publicbooleanNo该文章类型是否可公开访问。默认 true
supportsarrayNo要支持的功能:titleeditorthumbnailexcerptcommentsrevisionscustom-fields。默认 ["title","editor"]
has_archivebooleanNo是否启用文章类型归档页面。默认 false
menu_iconstringNo管理菜单图标的 Dashicons 类或 URL。默认 "dashicons-admin-post"
rewrite_slugstringNo文章类型的 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 注册的自定义文章类型。该类型的现有文章会保留在数据库中,但不再能通过该文章类型访问。

参数

ParameterTypeRequiredDescription
slugstringYes要移除的文章类型键

返回 { "success": true, "slug": "portfolio" }


自定义分类法

这些能力用于管理自定义分类法。与 CPT 一样,分类法注册信息会被持久保存。

register_taxonomy

注册一个新的自定义分类法。

参数

ParameterTypeRequiredDescription
slugstringYes分类法键(最多 32 个字符)
singular_labelstringYes人类可读的单数名称,例如 Project Category
plural_labelstringYes人类可读的复数名称,例如 Project Categories
post_typesarrayYes此分类法应附加到的文章类型 slug
hierarchicalbooleanNotrue 表示类别样式,false 表示标签样式。默认 true
publicbooleanNo术语是否可公开访问。默认 true
rewrite_slugstringNo分类法的 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 注册的自定义分类法。

参数

ParameterTypeRequiredDescription
slugstringYes要移除的分类法键

返回 { "success": true, "slug": "project-category" }


设计系统

设计系统能力用于修改 WordPress 站点的视觉呈现 — 从自定义 CSS 到区块模式和站点标志。

inject_custom_css

通过 wp_add_inline_style 将 CSS 追加到站点的 <head>。CSS 存储在 gratis_ai_agent_custom_css option 中,并在该能力重置时干净地取消入队。

参数

ParameterTypeRequiredDescription
cssstringYes要注入的有效 CSS
labelstringNo此 CSS 块的人类可读标签,用于调试日志。默认 "agent-injected"
replacebooleanNo如果为 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 模式库中注册一个可复用的区块模式。

参数

ParameterTypeRequiredDescription
slugstringYes模式标识符,例如 gratis/hero-dark
titlestringYes编辑器中显示的人类可读模式名称
contentstringYes该模式的序列化区块标记(HTML)
categoriesarrayNo模式类别 slug,例如 ["featured", "hero"]
descriptionstringNo模式选择器中显示的简短描述
keywordsarrayNo搜索关键词

返回 { "success": true, "slug": "gratis/hero-dark" }


list_block_patterns

列出由 agent 注册的所有区块模式。

参数 — 无

返回

{
"patterns": [
{
"slug": "gratis/hero-dark",
"title": "Dark Hero",
"categories": ["hero"]
}
]
}

将 WordPress 站点标志设置为给定的附件 ID 或远程图片 URL。提供 URL 时,图片会被下载并导入到媒体库中。

参数

ParameterTypeRequiredDescription
attachment_idintegerNo现有媒体库附件的 ID
urlstringNo要导入并设置为标志的远程图片 URL

必须提供 attachment_idurl 中的一个。

返回 { "success": true, "attachment_id": 42 }


apply_theme_json_preset

将命名的颜色/排版预设应用到当前启用主题的 theme.json(或 global-styles)。预设是由 Gratis AI Agent 团队维护的精选组合。

参数

ParameterTypeRequiredDescription
presetstringYes预设名称,例如 minimal-darkwarm-editorialcorporate-blue
mergebooleanNo如果为 true,则与现有值合并而不是替换。默认值为 false

可用预设

PresetDescription
minimal-dark近黑色背景、白色文本、单一强调色
warm-editorial暖调米白背景、衬线标题、自然色系强调色
corporate-blue海军蓝与白色配色,搭配专业排版
vibrant-startup明亮渐变、圆角、现代无衬线字体
classic-blog中性灰色、舒适行高、传统布局间距

返回 { "success": true, "preset": "minimal-dark" }


全局样式

全局样式功能通过 WordPress Global Styles API 读取和写入 theme.json 值,影响整个站点的所有区块和模板。

get_global_styles

返回当前全局样式配置。

参数

ParameterTypeRequiredDescription
pathstringNo指向特定值的 JSON 指针,例如 /color/palette/typography/fontSizes。如果省略,则返回整个对象。

返回 完整的全局样式对象或 path 处的值。


set_global_styles

更新全局样式配置中的一个或多个值。

参数

ParameterTypeRequiredDescription
pathstringYes指向要设置值的 JSON 指针,例如 /color/palette
valueanyYes新值

示例 — 向调色板添加一种颜色

{
"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 导航菜单。

参数

ParameterTypeRequiredDescription
namestringYes菜单名称,例如 Primary Navigation
locationstringNo要将此菜单分配到的主题位置,例如 primary

返回 { "success": true, "menu_id": 7 }


update_menu

重命名菜单或将其重新分配到主题位置。

参数

ParameterTypeRequiredDescription
menu_idintegerYes要更新的菜单 ID
namestringNo新菜单名称
locationstringNo要分配或重新分配的主题位置

返回 { "success": true, "menu_id": 7 }


add_menu_item

向现有导航菜单添加一个项目。

参数

ParameterTypeRequiredDescription
menu_idintegerYes目标菜单的 ID
typestringYes项目类型:custompost_typetaxonomy
titlestringNo菜单项目的标签(custom 类型必填)
urlstringNocustom 项目的 URL
object_idintegerNopost_type/taxonomy 项目的文章 ID 或术语 ID
parent_idintegerNo用于将此项目嵌套到其下的菜单项目 ID
positionintegerNo菜单中从零开始的位置

返回 { "success": true, "item_id": 12 }


remove_menu_item

从导航菜单中移除一个项目。

参数

ParameterTypeRequiredDescription
item_idintegerYes要移除的菜单项目 ID

返回 { "success": true, "item_id": 12 }


list_menus

列出所有 WordPress 导航菜单,包括它们分配的主题位置。

参数 — 无

返回

{
"menus": [
{
"menu_id": 7,
"name": "Primary Navigation",
"location": "primary",
"item_count": 5
}
]
}

选项管理

选项功能通过 get_option / update_option 读取和写入 WordPress 选项。内置安全阻止列表可防止意外修改关键设置。

get_option

读取 WordPress 选项。

参数

ParameterTypeRequiredDescription
option_namestringYes选项键,例如 blogname

返回 { "option_name": "blogname", "value": "My Site" }

如果 option_name 位于安全阻止列表中,则返回错误。


set_option

写入 WordPress 选项。

参数

ParameterTypeRequiredDescription
option_namestringYes选项键
valueanyYes新值(数组/对象会自动序列化)
autoloadstringNo"yes""no"。默认保留现有 autoload 设置

如果 option_name 在安全阻止列表中,则返回错误。

返回 { "success": true, "option_name": "blogname" }


delete_option

删除一个 WordPress 选项。

参数

参数类型必需描述
option_namestring要删除的选项键

如果 option_name 在安全阻止列表中,则返回错误。

返回 { "success": true, "option_name": "my_custom_option" }


list_options

列出匹配某个模式的 WordPress 选项。

参数

参数类型必需描述
patternstring用于筛选选项名称的 SQL LIKE 模式,例如 gratis_%。如果省略,则返回所有选项(在大型数据库上请谨慎使用)。
limitinteger最大结果数量。默认 50,最大 500

返回

{
"options": [
{ "option_name": "gratis_ai_agent_version", "autoload": "yes" }
],
"total": 1
}

内容管理

内容管理能力可创建和编辑 WordPress 文章和页面。会返回文章 ID,以便多能力计划中的后续步骤可以引用已创建的内容。

create_post

创建新的 WordPress 文章、页面或自定义文章类型条目。

参数

参数类型必需描述
titlestring文章标题
contentstring文章正文 — 接受纯文本、HTML 或序列化的区块标记
statusstringdraftpublishpendingprivate。默认 draft
post_typestring文章类型别名,例如 postpage,或任何已注册的 CPT。默认 post
excerptstring在归档和搜索结果中显示的简短摘要
categoriesarray要分配的分类名称或 ID 数组
tagsarray要分配的标签名称或 ID 数组
authorinteger要设为文章作者的 WordPress 用户 ID。默认为当前用户
datestringISO 8601 格式的发布日期,例如 2026-05-01T09:00:00
page_templatestring要分配给此文章或页面的模板文件,例如 page-full-width.php。仅当 post_typepage 或支持页面模板的 CPT 时才有意义。

示例

{
"title": "Welcome to Our New Site",
"content": "<!-- wp:paragraph --><p>Hello world!</p><!-- /wp:paragraph -->",
"status": "publish",
"post_type": "page",
"page_template": "page-full-width.php"
}

返回 { "success": true, "post_id": 42, "permalink": "https://example.com/welcome/" }


update_post

更新现有的 WordPress 文章或页面。

参数

参数类型必需描述
post_idinteger要更新的文章 ID
titlestring新的文章标题
contentstring新的文章正文
statusstring新状态:draftpublishpendingprivate
excerptstring新摘要
categoriesarray用此名称或 ID 数组替换完整分类列表
tagsarray用此名称或 ID 数组替换完整标签列表
page_templatestring要分配给此文章或页面的新模板文件,例如 page-full-width.php。传入空字符串可移除模板分配并恢复为 theme 默认值。

示例 — 创建后更改模板

{
"post_id": 42,
"page_template": "page-full-width.php"
}

返回 { "success": true, "post_id": 42 }


batch_create_posts

在一次能力调用中创建多篇文章,减少站点构建或批量内容导入期间的往返请求。文章会按顺序创建;如果其中一篇失败,其他文章会继续处理,并在结果数组中报告该失败。

参数

参数类型必需描述
postsarray文章对象数组,每个对象接受与 create_post 相同的参数
stop_on_errorboolean如果为 true,则在第一次失败后停止处理。默认 false

示例

{
"posts": [
{
"title": "About Us",
"post_type": "page",
"status": "publish",
"page_template": "page-full-width.php"
},
{
"title": "Services",
"post_type": "page",
"status": "publish"
},
{
"title": "Contact",
"post_type": "page",
"status": "publish"
}
]
}

返回

{
"created": 3,
"failed": 0,
"results": [
{ "success": true, "post_id": 42, "title": "About Us" },
{ "success": true, "post_id": 43, "title": "Services" },
{ "success": true, "post_id": 44, "title": "Contact" }
]
}

set_featured_image

为现有文章或页面分配特色图片(文章缩略图)。接受现有媒体库附件 ID 或远程图片 URL;提供 URL 时,会自动下载并导入该图片。

参数

参数类型必需描述
post_idinteger要更新的文章或页面 ID
attachment_idinteger现有媒体库附件的 ID
urlstring要导入并设为特色图片的远程图片 URL
alt_textstring如果附件是从 URL 导入的,则应用到该附件的替代文本

必须提供 attachment_idurl 之一。

返回 { "success": true, "post_id": 42, "attachment_id": 17 }


create_contact_form

使用当前启用的表单 plugin(Contact Form 7、WPForms、Fluent Forms 或 Gravity Forms,取决于已安装的 plugin)创建联系表单。返回一个可嵌入任何文章或页面的短代码。

参数

ParameterTypeRequiredDescription
titlestringYes表单 plugin 管理后台中显示的表单名称
fieldsarrayYes表单字段的有序列表(见下方 Field 对象)
recipientstringNo用于接收提交内容的电子邮件地址。默认使用 WordPress 管理员电子邮件
subjectstringNo电子邮件主题行。使用 Contact Form 7 时支持 [your-name][your-subject] 占位符
confirmation_messagestringNo成功提交后显示的消息。默认值:"Thank you for your message. We'll be in touch soon."

Field 对象

KeyTypeRequiredDescription
namestringYes内部字段名称 / 机器键
labelstringYes表单上显示的人类可读标签
typestringYestext, email, tel, textarea, select, checkbox, radio, file, date
requiredbooleanNo提交前是否必须填写该字段。默认值 false
optionsarrayNoselectcheckboxradio 字段的选项
placeholderstringNo文本类型输入的占位符文本

示例

{
"title": "Restaurant Booking Enquiry",
"fields": [
{ "name": "your-name", "label": "Name", "type": "text", "required": true },
{ "name": "your-email", "label": "Email", "type": "email", "required": true },
{ "name": "party-size", "label": "Party size", "type": "select", "options": ["1–2", "3–5", "6–10", "10+"] },
{ "name": "your-message", "label": "Special requests", "type": "textarea", "required": false }
],
"recipient": "[email protected]",
"subject": "New booking enquiry from [your-name]"
}

返回

{
"success": true,
"form_id": 3,
"shortcode": "[contact-form-7 id=\"3\" title=\"Restaurant Booking Enquiry\"]"
}

Visual Review

Visual Review 能力允许 agent 捕获实时页面的屏幕截图并对其进行分析,从而无需任何浏览器扩展即可进行自主设计评审、前后对比和视觉回归检查。

capture_screenshot

使用服务器端无头浏览器捕获指定 URL 上 WordPress 页面的屏幕截图。图像会保存到媒体库,并返回一个 CDN URL。

参数

ParameterTypeRequiredDescription
urlstringYes要截图的页面完整 URL,例如 https://example.com/about/
widthintegerNo视口宽度(像素)。默认值 1280
heightintegerNo视口高度(像素)。默认值 800
full_pagebooleanNo捕获完整可滚动页面,而不只是视口。默认值 false
delay_msintegerNo页面加载后等待多少毫秒再捕获,适用于动画内容。默认值 500
labelstringNo与媒体库中附件一起存储的人类可读标签

返回

{
"success": true,
"attachment_id": 88,
"url": "https://example.com/wp-content/uploads/2026/04/screenshot-about.png",
"width": 1280,
"height": 800
}

compare_screenshots

获取两张屏幕截图,并返回视觉差异分数以及突出显示变化区域的差异图像。适用于确认设计更改是否产生预期结果,或检测意外回归。

参数

ParameterTypeRequiredDescription
before_urlstringYes要作为“之前”状态捕获的页面 URL
after_urlstringYes要作为“之后”状态捕获的页面 URL。如果是跨时间比较,可以是同一 URL
widthintegerNo两次捕获的视口宽度。默认值 1280
thresholdfloatNo像素差异阈值(0.0–1.0)。此容差范围内的像素视为未变化。默认值 0.1

返回

{
"success": true,
"diff_score": 0.04,
"changed_pixels": 2340,
"total_pixels": 1024000,
"diff_attachment_id": 91,
"diff_url": "https://example.com/wp-content/uploads/2026/04/diff-about.png"
}

diff_score0.0 表示没有可见变化;1.0 表示每个像素都发生了变化。


review_page_design

捕获页面的屏幕截图并将其发送给语言模型进行视觉分析。返回涵盖布局、排版、颜色使用和无障碍问题的结构化评估。

参数

ParameterTypeRequiredDescription
urlstringYes要评审的页面完整 URL
focusstringNo逗号分隔的要重点关注的评审区域列表:layouttypographycolouraccessibilitymobile。默认值:所有区域
widthintegerNo视口宽度。默认值 1280

返回

{
"success": true,
"screenshot_url": "https://example.com/wp-content/uploads/2026/04/review-about.png",
"assessment": {
"overall": "The page structure is clean and readable. Two accessibility issues detected.",
"layout": "Good visual hierarchy. Hero section is prominent.",
"typography": "Body text is 15px — consider increasing to 16px for readability.",
"colour": "Contrast ratio on the CTA button (#fff on #4a90e2) is 3.1:1 — below the WCAG AA threshold of 4.5:1.",
"accessibility": ["Low contrast on CTA button", "Missing alt text on hero image"],
"suggestions": ["Darken the CTA button to #1a5cb0 to pass WCAG AA", "Add descriptive alt text to the hero image"]
}
}

可安装能力

可安装能力注册表允许你通过以 WordPress plugin 形式分发的附加能力包来扩展 agent。每个包使用标准能力 API 注册一个或多个能力。

list_available_abilities

返回可从注册表安装的能力包目录。

参数

参数类型必填描述
categorystring按类别筛选:ecommerceseomediasocialdeveloper

返回

{
"packs": [
{
"slug": "gratis-ai-agent-woocommerce",
"name": "WooCommerce Abilities",
"category": "ecommerce",
"version": "1.0.0",
"abilities": ["create_product", "update_pricing", "manage_inventory"],
"installed": false
}
]
}

install_ability

从注册表下载并激活一个能力包。

参数

参数类型必填描述
slugstring能力包 plugin slug

返回 { "success": true, "slug": "gratis-ai-agent-woocommerce", "abilities_added": 3 }


recommend_plugin

查询能力注册表,以找到最适合所描述用例的 plugin,并可选择安装它。

参数

参数类型必填描述
descriptionstring所需功能的自然语言描述
installboolean如果为 true,立即安装推荐的 plugin。默认值为 false

示例

{
"description": "I need a contact form with file upload support and spam protection",
"install": false
}

返回

{
"recommendation": {
"slug": "contact-form-7",
"name": "Contact Form 7",
"reason": "Widely adopted, supports file uploads, and integrates with Akismet for spam filtering.",
"alternatives": ["wpforms-lite", "fluent-forms"]
}
}