wp_localize_script with boolean and init

I have problem with wp_localize_script, That I cannot get boolean and int as variable

wp_enqueue_script( 'helloworld' , 'helloworld.js', false, '1.0.0', true);

$site_config = array();

$site_config['boo'] = (bool)true;
$site_config['number'] = (int)1;

wp_localize_script( 'helloworld' , 'site_config' , $site_config );

Why I getting :

var site_config = {"boo":"1","number":"1"};

Why not :

var site_config = {"boo":true,"number":1};
  • WordPress 4.6 (latest)
  • PHP 5.6.10

Does not it fixed ? https://core.trac.wordpress.org/ticket/25280 , I do anything wrong or missing something ?

4 Answers
4

I just do something like this so long :

wp_add_inline_script('helloworld','var site_config ='.json_encode($site_config));

Leave a Comment