wppaste
WordPress

WP_Block_Styles_Registry

Since
5.3.0
Source
wp-includes/class-wp-block-styles-registry.php:15
Class used for interacting with block styles.

Compatibility

WordPress
since 5.3.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 2

$registered_block_stylesarray[]private
Registered block styles, as $block_name => $block_style_name => $block_style_properties multidimensional arrays.
$instanceWP_Block_Styles_Registry|nullprivate static
Container for the main instance of the class.

Methods · 7

Source code

#[AllowDynamicProperties]final class WP_Block_Styles_Registry {	/**	 * Registered block styles, as `$block_name => $block_style_name => $block_style_properties` multidimensional arrays.	 *	 * @since 5.3.0	 *	 * @var array[]	 */	private $registered_block_styles = array(); 	/**	 * Container for the main instance of the class.	 *	 * @since 5.3.0	 *	 * @var WP_Block_Styles_Registry|null	 */	private static $instance = null; 	/**	 * 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.	 *	 * @since 5.3.0	 * @since 6.6.0 Added ability to register style across multiple block types along with theme.json-like style data.	 *	 * @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/	 *	 * @param string|string[] $block_name       Block type name including namespace or array of namespaced block type names.	 * @param array           $style_properties {	 *     Array containing the properties of the style.	 *	 *     @type string $name         The identifier of the style used to compute a CSS class.	 *     @type string $label        A human-readable label for the style.	 *     @type string $inline_style Inline CSS code that registers the CSS class required	 *                                for the style.	 *     @type string $style_handle The handle to an already registered style that should be	 *                                enqueued in places where block styles are needed.	 *     @type bool   $is_default   Whether this is the default style for the block type.	 *     @type array  $style_data   Theme.json-like object to generate CSS from.	 * }	 * @return bool True if the block style was registered with success and false otherwise.	 */	public 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;

Changelog

Introduced in 5.3.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-block-styles-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.