Blocks: Allow registering multiple items for all supported asset types

Follow-up #54337, [52069]. Part of https://github.com/WordPress/gutenberg/issues/41236. More details in https://github.com/WordPress/gutenberg/issues/33542.

Allow passing more than one script per block for `editorScript`, `script`, and `viewScript` fields in the `block.json` metadata file. This aligns with the previously added changes for `style` and `editorStyle` fields.

This change impacts the `WP_Block_Type` class and the REST API endpoint for block types. To ensure backward compatibiliy old names were soft deprecated in favor of new fields that work with array values and have `_handles` suffix.

Props zieladam, dlh, timothyblynjacobs, aristath, bernhard-reiter.
Fixes #56408.


Built from https://develop.svn.wordpress.org/trunk@54155


git-svn-id: http://core.svn.wordpress.org/trunk@53714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
gziolo
2022-09-14 10:52:08 +00:00
parent 1f47c2bcbf
commit 714e57b2fc
8 changed files with 410 additions and 220 deletions

View File

@@ -324,17 +324,16 @@ function _wp_get_iframed_editor_assets() {
$block_registry = WP_Block_Type_Registry::get_instance();
foreach ( $block_registry->get_all_registered() as $block_type ) {
if ( ! empty( $block_type->style ) ) {
$style_handles[] = $block_type->style;
}
$style_handles = array_merge(
$style_handles,
$block_type->style_handles,
$block_type->editor_style_handles
);
if ( ! empty( $block_type->editor_style ) ) {
$style_handles[] = $block_type->editor_style;
}
if ( ! empty( $block_type->script ) ) {
$script_handles[] = $block_type->script;
}
$script_handles = array_merge(
$script_handles,
$block_type->script_handles
);
}
$style_handles = array_unique( $style_handles );