Make WordPress Core

#57717 closed defect (bug) (duplicate)

Invalid argument supplied for `foreach()` in `WP_Theme_JSON::get_blocks_metadata()`

Reported by: davidbaumwald's profile davidbaumwald Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.2
Component: Editor Keywords:
Focuses: Cc:


[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

Change History (2)

#1 @SergeyBiryukov
13 months ago

Duplicate of #57706?

There was also a discussion in comment:11:ticket:57583.

#2 @davidbaumwald
13 months ago

  • Keywords dev-feedback removed
  • Milestone 6.2 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #57706.

Yep. Thank you @SergeyBiryukov.

Note: See TracTickets for help on using tickets.