@@ -36,26 +36,39 @@ function gutenberg_block_bindings_render_block( $block_content, $block, $instanc
3636 return $ block_content ;
3737 }
3838
39- $ attributes = $ instance ->parsed_block ['attrs ' ];
4039 // Process the block bindings and get attributes updated with the values from the sources.
4140 $ computed_attributes = gutenberg_process_block_bindings ( $ instance );
4241 if ( empty ( $ computed_attributes ) ) {
4342 return $ block_content ;
4443 }
4544
46- // Merge the computed attributes with the original attributes.
47- $ instance ->attributes = array_merge ( $ attributes , $ computed_attributes );
45+ /*
46+ * Merge the computed attributes with the original attributes.
47+ *
48+ * Note that this is not a recursive merge, meaning that nested attributes --
49+ * such as block bindings metadata -- will be completely replaced.
50+ * This is desirable. At this point, Core has already processed any block
51+ * bindings that it supports. What remains to be processed are only the attributes
52+ * for which support was added later (through the `block_bindings_supported_attributes`
53+ * filter). To do so, we'll run `$instance->render()` once more
54+ * so the block can update its content based on those attributes.
55+ */
56+ $ instance ->attributes = array_merge ( $ instance ->attributes , $ computed_attributes );
57+
58+ /*
59+ * If we're dealing with the Button block, we remove the bindings metadata
60+ * in order to avoid having it reprocessed, which would lead to Core
61+ * capitalizing the wrapper tag (e.g. <DIV>).
62+ */
63+ if ( 'core/button ' === $ instance ->name ) {
64+ unset( $ instance ->parsed_block ['attrs ' ]['metadata ' ]['bindings ' ] );
65+ }
4866
4967 /**
50- * This filter is called from WP_Block::render(), after the block content has
51- * already been rendered. However, dynamic blocks expect their render() method
52- * to receive block attributes to have their bound values. This means that we have
53- * to re-render the block here.
54- * To do so, we'll set a flag that this filter checks when invoked to avoid infinite
55- * recursion. Furthermore, we can unset all of the block's bindings, as we know that
56- * they have been processed by the time we reach this point.
68+ * This filter (`gutenberg_block_bindings_render_block`) is called from `WP_Block::render()`.
69+ * To avoid infinite recursion, we set a flag that this filter checks when invoked which tells
70+ * it to exit early.
5771 */
58- unset( $ instance ->parsed_block ['attrs ' ]['metadata ' ]['bindings ' ] );
5972 $ inside_block_bindings_render = true ;
6073 $ block_content = $ instance ->render ();
6174 $ inside_block_bindings_render = false ;
0 commit comments