Community程式設計與開發github.com

FSWP 區塊開發者

專為全端 WordPress 開發者設計的 Gutenberg 區塊編輯器技能,涵蓋自訂區塊、區塊樣板與互動 API。

FSWP 區塊開發者 是什麼?

這項技能專注於 WordPress 區塊編輯器(Gutenberg)的自訂開發,是 Full-Stack WP Developer 角色的一部分。它提供建立自訂區塊的完整指引,包括 static 與 dynamic 區塊的 block.json 設定、屬性、支援功能、InnerBlocks、變體、棄用處理以及區塊綁定。此外,還涵蓋區塊樣板(Block Patterns)的註冊與使用,以及 Interactivity API 的實作,讓開發者能夠透過 data-wp 指令、store 與伺服器端狀態來建立輕量、無框架的前端互動行為。此技能支援 @wordpress/scripts 的建置流程,並強調遵循 WordPress 編碼標準、安全性與無障礙性。開發者應優先使用核心區塊,僅在核心區塊無法滿足需求時才建立自訂區塊,並參考官方區塊編輯器手冊中的最新 API 與最低 WordPress 版本要求。

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

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

FSWP 區塊開發者 是做什麼的?

基礎(始終套用): fswp-developer/references/lean-coding.md(先簡潔再寫、重複使用)、fswp-developer/references/coding-standards.md(編碼標準、文件、國際化、無障礙)以及 fswp-security-engineer(輸入、輸出、授權)。

優先使用核心區塊;僅在核心區塊與樣板無法表達需求時才編寫自訂區塊。官方參考:fswp-developer/references/official-docs.md 中的區塊編輯器手冊連結。請針對每個 API 檢查其最低 WordPress 版本,並比對專案所宣告的最低版本。

結構

blocks/my-block/
  block.json      name, title, category, attributes, supports, render, editorScript, viewScriptModule, style
  edit.js         編輯器 UI(使用 useBlockProps)
  save.js         靜態標記,或動態區塊可省略
  render.php      動態區塊的伺服器端渲染
  view.js         前端行為(模組)
  style.scss / editor.scss

從 metadata 註冊:在 init 掛載點使用 register_block_type( __DIR__ . '/build/my-block' )(為 init 回呼命名一個函式)。設定 "apiVersion": 3(自 WordPress 6.3 起為現行版本)並加入 "$schema": "https://schemas.wp.org/trunk/block.json"。逐欄位參考,並對照區塊編輯器手冊:references/block-json.md。

決策

問題選擇
輸出僅取決於已儲存的屬性靜態區塊(save.js)
輸出取決於即時資料、需在未重新儲存的情況下變更,或包含邏輯動態區塊(render.php);save 回傳 null 或僅回傳 InnerBlocks
巢狀內容使用 InnerBlocks 搭配 allowedBlocks 和 template
將屬性綁定到資料(文章 meta、自訂來源)區塊綁定 API(register_block_bindings_source),前提是最低 WordPress 版本允許
現有區塊的替代預設值使用區塊變體或樣式,而非新區塊
可重複使用的佈局使用樣板,而非區塊

規則

  • 屬性:為每個屬性指定 type 和 default;從標記或註解中一致地取得來源;在 render.php 中驗證。
  • 使用 supports(顏色、間距、排版、對齊、錨點)而非自行編寫控制項。
  • 編輯器標記必須使用 useBlockProps();動態 PHP 使用 get_block_wrapper_attributes()。
  • render.php(block.json 中的 render,WordPress 6.1+)接收 $attributes、$content 與 $block(一個 WP_Block)。它在頁面上每個區塊實例只載入一次,因此絕對不要在裡面宣告函式或類別;應從其他檔案呼叫共享程式碼。
  • 腳本 vs 模組: viewScript 用於傳統腳本(以及任何依賴 WordPress 腳本的項目);viewScriptModule(6.5+)用於腳本模組,例如 Interactivity API。兩者不可互換,因此不要在兩者之間混合依賴。
  • 在 render.php 中跳脫所有內容(fswp-security-engineer);屬性屬於使用者輸入。
  • 變更已發佈靜態區塊的已儲存標記會破壞現有內容。請加入包含舊版 save、屬性和 migrate 函式的 deprecated 項目,然後變更區塊。
  • 在 JS 與 PHP 中翻譯字串(使用文字域的 __());使用 wp_set_script_translations 或 block.json 中的 textdomain。
  • 僅在區塊渲染的位置載入前端腳本(block.json 中的 viewScriptModule/script 會自動處理此項)。

樣板

關於樣板、變體、區塊掛鉤與綁定的更多細節:references/patterns-variations.md。Interactivity API 深入探討(伺服器端渲染、非同步動作、data-wp-each、監看器、效能):references/interactivity.md。

在 PHP 中使用 register_block_pattern()(以及 register_block_pattern_category())註冊,或作為主題中 patterns/ 目錄下的檔案。樣板使用預設值與翻譯文字;不要使用遠端圖片;為它們提供清晰的標題、類別與關鍵字。

Interactivity API

伺服器端渲染的標記加上小型響應式行為,無需框架。

  • 啟用方式:"supports": { "interactivity": true } 及 "viewScriptModule": "file:./view.js"。
  • 標記指令:data-wp-interactive="namespace"、data-wp-context='{"open":false}'、data-wp-on--click="actions.toggle"、data-wp-bind--hidden="!context.open"、data-wp-class--is-open="context.open"、data-wp-text="state.label"。
  • 在 view.js 中的 store:import { store, getContext } from '@wordpress/interactivity'; store( 'namespace', { state: {...}, actions: { toggle() { const c = getContext(); c.open = ! c.open; } } } );
  • 使用 wp_interactivity_state( 'namespace', array(...) ) 植入伺服器狀態,以確保首次渲染正確且無閃爍。保持狀態可序列化。
  • 為所有項目加上命名空間以避免衝突;切勿將秘密資料放入 state 或 context(兩者都會輸出到頁面中)。
  • 為確保無障礙性,請將 aria-expanded 與焦點處理綁定到狀態,並測試鍵盤操作。

建置與測試

使用 npx @wordpress/create-block 作為起點;使用 @wordpress/scripts 進行 build、start、lint-js、lint-style、test-unit-js。將建置後的檔案與 src/、package.json 及鎖定檔一起交付(編譯程式碼的目錄規則)。在編輯器中測試(插入、編輯、儲存、重新載入、切換到程式碼檢視)以及前端測試。交給 fswp-qa-engineer。

Individual skills in this repo

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

fswp-api-developer

Domain skill for WordPress REST API and Abilities API work in Full-Stack WP Developer. Covers registering routes with schemas, argument validation and sanitization, permission callbacks, controller classes, exposing post types and meta, authentication (cookie nonce, application passwords), pagination and errors, and registering abilities with input and output schemas and safety annotations. Use for any custom endpoint or machine-readable capability in a plugin or theme.

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-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.

相關技能