Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
working POC with the comments-form block.
  • Loading branch information
aristath committed Oct 7, 2021
commit 0b3f55b74ce8391761f25a3812667c8fd7711dc7
40 changes: 40 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,43 @@ function gutenberg_migrate_old_typography_shape( $metadata ) {
if ( ! function_exists( 'wp_migrate_old_typography_shape' ) ) {
add_filter( 'block_type_metadata', 'gutenberg_migrate_old_typography_shape' );
}

/**
* Allow multiple block styles.
*
* @param array $metadata Metadata for registering a block type.
*
* @return array
*/
function gutenberg_multiple_block_styles( $metadata ) {
foreach ( array( 'style', 'editorStyle' ) as $key ) {
if ( isset( $metadata[ $key ] ) && is_array( $metadata[ $key ] ) ) {

// Enqueue multiple styles on block render.
add_filter(
"render_block_{$metadata['name']}",
/**
* Filters the content of a single block.
*
* @since 5.0.0
*
* @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes.
*/
function( $block_content, $block ) use ( $metadata, $key ) {
foreach ( $metadata[ $key ] as $handle ) {
wp_enqueue_style( $handle );
}
return $block_content;
},
10,
2
);

// Only return the 1st item in the array.
$metadata[ $key ] = $metadata[ $key ][0];
}
}
return $metadata;
}
add_filter( 'block_type_metadata', 'gutenberg_multiple_block_styles' );
2 changes: 1 addition & 1 deletion packages/block-library/src/post-comments-form/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"lineHeight": true
}
},
"style": "wp-block-post-comments-form"
"style": [ "wp-block-post-comments-form", "wp-block-buttons", "wp-block-button" ]
}
14 changes: 0 additions & 14 deletions packages/block-library/src/post-comments-form/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,3 @@ function gutenberg_comment_form_block_form_defaults( $fields ) {
return $fields;
}
add_filter( 'comment_form_defaults', 'gutenberg_comment_form_block_form_defaults' );

add_action(
'wp_enqueue_scripts',
/**
* Add the button stylesheet as a dependency for the post-comment form stylesheet.
*/
function() {
global $wp_styles;
if ( ! empty( $wp_styles->registered ) && ! empty( $wp_styles->registered['wp-block-post-comments-form'] ) ) {
$wp_styles->registered['wp-block-post-comments-form']->deps[] = 'wp-block-button';
}
},
1
);