| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | // @phpstan-ignore-next-line |
| 31 | 31 | function () use ( $id, $name, $args ) { |
| 32 | 32 | require FrmAppHelper::plugin_path() . '/classes/views/shared/toggle.php'; |
| 33 | 33 | }, |
| 34 | - $args['echo'] ?? false | |
| 34 | + isset( $args['echo'] ) ? $args['echo'] : false | |
| 35 | 35 | ); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
| @@ -53,77 +53,6 @@ | ||
| 53 | 53 | selected( $selected ); |
| 54 | 54 | echo '>'; |
| 55 | 55 | echo esc_html( $option === '' ? ' ' : $option ); |
| 56 | 56 | echo '</option>'; |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * Renders a number input with unit selector. | |
| 61 | - * | |
| 62 | - * @since 6.24 | |
| 63 | - * | |
| 64 | - * @param array $args { | |
| 65 | - * Optional. Arguments to customize the unit input. | |
| 66 | - * | |
| 67 | - * @type array $field_attrs Attributes for the hidden input storing the field value. | |
| 68 | - * @type array $input_number_attrs Attributes for the visible number input. | |
| 69 | - * @type array $units Available units for selection. Default is ['px', '%', 'em']. | |
| 70 | - * @type string $value Initial value with optional unit (e.g. '10px', '50%'). | |
| 71 | - * } | |
| 72 | - * | |
| 73 | - * @return void | |
| 74 | - */ | |
| 75 | - public static function echo_unit_input( $args = array() ) { | |
| 76 | - $args = wp_parse_args( | |
| 77 | - $args, | |
| 78 | - array( | |
| 79 | - 'field_attrs' => array(), | |
| 80 | - 'input_number_attrs' => array(), | |
| 81 | - 'units' => array( '', 'px', '%', 'em' ), | |
| 82 | - 'default_unit' => 'px', | |
| 83 | - 'value' => '', | |
| 84 | - ) | |
| 85 | - ); | |
| 86 | - | |
| 87 | - $units = $args['units']; | |
| 88 | - $value = $args['value']; | |
| 89 | - | |
| 90 | - // Extract unit and number value if value is a string | |
| 91 | - if ( '' !== $value && ! is_numeric( $value ) ) { | |
| 92 | - $pattern = '/^([0-9.]*)(' . implode( '|', array_map( 'preg_quote', $units ) ) . ')?$/'; | |
| 93 | - preg_match( $pattern, $value, $matches ); | |
| 94 | - $selected_unit = $matches[2] ?? ''; | |
| 95 | - if ( ! empty( $matches[1] ) ) { | |
| 96 | - $value = $matches[1]; | |
| 97 | - } | |
| 98 | - } | |
| 99 | - | |
| 100 | - $input_number_attrs = array_merge( | |
| 101 | - $args['input_number_attrs'], | |
| 102 | - array( | |
| 103 | - 'type' => ! empty( $selected_unit ) ? 'number' : 'text', | |
| 104 | - 'value' => $value, | |
| 105 | - 'class' => trim( 'frm-unit-input-control ' . ( $args['input_number_attrs']['class'] ?? '' ) ), | |
| 106 | - ) | |
| 107 | - ); | |
| 108 | - | |
| 109 | - $hidden_value = $args['value']; | |
| 110 | - if ( is_numeric( $hidden_value ) ) { | |
| 111 | - $hidden_value .= $args['default_unit']; | |
| 112 | - } | |
| 113 | - ?> | |
| 114 | - <span class="frm-unit-input"> | |
| 115 | - <input type="hidden" value="<?php echo esc_attr( $hidden_value ); ?>" <?php FrmAppHelper::array_to_html_params( $args['field_attrs'], true ); ?> /> | |
| 116 | - <input <?php FrmAppHelper::array_to_html_params( $input_number_attrs, true ); ?> /> | |
| 117 | - <span class="frm-input-group-suffix"> | |
| 118 | - <select aria-label="<?php echo esc_attr__( 'Select unit', 'formidable' ); ?>" tabindex="0"> | |
| 119 | - <?php | |
| 120 | - foreach ( $units as $unit ) { | |
| 121 | - self::echo_dropdown_option( $unit, $unit === ( $selected_unit ?? $args['default_unit'] ), array( 'value' => $unit ) ); | |
| 122 | - } | |
| 123 | - ?> | |
| 124 | - </select> | |
| 125 | - </span> | |
| 126 | - </span> | |
| 127 | - <?php | |
| 128 | 57 | } |
| 129 | 58 | } |