Community程式設計與開發github.com

FSWP API 開發者

專為 WordPress REST API 與 Abilities API 開發設計的領域技能,涵蓋路由註冊、參數驗證、權限回呼、控制器類別、內容類型公開、認證機制,以及註冊具備輸入/輸出結構與安全註解的 Abilities。

FSWP API 開發者 是什麼?

FSWP API 開發者是一個專為在 Full-Stack WP Developer 框架中進行 WordPress REST API 及 Abilities API 工作而設計的領域技能。它詳細說明了如何註冊自訂路由,包括強制性的 `permission_callback`、參數的 `args` 定義(型別、必填、驗證與清理回呼)、使用 `WP_Error` 與正確 HTTP 狀態碼處理錯誤,以及透過 `rest_ensure_response()` 和 `WP_REST_Controller` 類別建構結構化的回應與集合端點。此外,也涵蓋認證方式,如同網站內 Cookie 與 nonce 標頭、外部應用的應用程式密碼,以及公開資料的免認證存取。對於 Abilities API,它指示開發者在核准前如何註冊類別與能力,定義 JSON Schema 的輸入/輸出,設定誠實的安全註解(唯讀、具破壞性),並確保回呼遵守這些宣告。此技能支援 Claude Code、Cursor 及類似平台,並強調遵循 `fswp-developer` 參考文件(精簡編碼、編碼標準)與 `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(管理後台、區塊、前端)使用帶有 X-WP-Nonce 標頭的 Cookie 認證(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 即可。

註冊 ability 時:

  • 先在文件中規定的鉤子上註冊類別,再註冊 ability。
  • 為其提供輸入和輸出的 JSON Schemas,以及一個檢查真實能力的 permission_callback。
  • 誠實設定安全註解:唯讀 abilities 不得執行寫入操作,具破壞性的必須標記。回呼在標記為唯讀的情況下執行寫入即為缺陷,fswp-reviewer 會將其視為缺陷。
  • 僅將應該可遠端呼叫的項目透過 REST 公開。

稽核與驗證程序:references/abilities.md。

若要提議哪些現有端點應轉換為 abilities,請列出每個路由及其方法、目前權限檢查、副作用以及建議的註解;在獲得核准前,請勿註冊任何內容。

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.

相關技能