Community编程与开发github.com

fswp-api-developer

Full-Stack WP 开发者领域的 WordPress REST API 与 Abilities API 专业技能。涵盖路由注册、参数验证与消毒、权限回调、控制器类、内容类型与元数据暴露、认证(Cookie nonce、应用密码)、分页与错误处理,以及带输入输出 schema 和安全注解的能力注册。适用于插件或主题中的任何自定义端点或机器可调用能力。

fswp-api-developer 是什么?

FSWP API Developer 是 Full-Stack WP Developer 中的一个领域技能,专门用于在 WordPress 插件或主题中开发 REST API 路由和 Abilities API 能力。它提供了从路由注册到认证、参数验证、权限控制、分页错误处理以及控制器类使用的完整指导,确保 API 安全、高效且符合 WordPress 编码标准。该技能特别强调了强制性的 `permission_callback`、参数 schema 声明、使用 `rest_ensure_response()` 标准化响应,以及通过 `WP_REST_Controller` 类的面向对象设计。对于 Abilities API,它指导如何注册具有输入输出 JSON Schema 和安全注解的机器可调用能力,并提供了严格的安全审计流程——读能力不能写,破坏性能力必须标注,否则视为缺陷。该技能适用于 Cursor、Claude Code 等 AI 编码代理,帮助开发者自动生成符合 WordPress 核心规范的端点和能力,同时遵循 `fswp-security-engineer` 的安全约束,确保代码质量和安全性。

兼容平台~Claude Code~Codex CLI~Cursor
Part ofMobile
npx skills add https://github.com/syncwin/fswp-developer/tree/main/skills/fswp-api-developer

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

FSWP API 开发者

始终应用的基础文档: fswp-developer/references/lean-coding.md(少写、先复用)、fswp-developer/references/coding-standards.md(编码标准、文档、国际化、可访问性),以及 fswp-security-engineer(输入、输出、授权)。

官方参考:REST API 手册(fswp-developer/references/official-docs.md)。fswp-security-engineer 中的安全规则适用于每条路由。

注册路由

function vp_register_routes() {
	register_rest_route( 'vendor-prefix/v1', '/items/(?P<id>\d+)', array(
		'methods'             => WP_REST_Server::READABLE,
		'callback'            => 'vp_get_item',
		'permission_callback' => function ( WP_REST_Request $r ) {
			return current_user_can( 'edit_post', (int) $r['id'] );
		},
		'args'                => array(
			'id' => array( 'type' => 'integer', 'required' => true, 'sanitize_callback' => 'absint' ),
		),
	) );
}
add_action( 'rest_api_init', 'vp_register_routes' );

规则

  • 命名空间和版本: vendor-prefix/v1。绝不在核心的 wp/v2 命名空间中注册。
  • permission_callback 是必需的。 返回一个权限检查,而不仅仅是登录状态。仅对真正公开的数据使用 __return_true,并附上注释解释原因。当请求中包含 ID 时,要检查对象级别的访问权限(edit_post、所有权)。
  • 声明 args,包括 type、required、enum、minimum/maximum、validate_callback 和 sanitize_callback。即使经过验证,请求也是不可信的;使用 $request->get_param() 的值作为类型后的值。
  • 使用 rest_ensure_response() 返回数据;错误使用 new WP_Error( 'vp_code', __( 'Message', 'text-domain' ), array( 'status' => 404 ) )。使用准确的状态码(400 无效、401 未认证、403 禁止、404 未找到、409 冲突、413 过大)。
  • Schema: 实现 get_item_schema()(或 schema 回调),以便客户端和索引可以描述资源;使用 prepare_item_for_response() 构建响应。
  • 集合: 支持带有硬上限的 page/per_page,设置 X-WP-Total 和 X-WP-TotalPages,绝不返回无边界列表。
  • 绝不返回 机密信息、密码哈希、原始选项或其他用户的私有数据。
  • 控制器: 对于超过几个路由的情况,扩展 WP_REST_Controller(register_routes、get_items、get_item、create_item、每种方法的权限检查)并只注册一次该类。
  • 暴露核心对象: 自定义文章类型和分类法使用 'show_in_rest' => true(和 rest_base);元数据使用 register_meta()/register_post_meta() 和 'show_in_rest' => true,同时提供 schema 和 auth_callback。
  • 缓存与性能: 廉价的 GET 处理器;缓存昂贵的结果(fswp-performance-engineer);避免在循环中进行查询。

认证

客户端方法
同站点 JS(后台、区块、前端)Cookie 认证,附带上 X-WP-Nonce 头(wp_create_nonce( 'wp_rest' ),或自动添加的 wp_localize_script / @wordpress/api-fetch)
外部服务器或应用通过 HTTPS 使用应用密码,或经过审查的 OAuth 插件
公开读取无需认证,仅当数据公开时

Nonce 不能替代权限检查。CORS:不要在已认证的路由上开放 Access-Control-Allow-Origin: *。

客户端

在区块和管理界面中使用 @wordpress/api-fetch。通过 code 和 message 处理错误,而不是通过解析文本。

Abilities API

