Skip to content

Commit a13f896

Browse files
committed
Themes: Use get_theme_file_path() in wp_theme_has_theme_json().
Ensure that all places where `theme.json` is included, use `get_theme_file_path` or `WP_Theme->get_file_path`, so that the path is run through `theme_file_path` filter. This change also means that the method `get_file_path_from_theme` can be deprecated, as it is no longer used in core. Props flixos90, spacedmonkey, costdev, johnbillion, oglekler, hellofromtonya, mukesh27, audrasjb, oandregal. Fixes #57629. git-svn-id: https://develop.svn.wordpress.org/trunk@56073 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 87a0ad4 commit a13f896

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/wp-includes/class-wp-theme-json-resolver.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ public static function get_theme_data( $deprecated = array(), $options = array()
238238
$options = wp_parse_args( $options, array( 'with_supports' => true ) );
239239

240240
if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) {
241-
$theme_json_file = static::get_file_path_from_theme( 'theme.json' );
242241
$wp_theme = wp_get_theme();
243-
if ( '' !== $theme_json_file ) {
242+
$theme_json_file = $wp_theme->get_file_path( 'theme.json' );
243+
if ( is_readable( $theme_json_file ) ) {
244244
$theme_json_data = static::read_json_file( $theme_json_file );
245245
$theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) );
246246
} else {
@@ -260,8 +260,8 @@ public static function get_theme_data( $deprecated = array(), $options = array()
260260

261261
if ( $wp_theme->parent() ) {
262262
// Get parent theme.json.
263-
$parent_theme_json_file = static::get_file_path_from_theme( 'theme.json', true );
264-
if ( '' !== $parent_theme_json_file ) {
263+
$parent_theme_json_file = $wp_theme->parent()->get_file_path( 'theme.json' );
264+
if ( $theme_json_file !== $parent_theme_json_file && is_readable( $parent_theme_json_file ) ) {
265265
$parent_theme_json_data = static::read_json_file( $parent_theme_json_file );
266266
$parent_theme_json_data = static::translate( $parent_theme_json_data, $wp_theme->parent()->get( 'TextDomain' ) );
267267
$parent_theme = new WP_Theme_JSON( $parent_theme_json_data );

src/wp-includes/global-styles-and-settings.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,7 @@ function wp_theme_has_theme_json() {
408408
}
409409

410410
// Does the theme have its own theme.json?
411-
$theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );
412-
413-
// Look up the parent if the child does not have a theme.json.
414-
if ( ! $theme_has_support ) {
415-
$theme_has_support = is_readable( get_template_directory() . '/theme.json' );
416-
}
411+
$theme_has_support = is_readable( get_theme_file_path( 'theme.json' ) );
417412

418413
return $theme_has_support;
419414
}

0 commit comments

Comments
 (0)