wpseek.com
A WordPress-centric search engine for devs and theme authors



_wp_multiple_block_styles › WordPress Function

Sincen/a
Deprecatedn/a
_wp_multiple_block_styles ( $metadata )
Parameters:
  • (array) $metadata Metadata for registering a block type.
    Required: Yes
Returns:
  • (array)
Defined at:
Codex:

Allow multiple block styles.



Source

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 );
					$args       = array(
						'handle' => sanitize_key( "{$metadata['name']}-{$style_path}" ),
						'src'    => plugins_url( $style_path, $metadata['file'] ),
					);
				}

				wp_enqueue_block_style( $metadata['name'], $args );
			}

			// Only return the 1st item in the array.
			$metadata[ $key ] = $default_style;
		}
	}
	return $metadata;
}