Sometimes you may need a conditional field in your addon.
WP Page Builder supports !=
and =
conditional keys.
Button Color
field shows when Button Style
value is primary
'button_style' => array(
'type' => 'select',
'title' => __('Button Style','your-textdomain'),
'values' => array(
'primary' => __('Primary','your-textdomain'),
'success' => __('Success','your-textdomain'),
'info' => __('Info','your-textdomain'),
),
'std' => 'primary',
),
'button_color' => array(
'type' => 'color',
'title' => __('Button Color','your-textdomain'),
'depends' => array( array('button_style', '=', 'primary' ) ),
),
Button Color
field shows when Button Style
value is primary
or info
'button_style' => array(
'type' => 'select',
'title' => __('Style','your-textdomain'),
'values' => array(
'primary' => __('Primary','your-textdomain'),
'success' => __('Success','your-textdomain'),
'info' => __('Info','your-textdomain'),
),
'std' => 'primary',
),
'button_color' => array(
'type' => 'color',
'title' => __('Button color','your-textdomain'),
'depends' => array( array('button_style', '=', array('primary','info') ) ),
),
Button Color
field shows when Button Style
value is primary
and Button Type
value is solid
'button_style' => array(
'type' => 'select',
'title' => __('Style','your-textdomain'),
'values' => array(
'primary' => __('Primary','your-textdomain'),
'success' => __('Success','your-textdomain'),
'info' => __('Info','your-textdomain'),
),
'std' => 'primary',
),
'button_type' => array(
'type' => 'select',
'title' => __('Button Type','your-textdomain'),
'values' => array(
'solid' => __('Solid Border','your-textdomain'),
'dotted' => __('Dotted Border','your-textdomain'),
),
'std' => 'primary',
),
'button_color' => array(
'type' => 'color',
'title' => __('Button color','your-textdomain'),
'depends' => array(
array('button_style', '=', 'primary' ),
array('button_type', '=', 'solid' ),
),
),
Button Color
field shows when Button Style
value is not equal primary
'button_style' => array(
'type' => 'select',
'title' => __('Button Style','your-textdomain'),
'values' => array(
'primary' => __('Primary','your-textdomain'),
'success' => __('Success','your-textdomain'),
'info' => __('Info','your-textdomain'),
),
'std' => 'primary',
),
'button_color' => array(
'type' => 'color',
'title' => __('Button Color','your-textdomain'),
'depends' => array( array('button_style', '!=', 'primary' ) ),
),