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'
));
}