[wp-trac] [WordPress Trac] #34590: Add an complementary method to wp_localize_script for non i18n related vars
WordPress Trac
noreply at wordpress.org
Thu Nov 5 09:53:56 UTC 2015
#34590: Add an complementary method to wp_localize_script for non i18n related vars
-----------------------------+-----------------------------
Reporter: sanchothefat | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: trunk
Severity: normal | Keywords:
Focuses: javascript |
-----------------------------+-----------------------------
There has been a lot of discussion and a few tickets raised around how
`wp_localize_script` handles integers and booleans for example.
The discussion in each case brings mention of needing a new method, from
@nacin [https://core.trac.wordpress.org/ticket/26111#comment:29 here] in
ticket #26111, and @adamsilverstein
[https://core.trac.wordpress.org/ticket/25280?cversion=2&cnum_hist=1#comment:3
here] agreeing with @c3mdigital on #25280 that `wp_localize_script` was
never intended for adding variables like the admin AJAX URL.
I couldn't find an actual ticket for discussing and possibly adding a new
method that works exactly like `wp_localize_script` but that does a
straight forward `json_encode` of the data so apologies if this is a dupe.
Advantages would be simplified javascript eg. less need for `parseInt`
etc, easier to use strict comparisons. The intention of the code would be
clearer too having a separation of i18n and generic variables.
Additionally developers could just switch to the new method to deliver
everything that way in future if they wished as strings would be
unaffected.
Possible name for the function would be `wp_add_script_vars`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34590>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list