[wp-trac] [WordPress Trac] #29722: wp_localize_script should be able to manage scalars
WordPress Trac
noreply at wordpress.org
Tue Jan 12 14:59:28 UTC 2021
#29722: wp_localize_script should be able to manage scalars
-------------------------------------------------+-------------------------
Reporter: Fab1en | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.7
Component: Script Loader | Version: 3.3
Severity: normal | Resolution:
Keywords: needs-docs php8 needs-dev-note has- | Focuses: javascript
unit-tests needs-patch |
-------------------------------------------------+-------------------------
Changes (by azaozz):
* keywords: has-patch needs-docs php8 needs-dev-note has-unit-tests =>
needs-docs php8 needs-dev-note has-unit-tests needs-patch
Comment:
Been chatting with @andraganescu about what's the right solution here.
This ticket is a partial duplicate of #25280. Specifically see this
comment: https://core.trac.wordpress.org/ticket/25280#comment:45. In
short:
1.
[https://developer.wordpress.org/reference/functions/wp_localize_script/
wp_localize_script()] should only be used to localize scripts, not to pass
arbitrary data to them. There is
[https://developer.wordpress.org/reference/functions/wp_add_inline_script/
wp_add_inline_script()] for that.
2. For translations `wp_localize_script()` and the underlaying
`WP_Scripts::localize()` have been phased out in core, in favor of
`WP_Scripts::set_translations()`.
In that terms thinking this ticket should be "wontfix", same as #25280.
The only thing that needs fixing is the PHP 8.0 bug, and perhaps some more
inline docs to explain why not to use this function for arbitrary data.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29722#comment:34>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list