Skip to content

Commit

Permalink
Enqueue styles only for the legacy version
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Jun 27, 2022
1 parent 7f011ec commit b325b0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 0 additions & 5 deletions packages/block-library/src/comments/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,5 @@
}
},
"editorStyle": "wp-block-comments-editor",
"style": [
"wp-block-post-comments",
"wp-block-buttons",
"wp-block-button"
],
"usesContext": [ "postId", "postType" ]
}
22 changes: 22 additions & 0 deletions packages/block-library/src/comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<div %1$s>%2$s</div>', $wrapper_attributes, $output );
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b325b0f

Please sign in to comment.