← All changes
|
includes/Frontend/Form/View/Theme/Fields/HtmlSelectField.php
+12
-5
3.1.3
→
V3.3.2
View file →
| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | if (isset($opt->val) && $opt->val === $val) { |
| 20 | 20 | $selected = 'selected'; |
| 21 | 21 | } elseif (isset($opt->lbl) && $opt->lbl === $val) { |
| 22 | 22 | $selected = 'selected'; |
| 23 | - } elseif (property_exists($opt, 'check')) { | |
| 23 | + } elseif (is_object($opt) && property_exists($opt, 'check')) { | |
| 24 | 24 | $selected = 'selected'; |
| 25 | 25 | } |
| 26 | 26 | return $selected; |
| 27 | 27 | } |
| @@ -61,10 +61,13 @@ | ||
| 61 | 61 | $fieldHelpers->kses_post($field->ph) |
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if (property_exists($field, 'opt')) { | |
| 65 | + if (property_exists($field, 'opt') && is_iterable($field->opt)) { | |
| 66 | 66 | foreach ($field->opt as $opt) { |
| 67 | + if (!is_object($opt)) { | |
| 68 | + continue; | |
| 69 | + } | |
| 67 | 70 | $disabled = property_exists($opt, 'disabled') ? 'disabled' : ''; |
| 68 | 71 | if (property_exists($opt, 'type')) { |
| 69 | 72 | $optionsHTML .= sprintf( |
| 70 | 73 | '<optgroup |
| @@ -78,10 +81,14 @@ | ||
| 78 | 81 | $fieldHelpers->getCustomClasses('slct-opt-grp'), |
| 79 | 82 | $fieldHelpers->esc_attr($opt->title), |
| 80 | 83 | $disabled |
| 81 | 84 | ); |
| 82 | - foreach ($opt->childs as $child) { | |
| 83 | - $val = isset($child->val) ? $child->val : $child->lbl; | |
| 85 | + $optChilds = isset($opt->childs) && is_iterable($opt->childs) ? $opt->childs : []; | |
| 86 | + foreach ($optChilds as $child) { | |
| 87 | + if (!is_object($child)) { | |
| 88 | + continue; | |
| 89 | + } | |
| 90 | + $val = isset($child->val) ? $child->val : ($child->lbl ?? ''); | |
| 84 | 91 | $selected = self::checkSelected($child, $value); |
| 85 | 92 | $disabled = property_exists($child, 'disabled') ? 'disabled' : ''; |
| 86 | 93 | $optionsHTML .= sprintf( |
| 87 | 94 | '<option |
| @@ -104,9 +111,9 @@ | ||
| 104 | 111 | } |
| 105 | 112 | $optionsHTML .= '</optgroup>'; |
| 106 | 113 | } else { |
| 107 | 114 | $selected = self::checkSelected($opt, $value); |
| 108 | - $val = isset($opt->val) ? $opt->val : $opt->lbl; | |
| 115 | + $val = isset($opt->val) ? $opt->val : ($opt->lbl ?? ''); | |
| 109 | 116 | $optionsHTML .= sprintf( |
| 110 | 117 | '<option |
| 111 | 118 | %1$s |
| 112 | 119 | class="%2$s %3$s" |