Skip to content

Conversation

@mikachan
Copy link
Member

@mikachan mikachan commented Nov 26, 2025

What?

This fixes the following error, which can be triggered by plugins calling the old gutenberg_get_block_template function with two arguments when the Template Activation experiment is enabled:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function gutenberg_get_block_template(), 2 passed in /wp-content/plugins/directorist/blocks/includes/class-block-templates-controller.php on line 93 and exactly 3 expected in /wordpress/plugins/gutenberg/22.1.2/lib/compat/wordpress-6.9/template-activate.php:591

This example is from the Directorist plugin, but this would happen for any plugin using this function with two args.

Why?

Prevents fatal errors from gutenberg_get_block_template().

How?

Allows all three args to be null, and if there are only two passed, treat them as get_block_template() would treat two args.

Testing Instructions

  1. Enable the Template Activation experiment in Gutenberg - Experiments
  2. Install any plugin that calls the gutenberg_get_block_template function with 2 args, e.g. Directorist
  3. Visit the front end of your site
  4. Ensure there are no errors

@mikachan mikachan added [Type] Bug An existing feature does not function as intended [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Nov 26, 2025
@mikachan mikachan requested review from ellatrix and removed request for spacedmonkey November 26, 2025 11:26
@github-actions
Copy link

github-actions bot commented Nov 26, 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: mikachan <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: scruffian <[email protected]>

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

@mikachan mikachan added No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release labels Nov 26, 2025
@scruffian
Copy link
Contributor

I'm surprised we added $output as the first argument since it will break all existing implementations of get_block_template. Is it too late to move $output to the third parameter?

@mikachan mikachan changed the title Template Activation: Allow 2 args in pre_get_block_template Template Activation: Rename gutenberg_get_block_template Nov 26, 2025
@mikachan mikachan merged commit b8335bf into trunk Nov 26, 2025
44 of 45 checks passed
@mikachan mikachan deleted the fix/template-activation-args-fix branch November 26, 2025 19:53
@github-actions github-actions bot added this to the Gutenberg 22.3 milestone Nov 26, 2025
@mikachan mikachan added Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) and removed Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release labels Nov 28, 2025
@mikachan
Copy link
Member Author

I just cherry-picked this PR to the release/22.2 branch to get it included in the next release: 5c38ef1

mikachan added a commit that referenced this pull request Nov 28, 2025
* Allow 2 args in gutenberg_get_block_template

* Fix copy paste error

* Simplify fix

* Update function name

Co-authored-by: mikachan <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: scruffian <[email protected]>
@mikachan mikachan added Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release and removed Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) labels Nov 28, 2025
@mikachan mikachan removed this from the Gutenberg 22.2 milestone Dec 3, 2025
@mikachan mikachan added this to the Gutenberg 22.1 milestone Dec 3, 2025
mikachan added a commit that referenced this pull request Dec 3, 2025
* Allow 2 args in gutenberg_get_block_template

* Fix copy paste error

* Simplify fix

* Update function name

Co-authored-by: mikachan <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: scruffian <[email protected]>
@mikachan
Copy link
Member Author

mikachan commented Dec 3, 2025

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

@mikachan mikachan removed the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Dec 3, 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] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants