From 299978551a2042f5d78ce3ab7f7913316ce0529c Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Tue, 18 Mar 2025 12:30:25 +0000 Subject: [PATCH] Themes: Improve error notice when `wp_is_block_theme()` is called too early. This is a follow-up to [59968] which improves error handling for when `wp_is_block_theme()` is called too early. Initially, `_doing_it_wrong()` was called in `WP_Theme::is_block_theme()` was called prior to themes being set up, in order to avoid the bug reported in #63062, where doing so would cause parent themes to not be resolved. After further investigation, the issue is only caused by calling `wp_is_block_theme()` before the root theme directory has been registered (e.g., when called on the `muplugins_loaded` hook). Moving This error message to `wp_is_block_theme()` when `$GLOBALS['wp_theme_directories']` is empty avoids unnecessary error messages. Props wildworks, sukhendu2002, SirLouen, dinhtungdu, narenin, joemcgill, peterwilsoncc, afragen. Fixes #63086. See #63062. Built from https://develop.svn.wordpress.org/trunk@60037 git-svn-id: http://core.svn.wordpress.org/trunk@59373 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme.php | 5 ----- wp-includes/theme.php | 5 +++++ wp-includes/version.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index 7c25d07b2c..ee74099766 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -1576,11 +1576,6 @@ 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/theme.php b/wp-includes/theme.php index 0a3f7c5d65..b4a71d855a 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -4352,6 +4352,11 @@ function create_initial_theme_features() { * @return bool Whether the active theme is a block-based theme or not. */ function wp_is_block_theme() { + if ( empty( $GLOBALS['wp_theme_directories'] ) ) { + _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before the theme directory is registered.' ), '6.8.0' ); + return false; + } + return wp_get_theme()->is_block_theme(); } diff --git a/wp-includes/version.php b/wp-includes/version.php index eb7ce2af40..2ba6f642a5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-beta2-60036'; +$wp_version = '6.8-beta2-60037'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.