From 4e28fde39aa81785d92d4b9d66df9e9f96c208f8 Mon Sep 17 00:00:00 2001 From: ellatrix Date: Tue, 4 Jun 2024 08:14:18 +0000 Subject: [PATCH] Editor: Fix block template files query for a post-type. See https://github.com/WordPress/gutenberg/pull/61244. See https://github.com/WordPress/wordpress-develop/pull/6468. Fixes #61110. Props mamaduka, mukesh27, grantmkin, vcanales, ellatrix, oandregal. Built from https://develop.svn.wordpress.org/trunk@58323 git-svn-id: http://core.svn.wordpress.org/trunk@57780 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-template-utils.php | 12 ++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 58ee129d2a..10ba863c62 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -362,6 +362,11 @@ function _get_block_templates_files( $template_type, $query = array() ) { return null; } + $default_template_types = array(); + if ( 'wp_template' === $template_type ) { + $default_template_types = get_default_block_template_types(); + } + // Prepare metadata from $query. $slugs_to_include = isset( $query['slug__in'] ) ? $query['slug__in'] : array(); $slugs_to_skip = isset( $query['slug__not_in'] ) ? $query['slug__not_in'] : array(); @@ -425,12 +430,19 @@ function _get_block_templates_files( $template_type, $query = array() ) { if ( 'wp_template' === $template_type ) { $candidate = _add_block_template_info( $new_template_item ); + $is_custom = ! isset( $default_template_types[ $candidate['slug'] ] ); + if ( ! $post_type || ( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) ) ) { $template_files[ $template_slug ] = $candidate; } + + // The custom templates with no associated post types are available for all post types. + if ( $post_type && ! isset( $candidate['postTypes'] ) && $is_custom ) { + $template_files[ $template_slug ] = $candidate; + } } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index d27d3f1c36..eb7b2bf517 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58322'; +$wp_version = '6.6-alpha-58323'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.