Skip to content

Commit b1b5761

Browse files
committed
Theme JSON: replace top-level background style objects on merge
This commit fixes an omission in the logic of `WP_Theme_JSON::merge()` where top-level background image style objects are not replaced, rather they are merged. Because background images are self contained objects, their properties are unique and should not be merged. Blocks are already catered for via `WP_Theme_JSON::get_block_nodes()`. Follow-up to [61858]. Props ramonopoly, andrewserong. Fixes #62328. git-svn-id: https://develop.svn.wordpress.org/trunk@59335 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 87821bc commit b1b5761

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/wp-includes/class-wp-theme-json.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,10 @@ public function merge( $incoming ) {
32683268
array(),
32693269
array( 'include_node_paths_only' => true )
32703270
);
3271+
3272+
// Add top-level styles.
3273+
$style_nodes[] = array( 'path' => array( 'styles' ) );
3274+
32713275
foreach ( $style_nodes as $style_node ) {
32723276
$path = $style_node['path'];
32733277
/*

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,9 @@ public function test_merge_incoming_background_styles() {
23442344
'styles' => array(
23452345
'background' => array(
23462346
'backgroundImage' => array(
2347-
'url' => 'http://example.org/quote.png',
2347+
'id' => 'uploaded',
2348+
'source' => 'file',
2349+
'url' => 'http://example.org/quote.png',
23482350
),
23492351
'backgroundSize' => 'cover',
23502352
),
@@ -2376,7 +2378,10 @@ public function test_merge_incoming_background_styles() {
23762378
'version' => WP_Theme_JSON::LATEST_SCHEMA,
23772379
'styles' => array(
23782380
'background' => array(
2379-
'backgroundSize' => 'contain',
2381+
'backgroundImage' => array(
2382+
'url' => 'http://example.org/site.png',
2383+
),
2384+
'backgroundSize' => 'contain',
23802385
),
23812386
'blocks' => array(
23822387
'core/group' => array(
@@ -2406,7 +2411,7 @@ public function test_merge_incoming_background_styles() {
24062411
'styles' => array(
24072412
'background' => array(
24082413
'backgroundImage' => array(
2409-
'url' => 'http://example.org/quote.png',
2414+
'url' => 'http://example.org/site.png',
24102415
),
24112416
'backgroundSize' => 'contain',
24122417
),

0 commit comments

Comments
 (0)