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.
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.
Share Improve this question asked Jun 16, 2019 at 13:41 pickos7pickos7 153 bronze badges1 Answer
Reset to default 1I'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