Created
October 3, 2015 03:58
-
-
Save goranefbl/607b46081d7c08c9c72c to your computer and use it in GitHub Desktop.
Dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dropdown(select with options) shortcode attribute type generator. | |
* | |
* @param $settings | |
* @param $value | |
* | |
* @since 4.4 | |
* @return string - html string. | |
*/ | |
function vc_dropdown_form_field( $settings, $value ) { | |
$output = ''; | |
$css_option = str_replace( '#', 'hash-', vc_get_dropdown_option( $settings, $value ) ); | |
$output .= '<select name="' | |
. $settings['param_name'] | |
. '" class="wpb_vc_param_value wpb-input wpb-select ' | |
. $settings['param_name'] | |
. ' ' . $settings['type'] | |
. ' ' . $css_option | |
. '" data-option="' . $css_option . '">'; | |
if ( is_array( $value ) ) { | |
$value = isset( $value['value'] ) ? $value['value'] : array_shift( $value ); | |
} | |
if ( ! empty( $settings['value'] ) ) { | |
foreach ( $settings['value'] as $index => $data ) { | |
if ( is_numeric( $index ) && ( is_string( $data ) || is_numeric( $data ) ) ) { | |
$option_label = $data; | |
$option_value = $data; | |
} elseif ( is_numeric( $index ) && is_array( $data ) ) { | |
$option_label = isset( $data['label'] ) ? $data['label'] : array_pop( $data ); | |
$option_value = isset( $data['value'] ) ? $data['value'] : array_pop( $data ); | |
} else { | |
$option_value = $data; | |
$option_label = $index; | |
} | |
$selected = ''; | |
if ( $value !== '' && (string) $option_value === (string) $value ) { | |
$selected = ' selected'; | |
} | |
$option_class = str_replace( '#', 'hash-', $option_value ); | |
$output .= '<option class="' . $option_class . '" value="' . $option_value . '"' . $selected . '>' | |
. htmlspecialchars( $option_label ) . '</option>'; | |
} | |
} | |
$output .= '</select>'; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment