From 3453109d7a9f549bb5e644ee623c8654e0ecba9d Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Tue, 11 Mar 2025 12:33:23 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@59968 git-svn-id: http://core.svn.wordpress.org/trunk@59310 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme.php | 5 +++++ wp-includes/default-filters.php | 1 + wp-includes/post.php | 16 +++++++++++----- wp-includes/version.php | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index ee74099766..7c25d07b2c 100644 --- a/wp-includes/class-wp-theme.php +++ b/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/wp-includes/default-filters.php b/wp-includes/default-filters.php index 36f3c949dd..2bc2e61e4a 100644 --- a/wp-includes/default-filters.php +++ b/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/wp-includes/post.php b/wp-includes/post.php index a9992071f0..4db40681bb 100644 --- a/wp-includes/post.php +++ b/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' ) ); + } +} diff --git a/wp-includes/version.php b/wp-includes/version.php index f961f12db1..fc9e8070cc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-beta1-59967'; +$wp_version = '6.8-beta1-59968'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.