WordPress REST API
Use this skill when the correct interface is HTTP against a WordPress site, not shell access with wp.
This skill is built around two facts:
- - WordPress core ships a large REST surface under INLINECODE1
- the truly complete endpoint list is site-specific because plugins and custom code can register more routes
Treat the reference files as the core map and use the discovery script for the live map.
Use This Skill For
- - inspecting
/wp-json on a live site - choosing the right core route before writing code or automation
- authenticating with application passwords for machine-to-machine calls
- checking cookie and nonce-based admin flows
- inspecting custom plugin routes and namespaces
- figuring out which methods and args a route accepts
- designing or reviewing
register_rest_route() implementations
Do Not Use This Skill For
- - normal shell-based site administration when
wp access already exists - WP-CLI command or package development
- pretending the static reference files can enumerate plugin routes on every site
Workflow
1. Discover The Live Route Index
Start with:
CODEBLOCK0
This fetches the site index at /wp-json/, prints the namespaces, and lists the live routes that site exposes.
If you need one route only:
CODEBLOCK1
Read references/core-endpoints.md before assuming a core route name from memory.
2. Choose The Right Auth Model
Default rule:
- - external automation: use application passwords over HTTPS
- logged-in browser admin flow: use cookie auth plus nonce handling
- public read-only data: use unauthenticated GET only when the site exposes it intentionally
Read references/auth-and-discovery.md.
3. Prefer Core Namespaces First
Core routes are more stable than plugin routes.
Common starting points:
- - posts, pages, media, comments, categories, tags
- users and settings when authenticated
- templates, template parts, patterns, and block-editor related routes on newer installs
- plugins and themes only when the target site and permissions allow them
4. Inspect Custom Routes Live
For plugin or theme APIs, do not guess.
Use the discovery index and OPTIONS:
CODEBLOCK2
Then read references/custom-route-rules.md if you are implementing or reviewing the server-side route registration.
5. Keep Calls Small And Explicit
Default patterns:
- - use
?_fields= to trim large responses - use
page, per_page, search, orderby, and order instead of client-side filtering when possible - check pagination headers such as
X-WP-Total and INLINECODE14 - use
OPTIONS before write automation when you do not control the site code
Files
- -
scripts/inspect-rest-api.sh: discover the live route index or inspect a single route with GET or OPTIONS - INLINECODE17 : core route families worth checking before you inspect plugin namespaces
- INLINECODE18 : application passwords, cookie auth, nonces, and route discovery rules
- INLINECODE19 : implementation-side guidance for registering or reviewing custom routes
WordPress REST API
当正确的接口是通过HTTP访问WordPress站点,而非使用wp进行shell访问时,请使用此技能。
此技能基于两个事实构建:
- - WordPress核心在/wp-json下提供了大量的REST接口
- 真正完整的端点列表是站点特定的,因为插件和自定义代码可以注册更多路由
将参考文件视为核心地图,并使用发现脚本获取实时地图。
使用此技能的场景
- - 检查在线站点的/wp-json
- 在编写代码或自动化之前选择正确的核心路由
- 使用应用程序密码进行机器对机器调用的身份验证
- 检查基于cookie和nonce的管理流程
- 检查自定义插件路由和命名空间
- 确定路由接受的方法和参数
- 设计或审查registerrestroute()实现
不使用此技能的场景
- - 当已存在wp访问权限时,进行常规的基于shell的站点管理
- WP-CLI命令或包开发
- 假设静态参考文件可以枚举每个站点上的插件路由
工作流程
1. 发现实时路由索引
从以下命令开始:
bash
scripts/inspect-rest-api.sh --site https://example.com
这将获取/wp-json/处的站点索引,打印命名空间,并列出该站点暴露的实时路由。
如果只需要一个路由:
bash
scripts/inspect-rest-api.sh --site https://example.com --route /wp/v2/posts
scripts/inspect-rest-api.sh --site https://example.com --route /wp/v2/posts --method OPTIONS
在凭记忆假设核心路由名称之前,请阅读references/core-endpoints.md。
2. 选择正确的认证模型
默认规则:
- - 外部自动化:通过HTTPS使用应用程序密码
- 已登录的浏览器管理流程:使用cookie认证加nonce处理
- 公共只读数据:仅在站点有意暴露时使用未经认证的GET请求
阅读references/auth-and-discovery.md。
3. 优先使用核心命名空间
核心路由比插件路由更稳定。
常见起点:
- - 文章、页面、媒体、评论、分类、标签
- 认证后的用户和设置
- 较新安装上的模板、模板部件、模式和块编辑器相关路由
- 仅当目标站点和权限允许时的插件和主题
4. 实时检查自定义路由
对于插件或主题API,不要猜测。
使用发现索引和OPTIONS:
bash
scripts/inspect-rest-api.sh --site https://example.com --route /my-namespace/v1/report --method OPTIONS
然后,如果您正在实现或审查服务器端路由注册,请阅读references/custom-route-rules.md。
5. 保持调用简洁明确
默认模式:
- - 使用?fields=来精简大型响应
- 尽可能使用page、perpage、search、orderby和order,而不是客户端过滤
- 检查分页头部,如X-WP-Total和X-WP-TotalPages
- 当您不控制站点代码时,在编写自动化之前使用OPTIONS
文件
- - scripts/inspect-rest-api.sh:发现实时路由索引,或使用GET或OPTIONS检查单个路由
- references/core-endpoints.md:在检查插件命名空间之前值得检查的核心路由系列
- references/auth-and-discovery.md:应用程序密码、cookie认证、nonce和路由发现规则
- references/custom-route-rules.md:注册或审查自定义路由的实现端指南