Skip to content

Commit

Permalink
Automatically enqueue view_script when the block is rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jul 27, 2021
1 parent a30b8f8 commit 1791165
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class WP_Block_Type {
* `uses_context`, and `provides_context` properties.
* @since 5.6.0 Added the `api_version` property.
* @since 5.8.0 Added the `variations` property.
* @since 5.9.0 Added the `view_script` property.
*
* @see register_block_type()
*
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ public function render( $options = array() ) {
wp_enqueue_script( $this->block_type->script );
}

if ( ! empty( $this->block_type->view_script ) && empty( $this->block_type->render_callback ) ) {
wp_enqueue_script( $this->block_type->view_script );
}

if ( ! empty( $this->block_type->style ) ) {
wp_enqueue_style( $this->block_type->style );
}
Expand Down

0 comments on commit 1791165

Please sign in to comment.