mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-06 13:44:30 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@54155 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2531,28 +2531,30 @@ function wp_enqueue_registered_block_scripts_and_styles() {
|
||||
return;
|
||||
}
|
||||
|
||||
$load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
|
||||
$load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
|
||||
|
||||
$block_registry = WP_Block_Type_Registry::get_instance();
|
||||
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
|
||||
// Front-end styles.
|
||||
if ( ! empty( $block_type->style ) ) {
|
||||
wp_enqueue_style( $block_type->style );
|
||||
// Front-end and editor styles.
|
||||
foreach ( $block_type->style_handles as $style_handle ) {
|
||||
wp_enqueue_style( $style_handle );
|
||||
}
|
||||
|
||||
// Front-end script.
|
||||
if ( ! empty( $block_type->script ) ) {
|
||||
wp_enqueue_script( $block_type->script );
|
||||
// Front-end and editor scripts.
|
||||
foreach ( $block_type->script_handles as $script_handle ) {
|
||||
wp_enqueue_script( $script_handle );
|
||||
}
|
||||
|
||||
// Editor styles.
|
||||
if ( $load_editor_scripts && ! empty( $block_type->editor_style ) ) {
|
||||
wp_enqueue_style( $block_type->editor_style );
|
||||
}
|
||||
if ( $load_editor_scripts_and_styles ) {
|
||||
// Editor styles.
|
||||
foreach ( $block_type->editor_style_handles as $editor_style_handle ) {
|
||||
wp_enqueue_style( $editor_style_handle );
|
||||
}
|
||||
|
||||
// Editor script.
|
||||
if ( $load_editor_scripts && ! empty( $block_type->editor_script ) ) {
|
||||
wp_enqueue_script( $block_type->editor_script );
|
||||
// Editor scripts.
|
||||
foreach ( $block_type->editor_script_handles as $editor_script_handle ) {
|
||||
wp_enqueue_script( $editor_script_handle );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user