#53006 closed enhancement (fixed)
Blocks: Add isDefault to server side block styles registry
Reported by: | gziolo | Owned by: | gziolo |
---|---|---|---|
Milestone: | 5.8 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Editor | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
Moved from GitHub (https://github.com/WordPress/gutenberg/issues/30356, reported by xavivars).
What problem does this address?
[As documented here](https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/filters/block-filters.md#block-style-variations), block styles can be registered both server side (using PHP method register_block_style
) and client side (using wp.blocks.registerBlockStyle
).
While server-side registration is a convenient method to easily register new block styles, it lacks the ability to register a style as the default one.
As an example, something that could easily be achieved like this in JS, is not doable in PHP
wp.blocks.registerBlockStyle( 'core/heading', [ { name: 'default', label: 'Default', isDefault: true, }, { name: 'alt', label: 'Alternate', } ]);
What is your proposed solution?
Extend register_block_style
to also accept isDefault
.
(it would probably require to change core code in https://github.com/WordPress/WordPress/blob/59d32bfe24cee58554ac82573d8a69dd6b6749ab/wp-includes/script-loader.php#L2311 )
Attachments (1)
Change History (9)
#4
@
4 years ago
So it seems it sounds like a idea. I didn't push a patch because I wanted to see what people thought before, via the github issue, but I'm glad you agree with the proposal
#5
@
4 years ago
This will require additional changes in https://developer.wordpress.org/block-editor/reference-guides/filters/block-filters/.
Given that I see inline_style
and style_handle
fields that use snake case, I'm leaning towards is_default
.
I tested with
register_block_style( 'core/list', array( 'name' => 'green-list', 'label' => __( 'Green List' ), ) ); register_block_style( 'core/list', array( 'name' => 'blue-list', 'label' => __( 'Blue List' ), 'is_default' => true, ) );
I can confirm that it correctly applies changes with the example used.
#7
@
4 years ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from new to closed
In 50703:
#8
@
4 years ago
Documentation changes applied on the Gutenberg project side in https://github.com/WordPress/gutenberg/pull/30792.
Initial patch