Block Editor: Introduce block templates for classic themes.

With this patch, users will be able to create custom block based templates
and assign them to specific pages/posts.

Themes can also opt-out of this feature

Props bernhard-reiter, carlomanf.
Fixes #53176.


git-svn-id: https://develop.svn.wordpress.org/trunk@51003 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Riad Benguella
2021-05-25 14:19:14 +00:00
parent 0ddb25467f
commit ea49625d59
20 changed files with 1825 additions and 0 deletions

View File

@@ -1182,6 +1182,7 @@ final class WP_Theme implements ArrayAccess {
* Returns the theme's post templates.
*
* @since 4.7.0
* @since 5.8.0 Include block templates.
*
* @return string[] Array of page templates, keyed by filename and post type,
* with the value of the translated header name.
@@ -1219,6 +1220,15 @@ 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 ) {
foreach ( $block_templates as $block_template ) {
$post_templates[ $type ][ $block_template->slug ] = $block_template->title;
}
}
}
$this->cache_add( 'post_templates', $post_templates );
}