最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Get a setting value conditionally in the Customizer api

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论