From 030dce856593b6ecb85cdf07ba6c2a1a05ec2131 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 8 Apr 2021 08:49:07 +0300 Subject: [PATCH] Add do_block_template_part function (#30345) * Add do_block_template_part function * Add functions for the header & footer template-parts * rename functions * rename functions --- lib/full-site-editing/template-parts.php | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/full-site-editing/template-parts.php b/lib/full-site-editing/template-parts.php index a64416cfc39f9..8e21622c03e87 100644 --- a/lib/full-site-editing/template-parts.php +++ b/lib/full-site-editing/template-parts.php @@ -201,3 +201,36 @@ function gutenberg_filter_template_part_area( $type ) { trigger_error( $warning_message, E_USER_NOTICE ); return WP_TEMPLATE_PART_AREA_UNCATEGORIZED; } + +/** + * Print a template-part. + * + * @param string $part The template-part to print. Use "header" or "footer". + * + * @return void + */ +function gutenberg_block_template_part( $part ) { + $template_part = gutenberg_get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' ); + if ( ! $template_part || empty( $template_part->content ) ) { + return; + } + echo do_blocks( $template_part->content ); +} + +/** + * Print the header template-part. + * + * @return void + */ +function gutenberg_block_header_area() { + gutenberg_block_template_part( 'header' ); +} + +/** + * Print the footer template-part. + * + * @return void + */ +function gutenberg_block_footer_area() { + gutenberg_block_template_part( 'footer' ); +}