Skip to content

Conversation

@mikachan
Copy link
Member

What?

Related to #73252

Adds more checks for the active_templates experiment.

Why? / How?

These runtime checks ensure that none of this code is run when the experiment is disabled.

Testing Instructions

  1. Go to Appearance - Editor - Templates
  2. Make a small change to a template (e.g. remove the title from the Archives template)
  3. View the front end and ensure the change is reflected there
  4. Go back to the Editor (or refresh after making the change), and ensure the change persists (i.e. the edited template is displayed, and not the template from the active theme)

@mikachan mikachan requested a review from ellatrix November 24, 2025 13:18
@mikachan mikachan added [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Experimental Experimental feature or API. labels Nov 24, 2025
public function get_template_fallback( $request ) {
// Check active_templates experiment status.
if ( ! gutenberg_is_experiment_enabled( 'active_templates' ) ) {
return rest_ensure_response( new stdClass() );
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't we have to call the parent get_template_fallback method here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see, we probably would. You mean like this: parent::get_template_fallback( $request )?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed this in 409c107.

@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: mikachan <mikachan@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

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

@ellatrix ellatrix added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Nov 24, 2025
*/
function gutenberg_resolve_block_template( $template_type, $template_hierarchy, $fallback_template ) {
// Check active_templates experiment status.
if ( ! gutenberg_is_experiment_enabled( 'active_templates' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess this one is not needed, it's not a filter

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, the fix still works without the check in gutenberg_resolve_block_template. Removed in 5d22b8b.

@ellatrix
Copy link
Member

When the experiment is toggled off it's working great, but when it's on, there's too many "created templates" and it's impossible to delete them, they just come back. Looking into it now.

@ellatrix
Copy link
Member

The issue seems to happen in trunk too. I'll investigate separately and perhaps we also need that to be fixed in a point release 😬

@github-actions
Copy link

Flaky tests detected in 5d22b8b.
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/19637963501
📝 Reported issues:

@mikachan
Copy link
Member Author

The issue seems to happen in trunk too. I'll investigate separately and perhaps we also need that to be fixed in a point release 😬

Ah OK, if it's happening in trunk I guess we can handle it separately to this PR.

I'm also struggling to reproduce this locally. With the experiment on, I only see one copy of the edited template under "Created templates".

@ellatrix
Copy link
Member

ellatrix commented Nov 24, 2025

Actually, I had the collab experiment on by accident, which is breaking things, so all good in normal trunk 😃

@mikachan mikachan merged commit 40d6f24 into trunk Nov 24, 2025
37 checks passed
@mikachan mikachan deleted the update/active-templates-check branch November 24, 2025 15:24
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 24, 2025
@mikachan mikachan added the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Nov 24, 2025
@mikachan
Copy link
Member Author

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

mikachan added a commit that referenced this pull request Nov 24, 2025
* Add more checks for active_templates

* Use get_template_fallback()

* Remove check for gutenberg_resolve_block_template

Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
@mikachan mikachan removed the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Templates API Related to API powering block template functionality in the Site Editor No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants