Blocks: Add is_default handling to server side block styles registry

Ensures that register_block_style lets developer pass `is_default` flag to mark one of the block style variations as the default one.

Props mukesh27, xavivars.
Fixes #53006.



git-svn-id: https://develop.svn.wordpress.org/trunk@50703 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Greg Ziółkowski
2021-04-13 08:02:33 +00:00
parent b18a87c9ce
commit 8603c6a006
2 changed files with 9 additions and 7 deletions

View File

@@ -2303,15 +2303,17 @@ function enqueue_editor_block_styles_assets() {
$register_script_lines = array( '( function() {' );
foreach ( $block_styles as $block_name => $styles ) {
foreach ( $styles as $style_properties ) {
$block_style = array(
'name' => $style_properties['name'],
'label' => $style_properties['label'],
);
if ( isset( $style_properties['is_default'] ) ) {
$block_style['isDefault'] = $style_properties['is_default'];
}
$register_script_lines[] = sprintf(
' wp.blocks.registerBlockStyle( \'%s\', %s );',
$block_name,
wp_json_encode(
array(
'name' => $style_properties['name'],
'label' => $style_properties['label'],
)
)
wp_json_encode( $block_style )
);
}
}