On this page
WP_Block_Styles_Registry::register( string $block_name, array $style_properties ): bool
Registers a block style for the given block type.
Description
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.
Parameters
$block_namestring Required-
Block type name including namespace.
$style_propertiesarray Required-
Array containing the properties of the style.
namestringThe identifier of the style used to compute a CSS class.labelstringA human-readable label for the style.inline_stylestringInline CSS code that registers the CSS class required for the style.style_handlestringThe handle to an already registered style that should be enqueued in places where block styles are needed.is_defaultboolWhether this is the default style for the block type.
Return
bool True if the block style was registered with success and false otherwise.
Source
File: wp-includes/class-wp-block-styles-registry.php. View all references
public function register( $block_name, $style_properties ) {
if ( ! isset( $block_name ) || ! is_string( $block_name ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Block name must be a string.' ),
'5.3.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'];
if ( ! isset( $this->registered_block_styles[ $block_name ] ) ) {
$this->registered_block_styles[ $block_name ] = array();
}
$this->registered_block_styles[ $block_name ][ $block_style_name ] = $style_properties;
return true;
}
Related
Uses
| Uses | Description |
|---|---|
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _doing_it_wrong() wp-includes/functions.php | Marks something as being incorrectly called. |
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_block_styles_registry/register