diff --git a/lib/compat/wordpress-6.0/block-template-utils.php b/lib/compat/wordpress-6.0/block-template-utils.php index 5a8f0c5eebab30..d224e9097768c9 100644 --- a/lib/compat/wordpress-6.0/block-template-utils.php +++ b/lib/compat/wordpress-6.0/block-template-utils.php @@ -97,7 +97,8 @@ function gutenberg_generate_block_templates_export_file() { } // Load theme.json into the zip file. - $tree = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data(); + $tree = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data( array(), array( 'with_supports' => false ) ); + // Merge with user data. $tree->merge( WP_Theme_JSON_Resolver_Gutenberg::get_user_data() ); $theme_json_raw = $tree->get_data(); @@ -114,8 +115,10 @@ function gutenberg_generate_block_templates_export_file() { // Convert to a string. $theme_json_encoded = wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); + // Replace 4 spaces with a tab. $theme_json_tabbed = preg_replace( '~(?:^|\G)\h{4}~m', "\t", $theme_json_encoded ); + // Add the theme.json file to the zip. $zip->addFromString( 'theme.json', diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php b/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php index b963477a30a9f5..512b1704a94e79 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php @@ -163,5 +163,4 @@ public function get_data() { return $flattened_theme_json; } - } diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php index 7714b6256d136b..2e743d0c1f9ccc 100644 --- a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php @@ -25,12 +25,14 @@ class WP_Theme_JSON_Resolver_Gutenberg extends WP_Theme_JSON_Resolver_6_0 { * the theme.json takes precedence. * * @param array $deprecated Deprecated argument. + * @param array $settings Contains a key called with_supports to determine whether to include theme supports in the data. * @return WP_Theme_JSON_Gutenberg Entity that holds theme data. */ - public static function get_theme_data( $deprecated = array() ) { + public static function get_theme_data( $deprecated = array(), $settings = array( 'with_supports' => true ) ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __METHOD__, '5.9' ); } + if ( null === static::$theme ) { $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); @@ -51,6 +53,10 @@ public static function get_theme_data( $deprecated = array() ) { } } + if ( ! $settings['with_supports'] ) { + return static::$theme; + } + /* * We want the presets and settings declared in theme.json * to override the ones declared via theme supports. diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index b138564896cb7c..a2367d13f48975 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -2451,4 +2451,25 @@ function test_export_data_deals_with_empty_theme_data() { $this->assertEqualSetsWithIndex( $expected, $actual ); } + function test_export_data_deals_with_empty_data() { + $theme_v2 = new WP_Theme_JSON_Gutenberg( + array( + 'version' => 2, + ), + 'theme' + ); + $actual_v2 = $theme_v2->get_data(); + $expected_v2 = array( 'version' => 2 ); + $this->assertEqualSetsWithIndex( $expected_v2, $actual_v2 ); + + $theme_v1 = new WP_Theme_JSON_Gutenberg( + array( + 'version' => 1, + ), + 'theme' + ); + $actual_v1 = $theme_v1->get_data(); + $expected_v1 = array( 'version' => 2 ); + $this->assertEqualSetsWithIndex( $expected_v1, $actual_v1 ); + } }