WordPress Version: 5.9
/**
* Allow multiple block styles.
*
* @since 5.9.0
*
* @param array $metadata Metadata for registering a block type.
* @return array Metadata for registering a block type.
*/
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;
}