From 887920cf61f83fcc4f8d512f1f5531d28321ee5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 23 Oct 2024 10:05:05 +0200 Subject: [PATCH 1/4] Fix _gutenberg_get_block_templates_files() so it returns the 'page' template from the theme when 'page' post type templates are queried --- lib/compat/wordpress-6.6/block-template-utils.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/compat/wordpress-6.6/block-template-utils.php b/lib/compat/wordpress-6.6/block-template-utils.php index 953f6bf20c077e..8e9a3bace97073 100644 --- a/lib/compat/wordpress-6.6/block-template-utils.php +++ b/lib/compat/wordpress-6.6/block-template-utils.php @@ -215,6 +215,10 @@ function _gutenberg_get_block_templates_files( $template_type, $query = array() $template_files[ $template_slug ] = $candidate; } + if ( 'page' === $post_type && 'page' === $template_slug ) { + $template_files[ $template_slug ] = $candidate; + } + // @core-merge: This code will go into Core's '_get_block_templates_files' function. // The custom templates with no associated post-types are available for all post-types. if ( $post_type && ! isset( $candidate['postTypes'] ) && $is_custom ) { From f957f646e3732b256ec34c60384052ff2fcb5190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Thu, 24 Oct 2024 19:03:27 +0200 Subject: [PATCH 2/4] Try different approach: don't use query to get the templates reference to use for filtering --- lib/compat/wordpress-6.6/block-template-utils.php | 4 ---- lib/compat/wordpress-6.7/compat.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/compat/wordpress-6.6/block-template-utils.php b/lib/compat/wordpress-6.6/block-template-utils.php index 8e9a3bace97073..953f6bf20c077e 100644 --- a/lib/compat/wordpress-6.6/block-template-utils.php +++ b/lib/compat/wordpress-6.6/block-template-utils.php @@ -215,10 +215,6 @@ function _gutenberg_get_block_templates_files( $template_type, $query = array() $template_files[ $template_slug ] = $candidate; } - if ( 'page' === $post_type && 'page' === $template_slug ) { - $template_files[ $template_slug ] = $candidate; - } - // @core-merge: This code will go into Core's '_get_block_templates_files' function. // The custom templates with no associated post-types are available for all post-types. if ( $post_type && ! isset( $candidate['postTypes'] ) && $is_custom ) { diff --git a/lib/compat/wordpress-6.7/compat.php b/lib/compat/wordpress-6.7/compat.php index cd533a42cc528e..2ee8ab38e9d43e 100644 --- a/lib/compat/wordpress-6.7/compat.php +++ b/lib/compat/wordpress-6.7/compat.php @@ -40,7 +40,7 @@ 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 ); + $template_files = _gutenberg_get_block_templates_files( $template_type ); /* * Add templates registered in the template registry. Filtering out the ones which have a theme file. From 1641d59468188dc87a0bb3527fdfbb2873b40a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 29 Oct 2024 09:29:48 +0100 Subject: [PATCH 3/4] Only unset post_type from the query --- lib/compat/wordpress-6.7/compat.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.7/compat.php b/lib/compat/wordpress-6.7/compat.php index 2ee8ab38e9d43e..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 ); + // 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. From f1ec716ef298f3d71d3e96b1a9db56b249a2cc20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 29 Oct 2024 10:53:23 +0100 Subject: [PATCH 4/4] Add backport file --- backport-changelog/6.7/7676.md | 3 +++ 1 file changed, 3 insertions(+) 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