wp-pattern-runtime-pitfalls
БесплатноБез исполняемых скриптовНе проверенAvoid the runtime traps of WordPress block patterns (patterns/*.php) that look like static markup but aren't. Use when a pattern renders nothing, shows…
от lightspeedwp★ 20 звёзд на GitHubОб этом скилле
WP Pattern Runtime Pitfalls
Overview
A file in patterns/*.php looks like static block markup, but it has a runtime model that trips people repeatedly: its PHP runs once at registration, not per render; a wp:pattern reference nested inside another pattern is silently dropped on the front end (while resolving fine in a WP-CLI do_blocks() test, so CLI lies to you); and per-request data has to arrive through block bindings, not inline PHP. This skill is the set of behaviours to design around, plus the cache resets and verification that keep you from chasing ghosts. It pairs with figma-to-block-theme (whose pattern mode generates production patterns) by documenting the traps that generation must respect.
When to use
- A pattern renders nothing on the live page (no markup, no leftover comment).
- A pattern shows the fallback / stale value instead of the current post/term's data.
- A pattern behaves differently on the live page than in a
do_blocks()CLI test. - You need to embed one pattern inside another, inject per-request data, or keep a hover-reveal panel editable in the editor.
Inputs required
- The theme's
patterns/directory and how patterns are registered (theme auto-registration vs explicit). - For dynamic data: where the theme keeps block binding sources (typically an
inc/file callingregister_block_bindings_source()). - Access to reset the pattern transient cache and OPcache on the running site (note the CLI PHP and the web/php-fpm OPcache are usually separate).
Procedure
- Keep each pattern self-contained in
patterns/<slug>.php. Don't relocate a pattern's rendering logic into aninc/helper — patterns should stay discoverable and editable in the standard location. (Binding source registration is different — that legitimately lives ininc/; see step 3.) - Embed one pattern in another with
require, not a nestedwp:pattern. A<!-- wp:pattern {"slug":"…"} /-->nested inside another pattern's content is silently dropped on front-end render. Userequire __DIR__ . '/<other-pattern>.php';(plainrequire, notrequire_once) to inline its output; the required file stays an independently registered pattern. Seereferences/nesting-and-embedding.md. - Get per-request data from a block binding or dynamic block — never from inline pattern PHP. Pattern PHP runs at
init, whenget_queried_object()is null, so its output is baked into the stored content string. Query-independent lookups (an attachment by slug) are fine inline; anything that depends on the current post/term must come from aregister_block_bindings_source()callback or a dynamic block (wp:query-title). Seereferences/registration-vs-render.md. - For hover-reveal styles, make the hidden panel visible in the editor with an
.editor-styles-wrapper-scoped rule in the block's enqueued style. Seereferences/editor-visibility.md. - After editing pattern files, reset caches before testing — the theme pattern transient and the web-SAPI OPcache. See
references/nesting-and-embedding.md.
Verification
- Test on the actual rendered front-end page, not a WP-CLI
do_blocks()call. The nested-pattern drop does not reproduce under CLI — a green CLI test can mask a broken live page. - After a pattern-file edit, confirm the cache is cleared (pattern transient + OPcache) or you'll be testing stale output.
- For dynamic data, verify with more than one post/term — a binding that's actually still baked will "work" on whichever object happened to be current at init and fail on the rest.
- If the page is a DB template/part override, remember your file edit may not be what renders at all — see
wp-db-override-reconciliation.
Failure modes
- Inner pattern renders nothing on the front end → it was referenced via nested
wp:pattern; inline it withrequire. →references/nesting-and-embedding.md - CLI says it works, live page doesn't → the nested-pattern bug is front-end-only; stop trusting
do_blocks()for it. →references/nesting-and-embedding.md - Always shows the fallback / one object's data → inline PHP ran at
initbefore the query; move it to a binding source. →references/registration-vs-render.md - Edited the pattern, page unchanged → stale pattern transient / OPcache (or a DB override is shadowing the file). →
references/nesting-and-embedding.md,wp-db-override-reconciliation - Hover-reveal text uneditable in the editor → the panel is collapsed in the editor too; add an editor-only reveal. →
references/editor-visibility.md
Escalation
- If a pattern needs dynamic data that has no bindable attribute (e.g. image
idfor srcset isn't bindable, onlyurl), flag the limitation — the baked fallbackidwill drive srcset even when theurlis overridden per request. - If the house rule "patterns stay in
patterns/" conflicts with a genuinely reusable helper
Установить wp-pattern-runtime-pitfalls в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл wp-pattern-runtime-pitfalls?
Avoid the runtime traps of WordPress block patterns (patterns/*.php) that look like static markup but aren't. Use when a pattern renders nothing, shows stale/fallback data, or behaves differently on the live page than in a WP-CLI test: nested wp:pattern references silently dropping on front-end render, raw pattern PHP running once at registration (init) instead of per-request, injecting queried-object data via block bindings, keeping hover-reveal panels editable in the editor, and the pattern/OPcache resets needed to see edits. Complements figma-to-block-theme (which generates patterns) with the behaviour to design around.
Как установить скилл wp-pattern-runtime-pitfalls?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл wp-pattern-runtime-pitfalls запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic