mihdan
10/26/2018 - 9:53 PM

visual-composer-multiselect.php

<?php
// Create multi dropdown param type
vc_add_shortcode_param( 'dropdown_multi', 'dropdown_multi_settings_field' );
function dropdown_multi_settings_field( $param, $value ) {

    $param_line = '';
    $param_line .= '<select multiple name="'. esc_attr( $param['param_name'] ).'" class="wpb_vc_param_value wpb-input wpb-select '. esc_attr( $param['param_name'] ).' '. esc_attr($param['type']).'">';
    foreach ( $param['value'] as $text_val => $val ) {
        if ( is_numeric($text_val) && (is_string($val) || is_numeric($val)) ) {
            $text_val = $val;
        }
        $text_val = __($text_val, "js_composer");
        $selected = '';

        if(!is_array($value)) {
            $param_value_arr = explode(',',$value);
        } else {
            $param_value_arr = $value;
        }

        if ($value!=='' && in_array($val, $param_value_arr)) {
            $selected = ' selected="selected"';
        }
        $param_line .= '<option class="'.$val.'" value="'.$val.'"'.$selected.'>'.$text_val.'</option>';
    }
    $param_line .= '</select>';

    return  $param_line;
}

vc_map(
    array(
        'name' => __('VC People', VAE_TEXT_DOMAIN),
        'base' => 'vc_people',
        'description' => __('VC People', VAE_TEXT_DOMAIN),
        'class' => 'vc_people',
        'category' => __('Events Elements', VAE_TEXT_DOMAIN),
        'icon' => '',
        'params' => array(
            array(
                'type' => 'dropdown_multi',
                'heading' => __( 'Select a person type', VAE_TEXT_DOMAIN ),
                'param_name' => 'person_type',
                'value' => $personTypeOption,
                'description' => __( 'Select a person type to filter', VAE_TEXT_DOMAIN ),
                'admin_label' => false,
                'save_always' => true,
            ),

        )
    )
);