| 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="'. $single_prefix . 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', 'profile-builder') .'</option>'; |
| 15 |
|
| 16 |
$field_name = Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ); |
| 17 |
|
| 18 |
// we're passing this further to a function. Need to make sure it exists so we don't get a notice. |
| 19 |
if( empty( $details['value'] ) ){ |
| 20 |
$details['value'] = false; |
| 21 |
} |
| 22 |
|
| 23 |
$options = ''; |
| 24 |
if( !empty( $details['options'] ) && !Wordpress_Creation_Kit_PB::wck_is_multi( $details['options'] ) ){ |
| 25 |
$i = 0; |
| 26 |
foreach( $details['options'] as $option ){ |
| 27 |
$optionOutput = Wordpress_Creation_Kit_PB::wck_generate_select_option($option, $details['value'], $i, $value); |
| 28 |
$options .= apply_filters( "wck_select_{$meta}_{$field_name}_option_{$i}", $optionOutput, $i); |
| 29 |
|
| 30 |
$i++; |
| 31 |
} |
| 32 |
} elseif( !empty( $details['options'] ) ){ |
| 33 |
$i = 0; |
| 34 |
foreach($details['options']['optgroups'] as $optgroup){ |
| 35 |
if(!empty($optgroup['options'])) { |
| 36 |
$options .= '<optgroup label="' . $optgroup['label'] . '">'; |
| 37 |
foreach($optgroup['options'] as $option ){ |
| 38 |
$optionOutput = Wordpress_Creation_Kit_PB::wck_generate_select_option($option, $details['value'], $i, $value); |
| 39 |
$options .= apply_filters( "wck_select_{$meta}_{$field_name}_option_{$i}", $optionOutput, $i); |
| 40 |
|
| 41 |
$i++; |
| 42 |
} |
| 43 |
$options .= '</optgroup>'; |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
$element .= apply_filters( "wck_select_{$meta}_{$field_name}_options", $options ); |
| 49 |
$element .= '</select>'; |
| 50 |
|
| 51 |
|