Skip to content

Commit e2531b1

Browse files
committed
Merge branch 'master' of https://github.com/kowsar89/wordpress-settings-api-class into kowsar89-master
2 parents 3e18002 + 76abee9 commit e2531b1

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/class.settings-api.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ function admin_init() {
132132
'std' => isset( $option['default'] ) ? $option['default'] : '',
133133
'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
134134
'type' => $type,
135+
'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'] : '',
135139
);
136140

137141
add_settings_field( $section . '[' . $option['name'] . ']', $option['label'], array( $this, 'callback_' . $type ), $section, $section, $args );
@@ -166,12 +170,13 @@ public function get_field_description( $args ) {
166170
*/
167171
function callback_text( $args ) {
168172

169-
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
170-
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
171-
$type = isset( $args['type'] ) ? $args['type'] : 'text';
173+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
174+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
175+
$type = isset( $args['type'] ) ? $args['type'] : 'text';
176+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
172177

173-
$html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"/>', $type, $size, $args['section'], $args['id'], $value );
174-
$html .= $this->get_field_description( $args );
178+
$html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
179+
$html .= $this->get_field_description( $args );
175180

176181
echo $html;
177182
}
@@ -191,7 +196,18 @@ function callback_url( $args ) {
191196
* @param array $args settings field args
192197
*/
193198
function callback_number( $args ) {
194-
$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;
195211
}
196212

197213
/**
@@ -286,11 +302,12 @@ function callback_select( $args ) {
286302
*/
287303
function callback_textarea( $args ) {
288304

289-
$value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
290-
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
305+
$value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
306+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
307+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
291308

292-
$html = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]">%4$s</textarea>', $size, $args['section'], $args['id'], $value );
293-
$html .= $this->get_field_description( $args );
309+
$html = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
310+
$html .= $this->get_field_description( $args );
294311

295312
echo $html;
296313
}

0 commit comments

Comments
 (0)