@@ -36,14 +36,6 @@ function gutenberg_interactivity_mark_root_blocks( $parsed_block, $source_block,
36
36
* @return string Filtered block content.
37
37
*/
38
38
function gutenberg_process_directives_in_root_blocks ( $ block_content , $ block ) {
39
- static $ directives = array (
40
- 'data-wp-context ' => 'gutenberg_interactivity_process_wp_context ' ,
41
- 'data-wp-bind ' => 'gutenberg_interactivity_process_wp_bind ' ,
42
- 'data-wp-class ' => 'gutenberg_interactivity_process_wp_class ' ,
43
- 'data-wp-style ' => 'gutenberg_interactivity_process_wp_style ' ,
44
- 'data-wp-text ' => 'gutenberg_interactivity_process_wp_text ' ,
45
- );
46
-
47
39
if ( WP_Directive_Processor::is_marked_as_root_block ( $ block ) ) {
48
40
WP_Directive_Processor::unmark_root_block ();
49
41
@@ -54,9 +46,9 @@ function gutenberg_process_directives_in_root_blocks( $block_content, $block ) {
54
46
55
47
foreach ( $ parsed_blocks as $ parsed_block ) {
56
48
if ( 'core/interactivity-wrapper ' === $ parsed_block ['blockName ' ] ) {
57
- $ processed_content .= gutenberg_process_interactive_block ( $ parsed_block , $ context, $ directives );
49
+ $ processed_content .= gutenberg_process_interactive_block ( $ parsed_block , $ context );
58
50
} elseif ( 'core/non-interactivity-wrapper ' === $ parsed_block ['blockName ' ] ) {
59
- $ processed_content .= gutenberg_process_non_interactive_block ( $ parsed_block , $ context, $ directives );
51
+ $ processed_content .= gutenberg_process_non_interactive_block ( $ parsed_block , $ context );
60
52
} else {
61
53
$ processed_content .= $ parsed_block ['innerHTML ' ];
62
54
}
@@ -126,11 +118,10 @@ function gutenberg_mark_block_interactivity( $block_content, $block, $block_inst
126
118
*
127
119
* @param array $interactive_block The interactive block to process.
128
120
* @param WP_Directive_Context $context The context to use when processing.
129
- * @param array $directives The directives to apply.
130
121
*
131
122
* @return string The processed HTML.
132
123
*/
133
- function gutenberg_process_interactive_block ( $ interactive_block , $ context, $ directives ) {
124
+ function gutenberg_process_interactive_block ( $ interactive_block , $ context ) {
134
125
$ block_index = 0 ;
135
126
$ content = '' ;
136
127
$ interactive_inner_blocks = array ();
@@ -146,7 +137,7 @@ function gutenberg_process_interactive_block( $interactive_block, $context, $dir
146
137
}
147
138
}
148
139
149
- return gutenberg_process_interactive_html ( $ content , $ context , $ directives , $ interactive_inner_blocks );
140
+ return gutenberg_process_interactive_html ( $ content , $ context , $ interactive_inner_blocks );
150
141
}
151
142
152
143
/**
@@ -156,11 +147,10 @@ function gutenberg_process_interactive_block( $interactive_block, $context, $dir
156
147
*
157
148
* @param array $non_interactive_block The non-interactive block to process.
158
149
* @param WP_Directive_Context $context The context to use when processing.
159
- * @param array $directives The directives to apply.
160
150
*
161
151
* @return string The processed HTML.
162
152
*/
163
- function gutenberg_process_non_interactive_block ( $ non_interactive_block , $ context, $ directives ) {
153
+ function gutenberg_process_non_interactive_block ( $ non_interactive_block , $ context ) {
164
154
$ block_index = 0 ;
165
155
$ content = '' ;
166
156
foreach ( $ non_interactive_block ['innerContent ' ] as $ inner_content ) {
@@ -174,9 +164,9 @@ function gutenberg_process_non_interactive_block( $non_interactive_block, $conte
174
164
$ inner_block = $ non_interactive_block ['innerBlocks ' ][ $ block_index ++ ];
175
165
176
166
if ( 'core/interactivity-wrapper ' === $ inner_block ['blockName ' ] ) {
177
- $ content .= gutenberg_process_interactive_block ( $ inner_block , $ context, $ directives );
167
+ $ content .= gutenberg_process_interactive_block ( $ inner_block , $ context );
178
168
} elseif ( 'core/non-interactivity-wrapper ' === $ inner_block ['blockName ' ] ) {
179
- $ content .= gutenberg_process_non_interactive_block ( $ inner_block , $ context, $ directives );
169
+ $ content .= gutenberg_process_non_interactive_block ( $ inner_block , $ context );
180
170
}
181
171
}
182
172
}
@@ -187,20 +177,25 @@ function gutenberg_process_non_interactive_block( $non_interactive_block, $conte
187
177
* Processes interactive HTML by applying directives to the HTML tags.
188
178
*
189
179
* It uses the WP_Directive_Processor class to parse the HTML and apply the
190
- * directives. The directives are specified in the $directives array and are
191
- * applied to the tags that have the corresponding data attribute. If a tag
192
- * contains a 'WP-INNER-BLOCKS' string and there are inner blocks to process,
193
- * the function processes these inner blocks and replaces the 'WP-INNER-BLOCKS'
194
- * tag in the HTML with those blocks.
180
+ * directives. If a tag contains a 'WP-INNER-BLOCKS' string and there are inner
181
+ * blocks to process, the function processes these inner blocks and replaces the
182
+ * 'WP-INNER-BLOCKS' tag in the HTML with those blocks.
195
183
*
196
184
* @param string $html The HTML to process.
197
185
* @param mixed $context The context to use when processing.
198
- * @param array $directives The directives to apply.
199
186
* @param array $inner_blocks The inner blocks to process.
200
187
*
201
188
* @return string The processed HTML.
202
189
*/
203
- function gutenberg_process_interactive_html ( $ html , $ context , $ directives , $ inner_blocks = array () ) {
190
+ function gutenberg_process_interactive_html ( $ html , $ context , $ inner_blocks = array () ) {
191
+ static $ directives = array (
192
+ 'data-wp-context ' => 'gutenberg_interactivity_process_wp_context ' ,
193
+ 'data-wp-bind ' => 'gutenberg_interactivity_process_wp_bind ' ,
194
+ 'data-wp-class ' => 'gutenberg_interactivity_process_wp_class ' ,
195
+ 'data-wp-style ' => 'gutenberg_interactivity_process_wp_style ' ,
196
+ 'data-wp-text ' => 'gutenberg_interactivity_process_wp_text ' ,
197
+ );
198
+
204
199
$ tags = new WP_Directive_Processor ( $ html );
205
200
$ prefix = 'data-wp- ' ;
206
201
$ tag_stack = array ();
@@ -212,9 +207,9 @@ function gutenberg_process_interactive_html( $html, $context, $directives, $inne
212
207
// Processes the inner blocks.
213
208
if ( str_contains ( $ tag_name , 'WP-INNER-BLOCKS ' ) && ! empty ( $ inner_blocks ) && ! $ tags ->is_tag_closer () ) {
214
209
if ( 'core/interactivity-wrapper ' === $ inner_blocks [ $ inner_blocks_index ]['blockName ' ] ) {
215
- $ inner_processed_blocks [ strtolower ( $ tag_name ) ] = gutenberg_process_interactive_block ( $ inner_blocks [ $ inner_blocks_index ++ ], $ context, $ directives );
210
+ $ inner_processed_blocks [ strtolower ( $ tag_name ) ] = gutenberg_process_interactive_block ( $ inner_blocks [ $ inner_blocks_index ++ ], $ context );
216
211
} elseif ( 'core/non-interactivity-wrapper ' === $ inner_blocks [ $ inner_blocks_index ]['blockName ' ] ) {
217
- $ inner_processed_blocks [ strtolower ( $ tag_name ) ] = gutenberg_process_non_interactive_block ( $ inner_blocks [ $ inner_blocks_index ++ ], $ context, $ directives );
212
+ $ inner_processed_blocks [ strtolower ( $ tag_name ) ] = gutenberg_process_non_interactive_block ( $ inner_blocks [ $ inner_blocks_index ++ ], $ context );
218
213
}
219
214
}
220
215
if ( $ tags ->is_tag_closer () ) {
0 commit comments