Skip to content

Commit

Permalink
Rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Jan 17, 2023
1 parent 71a3344 commit 4ed8ce5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
12 changes: 6 additions & 6 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,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 ) {
$wp_theme = wp_get_theme();
if ( wp_theme_has_theme_json( $wp_theme->get_stylesheet() ) ) {
$theme_json_file = static::get_file_path_from_theme( 'theme.json' );
$theme_json_data = static::read_json_file( $theme_json_file );
$theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) );
} else {
Expand All @@ -262,8 +262,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 ) {
if ( wp_theme_has_theme_json( $wp_theme->parent()->get_stylesheet() ) ) {
$parent_theme_json_file = static::get_file_path_from_theme( 'theme.json', true );
$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' ) );
// BEGIN OF EXPERIMENTAL CODE. Not to backport to core.
Expand Down Expand Up @@ -422,7 +422,7 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
* theme, the extra condition for whether $theme is the active theme is
* present here.
*/
if ( $theme->get_stylesheet() === get_stylesheet() && ! wp_theme_has_theme_json() ) {
if ( ! wp_theme_has_theme_json( $theme->get_stylesheet() ) ) {
return array();
}

Expand Down
38 changes: 26 additions & 12 deletions lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
* The result would be cached via the WP_Object_Cache.
* It can be cleared by calling wp_theme_has_theme_json_clean_cache().
*
* @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
*
* @return boolean
*/
function wp_theme_has_theme_json() {
function wp_theme_has_theme_json( $stylesheet = '' ) {
$cache_group = 'theme_json';
$cache_key = 'wp_theme_has_theme_json';
if ( empty( $stylesheet ) ) {
$stylesheet = get_stylesheet();
}
$cache_key = sprintf( 'wp_theme_has_theme_json_%s', $stylesheet );
$theme_has_support = wp_cache_get( $cache_key, $cache_group );

/**
Expand All @@ -32,15 +37,13 @@ function wp_theme_has_theme_json() {
return (bool) $theme_has_support;
}

// Has the own theme a 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' );
$wp_theme = wp_get_theme( $stylesheet );
if ( ! $wp_theme->exists() ) {
return false;
}

$theme_has_support = $theme_has_support ? 1 : 0;
// Has the own theme a theme.json?
$theme_has_support = is_readable( $wp_theme->get_file_path( 'theme.json' ) ) ? 1 : 0;

wp_cache_set( $cache_key, $theme_has_support, $cache_group );

Expand All @@ -53,9 +56,15 @@ function wp_theme_has_theme_json() {
* Function to clean the cache used by wp_theme_has_theme_json method.
*
* Not to backport to core. Delete it instead.
*
* @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
*/
function wp_theme_has_theme_json_clean_cache() {
_deprecated_function( __METHOD__, '14.7' );
function wp_theme_has_theme_json_clean_cache( $stylesheet = '' ) {
if ( empty( $stylesheet ) ) {
$stylesheet = get_stylesheet();
}
$cache_key = sprintf( 'wp_theme_has_theme_json_%s', $stylesheet );
wp_cache_delete( $cache_key, 'theme_json' );
}
}

Expand Down Expand Up @@ -190,7 +199,12 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
* @access private
*/
function _gutenberg_clean_theme_json_caches() {
wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' );
$stylesheet = get_stylesheet();
$template = get_template();
wp_theme_has_theme_json_clean_cache( $stylesheet );
if( $stylesheet !== $template ){
wp_theme_has_theme_json_clean_cache( $template );
}
wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_custom', 'theme_json' );
wp_cache_delete( 'gutenberg_get_global_settings_theme', 'theme_json' );
Expand Down

0 comments on commit 4ed8ce5

Please sign in to comment.