From 1afbc5b8a7491fa8799e7837f360798db9fe4e17 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 27 Jun 2023 17:12:26 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@56073 git-svn-id: http://core.svn.wordpress.org/trunk@55585 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json-resolver.php | 8 ++++---- wp-includes/global-styles-and-settings.php | 7 +------ wp-includes/version.php | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/wp-includes/class-wp-theme-json-resolver.php b/wp-includes/class-wp-theme-json-resolver.php index ac4f9eaf65..cce1cbba6a 100644 --- a/wp-includes/class-wp-theme-json-resolver.php +++ b/wp-includes/class-wp-theme-json-resolver.php @@ -238,9 +238,9 @@ class WP_Theme_JSON_Resolver { $options = wp_parse_args( $options, array( 'with_supports' => true ) ); if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) { - $theme_json_file = static::get_file_path_from_theme( 'theme.json' ); $wp_theme = wp_get_theme(); - if ( '' !== $theme_json_file ) { + $theme_json_file = $wp_theme->get_file_path( 'theme.json' ); + if ( is_readable( $theme_json_file ) ) { $theme_json_data = static::read_json_file( $theme_json_file ); $theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) ); } else { @@ -260,8 +260,8 @@ class WP_Theme_JSON_Resolver { if ( $wp_theme->parent() ) { // Get parent theme.json. - $parent_theme_json_file = static::get_file_path_from_theme( 'theme.json', true ); - if ( '' !== $parent_theme_json_file ) { + $parent_theme_json_file = $wp_theme->parent()->get_file_path( 'theme.json' ); + if ( $theme_json_file !== $parent_theme_json_file && is_readable( $parent_theme_json_file ) ) { $parent_theme_json_data = static::read_json_file( $parent_theme_json_file ); $parent_theme_json_data = static::translate( $parent_theme_json_data, $wp_theme->parent()->get( 'TextDomain' ) ); $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); diff --git a/wp-includes/global-styles-and-settings.php b/wp-includes/global-styles-and-settings.php index 6f7a717550..7a8446d60e 100644 --- a/wp-includes/global-styles-and-settings.php +++ b/wp-includes/global-styles-and-settings.php @@ -408,12 +408,7 @@ function wp_theme_has_theme_json() { } // Does the theme have its own theme.json? - $theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' ); - - // Look up the parent if the child does not have a theme.json. - if ( ! $theme_has_support ) { - $theme_has_support = is_readable( get_template_directory() . '/theme.json' ); - } + $theme_has_support = is_readable( get_theme_file_path( 'theme.json' ) ); return $theme_has_support; } diff --git a/wp-includes/version.php b/wp-includes/version.php index e45b540c72..e852fe382c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-56072'; +$wp_version = '6.3-alpha-56073'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.