From 98d38f61455b9aadb175b527bd25c59a7bd92736 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 20 Jan 2023 11:20:44 +0000 Subject: [PATCH 1/3] Use `get_theme_file_path` function. --- src/wp-includes/global-styles-and-settings.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index c625166524b63..86ebb31ad3925 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -264,15 +264,7 @@ function ( $item ) { * @return bool Returns true if theme or its parent has a theme.json file, false otherwise. */ 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' ); - } - - return $theme_has_support; + return is_readable( get_theme_file_path( 'theme.json' ) ); } /** From ac51e6d2633e9138160b5313a095d1dd3adb766e Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 7 Feb 2023 12:24:06 +0000 Subject: [PATCH 2/3] Fix Phpcs --- src/wp-includes/global-styles-and-settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 52e3c86e6fb47..9bae3a549c218 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -404,7 +404,7 @@ function wp_theme_has_theme_json() { // Does the theme have its own theme.json? $theme_has_support = is_readable( get_theme_file_path( 'theme.json' ) ); - + return $theme_has_support; } From cdd808477f026df9c5baa8dd4e67ab12c28bfc2c Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 7 Feb 2023 12:25:02 +0000 Subject: [PATCH 3/3] Ensure that theme json file now goes through filter as well. --- src/wp-includes/class-wp-theme-json-resolver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index d178f076e9251..4fc87cca324a5 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -238,9 +238,9 @@ public static function get_theme_data( $deprecated = array(), $options = array() $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 @@ public static function get_theme_data( $deprecated = array(), $options = array() 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 );