_wp_multiple_block_styles()
Allows multiple block styles.
This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.
No Hooks.
Return
Array
. Metadata for registering a block type.
Usage
_wp_multiple_block_styles( $metadata );
- $metadata(array) (required)
- Metadata for registering a block type.
Changelog
Since 5.9.0 | Introduced. |
Code of _wp_multiple_block_styles() wp multiple block styles WP 6.0
function _wp_multiple_block_styles( $metadata ) { foreach ( array( 'style', 'editorStyle' ) as $key ) { if ( ! empty( $metadata[ $key ] ) && is_array( $metadata[ $key ] ) ) { $default_style = array_shift( $metadata[ $key ] ); foreach ( $metadata[ $key ] as $handle ) { $args = array( 'handle' => $handle ); if ( 0 === strpos( $handle, 'file:' ) && isset( $metadata['file'] ) ) { $style_path = remove_block_asset_path_prefix( $handle ); $theme_path_norm = wp_normalize_path( get_theme_file_path() ); $style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) ); $is_theme_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $theme_path_norm ); $style_uri = plugins_url( $style_path, $metadata['file'] ); if ( $is_theme_block ) { $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) ); } $args = array( 'handle' => sanitize_key( "{$metadata['name']}-{$style_path}" ), 'src' => $style_uri, ); } wp_enqueue_block_style( $metadata['name'], $args ); } // Only return the 1st item in the array. $metadata[ $key ] = $default_style; } } return $metadata; }