Make WordPress Core


Ignore:
Timestamp:
09/14/2022 10:50:26 AM (2 years 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/class-wp-block.php

    r54133 r54155  
    261261        }
    262262
    263         if ( ! empty( $this->block_type->script ) ) {
    264             wp_enqueue_script( $this->block_type->script );
    265         }
    266 
    267         if ( ! empty( $this->block_type->view_script ) && empty( $this->block_type->render_callback ) ) {
    268             wp_enqueue_script( $this->block_type->view_script );
    269         }
    270 
    271         if ( ! empty( $this->block_type->style ) ) {
    272             wp_enqueue_style( $this->block_type->style );
     263        if ( ( ! empty( $this->block_type->script_handles ) ) ) {
     264            foreach ( $this->block_type->script_handles as $script_handle ) {
     265                wp_enqueue_script( $script_handle );
     266            }
     267        }
     268
     269        if ( ! empty( $this->block_type->view_script_handles ) && empty( $this->block_type->render_callback ) ) {
     270            foreach ( $this->block_type->view_script_handles as $view_script_handle ) {
     271                wp_enqueue_script( $view_script_handle );
     272            }
     273        }
     274
     275        if ( ( ! empty( $this->block_type->style_handles ) ) ) {
     276            foreach ( $this->block_type->style_handles as $style_handle ) {
     277                wp_enqueue_style( $style_handle );
     278            }
    273279        }
    274280
Note: See TracChangeset for help on using the changeset viewer.