From eb7f1db81fbbdeab072a77e076d836aeda36f136 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 27 Aug 2021 16:38:38 +0400 Subject: [PATCH] FSE: Add basic support for child themes --- lib/class-wp-theme-json-resolver-gutenberg.php | 10 +--------- lib/full-site-editing/full-site-editing.php | 2 +- packages/block-library/src/template-part/index.php | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index b96c43f8ddf4f..dd5d3f9cbc523 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -493,16 +493,8 @@ public static function theme_has_support() { * @return string The whole file path or empty if the file doesn't exist. */ private static function get_file_path_from_theme( $file_name ) { - // This used to be a locate_template call. - // However, that method proved problematic - // due to its use of constants (STYLESHEETPATH) - // that threw errors in some scenarios. - // - // When the theme.json merge algorithm properly supports - // child themes, this should also fallback - // to the template path, as locate_template did. $located = ''; - $candidate = get_stylesheet_directory() . '/' . $file_name; + $candidate = get_theme_file_path( $file_name ); if ( is_readable( $candidate ) ) { $located = $candidate; } diff --git a/lib/full-site-editing/full-site-editing.php b/lib/full-site-editing/full-site-editing.php index 0d00847b6b7d2..775c42d97645a 100644 --- a/lib/full-site-editing/full-site-editing.php +++ b/lib/full-site-editing/full-site-editing.php @@ -11,7 +11,7 @@ * @return boolean Whether the current theme is an FSE theme or not. */ function gutenberg_is_fse_theme() { - return is_readable( get_stylesheet_directory() . '/block-templates/index.html' ); + return is_readable( get_theme_file_path( '/block-templates/index.html' ) ); } /** diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 78b4d1fa32af9..8e1621f59cb54 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -53,7 +53,7 @@ function render_block_core_template_part( $attributes ) { } else { // Else, if the template part was provided by the active theme, // render the corresponding file content. - $template_part_file_path = get_stylesheet_directory() . '/block-template-parts/' . $attributes['slug'] . '.html'; + $template_part_file_path = get_theme_file_path( '/block-template-parts/' . $attributes['slug'] . '.html' ); if ( 0 === validate_file( $attributes['slug'] ) && file_exists( $template_part_file_path ) ) { $content = _gutenberg_inject_theme_attribute_in_content( file_get_contents( $template_part_file_path ) ); }