Block: Add slug attribute to core/block for registered pattern references#76216
Block: Add slug attribute to core/block for registered pattern references#76216youknowriad wants to merge 6 commits intotrunkfrom
Conversation
…nces Allows core/block to reference registered patterns by slug, maintaining persistent references and enabling pattern overrides without needing to save patterns to the database. When slug is set, the pattern resolves from WP_Block_Patterns_Registry instead of fetching a wp_block post by ID. - Add slug attribute to block.json alongside ref - Implement slug-based pattern resolution in server-side renderer (index.php) - Update client-side edit component (edit.js) with separate RefPatternEdit and SlugPatternEdit paths - Update block label resolution (__experimentalLabel) to handle slug-based patterns - Add e2e tests for slug-based pattern rendering and overrides This enables themes/plugins to ship patterns with pattern overrides support while keeping pattern source in version control. Co-Authored-By: Claude Opus <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @StreetDog71, @ariskuckovic-abtion, @radeeven, @mehicalen, @danielmarif. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +230 B (0%) Total Size: 6.87 MB
ℹ️ View Unchanged
|
|
This is still not fully working, the patterns are rendering properly but for some reason that I didn't find yet, the bindings are not editable. |
The test fixture was using named attribute bindings (e.g.
"content": {"source": "core/pattern-overrides"}) instead of the
canonical __default binding format. The RichText component checks
specifically for __default to determine if editing should be
enabled for pattern overrides, so using named bindings caused
inner blocks to be non-editable (contenteditable=false).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract PatternBlockUI as a shared component that handles layout,
loading spinner, missing warning, reset toolbar, and inner blocks
rendering. RefPatternEdit and SlugPatternEdit now only handle data
fetching and pass results to the shared component.
Also fixes the slug path showing "Block has been deleted" briefly
on load by checking hasFinishedResolution('getBlockPatterns') before
declaring a pattern as missing.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
This seems promising, the only thing I don't like is that it suffers from the same issue as the regular "pattern" block, there's an extra wrapper in the editor, but not clear solution for that to be honest. |
- Add @SInCE tag to render_block_core_block_content() - Move global $wp_embed declaration to function scope to avoid redeclaration warning - Fix prettier formatting in index.js Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Flaky tests detected in 0c17ebb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22740512853
|
It works well! I guess these are synced patterns but the original design can't be changed (except for editing the file). Is that something that will be useful for users? The other option is to make it work like template parts where a post is created whenever the pattern is modified. That's quite a bit of extra work though. I think the part that's missing from this PR is that when a pattern like this is added via the inserter the |
Yes, I agree with this. For copying like template parts, I'd love to avoid it, in fact, I'd love if template parts stop doing that but we'll see :) |
What?
Closes #59272
Allows
core/blockto reference registered patterns by slug, enabling pattern overrides and persistent references without storing patterns in the database.Why?
Currently,
core/blockonly references saved patterns (wp_block posts) by numeric ID. This prevents themes/plugins from shipping patterns that support overrides, since the pattern source must be in the database. Registered patterns can only be used viacore/pattern, which replaces itself with inline content and loses the connection. By adding slug support tocore/block, themes can ship patterns with overrides while maintaining version control.How?
slugattribute to core/block block.jsonTesting Instructions
gutenberg-test-pattern-slug-overrideplugin<!-- wp:block {"slug":"test/slug-pattern"} /--><!-- wp:block {"slug":"test/slug-pattern-with-overrides","content":{"heading":{"content":"Custom"}}} /-->npm run test:e2e -- test/e2e/specs/editor/various/pattern-slug-override.spec.jsTesting Instructions for Keyboard