Skip to content

Patterns: Add the pattern name to pattern blocks when they are converted #10248

Closed
ramonjd wants to merge 1 commit intoWordPress:trunkfrom
ramonjd:try/add-metadata-to-parsed-pattern-root-block-attributes
Closed

Patterns: Add the pattern name to pattern blocks when they are converted #10248
ramonjd wants to merge 1 commit intoWordPress:trunkfrom
ramonjd:try/add-metadata-to-parsed-pattern-root-block-attributes

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Oct 14, 2025

Builds upon #10180

Props to @scruffian

Modifies the resolve_pattern_blocks function to include metadata for single-root patterns, allowing the pattern name and title to be stored in the block attributes. The metadata contains the patternName and name attributes.

This enables identification of patterns inside templates and allows for special treatment in the editor.

This will be used to test contentOnly editing (WordPress/gutenberg#71517), so that themes that use patterns automatically opt into this behaviour.

Trac ticket: https://core.trac.wordpress.org/ticket/64123


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Oct 14, 2025

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ramonopoly, andrewserong, talldanwp, westonruter, scruffian.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ramonjd ramonjd force-pushed the try/add-metadata-to-parsed-pattern-root-block-attributes branch 3 times, most recently from b5812e5 to d8f1d20 Compare October 21, 2025 01:01
@ramonjd ramonjd changed the title Add the pattern name to pattern blocks when they are converted [unit tests] Oct 21, 2025
@ramonjd ramonjd self-assigned this Oct 21, 2025
@scruffian
Copy link
Contributor

Is there other metadata we could/should add to patterns - some of them seem to also contain a longer description. It would be good to support as much metadata as possible IMO.

@ramonjd
Copy link
Member Author

ramonjd commented Oct 22, 2025

Is there other metadata we could/should add to patterns - some of them seem to also contain a longer description. It would be good to support as much metadata as possible IMO.

Good question. What do you think the editor might need? There are also optional categories and block types, which could come in handy if the editor ever wanted to extend "change design" to patterns bundled with templates.

I'm not sure.

@ramonjd ramonjd requested review from scruffian and talldan October 22, 2025 22:20
@scruffian
Copy link
Contributor

The description would be useful for WordPress/gutenberg#72574. Not sure about the others.

@ramonjd ramonjd force-pushed the try/add-metadata-to-parsed-pattern-root-block-attributes branch from d8f1d20 to ed8d449 Compare October 24, 2025 01:45
@ramonjd
Copy link
Member Author

ramonjd commented Oct 24, 2025

The description would be useful for WordPress/gutenberg#72574.

Done!

@ramonjd ramonjd force-pushed the try/add-metadata-to-parsed-pattern-root-block-attributes branch 2 times, most recently from ef3a7bc to a640eaa Compare November 10, 2025 05:13
Comment on lines 1884 to 1886
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );

$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
@ramonjd ramonjd force-pushed the try/add-metadata-to-parsed-pattern-root-block-attributes branch from a640eaa to 44c4c8f Compare November 26, 2025 04:46
ramonjd added a commit to WordPress/gutenberg that referenced this pull request Nov 26, 2025
ramonjd added a commit to WordPress/gutenberg that referenced this pull request Nov 26, 2025
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Nov 26, 2025
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

Source: WordPress/gutenberg@ec6ec9e
@ramonjd ramonjd force-pushed the try/add-metadata-to-parsed-pattern-root-block-attributes branch 3 times, most recently from bbf23e7 to 2a32b89 Compare February 11, 2026 21:45
@ramonjd
Copy link
Member Author

ramonjd commented Feb 11, 2026

I've rebased this and it's ready for a final test.

It should reflect the changes committed to Gutenberg: gutenberg_resolve_pattern_blocks() https://github.com/WordPress/gutenberg/blob/trunk/lib/compat/wordpress-7.0/blocks.php

Checking with @talldan that this approach has been working well in your testing over the last few weeks. Thanks!

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests well for me, good code coverage and matches the changes that have been in Gutenberg for a fair while now. As this feature is slated for 7.0, I think this is a good time to land this, and it can continue to be tested throughout the Beta phase.

IMO this LGTM 🚀

…single-root patterns, allowing the pattern name and title to be stored in the block attributes.
@ramonjd ramonjd force-pushed the try/add-metadata-to-parsed-pattern-root-block-attributes branch from 2a32b89 to 9967b85 Compare February 12, 2026 02:29
@talldan
Copy link
Contributor

talldan commented Feb 12, 2026

Checking with @talldan that this approach has been working well in your testing over the last few weeks. Thanks!

Yep, I think so. There was some additional feedback in WordPress/gutenberg#75235, but I think it can be considered additive if there's an outcome.

@ramonjd
Copy link
Member Author

ramonjd commented Feb 12, 2026

Committed in r61617 and 4cedbfc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants