Skip to content
Open
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
35 changes: 35 additions & 0 deletions src/wp-includes/class-wp-block-patterns-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,41 @@ public function register( $pattern_name, $pattern_properties ) {
);
return false;
}

// Block Validation to check if blocks used in the pattern are allowed.
$blocks = parse_blocks( $pattern_properties['content'] );
$block_names = wp_list_pluck( $blocks, 'blockName' );
$allowed_blocks = apply_filters( 'allowed_block_types_all', true );

if ( is_array( $allowed_blocks ) ) {
$allowed_blocks = array_flip( $allowed_blocks );
foreach ( $block_names as $block_name ) {
if ( ! isset( $allowed_blocks[ $block_name ] ) ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %1$s: Pattern name, %2$s: Block name. */
__( 'Pattern "%1$s" contains disallowed block "%2$s".' ),
$pattern_name,
$block_name
),
'6.9.0'
);
return false;
}
}
} elseif ( ! $allowed_blocks ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %s: Pattern name. */
__( 'Pattern "%s" contains blocks, but all blocks are disallowed.' ),
$pattern_name
),
'6.9.0'
);
return false;
}
}

$pattern = array_merge(
Expand Down
Loading