Skip to content

Conversation

@ellatrix
Copy link
Member

What?

Closes #71770

Why?

Some plugins expect get_block_templates to always be called, which no longer happens when we return a template through pre_get_block_templates.

How?

Run the get_block_templates filter ourselves before returning the new template.

Testing Instructions

add_filter(
	'get_block_templates',
	function ( $templates, $query ) {
		do_action( 'qm/debug', $query );
		array_map(
			function ( $template ) {
				do_action( 'qm/debug', $template ); // use any method to log data
			},
			$templates
		);
		return $templates;
	},
	10,
	2
);

Run this code to log when get_block_templates is called. For example, when activating a custom 404 template, it should still log a call with the 404 template, not just the index template.

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@github-actions
Copy link

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: ellatrix <[email protected]>
Co-authored-by: kmanijak <[email protected]>

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

Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

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

I confirm the hook is fired and so it's always called allowing plugins like WooCommerce to react on it and update templates. 🙌

@ellatrix ellatrix force-pushed the add/template-activation-compat-filter branch 2 times, most recently from e245cd9 to 4ea6042 Compare October 1, 2025 17:40
@ellatrix ellatrix added this to the Gutenberg 21.8 milestone Oct 1, 2025
@github-actions
Copy link

github-actions bot commented Oct 1, 2025

Flaky tests detected in 4ea6042.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18170683104
📝 Reported issues:

@ellatrix ellatrix added the [Type] Bug An existing feature does not function as intended label Oct 2, 2025
@ellatrix ellatrix force-pushed the add/template-activation-compat-filter branch from 4ea6042 to 098a18c Compare October 7, 2025 19:02
@ellatrix ellatrix enabled auto-merge (squash) October 7, 2025 19:03
@ellatrix ellatrix merged commit 5c20c7b into trunk Oct 7, 2025
112 of 114 checks passed
@ellatrix ellatrix deleted the add/template-activation-compat-filter branch October 7, 2025 20:15
@ellatrix ellatrix added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Oct 7, 2025
cbravobernal pushed a commit that referenced this pull request Oct 8, 2025
@cbravobernal
Copy link
Contributor

I just cherry-picked this PR to the release/21.8 branch to get it included in the next release: dc60d4e

@cbravobernal cbravobernal removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Oct 8, 2025
sidharthpandita1 pushed a commit to sidharthpandita1/gutenberg that referenced this pull request Oct 10, 2025
ellatrix added a commit that referenced this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Template Activation] get_block_templates returns edited template as index

4 participants