6

I have created a variable number of fields to add images to a nivoslider. It works nicely, but I have to manually refresh the entire page and re-select the section from the customizer panel for the changes to take effect. I'm wondering if there is any way to get the customizer panel itself to refresh by php code, instead of just the live website area.

Here is the code

$wp_customize->add_section('slider_section',array(
        'title' => esc_html__('Slider Settings','customslide'),
        'description'   => esc_html__('Add slider images here.','customslide'),
        'priority'      => null
));

$wp_customize->add_setting('num_of_slides'.$i,array(
        'default'   => esc_html__('2','customslide'),
        'transport' => 'refresh',
        'sanitize_callback' => 'absint',
));

$wp_customize->add_control('num_of_slides',array(
        'label' => esc_html__('Number of Slides','customslide'),
        'section'   => 'slider_section',
        'type'  => 'text'
));


$num_of_slides_value = esc_html(get_theme_mod('num_of_slides','2'));

for ($i=1; $i<$num_of_slides_value+1; $i++) {
    // Slide Image i
    $wp_customize->add_setting('slide_image'.$i,array(
        'default'   => get_template_directory_uri().'/images/slides/slider'.$i.'.jpg',
        'sanitize_callback' => 'esc_url_raw',
    ));

    $wp_customize->add_control(
        new WP_Customize_Image_Control(
            $wp_customize,
            'slide_image'.$i,
            array(
                'label' => esc_html__('Slide Image '.$i.' (1440x700)','customslide'),
                'section' => 'slider_section',
                'settings' => 'slide_image'.$i
            )
        )
    );

    $wp_customize->add_setting('slide_title'.$i,array(
            'default'   => esc_html__('Responsive Design','customslide'),
            'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('slide_title'.$i,array(
            'label' => esc_html__('Slide Title '.$i,'customslide'),
            'section'   => 'slider_section',
            'type'  => 'text'
    ));

    $wp_customize->add_setting('slide_desc'.$i,array(
            'default'   => esc_html__('This is description for slider one.','customslide'),
            'sanitize_callback' => 'customslide_format_for_editor',
    ));

    $wp_customize->add_control('slide_desc'.$i,array(
            'label' => esc_html__('Slide Description '.$i,'customslide'),
            'section' => 'slider_section',
            'setting'   => 'slide_desc'.$i,
            'type'  => 'textarea'
    ));

    $wp_customize->add_setting('slide_link'.$i,array(
            'default'   => '#link'.$i,
            'sanitize_callback' => 'esc_url_raw',
    ));

    $wp_customize->add_control('slide_link'.$i,array(
            'label' => esc_html__('Slide Link '.$i,'customslide'),
            'section'   => 'slider_section',
            'type'      => 'text'
    ));

}
4
  • 2
    Have you read the docs about the Customizer API? There are two sections that explain two different methods of refreshing. developer.wordpress.org/themes/advanced-topics/customizer-api
    – ngearing
    Aug 2, 2016 at 23:24
  • 1
    Helpful link with the important anker - developer.wordpress.org/themes/advanced-topics/customizer-api/…
    – bueltge
    Aug 10, 2016 at 8:57
  • 3
    @Nath & bueltge Those are both refresh methods for the preview of the website, and not refreshing the customizer panel itself. The OP asks about how to refreshing the Customizer panel.
    – Kevin M
    Sep 2, 2016 at 0:07
  • I was looking for the same. I have different modules that I can activate/deactivate from the customizer, but the panel (or entire page) needs to be refreshed for each module's options to appear/disappear after activation/deactivation. Nov 18, 2021 at 13:37

1 Answer 1

2

In the current Wordpress version this is not possible, unless you hard write some JS code to dynamically update the customizer panel with your values. I've opened a ticket to update menu locations when switching navigation style, check out it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.