<!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>[11410] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Update block.json validation and discovery in block plugins.</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="http://meta.trac.wordpress.org/changeset/11410">11410</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/11410","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ryelle</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-01-04 23:40:07 +0000 (Tue, 04 Jan 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'>Plugin Directory: Update block.json validation and discovery in block plugins.

Start using `https://schemas.wp.org/trunk/block.json` to validate the `block.json`. This fixes a few mismatched field types between our validator and the official expected format. This also updates the block discovery code to merge found blocks (if a block is registered in both PHP and JS, for example).

Props gziolo, welcher, jeffpaul.
See <a href="http://meta.trac.wordpress.org/ticket/5303">#5303</a>, <a href="http://meta.trac.wordpress.org/ticket/5971">#5971</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonclassvalidatorphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryblockjsonclassvalidatorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php  2022-01-04 02:17:44 UTC (rev 11409)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/block-json/class-validator.php    2022-01-04 23:40:07 UTC (rev 11410)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -27,162 +27,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * The schema for the block.json file.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * This attempts to follow the schema for the schema.
-        * See https://json-schema.org/understanding-json-schema/reference/index.html
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Fetch the schema from `schemas.wp.org`, which redirects to the latest version
+        * of this file in GitHub.
+        * See https://github.com/WordPress/gutenberg/blob/trunk/schemas/json/block.json.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function schema() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return array(
-                       'type'                 => 'object',
-                       'properties'           => array(
-                               'apiVersion'   => array(
-                                       'type' => 'string',
-                               ),
-                               'attributes'   => array(
-                                       'type'                 => 'object',
-                                       'additionalProperties' => array(
-                                               'type'       => 'object',
-                                               'properties' => array(
-                                                       'attribute' => array(
-                                                               'type' => 'string',
-                                                       ),
-                                                       'meta'      => array(
-                                                               'type' => 'string',
-                                                       ),
-                                                       'multiline' => array(
-                                                               'type' => 'string',
-                                                       ),
-                                                       'query'     => array(
-                                                               'type' => 'object',
-                                                       ),
-                                                       'selector'  => array(
-                                                               'type' => 'string',
-                                                       ),
-                                                       'source'    => array(
-                                                               'type' => 'string',
-                                                               'enum' => array( 'attribute', 'text', 'html', 'query' ),
-                                                       ),
-                                                       'type'      => array(
-                                                               'type' => 'string',
-                                                               'enum' => array( 'null', 'boolean', 'object', 'array', 'number', 'string', 'integer' ),
-                                                       ),
-                                               ),
-                                               'required'   => array( 'type' ),
-                                       ),
-                               ),
-                               'category'     => array(
-                                       'type' => 'string',
-                               ),
-                               'comment'      => array(
-                                       'type' => 'string',
-                               ),
-                               'description'  => array(
-                                       'type' => 'string',
-                               ),
-                               'editorScript' => array(
-                                       'type'    => 'string',
-                                       'pattern' => '\.js$',
-                               ),
-                               'editorStyle'  => array(
-                                       'type'    => 'string',
-                                       'pattern' => '\.css$',
-                               ),
-                               'example'      => array(
-                                       'type'                 => 'object',
-                                       'additionalProperties' => array(
-                                               'type' => 'object',
-                                       ),
-                               ),
-                               'icon'         => array(
-                                       'type' => 'string',
-                               ),
-                               'keywords'     => array(
-                                       'type'  => 'array',
-                                       'items' => array(
-                                               'type' => 'string',
-                                       ),
-                               ),
-                               'name'         => array(
-                                       'type' => 'string',
-                               ),
-                               'parent'       => array(
-                                       'type'  => 'array',
-                                       'items' => array(
-                                               'type' => 'string',
-                                       ),
-                               ),
-                               'script'       => array(
-                                       'type'    => 'string',
-                                       'pattern' => '\.js$',
-                               ),
-                               'style'        => array(
-                                       'type'    => 'string',
-                                       'pattern' => '\.css$',
-                               ),
-                               'styles'       => array(
-                                       'type'  => 'array',
-                                       'items' => array(
-                                               'type'       => 'object',
-                                               'properties' => array(
-                                                       'isDefault' => array(
-                                                               'type' => 'boolean',
-                                                       ),
-                                                       'label'     => array(
-                                                               'type' => 'string',
-                                                       ),
-                                                       'name'      => array(
-                                                               'type' => 'string',
-                                                       ),
-                                               ),
-                                       ),
-                               ),
-                               'supports'     => array(
-                                       'type'       => 'object',
-                                       'properties' => array(
-                                               'align'           => array(
-                                                       'type'  => array( 'boolean', 'array' ),
-                                                       'items' => array(
-                                                               'type' => 'string',
-                                                               'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
-                                                       ),
-                                               ),
-                                               'alignWide'       => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'anchor'          => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'className'       => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'customClassName' => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'html'            => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'inserter'        => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'multiple'        => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                               'reusable'        => array(
-                                                       'type' => 'boolean',
-                                               ),
-                                       ),
-                               ),
-                               'textdomain'   => array(
-                                       'type' => 'string',
-                               ),
-                               'title'        => array(
-                                       'type' => 'string',
-                               ),
-                       ),
-                       'required'             => array( 'name', 'title' ),
-                       'additionalProperties' => false,
-               );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $schema_url = 'https://schemas.wp.org/trunk/block.json';
+               $response = wp_remote_get( $schema_url );
+               if ( is_wp_error( $response ) ) {
+                       return $response;
+               }
+
+               $body = wp_remote_retrieve_body( $response );
+               $schema = json_decode( $body, true );
+               return $schema;
</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">@@ -199,8 +59,19 @@
</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">                $schema = self::schema();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( is_wp_error( $schema ) ) {
+                       return $schema;
+               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->validate_object( $block_json, 'block.json', $schema );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $result = rest_validate_value_from_schema( $block_json, $schema, 'block.json' );
+
+               // Workaround for a bug in validation, `oneOf` incorrectly flags that the value matches multiple options.
+               // Getting this message means it passed the "string" condition, so this is not an error.
+               // See https://core.trac.wordpress.org/ticket/54740.
+               if ( is_wp_error( $result ) && 'rest_one_of_multiple_matches' !== $result->get_error_code() ) {
+                       $this->messages = $result;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->check_conditional_properties( $block_json );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $this->messages->has_errors() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -222,289 +93,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return;
</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">+                // phpcs:ignore WordPress.NamingConventions.ValidVariableName
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! isset( $block_json->script ) && ! isset( $block_json->editorScript ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->messages->add(
</span><span class="cx" style="display: block; padding: 0 10px">                                'error',
</span><span class="cx" style="display: block; padding: 0 10px">                                sprintf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        __( 'At least one of the following properties must be present: %s', 'wporg-plugins' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 __( 'block.json[script] At least one of the following properties must be present: %s', 'wporg-plugins' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                         // translators: used between list items, there is a space after the comma.
</span><span class="cx" style="display: block; padding: 0 10px">                                        '<code>script</code>' . __( ', ', 'wporg-plugins' ) . '<code>editorScript</code>'
</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">-                        $this->append_error_data( 'block.json:script', 'error' );
-                       $this->append_error_data( 'block.json:editorScript', 'error' );
</del><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="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Validate an object and its properties.
-        *
-        * @param object $object The value to validate as an object.
-        * @param string $prop   The name of the property, used in error reporting.
-        * @param array  $schema The schema for the property, used for validation.
-        *
-        * @return bool
-        */
-       protected function validate_object( $object, $prop, $schema ) {
-               if ( ! is_object( $object ) ) {
-                       $this->messages->add(
-                               'error',
-                               sprintf(
-                                       __( 'The %s property must contain an object value.', 'wporg-plugins' ),
-                                       '<code>' . $prop . '</code>'
-                               )
-                       );
-                       $this->append_error_data( $prop, 'error' );
-
-                       return false;
-               }
-
-               $results = array();
-
-               if ( isset( $schema['required'] ) ) {
-                       foreach ( $schema['required'] as $required_prop ) {
-                               if ( ! property_exists( $object, $required_prop ) ) {
-                                       $this->messages->add(
-                                               'error',
-                                               sprintf(
-                                                       __( 'The %1$s property is required in the %2$s object.', 'wporg-plugins' ),
-                                                       '<code>' . $required_prop . '</code>',
-                                                       '<code>' . $prop . '</code>'
-                                               )
-                                       );
-                                       $this->append_error_data( "$prop:$required_prop", 'error' );
-                                       $results[] = false;
-                               }
-                       }
-               }
-
-               if ( isset( $schema['properties'] ) ) {
-                       foreach ( $schema['properties'] as $subprop => $subschema ) {
-                               if ( ! isset( $object->$subprop ) ) {
-                                       continue;
-                               }
-
-                               if ( isset( $subschema['type'] ) ) {
-                                       $results[] = $this->route_validation_for_type(
-                                               $subschema['type'],
-                                               $object->$subprop,
-                                               "$prop:$subprop",
-                                               $subschema
-                                       );
-                               }
-                       }
-               }
-
-               if ( isset( $schema['additionalProperties'] ) ) {
-                       if ( false === $schema['additionalProperties'] ) {
-                               foreach ( array_keys( get_object_vars( $object ) ) as $key ) {
-                                       if ( ! isset( $schema['properties'][ $key ] ) ) {
-                                               $this->messages->add(
-                                                       'warning',
-                                                       sprintf(
-                                                               __( '%1$s is not a valid property in the %2$s object.', 'wporg-plugins' ),
-                                                               '<code>' . $key . '</code>',
-                                                               '<code>' . $prop . '</code>'
-                                                       )
-                                               );
-                                               $this->append_error_data( "$prop:$key", 'warning' );
-                                               $results[] = false;
-                                               continue;
-                                       }
-                               }
-                       } elseif ( isset( $schema['additionalProperties']['type'] ) ) {
-                               foreach ( $object as $subprop => $subvalue ) {
-                                       $results[] = $this->route_validation_for_type(
-                                               $schema['additionalProperties']['type'],
-                                               $subvalue,
-                                               "$prop:$subprop",
-                                               $schema['additionalProperties']
-                                       );
-                               }
-                       }
-               }
-
-               return ! in_array( false, $results, true );
-       }
-
-       /**
-        * Validate an array and its items.
-        *
-        * @param array  $array  The value to validate as an array.
-        * @param string $prop   The name of the property, used in error reporting.
-        * @param array  $schema The schema for the property, used for validation.
-        *
-        * @return bool
-        */
-       protected function validate_array( $array, $prop, $schema ) {
-               if ( ! is_array( $array ) ) {
-                       $this->messages->add(
-                               'error',
-                               sprintf(
-                                       __( 'The %s property must contain an array value.', 'wporg-plugins' ),
-                                       '<code>' . $prop . '</code>'
-                               )
-                       );
-                       $this->append_error_data( $prop, 'error' );
-
-                       return false;
-               }
-
-               if ( isset( $schema['items']['type'] ) ) {
-                       $results = array();
-                       $index   = 0;
-
-                       foreach ( $array as $item ) {
-                               $results[] = $this->route_validation_for_type(
-                                       $schema['items']['type'],
-                                       $item,
-                                       $prop . "[$index]",
-                                       $schema['items']
-                               );
-                               $index ++;
-                       }
-
-                       return ! in_array( false, $results, true );
-               }
-
-               return true;
-       }
-
-       /**
-        * Validate a string.
-        *
-        * @param string $string The value to validate as a string.
-        * @param string $prop   The name of the property, used in error reporting.
-        * @param array  $schema The schema for the property, used for validation.
-        *
-        * @return bool
-        */
-       protected function validate_string( $string, $prop, $schema ) {
-               if ( ! is_string( $string ) ) {
-                       $this->messages->add(
-                               'error',
-                               sprintf(
-                                       __( 'The %s property must contain a string value.', 'wporg-plugins' ),
-                                       '<code>' . $prop . '</code>'
-                               )
-                       );
-                       $this->append_error_data( $prop, 'error' );
-
-                       return false;
-               }
-
-               if ( isset( $schema['enum'] ) ) {
-                       if ( ! in_array( $string, $schema['enum'], true ) ) {
-                               $this->messages->add(
-                                       'warning',
-                                       sprintf(
-                                               __( '"%1$s" is not a valid value for the %2$s property.', 'wporg-plugins' ),
-                                               esc_html( $string ),
-                                               '<code>' . $prop . '</code>'
-                                       )
-                               );
-                               $this->append_error_data( $prop, 'warning' );
-                       }
-               }
-
-               if ( isset( $schema['pattern'] ) ) {
-                       if ( ! preg_match( '#' . $schema['pattern'] . '#', $string ) ) {
-                               $pattern_description = $this->get_human_readable_pattern_description( $schema['pattern'] );
-                               if ( $pattern_description ) {
-                                       $message = sprintf(
-                                               $pattern_description,
-                                               '<code>' . $prop . '</code>'
-                                       );
-                               } else {
-                                       $message = sprintf(
-                                               __( 'The value of %s does not match the required pattern.', 'wporg-plugins' ),
-                                               '<code>' . $prop . '</code>'
-                                       );
-                               }
-
-                               $this->messages->add( 'warning', $message );
-                               $this->append_error_data( $prop, 'warning' );
-                       }
-               }
-
-               return true;
-       }
-
-       /**
-        * Validate a boolean.
-        *
-        * @param bool   $boolean The value to validate as a boolean.
-        * @param string $prop    The name of the property, used in error reporting.
-        *
-        * @return bool
-        */
-       protected function validate_boolean( $boolean, $prop ) {
-               if ( ! is_bool( $boolean ) ) {
-                       $this->messages->add(
-                               'error',
-                               sprintf(
-                                       __( 'The %s property must contain a boolean value.', 'wporg-plugins' ),
-                                       '<code>' . $prop . '</code>'
-                               )
-                       );
-                       $this->append_error_data( $prop, 'error' );
-
-                       return false;
-               }
-
-               return true;
-       }
-
-       /**
-        * Send a property value to the correct validator depending on which type(s) it can be.
-        *
-        * @param string|array $valid_types
-        * @param mixed        $value
-        * @param string       $prop
-        * @param array        $schema
-        *
-        * @return bool
-        */
-       protected function route_validation_for_type( $valid_types, $value, $prop, $schema ) {
-               // There is a single valid type.
-               if ( is_string( $valid_types ) ) {
-                       $method = "validate_$valid_types";
-                       return $this->$method( $value, $prop, $schema );
-               }
-
-               // There are multiple valid types in an array.
-               foreach ( $valid_types as $type ) {
-                       switch ( $type ) {
-                               case 'boolean':
-                                       $check = 'is_bool';
-                                       break;
-                               default:
-                                       $check = "is_$type";
-                                       break;
-                       }
-
-                       if ( $check( $value ) ) {
-                               $method = "validate_$type";
-                               return $this->$method( $value, $prop, $schema );
-                       }
-               }
-
-               // Made it this far, it's none of the valid types.
-               $this->messages->add(
-                       'error',
-                       sprintf(
-                               __( 'The %1$s property must contain a value that is one of these types: %2$s', 'wporg-plugins' ),
-                               '<code>' . $prop . '</code>',
-                               // translators: used between list items, there is a space after the comma.
-                               '<code>' . implode( '</code>' . __( ', ', 'wporg-plugins' ) . '<code>', $valid_types ) . '</code>'
-                       )
-               );
-               $this->append_error_data( $prop, 'error' );
-
-               return false;
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Add more data to an error code.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * The `add_data` method in WP_Error replaces data with each subsequent call with the same error code.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -519,26 +121,4 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $data[] = $new_data;
</span><span class="cx" style="display: block; padding: 0 10px">                $this->messages->add_data( $data, $error_code );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-       /**
-        * Get a description of a regex pattern that can be understood by humans.
-        *
-        * @param string $pattern A regex pattern.
-        *
-        * @return string
-        */
-       protected function get_human_readable_pattern_description( $pattern ) {
-               $description = '';
-
-               switch ( $pattern ) {
-                       case '\.css$':
-                               $description = __( 'The value of %s must end in ".css".', 'wporg-plugins' );
-                               break;
-                       case '\.js$':
-                               $description = __( 'The value of %s must end in ".js".', 'wporg-plugins' );
-                               break;
-               }
-
-               return $description;
-       }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php    2022-01-04 02:17:44 UTC (rev 11409)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php      2022-01-04 23:40:07 UTC (rev 11410)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -625,7 +625,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        $relative_filename = str_replace( "$base_dir/", '', $filename );
</span><span class="cx" style="display: block; padding: 0 10px">                                        $potential_block_directories[] = dirname( $relative_filename );
</span><span class="cx" style="display: block; padding: 0 10px">                                        foreach ( $blocks_in_file as $block ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $blocks[ $block->name ] = $block;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( isset( $blocks[ $block->name ] ) ) {
+                                                       $blocks[ $block->name ] = (object) array_merge( (array) $blocks[ $block->name ], array_filter( (array) $block ) );
+                                               } else {
+                                                       $blocks[ $block->name ] = $block;
+                                               }
</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">@@ -791,15 +795,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! is_wp_error( $block ) && is_wp_error( $result ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                // Only certain properties must be valid for our purposes here.
</span><span class="cx" style="display: block; padding: 0 10px">                                $required_valid_props = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'block.json',
-                                       'block.json:editorScript',
-                                       'block.json:editorStyle',
-                                       'block.json:name',
-                                       'block.json:script',
-                                       'block.json:style',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'block.json[editorScript]',
+                                       'block.json[editorStyle]',
+                                       'block.json[name]',
+                                       'block.json[script]',
+                                       'block.json[style]',
</ins><span class="cx" style="display: block; padding: 0 10px">                                 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $invalid_props = array_intersect( $required_valid_props, $result->get_error_data( 'error' ) ?: [] );
-                               if ( empty( $invalid_props ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $error = $result->get_error_message();
+                               $is_json_valid = array_reduce(
+                                       $required_valid_props,
+                                       function( $is_valid, $prop ) use ( $error ) {
+                                               return $is_valid && ( false === strpos( $error, $prop ) );
+                                       },
+                                       true
+                               );
+                               if ( $is_json_valid ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $blocks[] = $block;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        } elseif ( true === $result ) {
</span></span></pre>
</div>
</div>

</body>
</html>