Registers a block style for the given block type.
If the block styles are present in a standalone stylesheet, register it and pass its handle as the style_handle argument. If the block styles should be inline, use the inline_style argument. Usually, one of them would be used to pass CSS styles. However, you could also skip them and provide CSS styles in any stylesheet or with an inline tag.
$block_namestring|string[]required
$style_propertiesarrayrequired
name stringlabel stringinline_style stringstyle_handle stringis_default boolstyle_data arraypublic function register( $block_name, $style_properties ) {
if ( ! is_string( $block_name ) && ! is_array( $block_name ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Block name must be a string or array.' ),
'6.6.0'
);
return false;
}
if ( ! isset( $style_properties['name'] ) || ! is_string( $style_properties['name'] ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Block style name must be a string.' ),
'5.3.0'
);
return false;
}
if ( str_contains( $style_properties['name'], ' ' ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Block style name must not contain any spaces.' ),
'5.9.0'
);
return false;
}
$block_style_name = $style_properties['name'];
$block_names = is_string( $block_name ) ? array( $block_name ) : $block_name;
foreach ( $block_names as $name ) {
if ( ! isset( $this->registered_block_styles[ $name ] ) ) {
$this->registered_block_styles[ $name ] = array();
}
$this->registered_block_styles[ $name ][ $block_style_name ] = $style_properties;
}
return true;
}
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_block_styles_registry/register