Skip to content

Commit

Permalink
Add partial override for getting global theme.json setting
Browse files Browse the repository at this point in the history
This only gets the settings working in the block editor. The Site Editor is reloading settings and somewhere it's base config isn't getting the correct settings.
  • Loading branch information
aaronrobertshaw committed Feb 16, 2022
1 parent 5da9def commit 840b77d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
37 changes: 37 additions & 0 deletions lib/compat/wordpress-6.0/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* API to interact with global settings & styles.
*
* @package gutenberg
*/

if ( ! function_exists( 'gutenberg_get_global_settings' ) ) {
/**
* Function to get the settings resulting of merging core, theme, and user data.
*
* @param array $path Path to the specific setting to retrieve. Optional.
* If empty, will return all settings.
* @param array $context {
* Metadata to know where to retrieve the $path from. Optional.
*
* @type string $block_name Which block to retrieve the settings from.
* If empty, it'll return the settings for the global context.
* @type string $origin Which origin to take data from.
* Valid values are 'all' (core, theme, and user) or 'base' (core and theme).
* If empty or unknown, 'all' is used.
* }
*
* @return array The settings to retrieve.
*/
function gutenberg_get_global_settings( $path = array(), $context = array() ) {
if ( ! empty( $context['block_name'] ) ) {
$path = array_merge( array( 'blocks', $context['block_name'] ), $path );
}
$origin = 'custom';
if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {
$origin = 'theme';
}
$settings = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $origin )->get_settings();
return _wp_array_get( $settings, $path, $settings );
}
}
5 changes: 3 additions & 2 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
$settings['styles'] = array_merge( $new_global_styles, $styles_without_existing_global_styles );
}

// Copied from get_block_editor_settings() at wordpress-develop/block-editor.php.
$settings['__experimentalFeatures'] = wp_get_global_settings();
// For 5.9, copied from get_block_editor_settings() at wordpress-develop/block-editor.php.
// For 6.0 calling gutenberg_get_global_settings() in order to include new valid settings/properties/styles in theme.json.
$settings['__experimentalFeatures'] = gutenberg_get_global_settings();

if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) {
$colors_by_origin = $settings['__experimentalFeatures']['color']['palette'];
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.0/class-gutenberg-rest-global-styles-controller.php';
require __DIR__ . '/compat/wordpress-6.0/class-gutenberg-rest-pattern-directory-controller.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php';
require __DIR__ . '/compat/wordpress-6.0/get-global-styles-and-settings.php';
require __DIR__ . '/compat/wordpress-6.0/rest-api.php';
require __DIR__ . '/compat/wordpress-6.0/block-patterns.php';
require __DIR__ . '/compat/experimental/blocks.php';
Expand Down

0 comments on commit 840b77d

Please sign in to comment.