这是一个用于注册离散的、机器可读能力的核心 API(名称、输入 schema、输出 schema、权限检查、执行回调),工具和 AI 代理可以发现并调用它们。这是较新的 API:在使用之前,请确认最低 WordPress 版本和确切的函数名(搜索“Abilities API”)。仅在 PRD 需要代理可调用函数时使用;普通的客户端-服务器调用适用普通 REST。

注册能力时:

  • 首先在文档化的钩子上注册类别,然后注册能力。
  • 为其提供输入和输出的 JSON Schema,以及一个检查真实能力的 permission_callback。
  • 诚实设置安全注解:只读能力不得写入,破坏性能力必须标记。一个写入数据但标记为只读的回调是缺陷,fswp-reviewer 会将其视为缺陷。
  • 只将应该远程调用的内容通过 REST 暴露出来。

审计和验证流程:references/abilities.md。

为了提议哪些现有端点应该成为能力,列出每个路由及其方法、当前权限检查、副作用和建议的注解;在获得批准之前不注册任何内容。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

fswp-architect

Planning stage of Full-Stack WP Developer. Classifies the work (new plugin, new theme, update to an existing plugin or theme, add-on for another product, or WordPress Core patch), triages existing code with a bundled detection script, asks one round of essential questions, does competitive research, and produces one reviewable PRD or change brief with a single approval gate. Also covers Migration mode and multi-session handoff docs. Invoked by fswp-developer before any code is written; consult directly for PRD, change-brief, or handoff-doc questions.

fswp-block-developer

Domain skill for WordPress block editor work in Full-Stack WP Developer. Covers building custom Gutenberg blocks (block.json, static and dynamic rendering, attributes, supports, InnerBlocks, variations, deprecations, block bindings), block patterns, and the Interactivity API (data-wp directives, stores, server-side state), with the @wordpress/scripts build workflow. Use for any custom block, pattern, or front-end interactivity in a plugin or theme.

fswp-core-contributor

WordPress Core contribution stage of Full-Stack WP Developer. Guides a contributor through finding or filing a Trac ticket, setting up the wordpress-develop checkout and test environment, writing a patch or GitHub pull request that follows Core coding standards, inline documentation, backward compatibility and tests, and preparing the ticket comment; also routes block-editor changes to the Gutenberg repository and security reports to the private process. Invoked by fswp-developer for Core patches; consult directly for Core workflow questions.

fswp-devops-engineer

Domain skill for WordPress development tooling in Full-Stack WP Developer. Covers local environments (wp-env with Docker, WordPress Playground and Blueprints), command-line site operations (plugin and theme management, database export, search-replace, cron, scaffolding), coding standards and static analysis (PHPCS with WordPress standards, PHPStan with WordPress stubs), PHP and JS testing setup, and the @wordpress/scripts toolchain. Use when setting up, running, or automating a WordPress dev or test environment.

fswp-maintainer

Change stage for existing WordPress code in Full-Stack WP Developer. Updates, fixes, refactors, and upgrades existing plugins and themes without breaking them, and builds add-ons for products you do not own (WooCommerce extensions, page-builder elements, extensions of other plugins) using hooks instead of edits to third-party files. Covers reading before changing, parity lists, deprecation, host compatibility, upgrade paths, and patch delivery. Invoked by fswp-developer after an approved change brief; consult directly for safe-change or add-on questions.

fswp-qa-engineer

Verification stage of Full-Stack WP Developer. Runs the mechanical gate for plugins and themes (house-rule scripts, PHP lint, PHPCS with WordPress standards, PHP compatibility, PHPStan with WordPress stubs), the manual checklist, PRD or change-brief scenario tests, and the pre-release check. Reports PASS, FAIL, or NOT RUN and never implies a skipped check passed. Invoked by fswp-developer after a build and again before delivery; consult directly to audit any plugin or theme folder.

fswp-reviewer

Independent review stage of Full-Stack WP Developer. Reviews a finished WordPress plugin, theme, add-on, or Core patch through a security lens (WordPress-specific vulnerabilities, REST and AJAX authorization with an API risk map, AI-generated-code risks), a quality lens (error handling, data and upgrade safety, performance, i18n, accessibility, comment accuracy, test gaps, class and type design, scope), and an optional lean lens for trimming over-engineering, reporting only high-confidence findings in a fixed format. Invoked by fswp-developer after the verify gate, normally through the fswp-code-reviewer agent; consult directly to review or optimize any WordPress code.

fswp-theme-developer

Theme build stage of Full-Stack WP Developer. Builds custom WordPress themes - block themes (theme.json, templates, template parts, patterns, style variations), classic themes (template hierarchy, functions.php, theme supports), hybrids, and child themes - with accessibility, escaping, and directory readiness built in, plus a scaffold script. Invoked by fswp-developer after an approved PRD for a new theme; consult directly for a specific theme pattern. For changes to an existing theme use fswp-maintainer.

syncwin/fswp-plugin-developer

Plugin build stage of Full-Stack WP Developer. House standards and code templates for real WordPress plugins (not shortcode snippets) - folder anatomy, activation/uninstall lifecycle, custom post types and tables, admin UI tiers, front-end output on the Atomic Framework, REST and cron, i18n, distribution, and the Tier 3 React admin stack - plus a scaffold script. Also the base structure for add-ons. Invoked by fswp-developer after an approved PRD; consult directly for a specific plugin build pattern.

相关技能