[wp-trac] [WordPress Trac] #58873: Add function to pass variables to scripts
WordPress Trac
noreply at wordpress.org
Sat Aug 16 21:38:53 UTC 2025
#58873: Add function to pass variables to scripts
-----------------------------+-----------------------
Reporter: apedog | Owner: (none)
Type: feature request | Status: reopened
Priority: normal | Milestone:
Component: Script Loader | Version: 5.7
Severity: normal | Resolution:
Keywords: 2nd-opinion | Focuses:
-----------------------------+-----------------------
Comment (by westonruter):
@jonsurrell What if we take your approach for script modules and make it
available to classic scripts as well?
Before printing any inline `before`/localize/translations scripts in
`WP_Scripts`, we apply `script_data_{$handle}` filters to obtain any data
intended to be exported from PHP to JS, and then construct a JSON `script`
to print first? This will then be available for classic scripts to parse
out of the `textContent` on demand.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58873#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list