| @@ -31,5 +31,26 @@ | ||
| 31 | 31 | }, |
| 32 | 32 | isset( $args['echo'] ) ? $args['echo'] : false |
| 33 | 33 | ); |
| 34 | 34 | } |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Echo a dropdown option. | |
| 38 | + * This is useful to avoid closing and opening PHP to echo <option> tags which leads to extra whitespace. | |
| 39 | + * Avoiding whitespace saves 5KB of HTML for an international address field with a country dropdown with 252 options. | |
| 40 | + * | |
| 41 | + * @since 6.3.1 | |
| 42 | + * | |
| 43 | + * @param string $option The string used as the option label. | |
| 44 | + * @param bool $selected True if the option should be selected. | |
| 45 | + * @param array $params Other HTML params for the option. | |
| 46 | + * @return void | |
| 47 | + */ | |
| 48 | + public static function echo_dropdown_option( $option, $selected, $params = array() ) { | |
| 49 | + echo '<option '; | |
| 50 | + FrmAppHelper::array_to_html_params( $params, true ); | |
| 51 | + selected( $selected ); | |
| 52 | + echo '>'; | |
| 53 | + echo esc_html( $option === '' ? ' ' : $option ); | |
| 54 | + echo '</option>'; | |
| 55 | + } | |
| 35 | 56 | } |