WordPress.org

Make WordPress Core

Opened 7 weeks ago

#52592 new defect (bug)

PHP notice when the label property is missing from register_block_style

Reported by: poena Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3
Component: Editor Keywords:
Focuses: Cc:

Description

If I register a block style using the PHP function
register_block_style, and I leave out the label property, there is a PHP notice:

Notice:  Undefined index: label in /var/www/src/wp-includes/script-loader.php on line 2312

The label is required, but the class does not check if a label exists or not, see:
https://core.trac.wordpress.org/browser/tags/5.6.1/src/wp-includes/class-wp-block-styles-registry.php#L43

In comparison, if I leave out the name property, a _doing_it_wrong message is shown.
I think a _doing_it_wrong should be shown for the label too.

Steps to reproduce the issue:

Register an incomplete block style in a theme or plugin file using register_block_style.

register_block_style(
    'core/quote',
    array(
        'inline_style' => '.wp-block-quote.is-style-blue-quote { color: blue; }',
    )
);

Confirm that the doing it wrong message for the name is showing.

Add the name property:

register_block_style(
    'core/quote',
    array(
	'name'  => 'test',
        'inline_style' => '.wp-block-quote.is-style-blue-quote { color: blue; }',
    )
);

Open the block editor. Confirm that a PHP notice for the label is showing.

Change History (0)

Note: See TracTickets for help on using tickets.