Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: Insert hooked blocks upon registration #5406

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/wp-includes/class-wp-block-patterns-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public function register( $pattern_name, $pattern_properties ) {
array( 'name' => $pattern_name )
);

// Set `theme` attribute in Template Part blocks, and insert hooked blocks.
$blocks = parse_blocks( $pattern['content'] );
$before_block_visitor = make_before_block_visitor( $pattern );
$after_block_visitor = make_after_block_visitor( $pattern );
$pattern['content'] = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );

$this->registered_patterns[ $pattern_name ] = $pattern;

// If the pattern is registered inside an action other than `init`, store it
Expand Down Expand Up @@ -165,13 +171,7 @@ public function get_registered( $pattern_name ) {
return null;
}

$pattern = $this->registered_patterns[ $pattern_name ];
$blocks = parse_blocks( $pattern['content'] );
$before_block_visitor = make_before_block_visitor( $pattern );
$after_block_visitor = make_after_block_visitor( $pattern );
$pattern['content'] = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );

return $pattern;
return $this->registered_patterns[ $pattern_name ];
}

/**
Expand All @@ -184,19 +184,11 @@ public function get_registered( $pattern_name ) {
* and per style.
*/
public function get_all_registered( $outside_init_only = false ) {
$patterns = array_values(
return array_values(
$outside_init_only
? $this->registered_patterns_outside_init
: $this->registered_patterns
);

foreach ( $patterns as $index => $pattern ) {
$blocks = parse_blocks( $pattern['content'] );
$before_block_visitor = make_before_block_visitor( $pattern );
$after_block_visitor = make_after_block_visitor( $pattern );
$patterns[ $index ]['content'] = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
}
return $patterns;
}

/**
Expand Down
Loading