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

@@ -36,7 +36,7 @@ final class WP_Block_Styles_Registry {
*
* @param string $block_name Block type name including namespace.
* @param array $style_properties Array containing the properties of the style name, label,
* style (name of the stylesheet to be enqueued),
* is_default, style_handle (name of the stylesheet to be enqueued),
* inline_style (string containing the CSS to be added).
* @return bool True if the block style was registered with success and false otherwise.
*/

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 )
);
}
}