Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#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 gziolo)

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)

53006.patch (550 bytes) - added by mukesh27 5 months ago.
Initial patch

Download all attachments as: .zip

Change History (9)

#1 @gziolo
5 months ago

  • Description modified (diff)

5 months ago

Initial patch

#2 @mukesh27
5 months ago

  • Keywords has-patch added

Hi there!

Initital 53006.patch patch uploaded.

#3 @gziolo
5 months ago

That was quick, I will test next week if nobody beats me up to it :)

#4 @xavivars
5 months 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 @gziolo
5 months 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

        'name'         => 'green-list',
        'label'        => __( 'Green List' ),
        'name'         => 'blue-list',
        'label'        => __( 'Blue List' ),
        'is_default'   => true,

I can confirm that it correctly applies changes with the example used.

#6 @gziolo
5 months ago

  • Component changed from General to Editor

#7 @gziolo
5 months ago

  • Owner set to gziolo
  • Resolution set to fixed
  • Status changed from new to closed

In 50703:

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.

#8 @gziolo
5 months ago

Documentation changes applied on the Gutenberg project side in https://github.com/WordPress/gutenberg/pull/30792.

Note: See TracTickets for help on using tickets.