From e4f2fc8d9f663d32dfc0087f953921efec08d1f4 Mon Sep 17 00:00:00 2001 From: Lars Gersmann Date: Fri, 3 Jan 2025 17:37:55 +0100 Subject: [PATCH 1/2] Fixes registered templates access in get_block_templates() --- src/wp-includes/block-template-utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index f974f6efbd9a5..07034b1e27485 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -1175,7 +1175,7 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' ) if ( 'wp_template' === $template_type ) { // Add templates registered in the template registry. Filtering out the ones which have a theme file. - $registered_templates = WP_Block_Templates_Registry::get_instance()->get_by_query( $query ); + $registered_templates = array_values( WP_Block_Templates_Registry::get_instance()->get_by_query( $query ) ); $matching_registered_templates = array_filter( $registered_templates, function ( $registered_template ) use ( $template_files ) { From d8d6de2f565b59003c9248345ad404a5222f8844 Mon Sep 17 00:00:00 2001 From: Lars Gersmann Date: Sat, 4 Jan 2025 13:05:30 +0100 Subject: [PATCH 2/2] Fixes block template assertion to use titles as keys in tests --- tests/phpunit/tests/block-template.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/block-template.php b/tests/phpunit/tests/block-template.php index d88895c872be1..ff66229f5b323 100644 --- a/tests/phpunit/tests/block-template.php +++ b/tests/phpunit/tests/block-template.php @@ -447,7 +447,8 @@ public function test_get_block_templates_from_registry() { $templates = get_block_templates(); - $this->assertArrayHasKey( $template_name, $templates ); + $templates_by_title = array_column( $templates, null, 'title' ); + $this->assertArrayHasKey( $template_name, $templates_by_title ); unregister_block_template( $template_name ); }