Make WordPress Core

Changeset 60037


Ignore:
Timestamp:
03/18/2025 12:28:17 PM (5 weeks ago)
Author:
joemcgill
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r59968 r60037  
    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 
    15841579        if ( isset( $this->block_theme ) ) {
    15851580            return $this->block_theme;
  • trunk/src/wp-includes/theme.php

    r59861 r60037  
    43534353 */
    43544354function wp_is_block_theme() {
     4355    if ( empty( $GLOBALS['wp_theme_directories'] ) ) {
     4356        _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before the theme directory is registered.' ), '6.8.0' );
     4357        return false;
     4358    }
     4359
    43554360    return wp_get_theme()->is_block_theme();
    43564361}
Note: See TracChangeset for help on using the changeset viewer.