Make WordPress Core

Opened 9 years ago

Closed 6 years ago

#34590 closed feature request (duplicate)

Add an complementary method to wp_localize_script for non i18n related vars

Reported by: sanchothefat's profile sanchothefat Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Script Loader Keywords:
Focuses: javascript Cc:


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 here in ticket #26111, and @adamsilverstein 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.

Change History (2)

#1 @SergeyBiryukov
9 years ago

Related: #11520, #21547, #23590.

[18464] introduced wp_add_script_data(), which was later reverted in [18490] and [18491].

[19217] introduced wp_add_script_before(), which was later reverted in [19573].

Relevant IRC discussion:

#2 @johnbillion
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #29722.

Note: See TracTickets for help on using tickets.