【问题标题】:Is it possible to change the value without refreshing the Customizer Edit Window?是否可以在不刷新定制器编辑窗口的情况下更改值?
【发布时间】:2021-03-12 01:10:22
【问题描述】:

我添加了自己的设置来更改字体。

这是我得到的代码。

$wp_customize->add_setting( 'calendar_title_font', array(
    'default'              => '',
    'sanitize_callback'    => 'skyrocket_text_sanitization',
    'sanitize_js_callback' => 'skyrocket_google_font_sanitization',
    'transport'            => 'postMessage',
) );

$wp_customize->add_control( new Skyrocket_Google_Font_Select_Custom_Control( $wp_customize, 'calendar_title_font', array(
    'label'       => __( 'Font Family', 'blah' ),
    'section'     => 'calendar_title',
    'input_attrs' => array(
        'font_count' => '20',
        'orderby'    => 'popular',
    ),
) ) );

JS代码

wp.customize( 'calendar_title_font', function( value ) {
    value.bind( function( to ) {
        $('h2.toolbar-title')
            .css('font-family', to );
    } );
} );

选择性刷新

$wp_customize->selective_refresh->add_partial( 'calendar_title', array(
    'selector' => 'h2.toolbar-title',
    'settings' => 'calendar_title_font',
    'render_callback' => function() {
        echo get_setting( 'calendar_title_font' );
    },
) );

我做错了什么?更改字体时,我只需要更新标题所在的部分,即<h2>Title</h2>。但我仍然有完整的定制器编辑窗口正在更新。显然,selective_refresh 有问题,我无法理解它是什么。

感谢您的帮助。

附:对不起我的英语。

【问题讨论】:

    标签: php settings partials


    【解决方案1】:

    也许您需要使用与您使用选择性刷新相同的 setting_id。

    你可以试试 $wp_customize->selective_refresh->add_partial( 'calendar_title_font', ...其余代码

    而不是 $wp_customize->selective_refresh->add_partial( 'calendar_title', ...其余代码

    【讨论】:

    • 我同意。但无论如何它并没有帮助,窗口仍然刷新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    相关资源
    最近更新 更多