mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
Editor: Fix get_block_templates() to get templates for a post type.
When a post type is passed to `get_block_templates()` in the query, return only the templates that match that post type. Fixes an issue where: * when a block template provided by a theme has been edited by the user * and that template has specific defined `postTypes` * but after editing, the template was available for all post types. Follow-up to [52062]. Props aljullu, bernhard-reiter, hellofromTonya. Fixes #55881. Built from https://develop.svn.wordpress.org/trunk@54184 git-svn-id: http://core.svn.wordpress.org/trunk@53743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
335203e971
commit
47d61a73ef
@ -552,8 +552,8 @@ function _build_block_template_result_from_post( $post ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$theme = $terms[0]->name;
|
$theme = $terms[0]->name;
|
||||||
$has_theme_file = wp_get_theme()->get_stylesheet() === $theme &&
|
$template_file = _get_block_template_file( $post->post_type, $post->post_name );
|
||||||
null !== _get_block_template_file( $post->post_type, $post->post_name );
|
$has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== $template_file;
|
||||||
|
|
||||||
$origin = get_post_meta( $post->ID, 'origin', true );
|
$origin = get_post_meta( $post->ID, 'origin', true );
|
||||||
|
|
||||||
@ -573,6 +573,10 @@ function _build_block_template_result_from_post( $post ) {
|
|||||||
$template->is_custom = true;
|
$template->is_custom = true;
|
||||||
$template->author = $post->post_author;
|
$template->author = $post->post_author;
|
||||||
|
|
||||||
|
if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) {
|
||||||
|
$template->post_types = $template_file['postTypes'];
|
||||||
|
}
|
||||||
|
|
||||||
if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) {
|
if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) {
|
||||||
$template->is_custom = false;
|
$template->is_custom = false;
|
||||||
}
|
}
|
||||||
@ -675,6 +679,13 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $post_type &&
|
||||||
|
isset( $template->post_types ) &&
|
||||||
|
! in_array( $post_type, $template->post_types, true )
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$query_result[] = $template;
|
$query_result[] = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.1-alpha-54183';
|
$wp_version = '6.1-alpha-54184';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user