diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 486156fcd3..b140601a43 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1106,8 +1106,8 @@ class WP_Theme_JSON { foreach ( $nodes as $metadata ) { foreach ( $to_replace as $property_path ) { $path = array_merge( $metadata['path'], $property_path ); - $node = _wp_array_get( $incoming_data, $path, array() ); - if ( ! empty( $node ) ) { + $node = _wp_array_get( $incoming_data, $path, null ); + if ( isset( $node ) ) { _wp_array_set( $this->theme_json, $path, $node ); } } diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 0b4f8268bf..27294aac96 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -667,6 +667,209 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * @ticket 53175 + */ + public function test_merge_incoming_data_empty_presets() { + $theme_json = new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'color' => array( + 'duotone' => array( + array( + 'slug' => 'value', + 'colors' => array( 'red', 'green' ), + ), + ), + 'gradients' => array( + array( + 'slug' => 'gradient', + 'gradient' => 'gradient', + ), + ), + 'palette' => array( + array( + 'slug' => 'red', + 'color' => 'red', + ), + ), + ), + 'spacing' => array( + 'units' => array( 'px', 'em' ), + ), + 'typography' => array( + 'fontSizes' => array( + array( + 'slug' => 'size', + 'value' => 'size', + ), + ), + ), + ), + ) + ); + + $theme_json->merge( + new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'color' => array( + 'duotone' => array(), + 'gradients' => array(), + 'palette' => array(), + ), + 'spacing' => array( + 'units' => array(), + ), + 'typography' => array( + 'fontSizes' => array(), + ), + ), + ) + ) + ); + + $actual = $theme_json->get_raw_data(); + $expected = array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'color' => array( + 'duotone' => array(), + 'gradients' => array( + 'theme' => array(), + ), + 'palette' => array( + 'theme' => array(), + ), + ), + 'spacing' => array( + 'units' => array(), + ), + 'typography' => array( + 'fontSizes' => array( + 'theme' => array(), + ), + ), + ), + ); + + $this->assertEqualSetsWithIndex( $expected, $actual ); + } + + /** + * @ticket 53175 + */ + public function test_merge_incoming_data_null_presets() { + $theme_json = new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'color' => array( + 'duotone' => array( + array( + 'slug' => 'value', + 'colors' => array( 'red', 'green' ), + ), + ), + 'gradients' => array( + array( + 'slug' => 'gradient', + 'gradient' => 'gradient', + ), + ), + 'palette' => array( + array( + 'slug' => 'red', + 'color' => 'red', + ), + ), + ), + 'spacing' => array( + 'units' => array( 'px', 'em' ), + ), + 'typography' => array( + 'fontSizes' => array( + array( + 'slug' => 'size', + 'value' => 'size', + ), + ), + ), + ), + ) + ); + + $theme_json->merge( + new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'color' => array( + 'custom' => false, + ), + 'spacing' => array( + 'customMargin' => false, + ), + 'typography' => array( + 'customLineHeight' => false, + ), + ), + ) + ) + ); + + $actual = $theme_json->get_raw_data(); + $expected = array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'color' => array( + 'custom' => false, + 'duotone' => array( + array( + 'slug' => 'value', + 'colors' => array( 'red', 'green' ), + ), + ), + 'gradients' => array( + 'theme' => array( + array( + 'slug' => 'gradient', + 'gradient' => 'gradient', + ), + ), + ), + 'palette' => array( + 'theme' => array( + array( + 'slug' => 'red', + 'color' => 'red', + ), + ), + ), + ), + 'spacing' => array( + 'customMargin' => false, + 'units' => array( 'px', 'em' ), + ), + 'typography' => array( + 'customLineHeight' => false, + 'fontSizes' => array( + 'theme' => array( + array( + 'slug' => 'size', + 'value' => 'size', + ), + ), + ), + ), + ), + ); + + $this->assertEqualSetsWithIndex( $expected, $actual ); + } + /** * @ticket 52991 */