-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename WP_Interactivity_Store and move filter to scripts file
- Loading branch information
1 parent
67c7764
commit 4894886
Showing
6 changed files
with
60 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Utils to optimize the interactive scripts. | ||
* | ||
* @package Gutenberg | ||
* @subpackage Interactivity API | ||
*/ | ||
|
||
/** | ||
* Move interactive scripts to the footer. This is a temporary measure to make | ||
* it work with `wp_store` and it should be replaced with deferred scripts or | ||
* modules. | ||
*/ | ||
function gutenberg_interactivity_move_interactive_scripts_to_the_footer() { | ||
// Move the @wordpress/interactivity package to the footer. | ||
wp_script_add_data( 'wp-interactivity', 'group', 1 ); | ||
|
||
// Move all the view scripts of the interactive blocks to the footer. | ||
$registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered(); | ||
foreach ( array_values( $registered_blocks ) as $block ) { | ||
if ( isset( $block->supports['interactivity'] ) && $block->supports['interactivity'] ) { | ||
foreach ( $block->view_script_handles as $handle ) { | ||
wp_script_add_data( $handle, 'group', 1 ); | ||
} | ||
} | ||
} | ||
} | ||
add_action( 'wp_enqueue_scripts', 'gutenberg_interactivity_move_interactive_scripts_to_the_footer', 11 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters