Skip to content
Merged
5 changes: 4 additions & 1 deletion lib/compat/wordpress-6.0/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,4 @@ public function get_data() {

return $flattened_theme_json;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand All @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}