Editor: Add functionality required for theme export in the site editor

This bring across changes to theme export functionality, and related code, and tests. Relates issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/39889.

Props scruffian, timothyblynjacobs, oandregal, ajlende, zieleadam.
See #55505.


Built from https://develop.svn.wordpress.org/trunk@53129


git-svn-id: http://core.svn.wordpress.org/trunk@52718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
gziolo
2022-04-11 10:38:00 +00:00
parent 5d78798b5c
commit 9e3c5a4215
6 changed files with 377 additions and 69 deletions

View File

@@ -151,14 +151,19 @@ class WP_Theme_JSON_Resolver {
*
* @since 5.8.0
* @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed.
* @since 6.0.0 Adds a second parameter to allow the theme data to be returned without theme supports.
*
* @param array $deprecated Deprecated. Not used.
* @param array $options Contains a key called with_supports to determine whether to include theme supports in the data.
* @return WP_Theme_JSON Entity that holds theme data.
*/
public static function get_theme_data( $deprecated = array() ) {
public static function get_theme_data( $deprecated = array(), $options = array() ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __METHOD__, '5.9.0' );
}
$options = wp_parse_args( $options, array( 'with_supports' => true ) );
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' ) );
@@ -177,6 +182,10 @@ class WP_Theme_JSON_Resolver {
}
}
if ( ! $options['with_supports'] ) {
return static::$theme;
}
/*
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
@@ -208,6 +217,9 @@ class WP_Theme_JSON_Resolver {
$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( $theme_support_data );
$with_theme_supports->merge( static::$theme );
@@ -477,4 +489,5 @@ class WP_Theme_JSON_Resolver {
}
return $variations;
}
}