script_module_data_(module_id) filter-hookWP 6.7.0

Filters data associated with a given Script Module.

Script Modules may require data that is required for initialization or is essential to have immediately available on page load. These are suitable use cases for this data.

The dynamic portion of the hook name, $module_id, refers to the Script Module ID that the data is associated with.

This is best suited to pass essential data that must be available to the module for initialization or immediately on page load. It does not replace the REST API or fetching data from the client.

Usage

add_filter( 'script_module_data_(module_id)', 'wp_kama_script_module_data_id_filter' );

/**
 * Function for `script_module_data_(module_id)` filter-hook.
 * 
 * @param array $data The data associated with the Script Module.
 *
 * @return array
 */
function wp_kama_script_module_data_id_filter( $data ){

	// filter...
	return $data;
}
$data(array)
The data associated with the Script Module.

Changelog

Since 6.7.0 Introduced.

Where the hook is called

WP_Script_Modules::print_script_module_data()
script_module_data_(module_id)
wp-includes/class-wp-script-modules.php 440
$data = apply_filters( "script_module_data_{$module_id}", array() );

Where the hook is used in WordPress

wp-includes/interactivity-api/class-wp-interactivity-api.php 349
add_filter( 'script_module_data_@wordpress/interactivity', array( $this, 'filter_script_module_interactivity_data' ) );
wp-includes/interactivity-api/class-wp-interactivity-api.php 350
add_filter( 'script_module_data_@wordpress/interactivity-router', array( $this, 'filter_script_module_interactivity_router_data' ) );