From b325b0fa9c75e57c721e8ba503d4641c76481db6 Mon Sep 17 00:00:00 2001 From: David Arenas Date: Mon, 27 Jun 2022 18:52:22 +0200 Subject: [PATCH] Enqueue styles only for the legacy version --- .../block-library/src/comments/block.json | 5 ----- packages/block-library/src/comments/index.php | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/comments/block.json b/packages/block-library/src/comments/block.json index 9469917ef150d0..51a926b8178151 100644 --- a/packages/block-library/src/comments/block.json +++ b/packages/block-library/src/comments/block.json @@ -29,10 +29,5 @@ } }, "editorStyle": "wp-block-comments-editor", - "style": [ - "wp-block-post-comments", - "wp-block-buttons", - "wp-block-button" - ], "usesContext": [ "postId", "postType" ] } diff --git a/packages/block-library/src/comments/index.php b/packages/block-library/src/comments/index.php index 2922821142ddcf..bc44255fd3cf52 100644 --- a/packages/block-library/src/comments/index.php +++ b/packages/block-library/src/comments/index.php @@ -65,6 +65,7 @@ function render_block_core_comments_query_loop( $attributes, $content, $block ) $output = ob_get_clean(); wp_enqueue_script( 'comment-reply' ); + enqueue_legacy_post_comments_block_styles( $block->name ); return sprintf( '
%2$s
', $wrapper_attributes, $output ); } @@ -100,6 +101,27 @@ function comments_query_loop_block_form_defaults( $fields ) { } add_filter( 'comment_form_defaults', 'comments_query_loop_block_form_defaults' ); +/** + * Enqueues styles for the legacy `core/post-comments` block. + * + * @param string $block_name Name of the new block type. + */ +function enqueue_legacy_post_comments_block_styles( $block_name ) { + static $are_styles_enqueued = false; + + if ( ! $are_styles_enqueued ) { + $handles = array( + 'wp-block-post-comments', + 'wp-block-buttons', + 'wp-block-button', + ); + foreach( $handles as $handle ) { + wp_enqueue_block_style( $block_name, array( 'handle' => $handle) ); + } + $are_styles_enqueued = true; + } +} + /** * Renders the legacy `core/post-comments` block on the server. * It triggers a developer warning and then calls the renamed