From a80b82579284a948fa73342f80e658f404518e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:05:12 +0200 Subject: [PATCH 1/4] Merge 6.0 and Experimental resolvers --- ...lass-wp-theme-json-resolver-gutenberg.php} | 33 +++++-- ...class-wp-theme-json-resolver-gutenberg.php | 97 ------------------- lib/load.php | 3 +- 3 files changed, 24 insertions(+), 109 deletions(-) rename lib/compat/wordpress-6.0/{class-wp-theme-json-resolver-6-0.php => class-wp-theme-json-resolver-gutenberg.php} (84%) delete mode 100644 lib/experimental/class-wp-theme-json-resolver-gutenberg.php diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php similarity index 84% rename from lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php rename to lib/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php index fb1cf53bda6ae..4216300ea9036 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php @@ -15,7 +15,7 @@ * * @access private */ -class WP_Theme_JSON_Resolver_6_0 extends WP_Theme_JSON_Resolver_5_9 { +class WP_Theme_JSON_Resolver_Gutenberg extends WP_Theme_JSON_Resolver_5_9 { /** * Given a theme.json structure modifies it in place * to update certain values by its translated strings @@ -61,21 +61,33 @@ 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' ) ); + + /* NOT TO MERGE IN CORE (START) */ + $theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $theme_json_data ); + /* NOT TO MERGE IN CORE (END) */ + static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data ); if ( wp_get_theme()->parent() ) { // Get parent theme.json. $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); + + /* NOT TO MERGE IN CORE (START) */ + $parent_theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $parent_theme_json_data ); + /* NOT TO MERGE IN CORE (END) */ + $parent_theme = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data ); // Merge the child theme.json into the parent theme.json. @@ -85,12 +97,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'] ) ) { @@ -116,9 +132,6 @@ public static function get_theme_data( $deprecated = 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 ); diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php deleted file mode 100644 index 2e743d0c1f9cc..0000000000000 --- a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php +++ /dev/null @@ -1,97 +0,0 @@ - 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' ) ); - $theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $theme_json_data ); - static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data ); - - if ( wp_get_theme()->parent() ) { - // Get parent theme.json. - $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); - $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); - $parent_theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $parent_theme_json_data ); - $parent_theme = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data ); - - // Merge the child theme.json into the parent theme.json. - // The child theme takes precedence over the parent. - $parent_theme->merge( static::$theme ); - static::$theme = $parent_theme; - } - } - - 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. - */ - $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'] ) ) { - $theme_support_data['settings']['color'] = array(); - } - - $default_palette = false; - if ( current_theme_supports( 'default-color-palette' ) ) { - $default_palette = true; - } - if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) { - // If the theme does not have any palette, we still want to show the core one. - $default_palette = true; - } - $theme_support_data['settings']['color']['defaultPalette'] = $default_palette; - - $default_gradients = false; - if ( current_theme_supports( 'default-gradient-presets' ) ) { - $default_gradients = true; - } - if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) { - // If the theme does not have any gradients, we still want to show the core ones. - $default_gradients = true; - } - $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; - } - $with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data ); - $with_theme_supports->merge( static::$theme ); - - return $with_theme_supports; - } -} diff --git a/lib/load.php b/lib/load.php index 7bc06b630def5..a9dd2d90d959b 100644 --- a/lib/load.php +++ b/lib/load.php @@ -102,13 +102,12 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-pattern-categories-controller.php'; require __DIR__ . '/compat/wordpress-6.0/functions.php'; require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php'; -require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php'; +require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php'; // needs to be loaded before the webfonts require __DIR__ . '/compat/wordpress-6.0/rest-api.php'; require __DIR__ . '/compat/wordpress-6.0/block-patterns.php'; require __DIR__ . '/compat/wordpress-6.0/block-template.php'; require __DIR__ . '/compat/wordpress-6.0/edit-form-blocks.php'; require __DIR__ . '/experimental/register-webfonts-from-theme-json.php'; -require __DIR__ . '/experimental/class-wp-theme-json-resolver-gutenberg.php'; require __DIR__ . '/experimental/class-wp-webfonts.php'; require __DIR__ . '/experimental/class-wp-webfonts-provider.php'; require __DIR__ . '/experimental/class-wp-webfonts-provider-local.php'; From b7c6330dd9c41940ec08d3c502bf4450f3c6a841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:32:55 +0200 Subject: [PATCH 2/4] Revert "Merge 6.0 and Experimental resolvers" This reverts commit a80b82579284a948fa73342f80e658f404518e5c. --- ...p => class-wp-theme-json-resolver-6-0.php} | 33 ++----- ...class-wp-theme-json-resolver-gutenberg.php | 97 +++++++++++++++++++ lib/load.php | 3 +- 3 files changed, 109 insertions(+), 24 deletions(-) rename lib/compat/wordpress-6.0/{class-wp-theme-json-resolver-gutenberg.php => class-wp-theme-json-resolver-6-0.php} (84%) create mode 100644 lib/experimental/class-wp-theme-json-resolver-gutenberg.php diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php similarity index 84% rename from lib/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php rename to lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php index 4216300ea9036..fb1cf53bda6ae 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php @@ -15,7 +15,7 @@ * * @access private */ -class WP_Theme_JSON_Resolver_Gutenberg extends WP_Theme_JSON_Resolver_5_9 { +class WP_Theme_JSON_Resolver_6_0 extends WP_Theme_JSON_Resolver_5_9 { /** * Given a theme.json structure modifies it in place * to update certain values by its translated strings @@ -61,33 +61,21 @@ 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(), $settings = array( 'with_supports' => true ) ) { + public static function get_theme_data( $deprecated = array() ) { 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' ) ); - - /* NOT TO MERGE IN CORE (START) */ - $theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $theme_json_data ); - /* NOT TO MERGE IN CORE (END) */ - static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data ); if ( wp_get_theme()->parent() ) { // Get parent theme.json. $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); - - /* NOT TO MERGE IN CORE (START) */ - $parent_theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $parent_theme_json_data ); - /* NOT TO MERGE IN CORE (END) */ - $parent_theme = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data ); // Merge the child theme.json into the parent theme.json. @@ -97,16 +85,12 @@ public static function get_theme_data( $deprecated = array(), $settings = 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'] ) ) { @@ -132,6 +116,9 @@ 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 ); diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php new file mode 100644 index 0000000000000..2e743d0c1f9cc --- /dev/null +++ b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php @@ -0,0 +1,97 @@ + 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' ) ); + $theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $theme_json_data ); + static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data ); + + if ( wp_get_theme()->parent() ) { + // Get parent theme.json. + $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); + $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); + $parent_theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $parent_theme_json_data ); + $parent_theme = new WP_Theme_JSON_Gutenberg( $parent_theme_json_data ); + + // Merge the child theme.json into the parent theme.json. + // The child theme takes precedence over the parent. + $parent_theme->merge( static::$theme ); + static::$theme = $parent_theme; + } + } + + 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. + */ + $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'] ) ) { + $theme_support_data['settings']['color'] = array(); + } + + $default_palette = false; + if ( current_theme_supports( 'default-color-palette' ) ) { + $default_palette = true; + } + if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) { + // If the theme does not have any palette, we still want to show the core one. + $default_palette = true; + } + $theme_support_data['settings']['color']['defaultPalette'] = $default_palette; + + $default_gradients = false; + if ( current_theme_supports( 'default-gradient-presets' ) ) { + $default_gradients = true; + } + if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) { + // If the theme does not have any gradients, we still want to show the core ones. + $default_gradients = true; + } + $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; + } + $with_theme_supports = new WP_Theme_JSON_Gutenberg( $theme_support_data ); + $with_theme_supports->merge( static::$theme ); + + return $with_theme_supports; + } +} diff --git a/lib/load.php b/lib/load.php index a9dd2d90d959b..7bc06b630def5 100644 --- a/lib/load.php +++ b/lib/load.php @@ -102,12 +102,13 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-pattern-categories-controller.php'; require __DIR__ . '/compat/wordpress-6.0/functions.php'; require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php'; -require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php'; // needs to be loaded before the webfonts +require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php'; require __DIR__ . '/compat/wordpress-6.0/rest-api.php'; require __DIR__ . '/compat/wordpress-6.0/block-patterns.php'; require __DIR__ . '/compat/wordpress-6.0/block-template.php'; require __DIR__ . '/compat/wordpress-6.0/edit-form-blocks.php'; require __DIR__ . '/experimental/register-webfonts-from-theme-json.php'; +require __DIR__ . '/experimental/class-wp-theme-json-resolver-gutenberg.php'; require __DIR__ . '/experimental/class-wp-webfonts.php'; require __DIR__ . '/experimental/class-wp-webfonts-provider.php'; require __DIR__ . '/experimental/class-wp-webfonts-provider-local.php'; From 33046e0fee76d596c02ed16b1fb9a34c534b4cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:37:36 +0200 Subject: [PATCH 3/4] Port to experimental missing changes --- lib/experimental/class-wp-theme-json-resolver-gutenberg.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php index 2e743d0c1f9cc..960ea659e8d2e 100644 --- a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php @@ -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; } + } From 29a23560c0b5b2f729d4108db32c3a1f054669a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 7 Apr 2022 13:38:56 +0200 Subject: [PATCH 4/4] Port to compat/6.0 missing changes --- .../class-wp-theme-json-resolver-6-0.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php index fb1cf53bda6ae..2ed23f15cc0b6 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php @@ -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' ) ); @@ -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'] ) ) { @@ -125,7 +131,6 @@ public static function get_theme_data( $deprecated = array() ) { return $with_theme_supports; } - /** * Returns the style variations defined by the theme. *