diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index ee74099766..7c25d07b2c 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1576,6 +1576,11 @@ final class WP_Theme implements ArrayAccess { * @return bool */ public function is_block_theme() { + if ( ! did_action( 'setup_theme' ) ) { + _doing_it_wrong( __METHOD__, __( 'This method should not be called before themes are set up.' ), '6.8.0' ); + return false; + } + if ( isset( $this->block_theme ) ) { return $this->block_theme; } diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 36f3c949dd..2bc2e61e4a 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -737,6 +737,7 @@ add_action( 'save_post_wp_template_part', 'wp_set_unique_slug_on_create_template add_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' ); add_action( 'wp_footer', 'the_block_template_skip_link' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_block_template_skip_link(). add_action( 'after_setup_theme', 'wp_enable_block_templates', 1 ); +add_action( 'after_setup_theme', 'wp_set_editor_default_mode', 2 ); // Run after enabling block templates. add_action( 'wp_loaded', '_add_template_loader_filters' ); // wp_navigation post type. diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index a9992071f0..4db40681bb 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -69,11 +69,6 @@ function create_initial_post_types() { ) ); - // Enhance page editor for block themes by rendering template and content blocks. - if ( wp_is_block_theme() && current_theme_supports( 'block-templates' ) ) { - add_post_type_support( 'page', 'editor', array( 'default-mode' => 'template-locked' ) ); - } - register_post_type( 'attachment', array( @@ -8529,3 +8524,14 @@ function wp_create_initial_post_meta() { ) ); } + +/** + * Sets the default editor mode based on support for block templates. + * + * @since 6.8.0 + */ +function wp_set_editor_default_mode() { + if ( wp_is_block_theme() && current_theme_supports( 'block-templates' ) ) { + add_post_type_support( 'page', 'editor', array( 'default-mode' => 'template-locked' ) ); + } +}