jpskill.com
🛠️ 開発・MCP コミュニティ

wp-block-development

Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports, dynamic rendering (render.php/render_callback), deprecations/migrations, viewScript vs viewScriptModule, and @wordpress/scripts/@wordpress/create-block build and test workflows.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o wp-block-development.zip https://jpskill.com/download/17345.zip && unzip -o wp-block-development.zip && rm wp-block-development.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17345.zip -OutFile "$d\wp-block-development.zip"; Expand-Archive "$d\wp-block-development.zip" -DestinationPath $d -Force; ri "$d\wp-block-development.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して wp-block-development.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → wp-block-development フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
12

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

WP Block Development

どのような時に使うか

このスキルは、以下のようなブロックに関する作業に使用します。

  • 新しいブロックの作成、または既存のブロックの更新
  • block.json の変更 (scripts/styles/supports/attributes/render/viewScriptModule)
  • 「ブロックが無効 / 保存されない / 属性が保持されない」の修正
  • 動的なレンダリングの追加 (render.php / render_callback)
  • ブロックの非推奨化と移行 (deprecated バージョン)
  • ブロックのビルドツール (@wordpress/scripts, @wordpress/create-block, wp-env)

必要な入力

  • リポジトリのルートとターゲット (プラグイン vs テーマ vs フルサイト)。
  • ブロックの名前/名前空間とそれが存在する場所 (block.json へのパスが分かっている場合)。
  • 対象の WordPress バージョン範囲 (特にモジュール / viewScriptModule を使用する場合)。

手順

0) トリアージとブロックの特定

  1. トリアージを実行します。
    • node skills/wp-project-triage/scripts/detect_wp_project.mjs
  2. ブロックをリスト表示します (決定論的なスキャン)。
    • node skills/wp-block-development/scripts/list_blocks.mjs
  3. 変更するブロックのルート (block.json を含むディレクトリ) を特定します。

このリポジトリがフルサイト (wp-content/ が存在する) の場合、どのプラグイン/テーマにブロックが含まれているかを明示的に示してください。

1) 新しいブロックの作成 (必要な場合)

新しいブロックを作成する場合は、手作業で構造を構築するよりも、スキャフォールディングを優先してください。

  • @wordpress/create-block を使用して、最新のブロック/プラグインのセットアップをスキャフォールディングします。
  • 最初から Interactivity API が必要な場合は、インタラクティブなテンプレートを使用します。

参照:

  • references/creating-new-blocks.md

スキャフォールディング後:

  1. ブロックリストスクリプトを再実行し、新しいブロックルートを確認します。
  2. 残りの手順 (モデルの選択、メタデータ、登録、シリアライゼーション) を続行します。

2) apiVersion 3 (WordPress 6.9+) を確認する

WordPress 6.9 では、block.json スキーマで apiVersion: 3 が強制されます。apiVersion 2 以下のブロックは、SCRIPT_DEBUG が有効になっている場合にコンソール警告をトリガーします。

なぜこれが重要なのか:

  • WordPress 7.0 では、ブロックの apiVersion に関係なく、iframe で投稿エディターが実行されます。
  • apiVersion 3 は、iframe エディター (スタイルの分離、ビューポート単位、メディアクエリ) 内でブロックが正しく動作することを保証します。

移行: バージョン 2 から 3 への変更は、通常、block.jsonapiVersion フィールドを更新するだけで済みます。ただし:

  • iframe エディターを有効にして、ローカル環境でテストします。
  • スタイルハンドルが block.json に含まれていることを確認します (iframe から欠落しているスタイルは適用されません)。
  • 特定の window にアタッチされたサードパーティスクリプトには、スコープの問題が発生する可能性があります。

参照:

  • references/block-json.md (apiVersion とスキーマの詳細)

3) 適切なブロックモデルを選択する

  • 静的ブロック (マークアップが投稿コンテンツに保存される): save() を実装します。属性のシリアライゼーションを安定に保ちます。
  • 動的ブロック (サーバーでレンダリングされる): block.jsonrender (または PHP で render_callback) を使用し、save() を最小限にするか null にします。
  • インタラクティブなフロントエンドの動作:
    • サポートされている場合は、最新のモジュールベースのビュースクリプトに viewScriptModule を優先します。
    • 主に data-wp-* ディレクティブまたはストアを操作する場合は、wp-interactivity-api も使用します。

4) block.json を安全に更新する

