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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user