Last active
December 22, 2015 07:18
-
-
Save petenelson/6436984 to your computer and use it in GitHub Desktop.
WordPress: wp_localize_script with a stdClass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$test_data = array(); | |
$test_data[] = new stdClass(); | |
$test_data[0]->field1 = 'hello'; | |
$test_data[0]->field2 = 'world'; | |
$test_data[0]->my_object = new stdClass(); | |
$test_data[0]->my_object->field3 = 'more hello world'; | |
wp_localize_script( 'gmec-intranet', 'test_data', $test_data ); | |
// outputs the following Javascript | |
// var test_data = [{"field1":"hello","field2":"world","my_object":{"field3":"more hello world"}}]; | |
// console screenshot: http://i.imgur.com/lhyhOPw.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment