Skip to content

Commit

Permalink
Register and enqueue comments form module
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Dec 12, 2023
1 parent 7c3ca02 commit da4d6dd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/block-library/src/post-comments-form/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@ class="wp-block-post-comments-form__error"
}
}

$view_asset = 'wp-block-post-comments-form-view';
if ( ! wp_script_is( $view_asset ) ) {
$script_handles = $block->block_type->view_script_handles;
$is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
$view_asset = 'wp-block-post-comments-form-view';
$script_handles = $block->block_type->view_script_handles;

if ( $is_gutenberg_plugin ) {
gutenberg_enqueue_module( '@wordpress/block-library/post-comments-form' );
// Remove the view script because we are using the module.
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
} elseif ( ! wp_script_is( $view_asset ) ) {
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
if ( ! $enhanced_submission && in_array( $view_asset, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
Expand Down Expand Up @@ -207,6 +213,15 @@ function register_block_core_post_comments_form() {
'render_callback' => 'render_block_core_post_comments_form',
)
);

if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
gutenberg_register_module(
'@wordpress/block-library/post-comments-form',
'/wp-content/plugins/gutenberg/build/interactivity/comments.min.js',
array( '@wordpress/interactivity' ),
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
);
}
}
add_action( 'init', 'register_block_core_post_comments_form' );

Expand Down

0 comments on commit da4d6dd

Please sign in to comment.