Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script Modules: Adjust filter and ID #62170

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/experimental/script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ function gutenberg_dequeue_module( $module_identifier ) {
* This embeds data in the page HTML so that it is available on page load.
*
* Data can be associated with a given Script Module by using the
* `scriptmoduledata_{$module_id}` filter.
* `script_module_data_{$module_id}` filter.
*
* The data for a given Script Module will be JSON serialized in a script tag with an ID
* like `wp-scriptmodule-data_{$module_id}`.
* like `wp-script-module-data-{$module_id}`.
*/
function gutenberg_print_script_module_data(): void {
$get_marked_for_enqueue = new ReflectionMethod( 'WP_Script_Modules', 'get_marked_for_enqueue' );
Expand Down Expand Up @@ -236,14 +236,14 @@ function gutenberg_print_script_module_data(): void {
* If the filter returns no data (an empty array), nothing will be embedded in the page.
*
* The data for a given Script Module, if provided, will be JSON serialized in a script tag
* with an ID like `wp-scriptmodule-data_{$module_id}`.
* with an ID like `wp-script-module-data-{$module_id}`.
*
* The dynamic portion of the hook name, `$module_id`, refers to the Script Module ID that
* the data is associated with.
*
* @param array $data The data that should be associated with the array.
*/
$data = apply_filters( "scriptmoduledata_{$module_id}", array() );
$data = apply_filters( "script_module_data_{$module_id}", array() );

if ( is_array( $data ) && ! empty( $data ) ) {
/*
Expand Down Expand Up @@ -281,7 +281,7 @@ function gutenberg_print_script_module_data(): void {
wp_json_encode( $data, $json_encode_flags ),
array(
'type' => 'application/json',
'id' => "wp-scriptmodule-data_{$module_id}",
'id' => "wp-script-module-data-{$module_id}",
)
);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/interactivity/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ export function store(
export const parseInitialData = ( dom = document ) => {
const jsonDataScriptTag =
// Preferred Script Module data passing form
dom.getElementById( 'wp-scriptmodule-data_@wordpress/interactivity' ) ??
dom.getElementById(
'wp-script-module-data-@wordpress/interactivity'
) ??
// Legacy form
dom.getElementById( 'wp-interactivity-data' );
if ( jsonDataScriptTag?.textContent ) {
Expand Down
Loading