Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes registered templates access in get_block_templates() #8086

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
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 @@ -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 ) {
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/tests/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Loading