| @@ -85,9 +85,10 @@ | ||
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * FrmFieldValueSelector constructor |
| 88 | 88 | * |
| 89 | - * @param int|string $field_id | |
| 89 | + * @param int|string $field_id Field ID. | |
| 90 | + * @param array $args Arguments for configuring the value selector. | |
| 90 | 91 | */ |
| 91 | 92 | public function __construct( $field_id, $args ) { |
| 92 | 93 | $this->set_html_name( $args ); |
| 93 | 94 | $this->set_value( $args ); |
| @@ -94,8 +95,9 @@ | ||
| 94 | 95 | $this->set_source( $args ); |
| 95 | 96 | $this->set_truncate( $args ); |
| 96 | 97 | |
| 97 | 98 | $this->field_id = (int) $field_id; |
| 99 | + | |
| 98 | 100 | if ( $this->field_id === 0 ) { |
| 99 | 101 | return; |
| 100 | 102 | } |
| 101 | 103 | |
| @@ -100,13 +102,15 @@ | ||
| 100 | 102 | } |
| 101 | 103 | |
| 102 | 104 | $this->set_db_row(); |
| 103 | 105 | |
| 104 | - if ( $this->has_db_row() ) { | |
| 105 | - $this->set_field_key(); | |
| 106 | - $this->set_field_settings(); | |
| 107 | - $this->set_options(); | |
| 106 | + if ( ! $this->has_db_row() ) { | |
| 107 | + return; | |
| 108 | 108 | } |
| 109 | + | |
| 110 | + $this->set_field_key(); | |
| 111 | + $this->set_field_settings(); | |
| 112 | + $this->set_options(); | |
| 109 | 113 | } |
| 110 | 114 | |
| 111 | 115 | /** |
| 112 | 116 | * Set the db_row property |
| @@ -277,22 +281,34 @@ | ||
| 277 | 281 | protected function display_dropdown() { |
| 278 | 282 | echo '<select name="' . esc_attr( $this->html_name ) . '">'; |
| 279 | 283 | echo '<option value="">' . esc_html( $this->blank_option_label ) . '</option>'; |
| 280 | 284 | |
| 281 | - if ( ! empty( $this->options ) ) { | |
| 285 | + if ( $this->options ) { | |
| 282 | 286 | $truncate = $this->truncate ?? 25; |
| 283 | 287 | |
| 284 | 288 | foreach ( $this->options as $key => $value ) { |
| 289 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 285 | 290 | if ( $value == '' ) { |
| 286 | 291 | continue; |
| 287 | 292 | } |
| 288 | 293 | |
| 289 | 294 | $option = $this->get_single_field_option( $key, $value ); |
| 290 | - $option->print_single_option( $this->value, $truncate ); | |
| 295 | + $option->print_single_option( $this->value, $truncate, $this->use_value_as_label_in_dropdown() ); | |
| 291 | 296 | } |
| 292 | 297 | } |
| 293 | 298 | |
| 294 | 299 | echo '</select>'; |
| 300 | + } | |
| 301 | + | |
| 302 | + /** | |
| 303 | + * Whether to use the field value as the option label in the dropdown when the label is empty. | |
| 304 | + * | |
| 305 | + * @since 6.25.1 | |
| 306 | + * | |
| 307 | + * @return bool | |
| 308 | + */ | |
| 309 | + protected function use_value_as_label_in_dropdown() { | |
| 310 | + return false; | |
| 295 | 311 | } |
| 296 | 312 | |
| 297 | 313 | /** |
| 298 | 314 | * Get an instance of FrmFieldOption |