diff --git a/lib/compat/wordpress-5.9/edit-site-export.php b/lib/compat/wordpress-5.9/edit-site-export.php index 825766cffcab7..db1b889793703 100644 --- a/lib/compat/wordpress-5.9/edit-site-export.php +++ b/lib/compat/wordpress-5.9/edit-site-export.php @@ -30,6 +30,19 @@ function wp_generate_edit_site_export_file() { $zip->addEmptyDir( 'theme/block-templates' ); $zip->addEmptyDir( 'theme/block-template-parts' ); + // Load theme and user styles. + $theme_data = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data(); + $user_data = WP_Theme_JSON_Resolver_Gutenberg::get_user_data(); + + // Merge the user config into the theme data. + // The user config takes precedence over the theme. + $theme_data->merge( $user_data ); + + $zip->addFromString( + 'theme/theme.json', + wp_json_encode( $theme_data->get_raw_data(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) + ); + // Load templates into the zip file. $templates = gutenberg_get_block_templates(); foreach ( $templates as $template ) { diff --git a/phpunit/class-edit-site-export-test.php b/phpunit/class-edit-site-export-test.php index ae56f11f283de..e540398df8821 100644 --- a/phpunit/class-edit-site-export-test.php +++ b/phpunit/class-edit-site-export-test.php @@ -8,15 +8,17 @@ class Edit_Site_Export_Test extends WP_UnitTestCase { function test_wp_generate_edit_site_export_file() { $filename = wp_generate_edit_site_export_file(); - $this->assertTrue( file_exists( $filename ), 'zip file is created at the specified path' ); + $this->assertFileExists( $filename, 'zip file is created at the specified path' ); $this->assertTrue( filesize( $filename ) > 0, 'zip file is larger than 0 bytes' ); // Open ZIP file and make sure the directories exist. $zip = new ZipArchive(); - $zip->open( $filename, ZipArchive::RDONLY ); + $zip->open( $filename ); + $has_theme_json = $zip->locateName( 'theme/theme.json' ) !== false; $has_theme_dir = $zip->locateName( 'theme/' ) !== false; $has_block_templates_dir = $zip->locateName( 'theme/block-templates/' ) !== false; $has_block_template_parts_dir = $zip->locateName( 'theme/block-template-parts/' ) !== false; + $this->assertTrue( $has_theme_json, 'theme.json file exists' ); $this->assertTrue( $has_theme_dir, 'theme directory exists' ); $this->assertTrue( $has_block_templates_dir, 'theme/block-templates directory exists' ); $this->assertTrue( $has_block_template_parts_dir, 'theme/block-template-parts directory exists' );