- Timestamp:
- 10/09/2023 04:38:25 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block-patterns-registry.php
r56649 r56805 154 154 155 155 /** 156 * Prepares the content of a block pattern. If hooked blocks are registered, they get injected into the pattern, 157 * when they met the defined criteria. 158 * 159 * @since 6.4.0 160 * 161 * @param array $pattern Registered pattern properties. 162 * @param array $hooked_blocks The list of hooked blocks. 163 * @return string The content of the block pattern. 164 */ 165 private function prepare_content( $pattern, $hooked_blocks ) { 166 $content = $pattern['content']; 167 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { 168 $blocks = parse_blocks( $content ); 169 $before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern ); 170 $after_block_visitor = make_after_block_visitor( $hooked_blocks, $pattern ); 171 $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 172 } 173 174 return $content; 175 } 176 177 /** 156 178 * Retrieves an array containing the properties of a registered block pattern. 157 179 * … … 166 188 } 167 189 168 $pattern = $this->registered_patterns[ $pattern_name ]; 169 $blocks = parse_blocks( $pattern['content'] ); 170 $before_block_visitor = make_before_block_visitor( $pattern ); 171 $after_block_visitor = make_after_block_visitor( $pattern ); 172 $pattern['content'] = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 190 $pattern = $this->registered_patterns[ $pattern_name ]; 191 $pattern['content'] = $this->prepare_content( $pattern, get_hooked_blocks() ); 173 192 174 193 return $pattern; … … 185 204 */ 186 205 public function get_all_registered( $outside_init_only = false ) { 187 $patterns = array_values(206 $patterns = array_values( 188 207 $outside_init_only 189 208 ? $this->registered_patterns_outside_init 190 209 : $this->registered_patterns 191 210 ); 192 211 $hooked_blocks = get_hooked_blocks(); 193 212 foreach ( $patterns as $index => $pattern ) { 194 $blocks = parse_blocks( $pattern['content'] ); 195 $before_block_visitor = make_before_block_visitor( $pattern ); 196 $after_block_visitor = make_after_block_visitor( $pattern ); 197 $patterns[ $index ]['content'] = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); 213 $patterns[ $index ]['content'] = $this->prepare_content( $pattern, $hooked_blocks ); 198 214 } 199 215 return $patterns;
Note: See TracChangeset
for help on using the changeset viewer.