Add actions which fire during the loading process of block template parts #36884
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
wp_template_part
post in the database.html
file in the themeI 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: