_wp_multiple_block_styles( array $metadata )

Allows multiple block styles.


Parameters

$metadata

(array) (Required) Metadata for registering a block type.


Top ↑

Return

(array) Metadata for registering a block type.


Top ↑

Source

File: wp-includes/blocks.php

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;
}


Top ↑

Changelog

Changelog
Version Description
5.9.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.