Make WordPress Core

Changeset 56085


Ignore:
Timestamp:
06/28/2023 05:55:04 AM (2 years ago)
Author:
peterwilsoncc
Message:

Script Loader: Prevent fatal error in load-styles.php.

Duplicates the code of get_theme_file_path() within wp_theme_has_theme_json(). This is to account for the load-styles.php context in which the former function is unavailable.

Follow up to [56073].

Props SergeyBiryukov, oglekler, spacedmonkey, joemcgill, dd32.
Fixes #57629.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r56073 r56085  
    408408    }
    409409
    410     // Does the theme have its own theme.json?
    411     $theme_has_support = is_readable( get_theme_file_path( 'theme.json' ) );
     410    // This is the same as get_theme_file_path(), which isn't available in load-styles.php context
     411    if ( file_exists( get_stylesheet_directory() . '/theme.json' ) ) {
     412        $path = get_stylesheet_directory() . '/theme.json';
     413    } else {
     414        $path = get_template_directory() . '/theme.json';
     415    }
     416
     417    /** This filter is documented in wp-includes/link-template.php */
     418    $path = apply_filters( 'theme_file_path', $path, 'theme.json' );
     419
     420    if ( file_exists( $path ) ) {
     421        $theme_has_support = true;
     422    } else {
     423        $theme_has_support = false;
     424    }
    412425
    413426    return $theme_has_support;
Note: See TracChangeset for help on using the changeset viewer.