[wp-trac] [WordPress Trac] #53006: Blocks: Add isDefault to server side block styles registry

WordPress Trac noreply at wordpress.org
Fri Apr 9 08:39:18 UTC 2021


#53006: Blocks: Add isDefault to server side block styles registry
-------------------------+---------------------
 Reporter:  gziolo       |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  5.8
Component:  General      |     Version:  trunk
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+---------------------
Description changed by gziolo:

Old description:

> Moved from GitHub (https://github.com/WordPress/gutenberg/issues/30356).
>
> ## 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 )

New description:

 Moved from GitHub (https://github.com/WordPress/gutenberg/issues/30356,
 reported by [https://github.com/xavivars 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 )

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53006#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list