Make WordPress Core


Ignore:
Timestamp:
09/15/2022 12:18:30 PM (20 months ago)
Author:
hellofromTonya
Message:

Themes: Introduces block-based template parts for Classic themes.

Allows Classic / Hybrid themes to use block-based template parts without using complete block-based templates.

  • Exposes the Site Editor's template parts UI
  • Adds Appearance > "Template Parts" menu
  • Enabled within the theme via adding a theme support for 'block-template-parts'
    add_theme_support( 'block-template-parts' );
    

This is a backport from Gutenberg.See WordPress/gutenberg PR 42729.

Follow-up to [52330], [52069], [52178].

Props mamaduka, fabiankaegy, poena, scruffian, manfcarlo, bernhard-reiter, hellofromTonya.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/site-editor.php

    r53784 r54176  
    2020}
    2121
    22 if ( ! wp_is_block_theme() ) {
     22if ( ! ( current_theme_supports( 'block-template-parts' ) || wp_is_block_theme() ) ) {
    2323    wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) );
     24}
     25
     26$is_template_part_editor = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] );
     27if ( ! wp_is_block_theme() && ! $is_template_part_editor ) {
     28    wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
    2429}
    2530
     
    6570$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
    6671$custom_settings      = array(
    67     'siteUrl'                  => site_url(),
    68     'postsPerPage'             => get_option( 'posts_per_page' ),
    69     'styles'                   => get_block_editor_theme_styles(),
    70     'defaultTemplateTypes'     => $indexed_template_types,
    71     'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(),
    72     '__unstableHomeTemplate'   => $home_template,
     72    'siteUrl'                   => site_url(),
     73    'postsPerPage'              => get_option( 'posts_per_page' ),
     74    'styles'                    => get_block_editor_theme_styles(),
     75    'defaultTemplateTypes'      => $indexed_template_types,
     76    'defaultTemplatePartAreas'  => get_allowed_block_template_part_areas(),
     77    'supportsLayout'            => WP_Theme_JSON_Resolver::theme_has_support(),
     78    'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
     79    '__unstableHomeTemplate'    => $home_template,
    7380);
     81
     82/**
     83 * Home template resolution is not needed when block template parts are supported.
     84 * Set the value to `true` to satisfy the editor initialization guard clause.
     85 */
     86if ( $custom_settings['supportsTemplatePartsMode'] ) {
     87    $custom_settings['__unstableHomeTemplate'] = true;
     88}
    7489
    7590// Add additional back-compat patterns registered by `current_screen` et al.
Note: See TracChangeset for help on using the changeset viewer.