ブロックの block.json で変更を行い、登録がメタデータと一致することを確認します。

フィールドごとのガイダンスについては、以下を参照してください。

  • references/block-json.md

よくある落とし穴:

  • name を変更すると互換性が損なわれます (安定した API として扱います)
  • deprecated を追加せずに保存されたマークアップを変更すると、「無効なブロック」が発生します
  • ソース/シリアライゼーションを正しく定義せずに属性を追加すると、「属性が保存されない」が発生します

5) ブロックを登録する (サーバー側を推奨)

特に以下の場合、メタデータを使用した PHP 登録を優先します。

  • 動的なレンダリングが必要な場合
  • 翻訳が必要な場合 (wp_set_script_translations)
  • 条件付きのアセットロードが必要な場合

以下を読んで適用してください。

  • references/registration.md

6) edit/save/render パターンを実装する

ラッパー属性のベストプラクティスに従ってください。

  • エディター: useBlockProps()
  • 静的保存: useBlockProps.save()
  • 動的レンダリング (PHP): get_block_wrapper_attributes()

参照:

  • references/supports-and-wrappers.md
  • references/dynamic-rendering.md (動的な場合)

7) インナーブロック (ブロックの構成)

ブロックが他のブロックをネストする「コンテナ」である場合、インナーブロックを第一級の機能として扱います。

  • useInnerBlocksProps() を使用して、インナーブロックをラッパープロパティと統合します。
  • インナーマークアップを変更する場合は、移行に注意してください。

参照:

  • references/inner-blocks.md

8) 属性とシリアライゼーション

属性を変更する前に:

  • 属性値が存在する場所 (コメント区切り文字 vs HTML vs コンテキスト) を確認します
  • 非推奨の meta 属性ソースは避けてください

参照:

  • references/attributes-and-serialization.md

9) 移行と非推奨化 ("無効なブロック" を避ける)

保存されたマークアップまたは属性を変更する場合:

  1. deprecated エントリを追加します (最新 → 最古)。
  2. 古いバージョンの save と、属性を正規化するためのオプションの migrate を提供します。

参照:

  • references/deprecations.md

10) ツールと検証コマンド

リポジトリがすでに使用しているものを優先します。

  • @wordpress/scripts (一般的) → 既存の npm スクリプトを実行します
  • wp-env (一般的) → ローカル WP + E2E に使用します

参照:

  • references/tooling-and-testing.md

検証

  • ブロックがインサーターに表示され、正常に挿入されます。
  • 保存 + リロードで「無効なブロック」が作成されません。
  • フロントエンドの出力が期待どおりに一致します (静的: 保存されたマークアップ、動的: サーバー出力)。
  • アセットが期待どおりにロードされます (エディター vs フロントエンド)。
  • トリアージが推奨するリポジトリの lint/build/tests を実行します。

失敗モード / デバッグ

何かが失敗した場合は、ここから始めてください。

  • references/debugging.md (一般的な失敗 + 最速のチェック)
  • references/attributes-and-serialization.md (属性が保存されない)
  • references/deprecations.md (変更後の無効なブロック)

エスカレーション

アップストリームの動作/バージョンサポートについて不明な点がある場合は、最初に標準ドキュメントを参照してください。

  • WordPress 開発者向けリソース (ブロックエディターハンドブック、テーマハンドブック、プラグインハンドブック)
  • 最先端の動作に関する Gutenberg リポジトリドキュメント
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

WP Block Development

When to use

Use this skill for block work such as:

  • creating a new block, or updating an existing one
  • changing block.json (scripts/styles/supports/attributes/render/viewScriptModule)
  • fixing “block invalid / not saving / attributes not persisting”
  • adding dynamic rendering (render.php / render_callback)
  • block deprecations and migrations (deprecated versions)
  • build tooling for blocks (@wordpress/scripts, @wordpress/create-block, wp-env)

Inputs required

  • Repo root and target (plugin vs theme vs full site).
  • The block name/namespace and where it lives (path to block.json if known).
  • Target WordPress version range (especially if using modules / viewScriptModule).

Procedure

0) Triage and locate blocks

  1. Run triage:
    • node skills/wp-project-triage/scripts/detect_wp_project.mjs
  2. List blocks (deterministic scan):
    • node skills/wp-block-development/scripts/list_blocks.mjs
  3. Identify the block root (directory containing block.json) you’re changing.

