[wp-trac] [WordPress Trac] #25280: wp_localize_script unexpectedly converts numbers to strings
WordPress Trac
noreply at wordpress.org
Wed May 7 17:44:50 UTC 2014
#25280: wp_localize_script unexpectedly converts numbers to strings
------------------------------------+-------------------------
Reporter: adamsilverstein | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.0
Component: I18N | Version: 3.2
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses: javascript
------------------------------------+-------------------------
Changes (by adamsilverstein):
* keywords: has-patch => has-patch dev-feedback
* focuses: => javascript
Comment:
Looks good, I verified this works correctly passing numbers as numbers and
booleans as booleans.
I added the following code to my template:
```
wp_enqueue_script( 'localize_test', get_template_directory_uri() .
'/localize_script.js', array(), '1.0.0', true );
$array_to_localize = array(
'a_string' => __( 'Some String' ),
'a_number' => 10,
't_boolean' => true,
'f_boolean' => false,
);
wp_localize_script( 'localize_test', 'localized_variable',
$array_to_localize );
```
the created a localize_script.js file with the single line ```console.log(
localized_variable );```
result was as expected:
[[Image(http://cl.ly/image/1N1T3a2O0J3B/revisions%20test%20%7C%20Local%20WordPress%20Trunk%20Dev%202014-05-07%2010-41-45%202014-05-07%2010-41-48.jpg)]]
by comparison, before the patch is applied all values are passed as
strings:
[[Image(http://cl.ly/image/241S0m2j2c0Y/revisions%20test%20%7C%20Local%20WordPress%20Trunk%20Dev%202014-05-07%2010-42-40%202014-05-07%2010-42-41.jpg)]]
--
Ticket URL: <https://core.trac.wordpress.org/ticket/25280#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list