| 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 |
|