If this repo is a full site (wp-content/ present), be explicit about which plugin/theme contains the block.

1) Create a new block (if needed)

If you are creating a new block, prefer scaffolding rather than hand-rolling structure:

  • Use @wordpress/create-block to scaffold a modern block/plugin setup.
  • If you need Interactivity API from day 1, use the interactive template.

Read:

  • references/creating-new-blocks.md

After scaffolding:

  1. Re-run the block list script and confirm the new block root.
  2. Continue with the remaining steps (model choice, metadata, registration, serialization).

2) Ensure apiVersion 3 (WordPress 6.9+)

WordPress 6.9 enforces apiVersion: 3 in the block.json schema. Blocks with apiVersion 2 or lower trigger console warnings when SCRIPT_DEBUG is enabled.

Why this matters:

  • WordPress 7.0 will run the post editor in an iframe regardless of block apiVersion.
  • apiVersion 3 ensures your block works correctly inside the iframed editor (style isolation, viewport units, media queries).

Migration: Changing from version 2 to 3 is usually as simple as updating the apiVersion field in block.json. However:

  • Test in a local environment with the iframe editor enabled.
  • Ensure any style handles are included in block.json (styles missing from the iframe won't apply).
  • Third-party scripts attached to a specific window may have scoping issues.

Read:

  • references/block-json.md (apiVersion and schema details)

3) Pick the right block model

  • Static block (markup saved into post content): implement save(); keep attributes serialization stable.
  • Dynamic block (server-rendered): use render in block.json (or render_callback in PHP) and keep save() minimal or null.
  • Interactive frontend behavior:
    • Prefer viewScriptModule for modern module-based view scripts where supported.
    • If you're working primarily on data-wp-* directives or stores, also use wp-interactivity-api.

4) Update block.json safely

Make changes in the block’s block.json, then confirm registration matches metadata.

For field-by-field guidance, read:

  • references/block-json.md

Common pitfalls:

  • changing name breaks compatibility (treat it as stable API)
  • changing saved markup without adding deprecated causes “Invalid block”
  • adding attributes without defining source/serialization correctly causes “attribute not saving”

5) Register the block (server-side preferred)

Prefer PHP registration using metadata, especially when:

  • you need dynamic rendering
  • you need translations (wp_set_script_translations)
  • you need conditional asset loading

Read and apply:

  • references/registration.md

6) Implement edit/save/render patterns

Follow wrapper attribute best practices:

  • Editor: useBlockProps()
  • Static save: useBlockProps.save()
  • Dynamic render (PHP): get_block_wrapper_attributes()

Read:

  • references/supports-and-wrappers.md
  • references/dynamic-rendering.md (if dynamic)

7) Inner blocks (block composition)

If your block is a “container” that nests other blocks, treat Inner Blocks as a first-class feature:

  • Use useInnerBlocksProps() to integrate inner blocks with wrapper props.
  • Keep migrations in mind if you change inner markup.

Read:

  • references/inner-blocks.md

8) Attributes and serialization

Before changing attributes:

  • confirm where the attribute value lives (comment delimiter vs HTML vs context)
  • avoid the deprecated meta attribute source

Read:

  • references/attributes-and-serialization.md

9) Migrations and deprecations (avoid "Invalid block")

If you change saved markup or attributes:

  1. Add a deprecated entry (newest → oldest).
  2. Provide save for old versions and an optional migrate to normalize attributes.

Read:

  • references/deprecations.md

10) Tooling and verification commands

Prefer whatever the repo already uses:

  • @wordpress/scripts (common) → run existing npm scripts
  • wp-env (common) → use for local WP + E2E

Read:

  • references/tooling-and-testing.md

Verification

  • Block appears in inserter and inserts successfully.
  • Saving + reloading does not create “Invalid block”.
  • Frontend output matches expectations (static: saved markup; dynamic: server output).
  • Assets load where expected (editor vs frontend).
  • Run the repo’s lint/build/tests that triage recommends.

Failure modes / debugging

If something fails, start here:

  • references/debugging.md (common failures + fastest checks)
  • references/attributes-and-serialization.md (attributes not saving)
  • references/deprecations.md (invalid block after change)

Escalation

If you’re uncertain about upstream behavior/version support, consult canonical docs first:

  • WordPress Developer Resources (Block Editor Handbook, Theme Handbook, Plugin Handbook)
  • Gutenberg repo docs for bleeding-edge behaviors

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。