Skip to content

Commit

Permalink
Use the register_block_type_args filter
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jun 8, 2021
1 parent d3b95b8 commit 67582a8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,21 @@ function gutenberg_migrate_old_typography_shape( $metadata ) {
/**
* Filters the content of a single block.
*
* @param array $metadata Metadata for registering a block type.
* @param array $args Array of arguments for registering a block type.
*
* @return array Returns the $metadata with any missing `style` and `editorStyle` added.
*/
function gutenberg_add_missing_styles_to_core_block_json( $metadata ) {
if ( ! empty( $metadata['name'] ) && 0 === strpos( $metadata['name'], 'core/' ) ) {
$block_name = str_replace( 'core/', '', $metadata['name'] );
function gutenberg_add_missing_styles_to_core_block_json( $args ) {
if ( ! empty( $args['name'] ) && 0 === strpos( $args['name'], 'core/' ) ) {
$block_name = str_replace( 'core/', '', $args['name'] );

if ( ! isset( $metadata['style'] ) ) {
$metadata['style'] = "wp-block-$block_name";
if ( ! isset( $args['style'] ) ) {
$args['style'] = "wp-block-$block_name";
}
if ( ! isset( $metadata['editorStyle'] ) ) {
$metadata['editorStyle'] = "wp-block-$block_name-editor";
if ( ! isset( $args['editor_style'] ) ) {
$args['editor_style'] = "wp-block-$block_name-editor";
}
}
return $metadata;
return $args;
}
add_filter( 'block_type_metadata', 'gutenberg_add_missing_styles_to_core_block_json' );
add_filter( 'register_block_type_args', 'gutenberg_add_missing_styles_to_core_block_json' );

0 comments on commit 67582a8

Please sign in to comment.