Skip to content

Commit 5f24c9d

Browse files
committed
Themes: Fix resolution of parent themes.
This fixes an issue introduced in [59885] whereby calling `WP_Theme:is_block_theme()` before themes are set up resulted in the parent theme to not be resolved. To address this, post support for editor default-mode has been moved to a standalone callback, `wp_set_editor_default_mode()`, which is called on the `after_setup_theme` hook. In addition, if `WP_Theme::is_block_theme` is called too early, a `_doing_it_wrong()` error will now be thrown. Props fabiankaegy, joemcgill, peterwilsoncc, jorbin, krupajnanda, riddhidave, ugyensupport, navi161, manojmaharrshi, Ankit K Gupta, narenin, shailu25, pooja1210. Fixes #63062. git-svn-id: https://develop.svn.wordpress.org/trunk@59968 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 16ee79b commit 5f24c9d

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/wp-includes/class-wp-theme.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,11 @@ public function is_allowed( $check = 'both', $blog_id = null ) {
15761576
* @return bool
15771577
*/
15781578
public function is_block_theme() {
1579+
if ( ! did_action( 'setup_theme' ) ) {
1580+
_doing_it_wrong( __METHOD__, __( 'This method should not be called before themes are set up.' ), '6.8.0' );
1581+
return false;
1582+
}
1583+
15791584
if ( isset( $this->block_theme ) ) {
15801585
return $this->block_theme;
15811586
}

src/wp-includes/default-filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@
737737
add_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' );
738738
add_action( 'wp_footer', 'the_block_template_skip_link' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_block_template_skip_link().
739739
add_action( 'after_setup_theme', 'wp_enable_block_templates', 1 );
740+
add_action( 'after_setup_theme', 'wp_set_editor_default_mode', 2 ); // Run after enabling block templates.
740741
add_action( 'wp_loaded', '_add_template_loader_filters' );
741742

742743
// wp_navigation post type.

src/wp-includes/post.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ function create_initial_post_types() {
6969
)
7070
);
7171

72-
// Enhance page editor for block themes by rendering template and content blocks.
73-
if ( wp_is_block_theme() && current_theme_supports( 'block-templates' ) ) {
74-
add_post_type_support( 'page', 'editor', array( 'default-mode' => 'template-locked' ) );
75-
}
76-
7772
register_post_type(
7873
'attachment',
7974
array(
@@ -8529,3 +8524,14 @@ function wp_create_initial_post_meta() {
85298524
)
85308525
);
85318526
}
8527+
8528+
/**
8529+
* Sets the default editor mode based on support for block templates.
8530+
*
8531+
* @since 6.8.0
8532+
*/
8533+
function wp_set_editor_default_mode() {
8534+
if ( wp_is_block_theme() && current_theme_supports( 'block-templates' ) ) {
8535+
add_post_type_support( 'page', 'editor', array( 'default-mode' => 'template-locked' ) );
8536+
}
8537+
}

0 commit comments

Comments
 (0)