From 9436bcb89156383cbefa3b2bfafb591688f471a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Fri, 8 Nov 2024 14:18:47 +0100 Subject: [PATCH] Fix flash when clicking template name in the editor when a plugin registered template matches a default WP theme template (#66359) * Fix _gutenberg_get_block_templates_files() so it returns the 'page' template from the theme when 'page' post type templates are queried * Try different approach: don't use query to get the templates reference to use for filtering * Only unset post_type from the query * Add backport file --- backport-changelog/6.7/7676.md | 3 +++ lib/compat/wordpress-6.7/compat.php | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 backport-changelog/6.7/7676.md diff --git a/backport-changelog/6.7/7676.md b/backport-changelog/6.7/7676.md new file mode 100644 index 00000000000000..19d9dc59048457 --- /dev/null +++ b/backport-changelog/6.7/7676.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/7676 + +* https://github.com/WordPress/gutenberg/pull/66359 diff --git a/lib/compat/wordpress-6.7/compat.php b/lib/compat/wordpress-6.7/compat.php index cd533a42cc528e..e58eca56ef71f9 100644 --- a/lib/compat/wordpress-6.7/compat.php +++ b/lib/compat/wordpress-6.7/compat.php @@ -40,7 +40,13 @@ function _gutenberg_add_block_templates_from_registry( $query_result, $query, $t } if ( ! isset( $query['wp_id'] ) ) { - $template_files = _gutenberg_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. + // See: https://github.com/WordPress/gutenberg/issues/65584 + $template_files_query = $query; + unset( $template_files_query['post_type'] ); + $template_files = _gutenberg_get_block_templates_files( $template_type, $template_files_query ); /* * Add templates registered in the template registry. Filtering out the ones which have a theme file.