From e49900a1cf44ebf928db7532ad445f4de9ad06ad Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 22 Mar 2021 17:00:23 +0200 Subject: [PATCH] _gutenberg_add_template_part_area_info from the new `templateParts` format. --- lib/full-site-editing/block-templates.php | 17 +++++++++++++---- phpunit/class-wp-theme-json-test.php | 6 ++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/full-site-editing/block-templates.php b/lib/full-site-editing/block-templates.php index b1ee167d99961..2a3472470d835 100644 --- a/lib/full-site-editing/block-templates.php +++ b/lib/full-site-editing/block-templates.php @@ -128,12 +128,21 @@ function _gutenberg_add_template_part_area_info( $template_info ) { $theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_template_parts(); } - if ( isset( $theme_data[ $template_info['slug'] ]['area'] ) ) { - $template_info['area'] = gutenberg_filter_template_part_area( $theme_data[ $template_info['slug'] ]['area'] ); - } else { - $template_info['area'] = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; + $found_area = null; + if ( isset( $template_info['slug'] ) && is_array( $theme_data ) ) { + foreach ( array_values( $theme_data ) as $value ) { + if ( ! ( isset( $value['name'] ) && isset( $value['area'] ) ) ) { + continue; + } + if ( $template_info['slug'] === $value['name'] ) { + $found_area = $value['area']; + break; + } + } } + $template_info['area'] = $found_area ? gutenberg_filter_template_part_area( $found_area ) : WP_TEMPLATE_PART_AREA_UNCATEGORIZED; + return $template_info; } diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 504ef7e049f41..b2bbf6e75d40b 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -801,7 +801,8 @@ function test_get_template_parts() { $theme_json = new WP_Theme_JSON( array( 'templateParts' => array( - 'header' => array( + array( + 'name' => 'header', 'area' => 'Some area', ), ), @@ -813,7 +814,8 @@ function test_get_template_parts() { $this->assertEqualSetsWithIndex( $template_parts, array( - 'header' => array( + array( + 'name' => 'header', 'area' => 'Some area', ), )