Skip to content

Commit

Permalink
Remove dependency from wp_theme_has_theme_json() to check if theme …
Browse files Browse the repository at this point in the history
…has theme.json file
  • Loading branch information
thelovekesh committed Jul 7, 2023
1 parent e65ef36 commit be8c3fb
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/ReaderThemeSupportFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,10 @@ public function get_relative_luminance_from_hex( $hex ) {
* @return bool False if `wp_get_global_settings()` not exists or theme.json not found, true otherwise.
*/
private function theme_has_theme_json() {
if ( function_exists( 'wp_theme_has_theme_json' ) ) {
return wp_theme_has_theme_json();
}
// @TODO: Uncomment this once `wp_theme_has_theme_json()` caching is fixed.
// if ( function_exists( 'wp_theme_has_theme_json' ) ) {
// return wp_theme_has_theme_json();
// }

static $theme_has_support = null;

Expand All @@ -605,14 +606,21 @@ private function theme_has_theme_json() {
return $theme_has_support;
}

// Does the theme have its own theme.json?
$theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );
$stylesheet_directory = get_stylesheet_directory();
$template_directory = get_template_directory();

// 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' );
// This is the same as get_theme_file_path(), which isn't available in load-styles.php context.
if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) {
$path = $stylesheet_directory . '/theme.json';
} else {
$path = $template_directory . '/theme.json';
}

/** This filter is documented in wp-includes/link-template.php */
$path = apply_filters( 'theme_file_path', $path, 'theme.json' );

$theme_has_support = file_exists( $path );

return $theme_has_support;
}

Expand Down

0 comments on commit be8c3fb

Please sign in to comment.