| 1 |
<?php |
| 2 |
/* @param string $meta Meta name. |
| 3 |
* @param array $details Contains the details for the field. |
| 4 |
* @param string $value Contains input value; |
| 5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.; |
| 6 |
* @return string $element input element html string. */ |
| 7 |
|
| 8 |
$element .= '<select name="'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" id="'; |
| 9 |
if( !empty( $frontend_prefix ) ) |
| 10 |
$element .= $frontend_prefix; |
| 11 |
$element .= esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" class="mb-select mb-field" >'; |
| 12 |
|
| 13 |
if( !empty( $details['default-option'] ) && $details['default-option'] ) |
| 14 |
$element .= '<option value="">'. __('...Choose', 'wck') .'</option>'; |
| 15 |
|
| 16 |
$field_name = Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ); |
| 17 |
|
| 18 |
$options = ''; |
| 19 |
if( !empty( $details['options'] ) ){ |
| 20 |
$i = 0; |
| 21 |
foreach( $details['options'] as $option ){ |
| 22 |
|
| 23 |
if( strpos( $option, '%' ) === false ){ |
| 24 |
$label = $option; |
| 25 |
if( !empty( $details['values'] ) ) |
| 26 |
$value_attr = $details['values'][$i]; |
| 27 |
else |
| 28 |
$value_attr = $option; |
| 29 |
} |
| 30 |
else{ |
| 31 |
$option_parts = explode( '%', $option ); |
| 32 |
if( !empty( $option_parts ) ){ |
| 33 |
if( empty( $option_parts[0] ) && count( $option_parts ) == 3 ){ |
| 34 |
$label = $option_parts[1]; |
| 35 |
if( !empty( $details['values'] ) ) |
| 36 |
$value_attr = $details['values'][$i]; |
| 37 |
else |
| 38 |
$value_attr = $option_parts[2]; |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
$optionOutput = '<option value="'. esc_attr( $value_attr ) .'" '. selected( $value_attr, $value, false ) .' >'. esc_html( $label ) .'</option>'; |
| 44 |
$options .= apply_filters( "wck_select_{$meta}_{$field_name}_option_{$i}", $optionOutput, $i); |
| 45 |
|
| 46 |
$i++; |
| 47 |
} |
| 48 |
} |
| 49 |
$element .= apply_filters( "wck_select_{$meta}_{$field_name}_options", $options ); |
| 50 |
$element .= '</select>'; |
| 51 |
?> |