[wp-hackers] wp_localize_script() issue

Philip Walton philip at philipwalton.com
Mon Jun 20 01:59:29 UTC 2011

When using wp_localize_script(), the third parameter accepts an array of 
data to pass.

I've just noticed that if the keys of the array contain minuses (dashes) 
in them, this will cause errors in your javascript. Firebug is telling 
me "missing : after property id", which I assume is a parse error.

I know I can solve this by not putting minuses in my array key names, 
but for backwards comparability, it would make my life much easier if I 
could in this situation.

Has anyone else encountered this? Is there a known workaround other than 
removing the minuses from the array keys or json_encoding the entire array?

More information about the wp-hackers mailing list