Added the ability to specify a class for <select><option> in the htmlSelect() function (functions.php)

This commit is contained in:
IgorA100
2026-05-28 12:44:59 +03:00
committed by GitHub
parent 9eddec677e
commit c2ebbc7ed5

View File

@@ -424,7 +424,7 @@ function htmlOptions($options, $values) {
$has_selected = false;
foreach ( $options as $value=>$option ) {
$disabled = 0;
$text = '';
$text = $class = '';
if ( is_array($option) ) {
if ( isset($option['Name']) )
@@ -435,6 +435,9 @@ function htmlOptions($options, $values) {
if ( isset($option['disabled']) ) {
$disabled = $option['disabled'];
}
if ( isset($option['class']) ) {
$class = $option['class'];
}
} else if ( is_object($option) ) {
$text = $option->Name();
} else {
@@ -450,6 +453,7 @@ function htmlOptions($options, $values) {
$options_html .= '<option value="'.htmlspecialchars($value, ENT_COMPAT | ENT_HTML401, ini_get('default_charset'), false).'"'.
($selected?' selected="selected"':'').
($disabled?' disabled="disabled"':'').
($class?' class='.$class:'').
'>'.htmlspecialchars($text, ENT_COMPAT | ENT_HTML401, ini_get('default_charset'), false).'</option>'.PHP_EOL;
} # end foreach options
if ( $values and ((!is_array($values)) or count($values) ) and ! $has_selected ) {