| @@ -23,9 +23,8 @@ | ||
| 23 | 23 | protected $option; |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var string |
| 27 | - * | |
| 28 | 27 | * @since 2.03.05 |
| 29 | 28 | */ |
| 30 | 29 | protected $saved_value = ''; |
| 31 | 30 | |
| @@ -30,20 +29,12 @@ | ||
| 30 | 29 | protected $saved_value = ''; |
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * @var string |
| 34 | - * | |
| 35 | 33 | * @since 2.03.05 |
| 36 | 34 | */ |
| 37 | 35 | protected $option_label = ''; |
| 38 | 36 | |
| 39 | - /** | |
| 40 | - * @param int|string $option_key | |
| 41 | - * @param array|string $option | |
| 42 | - * @param array $args | |
| 43 | - * | |
| 44 | - * @return void | |
| 45 | - */ | |
| 46 | 37 | public function __construct( $option_key, $option, $args = array() ) { |
| 47 | 38 | $this->option_key = $option_key; |
| 48 | 39 | $this->option = $option; |
| 49 | 40 | $this->set_option_label(); |
| @@ -58,9 +49,9 @@ | ||
| 58 | 49 | * @return void |
| 59 | 50 | */ |
| 60 | 51 | private function set_option_label() { |
| 61 | 52 | if ( is_array( $this->option ) ) { |
| 62 | - $this->option_label = ( $this->option['label'] ?? reset( $this->option ) ); | |
| 53 | + $this->option_label = ( isset( $this->option['label'] ) ? $this->option['label'] : reset( $this->option ) ); | |
| 63 | 54 | } else { |
| 64 | 55 | $this->option_label = $this->option; |
| 65 | 56 | } |
| 66 | 57 | } |
| @@ -80,28 +71,19 @@ | ||
| 80 | 71 | * Print a single option |
| 81 | 72 | * |
| 82 | 73 | * @since 2.03.05 |
| 83 | 74 | * |
| 84 | - * @param string $selected_value The value of the option to be selected. | |
| 85 | - * @param int $truncate Truncate the option label if true. | |
| 86 | - * @param bool $use_value_as_label Use the option value as the label if true. | |
| 75 | + * @param string $selected_value | |
| 76 | + * @param int $truncate | |
| 87 | 77 | * |
| 88 | 78 | * @return void |
| 89 | 79 | */ |
| 90 | - public function print_single_option( $selected_value, $truncate, $use_value_as_label = false ) { | |
| 91 | - if ( '' === $this->saved_value && ! $use_value_as_label ) { | |
| 92 | - return; | |
| 80 | + public function print_single_option( $selected_value, $truncate ) { | |
| 81 | + if ( '' !== $this->saved_value ) { | |
| 82 | + echo '<option value="' . esc_attr( $this->saved_value ) . '"'; | |
| 83 | + selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) ); | |
| 84 | + // TODO: add hook that can add attributes to option text | |
| 85 | + echo '>'; | |
| 86 | + echo esc_html( FrmAppHelper::truncate( $this->option_label, $truncate ) ) . '</option>'; | |
| 93 | 87 | } |
| 94 | - | |
| 95 | - if ( $use_value_as_label && '' === trim( $this->option_label ) ) { | |
| 96 | - $label = '' !== $this->saved_value ? $this->saved_value : FrmAppHelper::get_no_label_text(); | |
| 97 | - } else { | |
| 98 | - $label = $this->option_label; | |
| 99 | - } | |
| 100 | - | |
| 101 | - echo '<option value="' . esc_attr( $this->saved_value ) . '"'; | |
| 102 | - selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) ); | |
| 103 | - // TODO: add hook that can add attributes to option text | |
| 104 | - echo '>'; | |
| 105 | - echo esc_html( FrmAppHelper::truncate( $label, $truncate ) ) . '</option>'; | |
| 106 | 88 | } |
| 107 | 89 | } |