From 8fb284ba0e604060e43fd82d39ecf71202005d0a Mon Sep 17 00:00:00 2001 From: Herb Miller Date: Fri, 28 May 2021 12:26:25 +0100 Subject: [PATCH 1/2] Add rendering_template action (#32309) --- lib/full-site-editing/template-loader.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index 69b586bca1b26..d0b51e12a557f 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -58,6 +58,18 @@ function gutenberg_override_query_template( $template, $type, array $templates ) $block_template = gutenberg_resolve_template( $type, $templates ); + /** + * Fires before the template is rendered. + * + * Allows extensions to follow template processing. + * Called before the template is rendered. + * + * @param object $current_template The current template object. + * @param string $type Sanitized filename without extension. + * @param array $templates A list of template candidates, in descending order of priority. + */ + do_action( 'rendering_template', $block_template, $type, $templates ); + if ( $block_template ) { if ( empty( $block_template->content ) && is_user_logged_in() ) { $_wp_current_template_content = From 9712a6c4ffaacee1bf93c9ee11f322ccf64e3c0e Mon Sep 17 00:00:00 2001 From: Herb Miller Date: Fri, 28 May 2021 12:28:30 +0100 Subject: [PATCH 2/2] Add rendering_template_part action before and after rendering (#32309) --- packages/block-library/src/template-part/index.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index a30a1ca327e7e..51f702a5c8097 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -96,6 +96,17 @@ function render_block_core_template_part( $attributes ) { // Run through the actions that are typically taken on the_content. $seen_ids[ $template_part_id ] = true; + /** + * Fires before/after the template part is rendered. + * + * Allows extensions to follow template part processing. + * Called before and after each template part is rendered. + * + * @param array|null $attributes The template part attributes. Null after rendering. + * @param array $seen_ids The current template part nesting. + */ + do_action( 'rendering_template_part', $attributes, $seen_ids ); + $content = do_blocks( $content ); unset( $seen_ids[ $template_part_id ] ); $content = wptexturize( $content ); @@ -122,6 +133,9 @@ function render_block_core_template_part( $attributes ) { } $wrapper_attributes = get_block_wrapper_attributes(); + /** This action is documented in template-part.php */ + do_action( 'rendering_template_part', null, $seen_ids ); + return "<$html_tag $wrapper_attributes>" . str_replace( ']]>', ']]>', $content ) . ""; }