[wp-trac] [WordPress Trac] #29722: wp_localize_script should be able to manage scalars
WordPress Trac
noreply at wordpress.org
Sun Sep 21 23:29:05 UTC 2014
#29722: wp_localize_script should be able to manage scalars
-------------------------+-----------------------------
Reporter: Fab1en | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: trunk
Severity: normal | Keywords:
Focuses: javascript |
-------------------------+-----------------------------
We should be able to do this :
{{{
wp_localize_script( 'twentyfourteen-script', 'localized_variable', 1 );
}}}
As of version 4.0, this is working : it generates a JavaScript scalar
value, but a PHP Warning is thrown :
`Warning: Cannot use a scalar value as an array in
/server/wordpress/versions/git-repo/src/wp-includes/class.wp-scripts.php
on line 167`
Note that the correct JavaScript code is output :
{{{
<script type='text/javascript'>
/* <![CDATA[ */
var localized_variable = 1;
/* ]]> */
</script>
}}}
The warning is not triggered when the scalar variable is a string.
{{{
wp_localize_script( 'twentyfourteen-script', 'localized_variable', 'a
string' );
}}}
This is just because strings can be accessed like arrays, but this is not
the intended effect.
A simple test for scalar values can fix that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29722>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list