_wp_multiple_block_styles() – Allows multiple block styles.

You appear to be a bot. Output may be restricted

Description

Allows multiple block styles.

Usage

$array = _wp_multiple_block_styles( $metadata );

Parameters

$metadata
( array ) required – Metadata for registering a block type.

Returns

array Metadata for registering a block type.

Source

File name: wordpress/wp-includes/blocks.php
Lines:

1 to 33 of 33
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;
}
 

 View on GitHub View on Trac