equal
deleted
inserted
replaced
157 |
157 |
158 return true; |
158 return true; |
159 } |
159 } |
160 |
160 |
161 /** |
161 /** |
162 * Prepares the content of a block pattern. If hooked blocks are registered, they get injected into the pattern, |
|
163 * when they met the defined criteria. |
|
164 * |
|
165 * @since 6.4.0 |
|
166 * |
|
167 * @param array $pattern Registered pattern properties. |
|
168 * @param array $hooked_blocks The list of hooked blocks. |
|
169 * @return string The content of the block pattern. |
|
170 */ |
|
171 private function prepare_content( $pattern, $hooked_blocks ) { |
|
172 $content = $pattern['content']; |
|
173 |
|
174 $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; |
|
175 $after_block_visitor = null; |
|
176 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { |
|
177 $before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); |
|
178 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); |
|
179 } |
|
180 $blocks = parse_blocks( $content ); |
|
181 $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); |
|
182 |
|
183 return $content; |
|
184 } |
|
185 |
|
186 /** |
|
187 * Retrieves the content of a registered block pattern. |
162 * Retrieves the content of a registered block pattern. |
188 * |
163 * |
189 * @since 6.5.0 |
164 * @since 6.5.0 |
190 * |
165 * |
191 * @param string $pattern_name Block pattern name including namespace. |
166 * @param string $pattern_name Block pattern name including namespace. |
219 if ( ! $this->is_registered( $pattern_name ) ) { |
194 if ( ! $this->is_registered( $pattern_name ) ) { |
220 return null; |
195 return null; |
221 } |
196 } |
222 |
197 |
223 $pattern = $this->registered_patterns[ $pattern_name ]; |
198 $pattern = $this->registered_patterns[ $pattern_name ]; |
224 $pattern['content'] = $this->get_content( $pattern_name ); |
199 $content = $this->get_content( $pattern_name ); |
225 $pattern['content'] = $this->prepare_content( $pattern, get_hooked_blocks() ); |
200 $pattern['content'] = apply_block_hooks_to_content( |
|
201 $content, |
|
202 $pattern, |
|
203 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' |
|
204 ); |
226 |
205 |
227 return $pattern; |
206 return $pattern; |
228 } |
207 } |
229 |
208 |
230 /** |
209 /** |
241 ? $this->registered_patterns_outside_init |
220 ? $this->registered_patterns_outside_init |
242 : $this->registered_patterns; |
221 : $this->registered_patterns; |
243 $hooked_blocks = get_hooked_blocks(); |
222 $hooked_blocks = get_hooked_blocks(); |
244 |
223 |
245 foreach ( $patterns as $index => $pattern ) { |
224 foreach ( $patterns as $index => $pattern ) { |
246 $pattern['content'] = $this->get_content( $pattern['name'], $outside_init_only ); |
225 $content = $this->get_content( $pattern['name'], $outside_init_only ); |
247 $patterns[ $index ]['content'] = $this->prepare_content( $pattern, $hooked_blocks ); |
226 $patterns[ $index ]['content'] = apply_block_hooks_to_content( |
|
227 $content, |
|
228 $pattern, |
|
229 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' |
|
230 ); |
248 } |
231 } |
249 |
232 |
250 return array_values( $patterns ); |
233 return array_values( $patterns ); |
251 } |
234 } |
252 |
235 |