Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Styles: Add child theme support #30147

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,15 @@ public static function get_theme_data( $theme_support_data = array() ) {
if ( null === self::$theme ) {
$theme_json_data = self::read_json_file( self::get_file_path_from_theme( 'experimental-theme.json' ) );
$theme_json_data = self::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
self::$theme = new WP_Theme_JSON( $theme_json_data );

// If the current theme is a child theme then lets add data from the parent theme.
if( is_child_theme() ) {
$parent_theme_json_data = self::read_json_file( self::get_file_path_from_theme( 'experimental-theme.json', get_template_directory() ) );
$parent_theme_json_data = self::translate( $parent_theme_json_data, wp_get_theme( get_template() )->get( 'TextDomain' ) );
$theme_json_data = array_replace_recursive( $parent_theme_json_data, $theme_json_data );
}

self::$theme = new WP_Theme_JSON( $theme_json_data );
}

if ( empty( $theme_support_data ) ) {
Expand Down Expand Up @@ -516,9 +524,10 @@ public static function theme_has_support() {
* otherwise returns the whole file path.
*
* @param string $file_name Name of the file.
* @param string $directory The theme directory.
* @return string The whole file path or empty if the file doesn't exist.
*/
private static function get_file_path_from_theme( $file_name ) {
private static function get_file_path_from_theme( $file_name, $directory = '' ) {
// This used to be a locate_template call.
// However, that method proved problematic
// due to its use of constants (STYLESHEETPATH)
Expand All @@ -528,11 +537,14 @@ private static function get_file_path_from_theme( $file_name ) {
// child themes, this should also fallback
// to the template path, as locate_template did.
$located = '';
$candidate = get_stylesheet_directory() . '/' . $file_name;
if ( empty ( $directory ) ) {
$directory = get_stylesheet_directory();
}

$candidate = $directory . '/' . $file_name;
if ( is_readable( $candidate ) ) {
$located = $candidate;
}
return $located;
}

}