context['commentId'] ) ) { return ''; } $comment = get_comment( $block->context['commentId'] ); if ( ! $comment ) { return ''; } // This is the only way to retrieve style and classes on different instances. $wrapper_attributes = WP_Block_Supports::get_instance()->apply_block_supports(); /** * We get the spacing attributes and transform the array provided into a string formatted for being applied as a style html tag. * Good candidate to be moved to a separate function in core. */ $spacing_attributes = $attributes['style']['spacing'] ?? null; if ( isset( $spacing_attributes ) && ! empty( $spacing_attributes ) ) { $spacing_array = array(); foreach ( $spacing_attributes as $spacing_attribute_key => $spacing_attribute_value ) { foreach ( $spacing_attribute_value as $position_key => $position_value ) { $spacing_array[] = $spacing_attribute_key . '-' . $position_key . ': ' . $position_value; } } $spacing_string = implode( ';', $spacing_array ); } $width = $attributes['width'] ?? 96; $height = $attributes['height'] ?? 96; $styles = $wrapper_attributes['style'] ?? ''; $classes = $wrapper_attributes['class'] ?? ''; /* translators: %s: Author name. */ $alt = sprintf( __( '%s Avatar' ), $comment->comment_author ); $avatar_block = get_avatar( $comment, null, '', $alt, array( 'height' => $height, 'width' => $width, 'extra_attr' => sprintf( 'style="%1s"', $styles ), 'class' => $classes, ) ); if ( isset( $spacing_attributes ) ) { return sprintf( '