0

I have managed to convert sections/panels/controls from PHP to javascript.

When I am registering custom controls through JS it was not working and not sure about the settings and partial rendering.

How to convert this code to JS customizer API?

   function wp_customize_register( $wp_customize ) {

    $wp_customize->add_section( 'my_section', array (
        'title'    => __( 'My Section', 'text-domain' ),
        'priority' => 999,
    ) );

    $wp_customize->add_setting( 'my_custom_control' , array(
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage'
    ) );

    $wp_customize->add_control( 'my_custom_control', array(
        'label'    => __( 'Page to use for intro section', 'text-domain' ),
        'section'  => 'intro',
        'settings' => 'my_custom_control',
        'type'     => 'dropdown-pages',
        'priority' => 1
    ) );

    $wp_customize->selective_refresh->add_partial( 'my_custom_control', array(
        'selector'            => '.cta-wrap',
        'container_inclusive' => true,
        'render_callback'     => 'render_my_custom_control',
        'fallback_refresh'    => false,
    ) );
}
add_action( 'customize_register', 'wp_customize_register' );

JS Converted code:

Panel:   api.panel.add( new api.Panel( config['name'], config ) );
Section:  api.section.add( new api.Section( config['name'], config ) );

Your Answer

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

Browse other questions tagged or ask your own question.