Question

I'm having problems adding "transport" capabilities for existing settings using the customize API. I can add and delete settings without issue, but adding transport to current ones doesn't seem to take. The js is loaded without issue, but the "refresh" method is still utilized.

Are you able to add "postMessage Transport" within a plugin? These calls within a theme worked fine.

function __construct() {

    add_action( 'customize_register', array( $this, 'base_customize_register' ) );
    add_action( 'customize_preview_init', array( $this, 'base_customize_preview_js' ) );

}   

function base_customize_register( $wp_customize ) {
    $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
    $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
    $wp_customize->remove_section( 'static_front_page');
}

function base_customize_preview_js() {
    wp_enqueue_script( 'base_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20131008', true );
}
Was it helpful?

Solution

Looks like it is a timing issue. Unfortunately, the sections don't yet exist in the chain, so manipulating them does not have the desired effect. I ended up having to keep the logic which handles default settings in the theme.

OTHER TIPS

I also had the same exact problem. I solved this by using priority argument on add_action function.

add_action( "customize_register", "wpcb_theme_customize_register",999,1);
function wpcb_theme_customize_register($wp_customize){
    $wp_customize->get_section( 'title_tagline' )->priority = 999;
    $wp_customize->get_section( 'static_front_page' )->priority = 1000;
}

Hope this helps for someone :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top