Skip to content

Commit cfa9494

Browse files
authored
Guard against empty block context in placeholder state (#152)
1 parent 12171d4 commit cfa9494

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

inc/Editor/DataBinding/BlockBindings.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ public static function get_value( array $source_args, WP_Block|array $block ): s
198198
return $fallback_content;
199199
}
200200

201-
202201
$value = self::get_remote_value( $block_context, $source_args );
203202

204203
if ( ! is_string( $value ) ) {
@@ -241,7 +240,13 @@ public static function loop_block_render_callback( array $attributes, string $co
241240
// context available on the block's context property. However, context for
242241
// children blocks comes from this block's `remoteData` attribtue (see
243242
// block.json#providesContext), so we can access it directly.
244-
$block_context = $attributes['remoteData'];
243+
$block_context = $attributes['remoteData'] ?? [];
244+
245+
// Fallback to the content if we don't have the expected context.
246+
if ( ! isset( $block_context['blockName'] ) || ! isset( $block_context['queryInput'] ) ) {
247+
self::log_error( sprintf( 'Missing block context for block binding %s', self::$context_name ), 'unknown' );
248+
return $content;
249+
}
245250

246251
$loop_template = $block->parsed_block['innerBlocks'];
247252
$loop_template_content = $block->parsed_block['innerContent'];

0 commit comments

Comments
 (0)