Customizer JS API: Adding Setting Dynamically Not Working

When you register the setting in JS, you need to supply the current value saved in the DB as the value, not some default value. So instead of:

var setting = new api.Setting( 'mySetting', 'JS Default Value?' );

You would need to obtain the value via some means like the REST API and then use it when instantiating. You also need to provide the transport. So it would look like this:

var setting = new api.Setting( 'mySetting', someResponse.value, { transport: 'postMessage' } );

Here are some examples of doing this:

Leave a Comment