[wp-trac] [WordPress Trac] #56707: `register_block_type`'s `editor_script` handle fails if it is an array.

WordPress Trac noreply at wordpress.org
Tue Oct 18 03:42:52 UTC 2022


#56707: `register_block_type`'s `editor_script` handle fails if it is an array.
-------------------------------------------------+-------------------------
 Reporter:  nendeb55                             |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.1
Component:  Editor                               |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  needs-testing has-testing-info dev-  |     Focuses:
  feedback                                       |
-------------------------------------------------+-------------------------

Comment (by costdev):

 @nendeb55 I may be mistaken on this, so I defer to others more experienced
 with this feature, but I would assume that `$value` should either be a
 string, or a string array.

 The documentation says `$value` is `mixed`, but for deprecated properties,
 only strings are currently supported. Therefore, if we are going to add
 back support for arrays, I assume that these should only be string arrays.

 If that's the case, and we want to remove any incorrect data, then we
 could do this:

 {{{#!php
 <?php

 if ( is_array( $value ) ) {
     $this->{$new_name} = array_filter( $value, 'is_string' );
 }
 }}}

 or:

 {{{#!php
 <?php

 if ( is_array( $value ) ) {
     $filtered = array_filter( $value, 'is_string' );

     if ( count( $filtered ) !== count( $value ) ) {
         _doing_it_wrong(
             __METHOD__,
             sprintf(
                 /* translators: %s: The '$value' argument. */
                 __( 'The %s argument must be a string or a string array.'
 ),
                 '<code>$value</code>'
             ),
             'x.x.x',
         );
     }

     $this->{$new_name} = $filtered;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56707#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list