Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ function ( $template ) {
$matching_registered_templates
);

$query_result = array_merge( $query_result, $matching_registered_templates );
$query_result = array_merge( $query_result, array_values( $matching_registered_templates ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public function test_get_block_templates_from_registry() {

$templates = get_block_templates();

$this->assertArrayHasKey( $template_name, $templates );
$this->assertContains( 'test-plugin', wp_list_pluck( $templates, 'plugin' ) );

unregister_block_template( $template_name );
}
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/tests/blocks/getBlockTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,33 @@ public function test_get_block_templates_should_not_leak_plugin_registered_templ
unregister_block_template( $template_name );
}

/**
* Plugin-registered templates must be merged into a list so that callers
* can reliably access the first result by index.
*
* @ticket 64216
*
* @covers ::get_block_templates
*/
public function test_get_block_templates_should_return_a_list_when_a_plugin_registered_template_is_included() {
$template_name = 'test-plugin//single-post-64216';
$template_args = array(
'content' => 'Template content',
'title' => 'Test Template',
'description' => 'Description of test template',
'post_types' => array( 'post' ),
);
register_block_template( $template_name, $template_args );

$templates = get_block_templates( array( 'slug__in' => array( 'single-post-64216' ) ) );

$this->assertTrue( array_is_list( $templates ) );
$this->assertCount( 1, $templates );
$this->assertSame( 'single-post-64216', $templates[0]->slug );

unregister_block_template( $template_name );
}

/**
* Data provider.
*
Expand Down
Loading