diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index f6e023c67f115..8c272c088aad2 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -71,6 +71,14 @@ function remove_block_asset_path_prefix( $asset_handle_or_path ) { * @return string Generated asset name for the block's field. */ function generate_block_asset_handle( $block_name, $field_name ) { + if ( 0 === strpos( $block_name, 'core/' ) ) { + $asset_handle = str_replace( 'core/', 'wp-block-', $block_name ); + if ( 0 === strpos( $field_name, 'editor' ) ) { + $asset_handle .= '-editor'; + } + return $asset_handle; + } + $field_mappings = array( 'editorScript' => 'editor-script', 'script' => 'script', diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 392f7e2977b5a..e9e607d89aa00 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -144,6 +144,30 @@ function test_generate_block_asset_handle() { ); } + /** + * @ticket 50328 + */ + function test_generate_block_asset_handle_core_block() { + $block_name = 'core/paragraph'; + + $this->assertSame( + 'wp-block-paragraph-editor', + generate_block_asset_handle( $block_name, 'editorScript' ) + ); + $this->assertSame( + 'wp-block-paragraph', + generate_block_asset_handle( $block_name, 'script' ) + ); + $this->assertSame( + 'wp-block-paragraph-editor', + generate_block_asset_handle( $block_name, 'editorStyle' ) + ); + $this->assertSame( + 'wp-block-paragraph', + generate_block_asset_handle( $block_name, 'style' ) + ); + } + /** * @ticket 50263 */