creating-blocks

โดย automattic

Templates and guidelines for creating new WordPress blocks from scratch — load this before generating block files

npx skills add https://github.com/automattic/studio --skill creating-blocks

When to use me

Use this skill when creating a new block from scratch. Do not use this skill when modifying an existing block.

Generating Blocks Instructions

  • Always use the current folder to generate the block
  • Always remove space before the PHP opening tag, nor leave more than one empty new line at the end of any file
  • Always use block props to make sure the block is selectable in the canvas
  • Always use the lowercase for block name slugs
  • Never close the last PHP opening tag, you always leave it open
  • Never suggest or generate code outside the specification, such as REST controllers, PHP classes, or other code that is not part of a standard WordPress block
  • Prefer building blocks that have the same behaviour on the frontend and the backend, unless the user asks for a block that is specifically different on the frontend
  • Do not opt for placeholders in the editor
  • Be proactive in adding inspector or block toolbar controls that can make the block more interactive and customizable
  • Never redeclare functions in PHP and always guard with function_exists
  • Do not create additional markdown files with extense documentations or installation instructions
  • Make sure the block is registered correctly so that it renders on the front end
  • Use the InnerBlocks component from @wordpress/block-editor as much as possible.

Interactive Blocks

When the block requires frontend interactivity (clicks, toggles, accordions, modals, carousels, counters, tabs, search filters):

  • The block MUST also be dynamic (uses render.php, no save.js)
  • Use plain JavaScript with standard DOM APIs (querySelector, addEventListener, classList, etc.) in view.js — never use the WordPress Interactivity API
  • In block.json: use "viewScript": "file:./view.js" (not viewScriptModule)
  • In render.php: use standard HTML attributes and CSS classes that your JavaScript targets
  • Use data-* attributes on the block wrapper to pass server-side values to JavaScript

Reference Files

Before generating block files, read the relevant references from the references/ directory next to this skill file.

  • references/artefact-templates.md — REQUIRED: read this FIRST before generating any block files. Contains exact file templates with correct paths, asset references, and build pipeline details. You MUST follow these templates exactly.
  • references/file-templates.md — additional guidelines for each block file type
  • references/inner-blocks.md — read this if the block uses InnerBlocks or child blocks
  • references/dynamic-vs-static.md — read this if you need to decide between a dynamic, static, or interactive rendering approach
  • references/interactivity-api.md — read this when creating an interactive block that needs frontend JavaScript

Skills เพิ่มเติมจาก automattic

wp-phpstan
automattic
ใช้เมื่อกำหนดค่า เรียกใช้ หรือแก้ไขการวิเคราะห์แบบสแตติกของ PHPStan ในโปรเจกต์ WordPress (ปลั๊กอิน/ธีม/ไซต์): การตั้งค่า phpstan.neon, เบสไลน์,…
official
wp-playground
automattic
ใช้สำหรับเวิร์กโฟลว์ของ WordPress Playground: อินสแตนซ์ WP แบบใช้แล้วทิ้งที่รวดเร็วในเบราว์เซอร์หรือในเครื่องผ่าน @wp-playground/cli (server, run-blueprint, build-snapshot),…
official
wp-plugin-development
automattic
ใช้เมื่อพัฒนา WordPress plugins: สถาปัตยกรรมและ hooks, การเปิดใช้งาน/ปิดใช้งาน/ถอนการติดตั้ง, UI สำหรับผู้ดูแลระบบและ Settings API, การจัดเก็บข้อมูล, cron/งาน, ความปลอดภัย…
official
wp-project-triage
automattic
ใช้เมื่อคุณต้องการตรวจสอบที่เก็บ WordPress (ปลั๊กอิน/ธีม/ธีมบล็อก/WP core/Gutenberg/ทั้งไซต์) อย่างแน่นอน รวมถึงเครื่องมือ/การทดสอบ/เวอร์ชัน…
official
wp-rest-api
automattic
ใช้เมื่อสร้าง ขยาย หรือดีบักเอนด์พอยต์/เส้นทางของ WordPress REST API: register_rest_route, คลาส WP_REST_Controller/controller, schema/argument…
official
wp-wpcli-and-ops
automattic
ใช้เมื่อทำงานกับ WP-CLI (wp) สำหรับการดำเนินการ WordPress: การค้นหาและแทนที่อย่างปลอดภัย, การส่งออก/นำเข้าฐานข้อมูล, การจัดการปลั๊กอิน/ธีม/ผู้ใช้/เนื้อหา, cron, การล้างแคช,…
official
wpds
automattic
ใช้เมื่อสร้าง UI ที่ใช้ประโยชน์จาก WordPress Design System (WPDS) และส่วนประกอบ โทเค็น รูปแบบ ฯลฯ
official
woocommerce-finalize
automattic
การตรวจสอบสุขภาพโค้ดและความสามารถในการตรวจสอบย้อนกลับก่อนเผยแพร่สำหรับปลั๊กอิน WooCommerce ดำเนินการหลังจากการตรวจสอบโค้ด -- เน้นที่โค้ดที่ไม่ได้ใช้ การซ้ำซ้อน ความซับซ้อนเชิงโครงสร้าง และ...
official