Skip to content

Commit 3b32ea9

Browse files
author
Md. Kowsar Hossain
committed
placeholder support added for text and textarea
1 parent ecb2778 commit 3b32ea9

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/class.settings-api.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ 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'] : '',
135136
);
136137

137138
add_settings_field( $section . '[' . $option['name'] . ']', $option['label'], array( $this, 'callback_' . $type ), $section, $section, $args );
@@ -166,12 +167,13 @@ public function get_field_description( $args ) {
166167
*/
167168
function callback_text( $args ) {
168169

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';
170+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
171+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
172+
$type = isset( $args['type'] ) ? $args['type'] : 'text';
173+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
172174

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 );
175+
$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 );
176+
$html .= $this->get_field_description( $args );
175177

176178
echo $html;
177179
}
@@ -286,11 +288,12 @@ function callback_select( $args ) {
286288
*/
287289
function callback_textarea( $args ) {
288290

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';
291+
$value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
292+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
293+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
291294

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 );
295+
$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 );
296+
$html .= $this->get_field_description( $args );
294297

295298
echo $html;
296299
}

0 commit comments

Comments
 (0)