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

Fix: Allow themes to disable the color and gradients palette. #32225

Closed
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
37 changes: 36 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class WP_Theme_JSON_Gutenberg {
*/
private $theme_json = null;

/**
* Container of append paths that were merged with a non null value before.
*
* @var array
*/
private $merged_append_paths_with_data = array();

/**
* Holds block metadata extracted from block.json
* to be shared among all instances so we don't
Expand Down Expand Up @@ -1119,13 +1126,41 @@ public function merge( $incoming, $update_or_remove = 'remove' ) {
}
foreach ( $to_append as $path_to_append ) {
$path = array_merge( $metadata['path'], $path_to_append );
$incoming_node = _wp_array_get( $incoming_data, $path, array() );
$incoming_node = _wp_array_get( $incoming_data, $path, null );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply remove the 3rd argument here... $default is already null in the function.

Suggested change
$incoming_node = _wp_array_get( $incoming_data, $path, null );
$incoming_node = _wp_array_get( $incoming_data, $path );

$existing_node = _wp_array_get( $existing_data, $path, array() );

if ( empty( $incoming_node ) && empty( $existing_node ) ) {
continue;
}

// If we are merging with something that has no values
// core origin should be treated as if the values were present
// and we can remove the origin.
Comment on lines +1136 to +1138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we no longer want to use we phrasing in inline docs...

Suggested change
// If we are merging with something that has no values
// core origin should be treated as if the values were present
// and we can remove the origin.
// If merging with something that has no values,
// core origin should be treated as if the values were present
// and the origin can be removed.

if ( null === $incoming_node ) {
if ( _wp_array_get( $this->merged_append_paths_with_data, $path, false ) ) {
continue;
}
$all_nodes_are_core_origin = true;
foreach ( $existing_node as $value ) {
if ( ! ( isset( $value['origin'] ) && 'core' === $value['origin'] ) ) {
$all_nodes_are_core_origin = false;
break;
}
}
if ( $all_nodes_are_core_origin ) {
$merged = array();
foreach ( $existing_node as $value ) {
unset( $value['origin'] );
$merged[] = $value;
}
gutenberg_experimental_set( $this->theme_json, $path, $merged );
}
continue;
}
if ( ! empty( $existing_node ) ) {
gutenberg_experimental_set( $this->merged_append_paths_with_data, $path, true );
}

$index_table = array();
$existing_slugs = array();
$merged = array();
Expand Down
16 changes: 16 additions & 0 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
unset( $settings['__experimentalFeatures']['spacing']['customPadding'] );
}

// On the site-editor for now we still need the core origin colors.
if ( 'site-editor' !== $context ) {
$settings_with_core_origin = array( 'colors', 'gradients' );
foreach ( $settings_with_core_origin as $setting_key ) {
if ( isset( $settings[ $setting_key ] ) ) {
$new_setting = array();
foreach ( $settings[ $setting_key ] as $node ) {
if ( ! ( isset( $node['origin'] ) && 'core' === $node['origin'] ) ) {
$new_setting[] = $node;
}
}
$settings[ $setting_key ] = $new_setting;
}
}
}

return $settings;
}

Expand Down