Make WordPress Core


Ignore:
Timestamp:
09/14/2022 10:50:26 AM (20 months ago)
Author:
gziolo
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r54118 r54155  
    25322532    }
    25332533
    2534     $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
     2534    $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
    25352535
    25362536    $block_registry = WP_Block_Type_Registry::get_instance();
    25372537    foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
    2538         // Front-end styles.
    2539         if ( ! empty( $block_type->style ) ) {
    2540             wp_enqueue_style( $block_type->style );
    2541         }
    2542 
    2543         // Front-end script.
    2544         if ( ! empty( $block_type->script ) ) {
    2545             wp_enqueue_script( $block_type->script );
    2546         }
    2547 
    2548         // Editor styles.
    2549         if ( $load_editor_scripts && ! empty( $block_type->editor_style ) ) {
    2550             wp_enqueue_style( $block_type->editor_style );
    2551         }
    2552 
    2553         // Editor script.
    2554         if ( $load_editor_scripts && ! empty( $block_type->editor_script ) ) {
    2555             wp_enqueue_script( $block_type->editor_script );
     2538        // Front-end and editor styles.
     2539        foreach ( $block_type->style_handles as $style_handle ) {
     2540            wp_enqueue_style( $style_handle );
     2541        }
     2542
     2543        // Front-end and editor scripts.
     2544        foreach ( $block_type->script_handles as $script_handle ) {
     2545            wp_enqueue_script( $script_handle );
     2546        }
     2547
     2548        if ( $load_editor_scripts_and_styles ) {
     2549            // Editor styles.
     2550            foreach ( $block_type->editor_style_handles as $editor_style_handle ) {
     2551                wp_enqueue_style( $editor_style_handle );
     2552            }
     2553
     2554            // Editor scripts.
     2555            foreach ( $block_type->editor_script_handles as $editor_script_handle ) {
     2556                wp_enqueue_script( $editor_script_handle );
     2557            }
    25562558        }
    25572559    }
Note: See TracChangeset for help on using the changeset viewer.