Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actions which fire during the loading process of block template parts #36884

Merged
merged 1 commit into from
Dec 6, 2021

Conversation

johnbillion
Copy link
Member

@johnbillion johnbillion commented Nov 25, 2021

Description

The template hierarchy and template part system in WordPress core is mature and over the years actions and filters have been introduced which allow developers to debug template file and template part loading.

The template part block introduced a new way of loading template parts which the existing actions and filters don't cover. This means, for example, it's not possible for a debugging plugin such as Query Monitor to identify which template parts were loaded during a given request.

The addition of these actions covers all three potential situations with the template part block:

  • The template part is found and loaded from a wp_template_part post in the database
  • The template part is found and loaded from a .html file in the theme
  • The template part is not found

I think it would be a good idea to get this into WP 5.9. Developers who are new to FSE are going to be interested in seeing how their pages are constructed with these new paradigms, and this debugging info will help with that.

I did consider implementing this as a filter on the $content variable, but that becomes an API change that warrants a bit more discussion. An action solves the immediate problem without affecting the architecture.

How has this been tested?

I've been testing this with a development version of Query Monitor while using FSE. It allows QM to additionally show all the post- and HTML-based template parts loaded during the request just like it does for PHP-based template parts when FSE isn't in use. Example screenshot:

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@johnbillion johnbillion added [Block] Template Part Affects the Template Parts Block [Type] Task Issues or PRs that have been broken down into an individual action to take labels Nov 25, 2021
@gziolo
Copy link
Member

gziolo commented Nov 29, 2021

@noisysocks and @Mamaduka - this looks like a potential candidate for WP 5.9.

How about the Navigation block? Is it using a similar logic for loading HTML templates?

@Mamaduka
Copy link
Member

It makes sense to include in 5.9.

The navigation block uses render_callback; I don't think any special hook is required there.

@noisysocks noisysocks added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 30, 2021
@noisysocks
Copy link
Member

Since it's not a significant code change I'd say it's okay for 5.9 beta 2.

@noisysocks noisysocks merged commit 4d3e957 into trunk Dec 6, 2021
@noisysocks noisysocks deleted the block-template-part-debugging branch December 6, 2021 01:10
@github-actions github-actions bot added this to the Gutenberg 12.2 milestone Dec 6, 2021
@noisysocks noisysocks removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants