From 80d5fd6bd7355a15b18544d569d5832ed7628f3a Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 1 Nov 2024 12:47:44 +1100 Subject: [PATCH] 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 --- lib/class-wp-theme-json-gutenberg.php | 4 ++++ phpunit/class-wp-theme-json-test.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 09f388e7d3b93f..dafa8b25f278fc 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 29d454f6f4f0b0..50a0af4f9b3ff3 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', ),