#61510 closed feature request (fixed)
Script Modules: Add mechanism to pass data from server to client
| Reported by: | jonsurrell | Owned by: | jonsurrell |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.7 |
| Component: | Script Loader | Version: | 6.5 |
| Severity: | normal | Keywords: | has-patch has-unit-tests needs-dev-note |
| Cc: | Focuses: | javascript |
Description
One useful feature available to Scripts that Script Modules do not support is a way for the server to send data to the client with the page. Scripts typically do this with wp_add_inline_script.
Proposal: Server to client data sharing for Script Modules proposes a mechanism for Script Modules to fill this need.
Part of #60647.
Change History (6)
This ticket was mentioned in PR #6682 on WordPress/wordpress-develop by @jonsurrell.
2 years ago
#2
- Keywords has-patch has-unit-tests added
@Bernhard Reiter commented on PR #6682:
2 years ago
#3
Committed to Core in https://core.trac.wordpress.org/changeset/58579.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Add the
print_script_module_datafunction to theWP_Script_Modulesclass.Register hooks to call this function on
wp_footerandadmin_print_footer_scripts.See the Make/Core Proposal and the PR in Gutenberg. In summary (from the proposal):
The new filter is
"script_module_data_{$module_id}". It should accept and return an array that will be serialized in page HTML (if it is not empty):#6683 includes an example of usage in for Core Script Modules.
Closes #6433 (superseded).
Trac ticket: https://core.trac.wordpress.org/ticket/61510