Skip to content

Commit

Permalink
Editor: Add a fallback to WP_Block_Styles_Registry if the label is …
Browse files Browse the repository at this point in the history
…missing.

Both `name` and `label` properties are required when registering a block style. If the label is missing, assign `name` as the value for the `label`, to ensure the property is defined. This avoids a PHP warning in such case.

Props poena, Rahmohn, aaronrobertshaw, audrasjb, rinkalpagdar.
Fixes #52592.




git-svn-id: https://develop.svn.wordpress.org/trunk@59760 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
audrasjb committed Feb 4, 2025
1 parent bce13fd commit 39b293e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/wp-includes/class-wp-block-styles-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public function register( $block_name, $style_properties ) {
$block_style_name = $style_properties['name'];
$block_names = is_string( $block_name ) ? array( $block_name ) : $block_name;

// Ensure there is a label defined.
if ( empty( $style_properties['label'] ) ) {
$style_properties['label'] = $block_style_name;
}

foreach ( $block_names as $name ) {
if ( ! isset( $this->registered_block_styles[ $name ] ) ) {
$this->registered_block_styles[ $name ] = array();
Expand Down

0 comments on commit 39b293e

Please sign in to comment.