PluginProbe
Gutenberg / 16.2.0
Gutenberg v16.2.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / experimental / interactivity-api / scripts.php

scripts.php in Gutenberg 16.2.0, at lib/experimental/interactivity-api/scripts.php

29 lines 1019 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Utils to optimize the interactive scripts.
4 *
5 * @package Gutenberg
6 * @subpackage Interactivity API
7 */
8
9 /**
10 * Move interactive scripts to the footer. This is a temporary measure to make
11 * it work with `wp_store` and it should be replaced with deferred scripts or
12 * modules.
13 */
14 function gutenberg_interactivity_move_interactive_scripts_to_the_footer() {
15 // Move the @wordpress/interactivity package to the footer.
16 wp_script_add_data( 'wp-interactivity', 'group', 1 );
17
18 // Move all the view scripts of the interactive blocks to the footer.
19 $registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
20 foreach ( array_values( $registered_blocks ) as $block ) {
21 if ( isset( $block->supports['interactivity'] ) && $block->supports['interactivity'] ) {
22 foreach ( $block->view_script_handles as $handle ) {
23 wp_script_add_data( $handle, 'group', 1 );
24 }
25 }
26 }
27 }
28 add_action( 'wp_enqueue_scripts', 'gutenberg_interactivity_move_interactive_scripts_to_the_footer', 11 );
29