From 64d5c55b1485b9fa7f262e264a45cdb5c94586ec Mon Sep 17 00:00:00 2001 From: Ramon Date: Fri, 1 Nov 2024 15:47:31 +1100 Subject: [PATCH] Theme JSON: replace top-level background style objects on merge (#66656) This commit fixes an omission in the theme json merge logic where top-level background image objects are not replaced, rather they are merged, which was the state of affairs before https://github.com/WordPress/gutenberg/pull/64128 Co-authored-by: ramonjd Co-authored-by: andrewserong --- backport-changelog/6.8/7697.md | 3 +++ lib/class-wp-theme-json-gutenberg.php | 4 ++++ phpunit/class-wp-theme-json-test.php | 11 ++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 backport-changelog/6.8/7697.md diff --git a/backport-changelog/6.8/7697.md b/backport-changelog/6.8/7697.md new file mode 100644 index 0000000000000..e53fbf4bdb8ae --- /dev/null +++ b/backport-changelog/6.8/7697.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/7697 + +* https://github.com/WordPress/gutenberg/pull/66656 diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 09f388e7d3b93..dafa8b25f278f 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -3297,6 +3297,10 @@ public function merge( $incoming ) { array(), array( 'include_node_paths_only' => true ) ); + + // Add top-level styles. + $style_nodes[] = array( 'path' => array( 'styles' ) ); + foreach ( $style_nodes as $style_node ) { $path = $style_node['path']; /* diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index 29d454f6f4f0b..50a0af4f9b3ff 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -2301,7 +2301,9 @@ public function test_merge_incoming_background_styles() { 'styles' => array( 'background' => array( 'backgroundImage' => array( - 'url' => 'http://example.org/quote.png', + 'id' => 'uploaded', + 'source' => 'file', + 'url' => 'http://example.org/quote.png', ), 'backgroundSize' => 'cover', ), @@ -2333,7 +2335,10 @@ public function test_merge_incoming_background_styles() { 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'styles' => array( 'background' => array( - 'backgroundSize' => 'contain', + 'backgroundImage' => array( + 'url' => 'http://example.org/site.png', + ), + 'backgroundSize' => 'contain', ), 'blocks' => array( 'core/group' => array( @@ -2363,7 +2368,7 @@ public function test_merge_incoming_background_styles() { 'styles' => array( 'background' => array( 'backgroundImage' => array( - 'url' => 'http://example.org/quote.png', + 'url' => 'http://example.org/site.png', ), 'backgroundSize' => 'contain', ),