Skip to content

Commit 76abee9

Browse files
author
Md. Kowsar Hossain
committed
min, max and step attributes added in number field
1 parent 3b32ea9 commit 76abee9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/class.settings-api.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ function admin_init() {
133133
'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
134134
'type' => $type,
135135
'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : '',
136+
'min' => isset( $option['min'] ) ? $option['min'] : '',
137+
'max' => isset( $option['max'] ) ? $option['max'] : '',
138+
'step' => isset( $option['step'] ) ? $option['step'] : '',
136139
);
137140

138141
add_settings_field( $section . '[' . $option['name'] . ']', $option['label'], array( $this, 'callback_' . $type ), $section, $section, $args );
@@ -193,7 +196,18 @@ function callback_url( $args ) {
193196
* @param array $args settings field args
194197
*/
195198
function callback_number( $args ) {
196-
$this->callback_text( $args );
199+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
200+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
201+
$type = isset( $args['type'] ) ? $args['type'] : 'number';
202+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
203+
$min = empty( $args['min'] ) ? '' : ' min="'.$args['min'].'"';
204+
$max = empty( $args['max'] ) ? '' : ' max="'.$args['max'].'"';
205+
$step = empty( $args['step'] ) ? '' : ' step="1"';
206+
207+
$html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
208+
$html .= $this->get_field_description( $args );
209+
210+
echo $html;
197211
}
198212

199213
/**

0 commit comments

Comments
 (0)