mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 05:04:31 +00:00
Filter custom block templates with PHP
This method calls get_block_templates once and uses block template properties directly for filtering. This way, we can avoid hitting the database for each public post type. The previous method is useful when we already know the current post type we request templates for, like when using REST API. Follows [52334]. See #54335. Props mamaduka, youknowriad. git-svn-id: https://develop.svn.wordpress.org/trunk@52365 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1250,9 +1250,17 @@ final class WP_Theme implements ArrayAccess {
|
||||
}
|
||||
|
||||
if ( current_theme_supports( 'block-templates' ) ) {
|
||||
$block_templates = get_block_templates( array(), 'wp_template' );
|
||||
foreach ( get_post_types( array( 'public' => true ) ) as $type ) {
|
||||
$block_templates = get_block_templates( array( 'post_type' => $type ), 'wp_template' );
|
||||
foreach ( $block_templates as $block_template ) {
|
||||
if ( ! $block_template->is_custom ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $block_template->post_types ) && ! in_array( $type, $block_template->post_types, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$post_templates[ $type ][ $block_template->slug ] = $block_template->title;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user