Skip to content
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
3 changes: 2 additions & 1 deletion src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ public static function get_merged_data( $origin = 'custom' ) {
_deprecated_argument( __FUNCTION__, '5.9.0' );
}

$result = static::get_core_data();
$result = new WP_Theme_JSON();
$result->merge( static::get_core_data() );
if ( 'default' === $origin ) {
$result->set_spacing_sizes();
return $result;
Expand Down
43 changes: 43 additions & 0 deletions tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,49 @@ static function( $element ) {

}

/**
* Tests that get_merged_data returns the data merged up to the proper origin
* and that the core values have the proper data.
*
* @ticket 57824
*
* @covers WP_Theme_JSON_Resolver::get_merged_data
*
*/
public function test_get_merged_data_returns_origin_proper() {
// Make sure the theme has a theme.json
// though it doesn't have any data for styles.spacing.padding.
switch_theme( 'block-theme' );

// Make sure the user defined some data for styles.spacing.padding.
wp_set_current_user( self::$administrator_id );
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme(), true );
$config = json_decode( $user_cpt['post_content'], true );
$config['styles']['spacing']['padding'] = array(
'top' => '23px',
'left' => '23px',
'bottom' => '23px',
'right' => '23px',
);
$user_cpt['post_content'] = wp_json_encode( $config );
wp_update_post( $user_cpt, true, false );

// Query data from the user origin and then for the theme origin.
$theme_json_user = WP_Theme_JSON_Resolver::get_merged_data( 'custom' );
$padding_user = $theme_json_user->get_raw_data()['styles']['spacing']['padding'];
$theme_json_theme = WP_Theme_JSON_Resolver::get_merged_data( 'theme' );
$padding_theme = $theme_json_theme->get_raw_data()['styles']['spacing']['padding'];

$this->assertSame( '23px', $padding_user['top'] );
$this->assertSame( '23px', $padding_user['right'] );
$this->assertSame( '23px', $padding_user['bottom'] );
$this->assertSame( '23px', $padding_user['left'] );
$this->assertSame( '0px', $padding_theme['top'] );
Copy link
Member Author

Choose a reason for hiding this comment

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

The $padding_theme values should be failing without the fix, but they are not. Not sure what's wrong with this test, but I'd consider removing it if it cannot reproduce that the behavior broke.

$this->assertSame( '0px', $padding_theme['right'] );
$this->assertSame( '0px', $padding_theme['bottom'] );
$this->assertSame( '0px', $padding_theme['left'] );
}

/**
* Data provider.
*
Expand Down