How to move Data from PHP to JS
Simple as it is: wp_localize_script()
Example: (can be used with login_enqueue_scripts and admin_enqueue_scripts hooks as well)
add_action( 'wp_enqueue_scripts', 'wpse115840_scripts' );
wp_enqueue_script( 'wpse_handle', etc... );
// Here goes the magic:
wp_localize_script( 'wpse_handle', 'wspeObject', array(
'foo' => 'bar',
'bar' => get_option( 'baz' )
console.log( wpseObject.foo );
and your wpseObject.bar would hold your baz setting value.
This is absolutely inspired… Posting it just as a reminder to use it in the future.
Updated (28 May 2014)
I finally incorporated this into a plugin I’m working on (PJ jQuery UI Helper to be exact). And it was surprisingly more difficult than I thought it would be.
I plan to make a full post on the changes made to PJ jQuery UI Helper this weekend to further improve on the perfection from the practice and hopefully help somebody else who may fall into the same traps that I did.