Skip to content

Commit

Permalink
Try merging separator variation colors
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jan 6, 2025
1 parent 4074641 commit de09644
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ public static function get_theme_data( $deprecated = array(), $options = array()
}
}

$separator_variations = $theme_json_data['styles']['blocks']['core/separator']['variations'] ?? array();
foreach ( $separator_variations as $variation => $variation_data ) {
$variation_separator_color = $variation_data['color']['background'] ?? null;
if ( $variation_separator_color ) {
if ( ! isset( $variation_data['color']['text'] ) ) {
_wp_array_set( $theme_json_data, array( 'styles', 'blocks', 'core/separator', 'variations', $variation, 'color', 'text' ), $variation_separator_color );
}
if ( ! isset( $variation_data['border']['color'] ) ) {
_wp_array_set( $theme_json_data, array( 'styles', 'blocks', 'core/separator', 'variations', $variation, 'border', 'color' ), $variation_separator_color );
}
}
}

/**
* Filters the data provided by the theme for global styles and settings.
*
Expand Down Expand Up @@ -599,6 +612,15 @@ public static function get_user_data() {
_wp_array_set( $config, array( 'styles', 'blocks', 'core/separator', 'border', 'color' ), $separator_color );
}

$separator_variations = $config['styles']['blocks']['core/separator']['variations'] ?? array();
foreach ( $separator_variations as $variation => $variation_data ) {
$variation_separator_color = $variation_data['color']['background'] ?? null;
if ( $variation_separator_color ) {
_wp_array_set( $config, array( 'styles', 'blocks', 'core/separator', 'variations', $variation, 'color', 'text' ), $variation_separator_color );
_wp_array_set( $config, array( 'styles', 'blocks', 'core/separator', 'variations', $variation, 'border', 'color' ), $variation_separator_color );
}
}

/** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
static::$user = $theme_json->get_theme_json();
Expand Down
88 changes: 87 additions & 1 deletion phpunit/class-wp-theme-json-resolver-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function set_up() {
add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
$this->queries = array();
// Clear caches.
WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] );
}
Expand Down Expand Up @@ -1508,7 +1509,8 @@ function ( $path ) use ( $temp_theme_json ) {
return $temp_theme_json;
}
return $path;
}
},
PHP_INT_MAX
);

// Get the merged data.
Expand Down Expand Up @@ -1611,6 +1613,48 @@ public function data_separator_color_merge_user_data() {
),
),
),
'block style variations' => array(
'input_styles' => array(
'variations' => array(
'wide' => array(
'color' => array(
'background' => 'green',
'text' => 'red',
),
),
'dots' => array(
'color' => array(
'background' => 'blue',
),
'border' => array(
'color' => 'pink',
),
),
),
),
'expected_styles' => array(
'variations' => array(
'wide' => array(
'color' => array(
'background' => 'green',
'text' => 'green', // Always set to match background.
),
'border' => array(
'color' => 'green', // Always overridden by background.
),
),
'dots' => array(
'color' => array(
'background' => 'blue',
'text' => 'blue', // Always set to match background.
),
'border' => array(
'color' => 'blue', // Always overridden by background.
),
),
),
),
),
);
}

Expand Down Expand Up @@ -1705,6 +1749,48 @@ public function data_separator_color_merge_theme_data() {
),
),
),
'block style variations' => array(
'input_styles' => array(
'variations' => array(
'wide' => array(
'color' => array(
'background' => 'green',
'text' => 'red',
),
),
'dots' => array(
'color' => array(
'background' => 'blue',
),
'border' => array(
'color' => 'pink',
),
),
),
),
'expected_styles' => array(
'variations' => array(
'wide' => array(
'color' => array(
'background' => 'green',
'text' => 'red', // Kept because already defined.
),
'border' => array(
'color' => 'green', // Set because not defined.
),
),
'dots' => array(
'color' => array(
'background' => 'blue',
'text' => 'blue', // Always set to match background.
),
'border' => array(
'color' => 'pink', // Always overridden by background.
),
),
),
),
),
);
}
}

0 comments on commit de09644

Please sign in to comment.