Kirki: Can't get active_callback to work

Created on 27 Feb 2018  路  2Comments  路  Source: kirki-framework/kirki

Issue description:

Hi, I'm trying to use active_callback to show/hide options depending on setting. I've tried lots of variations, but without any luck.

Version used:

3.0.25

Using theme_mods or options?

theme_mods

Code to reproduce the issue (config + field(s))

// Featured Slider Show control
Kirki::add_field( 'deo_config', array(
  'type'        => 'switch',
  'settings'    => 'deo_featured_slider_show_settings',
  'label'       => esc_html__( 'Show Featured Slider', 'meridia' ),
  'section'     => 'deo_featured_slider',
  'default'     => 1,
  'priority'    => 10,
  'choices'     => array(
    'on'   => esc_attr__( 'On', 'meridia' ),
    'off' => esc_attr__( 'Off', 'meridia' ),
  ),
) );

// Featured Slider Posts control
Kirki::add_field( 'deo_config', array(
  'type'        => 'number',
  'settings'    => 'deo_featured_slider_posts_settings',
  'label'       => esc_html__( 'How many posts to show', 'meridia' ),
  'section'     => 'deo_featured_slider',
  'default'     => 3,
  'priority'    => 10,
  'active_callback'  => array(
    'setting'  => 'deo_featured_slider_show_settings',
    'value'    => 'on',
    'operator' => '==',
  ),
  'choices'     => array(
    'min'   => 0,
    'max' => 10,
    'step' => 1,
  ),
) );

Most helpful comment

Great, nested array did the trick, thanks.

All 2 comments

Please read https://aristath.github.io/kirki/docs/controls/switch.html

They return a boolean

The do not return on/off strings. The on/off - as stated in the docs is only used for the labels.

Furthermore, the active_callback is an array of arrays. 韦ry something like this:

'active_callback'  => array(
    array(
        'setting'  => 'deo_featured_slider_show_settings',
        'value'    => true,
        'operator' => '==',
    ),
),

Great, nested array did the trick, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

runnickrun picture runnickrun  路  3Comments

daviedR picture daviedR  路  6Comments

hellor0bot picture hellor0bot  路  3Comments

pagelab picture pagelab  路  3Comments

ravishakya picture ravishakya  路  5Comments