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.


Built from https://develop.svn.wordpress.org/trunk@50703


git-svn-id: http://core.svn.wordpress.org/trunk@50312 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
gziolo 2021-04-13 08:04:13 +00:00
parent 989ec57389
commit b31964a44b
3 changed files with 10 additions and 8 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 )
);
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-alpha-50702';
$wp_version = '5.8-alpha-50703';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.