Editor: Fix unexpected behavior due to conflicting custom block template.
This changeset fixes both a visual and functional bug related to template selection in the editor that occurred when having a custom block template registered that was using the same slug as another block template already registered by the theme, including the default block templates. Props aljullu, antonvlasenko, apermo, audrasjb, azaozz, ntsekouras. Fixes #62319. Built from https://develop.svn.wordpress.org/trunk@59951 git-svn-id: http://core.svn.wordpress.org/trunk@59293 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1185,9 +1185,35 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
||||
* over the theme-provided ones, so we skip querying and building them.
|
||||
*/
|
||||
$query['slug__not_in'] = wp_list_pluck( $query_result, 'slug' );
|
||||
$template_files = _get_block_templates_files( $template_type, $query );
|
||||
/*
|
||||
* We need to unset the post_type query param because some templates
|
||||
* would be excluded otherwise, like `page.html` when looking for
|
||||
* `page` templates. We need all templates so we can exclude duplicates
|
||||
* from plugin-registered templates.
|
||||
* See: https://github.com/WordPress/gutenberg/issues/65584
|
||||
*/
|
||||
$template_files_query = $query;
|
||||
unset( $template_files_query['post_type'] );
|
||||
$template_files = _get_block_templates_files( $template_type, $template_files_query );
|
||||
foreach ( $template_files as $template_file ) {
|
||||
// If the query doesn't specify a post type, or it does and the template matches the post type, add it.
|
||||
if (
|
||||
! isset( $query['post_type'] ) ||
|
||||
(
|
||||
isset( $template_file['postTypes'] ) &&
|
||||
in_array( $query['post_type'], $template_file['postTypes'], true )
|
||||
)
|
||||
) {
|
||||
$query_result[] = _build_block_template_result_from_file( $template_file, $template_type );
|
||||
} elseif ( ! isset( $template_file['postTypes'] ) ) {
|
||||
// The custom templates with no associated post types are available for all post types as long
|
||||
// as they are not default templates.
|
||||
$candidate = _build_block_template_result_from_file( $template_file, $template_type );
|
||||
$default_template_types = get_default_block_template_types();
|
||||
if ( ! isset( $default_template_types[ $candidate->slug ] ) ) {
|
||||
$query_result[] = $candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'wp_template' === $template_type ) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.8-beta1-59950';
|
||||
$wp_version = '6.8-beta1-59951';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user