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

Consolidate WP_Theme_JSON_Resolver changes in both lib/compat/wordpress-6.0 and lib/experimental #40140

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ public static function get_core_data() {
* the theme.json takes precedence.
*
* @param array $deprecated Deprecated argument.
* @param array $settings Contains a key called with_supports to determine whether to include theme supports in the data.
* @return WP_Theme_JSON_Gutenberg Entity that holds theme data.
*/
public static function get_theme_data( $deprecated = array() ) {
public static function get_theme_data( $deprecated = array(), $settings = array( 'with_supports' => true ) ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __METHOD__, '5.9' );
}

if ( null === static::$theme ) {
$theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) );
$theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
Expand All @@ -85,12 +87,16 @@ public static function get_theme_data( $deprecated = array() ) {
}
}

if ( ! $settings['with_supports'] ) {
return static::$theme;
}

/*
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
* So we take theme supports, transform it to theme.json shape
* and merge the static::$theme upon that.
*/
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
* So we take theme supports, transform it to theme.json shape
* and merge the static::$theme upon that.
*/
$theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_default_block_editor_settings() );
if ( ! static::theme_has_support() ) {
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
Expand Down Expand Up @@ -125,7 +131,6 @@ public static function get_theme_data( $deprecated = array() ) {

return $with_theme_supports;
}

/**
* Returns the style variations defined by the theme.
*
Expand Down
4 changes: 4 additions & 0 deletions lib/experimental/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ public static function get_theme_data( $deprecated = array(), $settings = array(
$default_gradients = true;
}
$theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;

// Classic themes without a theme.json don't support global duotone.
$theme_support_data['settings']['color']['defaultDuotone'] = false;
}
$with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data );
$with_theme_supports->merge( static::$theme );

return $with_theme_supports;
}

}