diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 00b7a4f756..2f2b596c2a 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -552,8 +552,8 @@ function _build_block_template_result_from_post( $post ) { } $theme = $terms[0]->name; - $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && - null !== _get_block_template_file( $post->post_type, $post->post_name ); + $template_file = _get_block_template_file( $post->post_type, $post->post_name ); + $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== $template_file; $origin = get_post_meta( $post->ID, 'origin', true ); @@ -573,6 +573,10 @@ function _build_block_template_result_from_post( $post ) { $template->is_custom = true; $template->author = $post->post_author; + if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) { + $template->post_types = $template_file['postTypes']; + } + if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) { $template->is_custom = false; } @@ -675,6 +679,13 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' ) continue; } + if ( $post_type && + isset( $template->post_types ) && + ! in_array( $post_type, $template->post_types, true ) + ) { + continue; + } + $query_result[] = $template; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4ac654459d..b37eccdb40 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54183'; +$wp_version = '6.1-alpha-54184'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.