[wp-trac] [WordPress Trac] #57717: Invalid argument supplied for `foreach()` in `WP_Theme_JSON::get_blocks_metadata()`

WordPress Trac noreply at wordpress.org
Tue Feb 14 16:07:58 UTC 2023


#57717: Invalid argument supplied for `foreach()` in
`WP_Theme_JSON::get_blocks_metadata()`
---------------------------+--------------------------
 Reporter:  davidbaumwald  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  6.2
Component:  Editor         |    Version:  trunk
 Severity:  normal         |   Keywords:  dev-feedback
  Focuses:                 |
---------------------------+--------------------------
 [55172] added server-side support for editing of block style variations in
 global styles.

 The issue arises from this block, specifically the `foreach`.

 {{{
 if ( ! empty( $block_type->styles ) ) {
         $style_selectors = array();
         foreach ( $block_type->styles as $style ) {
                 // The style variation classname is duplicated in the
 selector to ensure that it overrides core block styles.
                 $style_selectors[ $style['name'] ] =
 static::append_to_selector( '.is-style-' . $style['name'] . '.is-style-' .
 $style['name'], static::$blocks_metadata[ $block_name ]['selector'] );
         }
         static::$blocks_metadata[ $block_name ]['styleVariations'] =
 $style_selectors;
 }
 }}}

 However, under some circumstances apparently, `$block_type->styles` is not
 an array. and elicits an `Invalid argument supplied for foreach()`
 warning.

 Unsure of the resolution.  Seems type checking `$block_type->styles` would
 resolve the warning.  Or, perhaps `$block_type->styles` should always be
 an array, and something along the path to this point is doing it wrong?

 Moving into the 6.2 milestone for triaging.

 CC @hellofromTonya

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57717>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list