Skip to content

Commit

Permalink
Editor: Fix block template files query for a post-type.
Browse files Browse the repository at this point in the history
See WordPress/gutenberg#61244.
See WordPress/wordpress-develop#6468.

Fixes #61110.

Props mamaduka, mukesh27, grantmkin, vcanales, ellatrix, oandregal.


Built from https://develop.svn.wordpress.org/trunk@58323


git-svn-id: https://core.svn.wordpress.org/trunk@57780 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ellatrix committed Jun 4, 2024
1 parent 7255f9a commit cad37fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cad37fa

Please sign in to comment.