Skip to content

Commit 44c4c8f

Browse files
committed
Refactor comments in resolve_pattern_blocks function for clarity
Improves the documentation within the `resolve_pattern_blocks` function by enhancing comments related to metadata handling for single-root patterns. This change aims to provide clearer guidance on the merging process of pattern metadata with existing block metadata.
1 parent 5e54013 commit 44c4c8f

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/wp-includes/blocks.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,31 +1883,29 @@ function resolve_pattern_blocks( $blocks ) {
18831883

18841884
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
18851885

1886-
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
1887-
18881886
/*
1889-
* For single-root patterns, add the pattern name to make this a pattern instance in the editor.
1890-
* If the pattern has metadata, merge it with the existing metadata.
1891-
*/
1887+
* For single-root patterns, add the pattern name to make this a pattern instance in the editor.
1888+
* If the pattern has metadata, merge it with the existing metadata.
1889+
*/
18921890
if ( count( $blocks_to_insert ) === 1 ) {
18931891
$block_metadata = $blocks_to_insert[0]['attrs']['metadata'] ?? array();
18941892
$block_metadata['patternName'] = $slug;
18951893

18961894
/*
1897-
* Merge pattern metadata with existing block metadata.
1898-
* Pattern metadata takes precedence, but existing block metadata
1899-
* is preserved as a fallback when the pattern doesn't define that field.
1900-
* Only the defined fields (name, description, categories) are updated;
1901-
* other metadata keys are preserved.
1902-
*/
1895+
* Merge pattern metadata with existing block metadata.
1896+
* Pattern metadata takes precedence, but existing block metadata
1897+
* is preserved as a fallback when the pattern doesn't define that field.
1898+
* Only the defined fields (name, description, categories) are updated;
1899+
* other metadata keys are preserved.
1900+
*/
19031901
foreach ( array(
19041902
'name' => 'title', // 'title' is the field in the pattern object 'name' is the field in the block metadata.
19051903
'description' => 'description',
19061904
'categories' => 'categories',
19071905
) as $key => $pattern_key ) {
19081906
$value = $pattern[ $pattern_key ] ?? $block_metadata[ $key ] ?? null;
19091907
if ( $value ) {
1910-
$block_metadata[ $key ] = 'categories' === $key && is_array( $value )
1908+
$block_metadata[ $key ] = is_array( $value )
19111909
? array_map( 'sanitize_text_field', $value )
19121910
: sanitize_text_field( $value );
19131911
}

0 commit comments

Comments
 (0)