<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[53129] trunk: Editor: Add functionality required for theme export in the site editor</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/53129">53129</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/53129","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>gziolo</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-04-11 10:36:02 +0000 (Mon, 11 Apr 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor: Add functionality required for theme export in the site editor
This bring across changes to theme export functionality, and related code, and tests. Relates issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/39889.
Props scruffian, timothyblynjacobs, oandregal, ajlende, zieleadam.
See <a href="https://core.trac.wordpress.org/ticket/55505">#55505</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocktemplateutilsphp">trunk/src/wp-includes/block-template-utils.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonresolverphp">trunk/src/wp-includes/class-wp-theme-json-resolver.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresteditsiteexportcontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php</a></li>
<li><a href="#trunktestsphpunittestsblocktemplateutilsphp">trunk/tests/phpunit/tests/block-template-utils.php</a></li>
<li><a href="#trunktestsphpunittestsfunctionsphp">trunk/tests/phpunit/tests/functions.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonphp">trunk/tests/phpunit/tests/theme/wpThemeJson.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocktemplateutilsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-template-utils.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-template-utils.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/src/wp-includes/block-template-utils.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -119,11 +119,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'home' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => _x( 'Home', 'Template name' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'Displays as the site\'s home page, or as the Posts page when a static home page isn\'t set.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => __( 'Displays posts on the homepage, or on the Posts page if a static homepage is set.' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'front-page' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => _x( 'Front Page', 'Template name' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'Displays as the site\'s home page.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => __( 'Displays the homepage.' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'singular' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => _x( 'Singular', 'Template name' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -162,12 +162,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Displays latest posts with a single post tag.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'attachment' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'title' => __( 'Attachment' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'title' => __( 'Media' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Displays individual media items or attachments.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'search' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => _x( 'Search', 'Template name' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'Template used to display search results.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => __( 'Displays search results.' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'privacy-policy' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => __( 'Privacy Policy' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -903,11 +903,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filters theme directories that should be ignored during export.
+ *
+ * @since 6.0.0
+ *
+ * @param string $path The path of the file in the theme.
+ * @return Bool Whether this file is in an ignored directory.
+ */
+function wp_is_theme_directory_ignored( $path ) {
+ $directories_to_ignore = array( '.svn', '.git', '.hg', '.bzr', 'node_modules', 'vendor' );
+ foreach ( $directories_to_ignore as $directory ) {
+ if ( strpos( $path, $directory ) === 0 ) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Creates an export of the current templates and
</span><span class="cx" style="display: block; padding: 0 10px"> * template parts from the site editor at the
</span><span class="cx" style="display: block; padding: 0 10px"> * specified path in a ZIP file.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0 Adds the whole theme to the export archive.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Error|string Path of the ZIP file or error on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -916,18 +936,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $obscura = wp_generate_password( 12, false, false );
- $filename = get_temp_dir() . 'edit-site-export-' . $obscura . '.zip';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $obscura = wp_generate_password( 12, false, false );
+ $theme_name = wp_get_theme()->get( 'TextDomain' );
+ $filename = get_temp_dir() . $theme_name . $obscura . '.zip';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $zip = new ZipArchive();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( true !== $zip->open( $filename, ZipArchive::CREATE ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( true !== $zip->open( $filename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $zip->addEmptyDir( 'theme' );
- $zip->addEmptyDir( 'theme/templates' );
- $zip->addEmptyDir( 'theme/parts' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $zip->addEmptyDir( 'templates' );
+ $zip->addEmptyDir( 'parts' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get path of the theme.
+ $theme_path = wp_normalize_path( get_stylesheet_directory() );
+
+ // Create recursive directory iterator.
+ $theme_files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator( $theme_path ),
+ RecursiveIteratorIterator::LEAVES_ONLY
+ );
+
+ // Make a copy of the current theme.
+ foreach ( $theme_files as $file ) {
+ // Skip directories as they are added automatically.
+ if ( ! $file->isDir() ) {
+ // Get real and relative path for current file.
+ $file_path = wp_normalize_path( $file );
+ $relative_path = substr( $file_path, strlen( $theme_path ) + 1 );
+
+ if ( ! wp_is_theme_directory_ignored( $relative_path ) ) {
+ $zip->addFile( $file_path, $relative_path );
+ }
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Load templates into the zip file.
</span><span class="cx" style="display: block; padding: 0 10px"> $templates = get_block_templates();
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $templates as $template ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -934,7 +977,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $template->content = _remove_theme_attribute_in_block_template_content( $template->content );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $zip->addFromString(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'theme/templates/' . $template->slug . '.html',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'templates/' . $template->slug . '.html',
</ins><span class="cx" style="display: block; padding: 0 10px"> $template->content
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -943,11 +986,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $template_parts = get_block_templates( array(), 'wp_template_part' );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $template_parts as $template_part ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $zip->addFromString(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'theme/parts/' . $template_part->slug . '.html',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'parts/' . $template_part->slug . '.html',
</ins><span class="cx" style="display: block; padding: 0 10px"> $template_part->content
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Load theme.json into the zip file.
+ $tree = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) );
+ // Merge with user data.
+ $tree->merge( WP_Theme_JSON_Resolver::get_user_data() );
+
+ $theme_json_raw = $tree->get_data();
+ // If a version is defined, add a schema.
+ if ( $theme_json_raw['version'] ) {
+ global $wp_version;
+ $theme_json_version = 'wp/' . substr( $wp_version, 0, 3 );
+ $schema = array( '$schema' => 'https://schemas.wp.org/' . $theme_json_version . '/theme.json' );
+ $theme_json_raw = array_merge( $schema, $theme_json_raw );
+ }
+
+ // 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',
+ $theme_json_tabbed
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Save changes to the zip file.
</span><span class="cx" style="display: block; padding: 0 10px"> $zip->close();
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonresolverphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme-json-resolver.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json-resolver.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/src/wp-includes/class-wp-theme-json-resolver.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -151,14 +151,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0 Adds a second parameter to allow the theme data to be returned without theme supports.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $deprecated Deprecated. Not used.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $options Contains a key called with_supports to determine whether to include theme supports in the data.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Theme_JSON Entity that holds theme data.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public static function get_theme_data( $deprecated = array() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_theme_data( $deprecated = array(), $options = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $deprecated ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_argument( __METHOD__, '5.9.0' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $options = wp_parse_args( $options, array( 'with_supports' => true ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( null === static::$theme ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -177,6 +182,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $options['with_supports'] ) {
+ return static::$theme;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /*
</span><span class="cx" style="display: block; padding: 0 10px"> * We want the presets and settings declared in theme.json
</span><span class="cx" style="display: block; padding: 0 10px"> * to override the ones declared via theme supports.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -208,6 +217,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $default_gradients = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Classic themes without a theme.json don't support global duotone.
+ $theme_support_data['settings']['color']['defaultDuotone'] = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $with_theme_supports = new WP_Theme_JSON( $theme_support_data );
</span><span class="cx" style="display: block; padding: 0 10px"> $with_theme_supports->merge( static::$theme );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -477,4 +489,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $variations;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme-json.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/src/wp-includes/class-wp-theme-json.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -74,41 +74,49 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * This contains the necessary metadata to process them:
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * - path => where to find the preset within the settings section
- * - override => whether a theme preset with the same slug as a default preset
- * can override it
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * - path => Where to find the preset within the settings section.
+ * - prevent_override => Disables override of default presets by theme presets.
+ * The relationship between whether to override the defaults
+ * and whether the defaults are enabled is inverse:
+ * - If defaults are enabled => theme presets should not be overriden
+ * - If defaults are disabled => theme presets should be overriden
+ * For example, a theme sets defaultPalette to false,
+ * making the default palette hidden from the user.
+ * In that case, we want all the theme presets to be present,
+ * so they should override the defaults by setting this false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * - use_default_names => whether to use the default names
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * - value_key => the key that represents the value
- * - value_func => optionally, instead of value_key, a function to generate
- * the value that takes a preset as an argument
- * (either value_key or value_func should be present)
- * - css_vars => template string to use in generating the CSS Custom Property.
- * Example output: "--wp--preset--duotone--blue: <value>" will generate
- * as many CSS Custom Properties as presets defined
- * substituting the $slug for the slug's value for each preset value.
- * - classes => array containing a structure with the classes to
- * generate for the presets, where for each array item
- * the key is the class name and the value the property name.
- * The "$slug" substring will be replaced by the slug of each preset.
- * For example:
- * 'classes' => array(
- * '.has-$slug-color' => 'color',
- * '.has-$slug-background-color' => 'background-color',
- * '.has-$slug-border-color' => 'border-color',
- * )
- * - properties => array of CSS properties to be used by kses to
- * validate the content of each preset
- * by means of the remove_insecure_properties method.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * - value_key => the key that represents the value
+ * - value_func => optionally, instead of value_key, a function to generate
+ * the value that takes a preset as an argument
+ * (either value_key or value_func should be present)
+ * - css_vars => template string to use in generating the CSS Custom Property.
+ * Example output: "--wp--preset--duotone--blue: <value>" will generate as many CSS Custom Properties as presets defined
+ * substituting the $slug for the slug's value for each preset value.
+ * - classes => array containing a structure with the classes to
+ * generate for the presets, where for each array item
+ * the key is the class name and the value the property name.
+ * The "$slug" substring will be replaced by the slug of each preset.
+ * For example:
+ * 'classes' => array(
+ * '.has-$slug-color' => 'color',
+ * '.has-$slug-background-color' => 'background-color',
+ * '.has-$slug-border-color' => 'border-color',
+ * )
+ * - properties => array of CSS properties to be used by kses to
+ * validate the content of each preset
+ * by means of the remove_insecure_properties method.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0 Added the `color.duotone` and `typography.fontFamilies` presets,
</span><span class="cx" style="display: block; padding: 0 10px"> * `use_default_names` preset key, and simplified the metadata structure.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0 Replaced `override` with `prevent_override` and updated the
+ * `prevent_overried` value for `color.duotone` to use `color.defaultDuotone`.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const PRESETS_METADATA = array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'color', 'palette' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'override' => array( 'color', 'defaultPalette' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'prevent_override' => array( 'color', 'defaultPalette' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'use_default_names' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'value_key' => 'color',
</span><span class="cx" style="display: block; padding: 0 10px"> 'css_vars' => '--wp--preset--color--$slug',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -121,7 +129,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'color', 'gradients' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'override' => array( 'color', 'defaultGradients' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'prevent_override' => array( 'color', 'defaultGradients' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'use_default_names' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'value_key' => 'gradient',
</span><span class="cx" style="display: block; padding: 0 10px"> 'css_vars' => '--wp--preset--gradient--$slug',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -130,7 +138,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'color', 'duotone' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'override' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'prevent_override' => array( 'color', 'defaultDuotone' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'use_default_names' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'value_func' => 'wp_get_duotone_filter_property',
</span><span class="cx" style="display: block; padding: 0 10px"> 'css_vars' => '--wp--preset--duotone--$slug',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -139,7 +147,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'typography', 'fontSizes' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'override' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'prevent_override' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'use_default_names' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'value_key' => 'size',
</span><span class="cx" style="display: block; padding: 0 10px"> 'css_vars' => '--wp--preset--font-size--$slug',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -148,7 +156,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'path' => array( 'typography', 'fontFamilies' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'override' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'prevent_override' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'use_default_names' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'value_key' => 'fontFamily',
</span><span class="cx" style="display: block; padding: 0 10px"> 'css_vars' => '--wp--preset--font-family--$slug',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -229,10 +237,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const VALID_TOP_LEVEL_KEYS = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'customTemplates',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'patterns',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'settings',
</span><span class="cx" style="display: block; padding: 0 10px"> 'styles',
</span><span class="cx" style="display: block; padding: 0 10px"> 'templateParts',
</span><span class="cx" style="display: block; padding: 0 10px"> 'version',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'title',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -242,6 +252,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0 Renamed from `ALLOWED_SETTINGS` to `VALID_SETTINGS`,
</span><span class="cx" style="display: block; padding: 0 10px"> * added new properties for `border`, `color`, `spacing`,
</span><span class="cx" style="display: block; padding: 0 10px"> * and `typography`, and renamed others according to the new schema.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0 Added `color.defaultDuotone`.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const VALID_SETTINGS = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -257,6 +268,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'custom' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'customDuotone' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'customGradient' => null,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'defaultDuotone' => null,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'defaultGradients' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'defaultPalette' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'duotone' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -348,6 +360,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Options that settings.appearanceTools enables.
+ *
+ * @since 6.0.0
+ * @var array
+ */
+ const APPEARANCE_TOOLS_OPT_INS = array(
+ array( 'border', 'color' ),
+ array( 'border', 'radius' ),
+ array( 'border', 'style' ),
+ array( 'border', 'width' ),
+ array( 'color', 'link' ),
+ array( 'spacing', 'blockGap' ),
+ array( 'spacing', 'margin' ),
+ array( 'spacing', 'padding' ),
+ array( 'typography', 'lineHeight' ),
+ );
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * The latest version of the schema in use.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -429,19 +459,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $context The context to which the settings belong.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected static function do_opt_in_into_settings( &$context ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $to_opt_in = array(
- array( 'border', 'color' ),
- array( 'border', 'radius' ),
- array( 'border', 'style' ),
- array( 'border', 'width' ),
- array( 'color', 'link' ),
- array( 'spacing', 'blockGap' ),
- array( 'spacing', 'margin' ),
- array( 'spacing', 'padding' ),
- array( 'typography', 'lineHeight' ),
- );
-
- foreach ( $to_opt_in as $path ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( static::APPEARANCE_TOOLS_OPT_INS as $path ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Use "unset prop" as a marker instead of "null" because
</span><span class="cx" style="display: block; padding: 0 10px"> // "null" can be a valid value for some props (e.g. blockGap).
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'unset prop' === _wp_array_get( $context, $path, 'unset prop' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -830,8 +848,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_block_gap_support ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $block_rules .= '.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }';
- $block_rules .= '.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $block_rules .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
+ $block_rules .= '.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1502,6 +1520,45 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * For metadata values that can either be booleans or paths to booleans, gets the value.
+ *
+ * ```php
+ * $data = array(
+ * 'color' => array(
+ * 'defaultPalette' => true
+ * )
+ * );
+ *
+ * static::get_metadata_boolean( $data, false );
+ * // => false
+ *
+ * static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) );
+ * // => true
+ * ```
+ *
+ * @since 6.0.0
+ *
+ * @param array $data The data to inspect.
+ * @param bool|array $path Boolean or path to a boolean.
+ * @param bool $default Default value if the referenced path is missing.
+ * @return boolean
+ */
+ protected static function get_metadata_boolean( $data, $path, $default = false ) {
+ if ( is_bool( $path ) ) {
+ return $path;
+ }
+
+ if ( is_array( $path ) ) {
+ $value = _wp_array_get( $data, $path );
+ if ( null !== $value ) {
+ return $value;
+ }
+ }
+
+ return $default;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Merge new incoming data.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.8.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1550,7 +1607,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Replace the presets.
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( static::PRESETS_METADATA as $preset ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['override'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $override_preset = ! static::get_metadata_boolean( $this->theme_json['settings'], $preset['prevent_override'], true );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( static::VALID_ORIGINS as $origin ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $base_path = array_merge( $node['path'], $preset['path'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1624,13 +1681,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Returns whether a presets should be overridden or not.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 6.0.0 Use {@see 'get_metadata_boolean'} instead.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $theme_json The theme.json like structure to inspect.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $path Path to inspect.
- * @param bool|array $override Data to compute whether to override the preset.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $path Path to inspect.
+ * @param bool|array $override Data to compute whether to override the preset.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return boolean
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected static function should_override_preset( $theme_json, $path, $override ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _deprecated_function( __METHOD__, '6.0.0', 'get_metadata_boolean' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_bool( $override ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $override;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2013,4 +2073,151 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $theme_settings;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Returns the current theme's wanted patterns(slugs) to be
+ * registered from Pattern Directory.
+ *
+ * @since 6.0.0
+ *
+ * @return string[]
+ */
+ public function get_patterns() {
+ if ( isset( $this->theme_json['patterns'] ) && is_array( $this->theme_json['patterns'] ) ) {
+ return $this->theme_json['patterns'];
+ }
+ return array();
+ }
+
+ /**
+ * Returns a valid theme.json as provided by a theme.
+ *
+ * Unlike get_raw_data() this returns the presets flattened, as provided by a theme.
+ * This also uses appearanceTools instead of their opt-ins if all of them are true.
+ *
+ * @since 6.0.0
+ *
+ * @return array
+ */
+ public function get_data() {
+ $output = $this->theme_json;
+ $nodes = static::get_setting_nodes( $output );
+
+ /**
+ * Flatten the theme & custom origins into a single one.
+ *
+ * For example, the following:
+ *
+ * {
+ * "settings": {
+ * "color": {
+ * "palette": {
+ * "theme": [ {} ],
+ * "custom": [ {} ]
+ * }
+ * }
+ * }
+ * }
+ *
+ * will be converted to:
+ *
+ * {
+ * "settings": {
+ * "color": {
+ * "palette": [ {} ]
+ * }
+ * }
+ * }
+ */
+ foreach ( $nodes as $node ) {
+ foreach ( static::PRESETS_METADATA as $preset_metadata ) {
+ $path = array_merge( $node['path'], $preset_metadata['path'] );
+ $preset = _wp_array_get( $output, $path, null );
+ if ( null === $preset ) {
+ continue;
+ }
+
+ $items = array();
+ if ( isset( $preset['theme'] ) ) {
+ foreach ( $preset['theme'] as $item ) {
+ $slug = $item['slug'];
+ unset( $item['slug'] );
+ $items[ $slug ] = $item;
+ }
+ }
+ if ( isset( $preset['custom'] ) ) {
+ foreach ( $preset['custom'] as $item ) {
+ $slug = $item['slug'];
+ unset( $item['slug'] );
+ $items[ $slug ] = $item;
+ }
+ }
+ $flattened_preset = array();
+ foreach ( $items as $slug => $value ) {
+ $flattened_preset[] = array_merge( array( 'slug' => $slug ), $value );
+ }
+ _wp_array_set( $output, $path, $flattened_preset );
+ }
+ }
+
+ // If all of the static::APPEARANCE_TOOLS_OPT_INS are true,
+ // this code unsets them and sets 'appearanceTools' instead.
+ foreach ( $nodes as $node ) {
+ $all_opt_ins_are_set = true;
+ foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) {
+ $full_path = array_merge( $node['path'], $opt_in_path );
+ // Use "unset prop" as a marker instead of "null" because
+ // "null" can be a valid value for some props (e.g. blockGap).
+ $opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' );
+ if ( 'unset prop' === $opt_in_value ) {
+ $all_opt_ins_are_set = false;
+ break;
+ }
+ }
+
+ if ( $all_opt_ins_are_set ) {
+ _wp_array_set( $output, array_merge( $node['path'], array( 'appearanceTools' ) ), true );
+ foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) {
+ $full_path = array_merge( $node['path'], $opt_in_path );
+ // Use "unset prop" as a marker instead of "null" because
+ // "null" can be a valid value for some props (e.g. blockGap).
+ $opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' );
+ if ( true !== $opt_in_value ) {
+ continue;
+ }
+
+ // The following could be improved to be path independent.
+ // At the moment it relies on a couple of assumptions:
+ //
+ // - all opt-ins having a path of size 2.
+ // - there's two sources of settings: the top-level and the block-level.
+ if (
+ ( 1 === count( $node['path'] ) ) &&
+ ( 'settings' === $node['path'][0] )
+ ) {
+ // Top-level settings.
+ unset( $output['settings'][ $opt_in_path[0] ][ $opt_in_path[1] ] );
+ if ( empty( $output['settings'][ $opt_in_path[0] ] ) ) {
+ unset( $output['settings'][ $opt_in_path[0] ] );
+ }
+ } elseif (
+ ( 3 === count( $node['path'] ) ) &&
+ ( 'settings' === $node['path'][0] ) &&
+ ( 'blocks' === $node['path'][1] )
+ ) {
+ // Block-level settings.
+ $block_name = $node['path'][2];
+ unset( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ][ $opt_in_path[1] ] );
+ if ( empty( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ] ) ) {
+ unset( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ] );
+ }
+ }
+ }
+ }
+ }
+
+ wp_recursive_ksort( $output );
+
+ return $output;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/src/wp-includes/functions.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8440,3 +8440,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return abs( (float) $expected - (float) $actual ) <= $precision;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Sorts the keys of an array alphabetically.
+ * The array is passed by reference so it doesn't get returned
+ * which mimics the behaviour of ksort.
+ *
+ * @since 6.0.0
+ *
+ * @param array $array The array to sort, passed by reference.
+ */
+function wp_recursive_ksort( &$array ) {
+ foreach ( $array as &$value ) {
+ if ( is_array( $value ) ) {
+ wp_recursive_ksort( $value );
+ }
+ }
+ ksort( $array );
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswpresteditsiteexportcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -53,15 +53,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Error|true True if the request has access, or WP_Error object.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function permissions_check() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! current_user_can( 'edit_theme_options' ) ) {
- return new WP_Error(
- 'rest_cannot_export_templates',
- __( 'Sorry, you are not allowed to export templates and template parts.' ),
- array( 'status' => rest_authorization_required_code() )
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( current_user_can( 'edit_theme_options' ) ) {
+ return true;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return new WP_Error(
+ 'rest_cannot_export_templates',
+ __( 'Sorry, you are not allowed to export templates and template parts.' ),
+ array( 'status' => rest_authorization_required_code() )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,8 +82,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $filename;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $theme_name = wp_get_theme()->get( 'TextDomain' );
</ins><span class="cx" style="display: block; padding: 0 10px"> header( 'Content-Type: application/zip' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- header( 'Content-Disposition: attachment; filename=edit-site-export.zip' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ header( 'Content-Disposition: attachment; filename=' . $theme_name . '.zip' );
</ins><span class="cx" style="display: block; padding: 0 10px"> header( 'Content-Length: ' . filesize( $filename ) );
</span><span class="cx" style="display: block; padding: 0 10px"> flush();
</span><span class="cx" style="display: block; padding: 0 10px"> readfile( $filename );
</span></span></pre></div>
<a id="trunktestsphpunittestsblocktemplateutilsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/block-template-utils.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-template-utils.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/tests/phpunit/tests/block-template-utils.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -357,10 +357,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Open ZIP file and make sure the directories exist.
</span><span class="cx" style="display: block; padding: 0 10px"> $zip = new ZipArchive();
</span><span class="cx" style="display: block; padding: 0 10px"> $zip->open( $filename );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_theme_dir = $zip->locateName( 'theme/' ) !== false;
- $has_block_templates_dir = $zip->locateName( 'theme/templates/' ) !== false;
- $has_block_template_parts_dir = $zip->locateName( 'theme/parts/' ) !== false;
- $this->assertTrue( $has_theme_dir, 'theme directory exists' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_theme_json = $zip->locateName( 'theme.json' ) !== false;
+ $has_block_templates_dir = $zip->locateName( 'templates/' ) !== false;
+ $has_block_template_parts_dir = $zip->locateName( 'parts/' ) !== false;
+ $this->assertTrue( $has_theme_json, 'theme.json exists' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $has_block_templates_dir, 'theme/templates directory exists' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $has_block_template_parts_dir, 'theme/parts directory exists' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/functions.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/tests/phpunit/tests/functions.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2173,4 +2173,91 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 111, wp_filesize( $file ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 55505
+ * @covers ::wp_recursive_ksort
+ */
+ function test_wp_recursive_ksort() {
+ // Create an array to test.
+ $theme_json = array(
+ 'version' => 1,
+ 'settings' => array(
+ 'typography' => array(
+ 'fontFamilies' => array(
+ 'fontFamily' => 'DM Sans, sans-serif',
+ 'slug' => 'dm-sans',
+ 'name' => 'DM Sans',
+ ),
+ ),
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'foreground',
+ 'color' => '#242321',
+ 'name' => 'Foreground',
+ ),
+ array(
+ 'slug' => 'background',
+ 'color' => '#FCFBF8',
+ 'name' => 'Background',
+ ),
+ array(
+ 'slug' => 'primary',
+ 'color' => '#71706E',
+ 'name' => 'Primary',
+ ),
+ array(
+ 'slug' => 'tertiary',
+ 'color' => '#CFCFCF',
+ 'name' => 'Tertiary',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ // Sort the array.
+ wp_recursive_ksort( $theme_json );
+
+ // Expected result.
+ $expected_theme_json = array(
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'color' => '#242321',
+ 'name' => 'Foreground',
+ 'slug' => 'foreground',
+ ),
+ array(
+ 'color' => '#FCFBF8',
+ 'name' => 'Background',
+ 'slug' => 'background',
+ ),
+ array(
+ 'color' => '#71706E',
+ 'name' => 'Primary',
+ 'slug' => 'primary',
+ ),
+ array(
+ 'color' => '#CFCFCF',
+ 'name' => 'Tertiary',
+ 'slug' => 'tertiary',
+ ),
+ ),
+ ),
+ 'typography' => array(
+ 'fontFamilies' => array(
+ 'fontFamily' => 'DM Sans, sans-serif',
+ 'name' => 'DM Sans',
+ 'slug' => 'dm-sans',
+ ),
+ ),
+ ),
+ 'version' => 1,
+ );
+ $this->assertEquals( $theme_json, $expected_theme_json );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitteststhemewpThemeJsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/wpThemeJson.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpThemeJson.php 2022-04-11 10:12:56 UTC (rev 53128)
+++ trunk/tests/phpunit/tests/theme/wpThemeJson.php 2022-04-11 10:36:02 UTC (rev 53129)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -423,9 +423,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expected = 'body { margin: 0; }body{--wp--style--block-gap: 1em;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }';
- $this->assertSame( $expected, $theme_json->get_stylesheet() );
- $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = 'body { margin: 0; }body{--wp--style--block-gap: 1em;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }';
+ $this->assertEquals( $expected, $theme_json->get_stylesheet() );
+ $this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -553,13 +553,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $variables = 'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $styles = 'body { margin: 0; }body{color: var(--wp--preset--color--grey);}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }a{background-color: #333;color: #111;}.wp-block-group{border-radius: 10px;padding: 24px;}.wp-block-group a{color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a{background-color: #777;color: #555;}.wp-block-image{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;}';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $styles = 'body { margin: 0; }body{color: var(--wp--preset--color--grey);}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }a{background-color: #333;color: #111;}.wp-block-group{border-radius: 10px;padding: 24px;}.wp-block-group a{color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a{background-color: #777;color: #555;}.wp-block-image{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;}';
</ins><span class="cx" style="display: block; padding: 0 10px"> $presets = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}';
</span><span class="cx" style="display: block; padding: 0 10px"> $all = $variables . $styles . $presets;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( $all, $theme_json->get_stylesheet() );
- $this->assertSame( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
- $this->assertSame( $presets, $theme_json->get_stylesheet( array( 'presets' ) ) );
- $this->assertSame( $variables, $theme_json->get_stylesheet( array( 'variables' ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( $all, $theme_json->get_stylesheet() );
+ $this->assertEquals( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
+ $this->assertEquals( $presets, $theme_json->get_stylesheet( array( 'presets' ) ) );
+ $this->assertEquals( $variables, $theme_json->get_stylesheet( array( 'variables' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2384,4 +2384,241 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEqualSetsWithIndex( $expected, $actual );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @ticket 55505
+ */
+ function test_export_data() {
+ $theme = new WP_Theme_JSON(
+ array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => 'white',
+ 'label' => 'White',
+ ),
+ array(
+ 'slug' => 'black',
+ 'color' => 'black',
+ 'label' => 'Black',
+ ),
+ ),
+ ),
+ ),
+ )
+ );
+ $user = new WP_Theme_JSON(
+ array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => '#fff',
+ 'label' => 'User White',
+ ),
+ array(
+ 'slug' => 'hotpink',
+ 'color' => 'hotpink',
+ 'label' => 'hotpink',
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'custom'
+ );
+
+ $theme->merge( $user );
+ $actual = $theme->get_data();
+ $expected = array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => '#fff',
+ 'label' => 'User White',
+ ),
+ array(
+ 'slug' => 'black',
+ 'color' => 'black',
+ 'label' => 'Black',
+ ),
+ array(
+ 'slug' => 'hotpink',
+ 'color' => 'hotpink',
+ 'label' => 'hotpink',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
+
+ /**
+ * @ticket 55505
+ */
+ function test_export_data_deals_with_empty_user_data() {
+ $theme = new WP_Theme_JSON(
+ array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => 'white',
+ 'label' => 'White',
+ ),
+ array(
+ 'slug' => 'black',
+ 'color' => 'black',
+ 'label' => 'Black',
+ ),
+ ),
+ ),
+ ),
+ )
+ );
+
+ $actual = $theme->get_data();
+ $expected = array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => 'white',
+ 'label' => 'White',
+ ),
+ array(
+ 'slug' => 'black',
+ 'color' => 'black',
+ 'label' => 'Black',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
+
+ /**
+ * @ticket 55505
+ */
+ function test_export_data_deals_with_empty_theme_data() {
+ $user = new WP_Theme_JSON(
+ array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => '#fff',
+ 'label' => 'User White',
+ ),
+ array(
+ 'slug' => 'hotpink',
+ 'color' => 'hotpink',
+ 'label' => 'hotpink',
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'custom'
+ );
+
+ $actual = $user->get_data();
+ $expected = array(
+ 'version' => 2,
+ 'settings' => array(
+ 'color' => array(
+ 'palette' => array(
+ array(
+ 'slug' => 'white',
+ 'color' => '#fff',
+ 'label' => 'User White',
+ ),
+ array(
+ 'slug' => 'hotpink',
+ 'color' => 'hotpink',
+ 'label' => 'hotpink',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
+
+ /**
+ * @ticket 55505
+ */
+ function test_export_data_deals_with_empty_data() {
+ $theme_v2 = new WP_Theme_JSON(
+ 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(
+ array(
+ 'version' => 1,
+ ),
+ 'theme'
+ );
+ $actual_v1 = $theme_v1->get_data();
+ $expected_v1 = array( 'version' => 2 );
+ $this->assertEqualSetsWithIndex( $expected_v1, $actual_v1 );
+ }
+
+ /**
+ * @ticket 55505
+ */
+ function test_export_data_sets_appearance_tools() {
+ $theme = new WP_Theme_JSON(
+ array(
+ 'version' => 2,
+ 'settings' => array(
+ 'appearanceTools' => true,
+ 'blocks' => array(
+ 'core/paragraph' => array(
+ 'appearanceTools' => true,
+ ),
+ ),
+ ),
+ )
+ );
+
+ $actual = $theme->get_data();
+ $expected = array(
+ 'version' => 2,
+ 'settings' => array(
+ 'appearanceTools' => true,
+ 'blocks' => array(
+ 'core/paragraph' => array(
+ 'appearanceTools' => true,
+ ),
+ ),
+ ),
+ );
+
+ $this->assertEqualSetsWithIndex( $expected, $actual );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>