Skip to content

Commit

Permalink
use an object rather than a string to fetch other values
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jun 15, 2022
1 parent 444f175 commit 7b9f7ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,22 +376,17 @@ protected static function compute_style_properties( $styles, $settings = array()
protected static function get_property_value( $styles, $path, $theme_json = null ) {
$value = _wp_array_get( $styles, $path, '' );

if ( '' === $value || is_array( $value ) ) {
return $value;
if( is_array( $value ) && array_key_exists( 'source', $value ) ) {
$value_path = explode( '.', $value['source'] );
$source_value = _wp_array_get( $theme_json, $value_path );
// Only use the source value if we find anything.
if ( ! empty( $source_value ) && is_string( $source_value ) ) {
$value = $source_value;
}
}

// If the value begins with styles then
// get the corresponding value from that place in theme.json.
$styles_prefix = 'styles';
$styles_prefix_len = strlen( $styles_prefix );
if ( 0 === strncmp( $value, $styles_prefix, $styles_prefix_len ) ) {
// Get the path of the style/setting.
$value_path = explode( '.', $value );
$new_value = _wp_array_get( $theme_json, $value_path );
// Only use the new value if we find anything.
if ( ! empty( $new_value ) && is_string( $new_value ) ) {
$value = $new_value;
}
if ( '' === $value || is_array( $value ) ) {
return $value;
}

// Convert custom CSS properties.
Expand Down
4 changes: 2 additions & 2 deletions lib/experimental/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
"elements": {
"button": {
"color": {
"background": "styles.color.text",
"text": "styles.color.background"
"background": { "source": "styles.color.text" },
"text": { "source": "styles.color.background" }
}
}
}
Expand Down

0 comments on commit 7b9f7ae

Please sign in to comment.