Skip to content

Conversation

@ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 18, 2025

What? How?

Partly addresses #73262

Follow up to #72988

This PR extends WP_REST_Block_Patterns_Controller so that it can call gutenberg_resolve_pattern_blocks, which was introduced in #72988

WP_REST_Block_Patterns_Controller calls resolve_pattern_blocks here in Core.

Why?

Some patterns comprise other patterns, e.g., see TT5's page templates

Business homepage
Landing page for book
Landing page for event
Landing page for podcast

Sibling patterns should be parsed.

Before

Image

After

Screenshot 2025-11-18 at 2 23 46 pm

Testing Instructions

Fire up this PR and enable the content only experiment.

Screenshot 2025-11-18 at 4 55 29 pm

Open a new page or post and insert of the page patterns mentioned above.

The patterns within those patterns should be parsed, and therefore, they'll be in "content only" mode in the editor.

You'll be able to tell because the list view will show the pattern icons, and the block inspector will show their editable fields.

Screenshots or screencast

Kapture.2025-11-18.at.15.16.17.mp4

- Introduced `Gutenberg_REST_Block_Patterns_Controller_7_0` to handle block patterns via the REST API.
- Registered new REST API routes for block patterns in WordPress 7.0.
- Updated existing files to include the new controller and ensure proper functionality.
- Added unit tests for pattern block resolution in REST API responses.
@github-actions
Copy link

github-actions bot commented Nov 18, 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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: jasmussen <[email protected]>

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

),
'schema' => array( $this, 'get_public_item_schema' ),
),
true // Override the core route.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is required to ensure this controller's routes take precedence

Comment on lines +165 to +169
$this->assertSame(
'<!-- wp:paragraph {"metadata":{"patternName":"test/single-block-pattern-1","name":"Single Block Pattern 1","description":"A single block pattern 1.","categories":["text"]}} -->Single block pattern 1 content<!-- /wp:paragraph --><!-- wp:paragraph {"metadata":{"patternName":"test/single-block-pattern-2","name":"Single Block Pattern 2","description":"A single block pattern 2."}} -->Single block pattern 2 content<!-- /wp:paragraph -->',
$nested_pattern['content'],
'Sibling patterns pattern should contain the two resolved patterns.'
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that it doesn't yet consider other children.

What if we have a pattern that contains the following:

<!-- wp:pattern...
<!--wp:heading...
<!--wp:paragraph...

Should they be grouped?

Maybe we need to wrap all patterns that don't have a single root block?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are definitely some edge cases, but I think this PR helps get us to about 99% (at least of the core patterns) working well.

Perhaps we can keep the issue open to discuss the edge cases.

We can also publish a dev note to help educate theme/pattern devs about making compliant patterns.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good ideas, thanks for testing this PR!

Copy link
Member Author

Choose a reason for hiding this comment

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

We can also publish a dev note to help educate theme/pattern devs about making compliant patterns.

I'll add this note to the documentation issue: #71572

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Thanks, this works well for me, and solves the most pressing issue!

@ramonjd ramonjd merged commit 52cf722 into trunk Nov 18, 2025
44 of 45 checks passed
@ramonjd ramonjd deleted the update/patterns-endpoint-parse-patterns branch November 18, 2025 22:12
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Pattern Directory The Pattern Directory, a place to find patterns [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants