1

I'm doing this the normal way, instead of refresh I edit the element with JS according to the user selection, but in one case, I need a value that depends on another value and I can't get that.

Here's my JS:

wp.customize( 'myplugin[border_width]', function( value ) {
 value.bind( function( to ) {
    window.border_style ='';
    window.border_color ='';

    wp.customize( 'myplugin[border_style]', function( value ) {
       value.bind( function( to ) {
          border_style = to;
       } );
    } );
    wp.customize( 'myplugin[border_color]', function( value ) {
       value.bind( function( to ) {
          border_color = to;
       } );
    } );

    if ( !empty(to) ) {
       console.log(to); // works
       console.log(border_style); // empty
       console.log(border_color); // empty
    }
 } );
} );

Both the style and color values are empty always, even when I change them in the customizer.

1

I'm not sure if this is what you wanted, but you can use wp.customize.get() to get all the currently set Customizer settings:

var settings = wp.customize.get(); // get all settings
var border_style = settings['myplugin[border_style]'];
var border_color = settings['myplugin[border_color]'];

// Or, this works, too.
var border_style = wp.customize.get()['myplugin[border_style]'];
var border_color = wp.customize.get()['myplugin[border_color]'];

Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.