Community编程与开发github.com

FSWP Block Developer

WordPress区块编辑器开发技能,涵盖自定义Gutenberg区块、区块模式、Interactivity API及@wordpress/scripts构建工作流。

FSWP Block Developer 是什么?

FSWP Block Developer 是一个面向全栈WordPress开发者(站点编辑)的AI代理技能,专注于Gutenberg区块编辑器生态。它指导开发者构建自定义区块,包括block.json配置、静态与动态渲染、属性、支持、InnerBlocks、变体、弃用处理和区块绑定,同时涵盖区块模式与Interactivity API(data-wp指令、存储、服务器端状态),并结合@wordpress/scripts构建工作流。该技能适用于任何需要在插件或主题中实现自定义区块、模式或前端交互的场景。它包含详细的决策指南、规则与最佳实践,如优先使用核心区块、正确管理属性与支持、使用useBlockProps与get_block_wrapper_attributes、脚本与模块(viewScript vs viewScriptModule)的区别处理,以及弃用与迁移策略。此外,还包含Interactivity API的指令与存储用法、性能考虑、可访问性要求,以及构建与测试流程。技能文档链接了官方参考资料、安全规则(出自fswp-security-engineer)和编码标准,确保输出专业且安全。

兼容平台~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(输入、输出、授权)。

优先使用核心区块;仅在核心区块和模式无法满足需求时编写自定义区块。官方参考:Block Editor Handbook 链接位于 fswp-developer/references/official-docs.md。对照项目声明的WordPress最低版本,检查每个API所需的WordPress版本。

区块结构

blocks/my-block/
  block.json      名称、标题、分类、属性、支持、渲染、editorScript、viewScriptModule、style
  edit.js         编辑器UI(使用 useBlockProps)
  save.js         静态标记,动态区块可省略
  render.php      动态区块的服务器端渲染
  view.js         前端行为(模块)
  style.scss / editor.scss

通过元数据注册:register_block_type( __DIR__ . '/build/my-block' ) 在 init 钩子上(为 init 回调使用具名函数)。设置 "apiVersion": 3(自WordPress 6.3起)并添加 "$schema": "https://schemas.wp.org/trunk/block.json"。字段参考(已对照Block Editor Handbook验证):references/block-json.md。

决策指南

问题选择
输出仅依赖于保存的属性静态区块(save.js)
输出依赖于实时数据、必须在不重新保存的情况下更改,或包含逻辑动态区块(render.php);save 返回 null 或仅返回 InnerBlocks
嵌套内容InnerBlocks 配合 allowedBlocks 和 template
将属性绑定到数据(文章元数据、自定义来源)Block Bindings 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):import { store, getContext } from '@wordpress/interactivity'; store( 'namespace', { state: {...}, actions: { toggle() { const c = getContext(); c.open = ! c.open; } } } );
  • 使用 wp_interactivity_state( 'namespace', array(...) ) 注入服务器端状态,以确保首次渲染正确且无闪烁。保持状态可序列化。
  • 所有内容添加命名空间以避免冲突;切勿将机密信息放入状态或上下文中(两者都会打印到页面中)。
  • 对于可访问性,将 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.

相关技能