Skip to content

Commit 137238e

Browse files
committed
Add url input type
It's basically the same as text input so we reuse it. Using the url input type will let us use the browser input validation and/or scripts input validation more easily. Signed-off-by: Roi Dayan <roi.dayan@gmail.com>
1 parent 72e485a commit 137238e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

class.settings-api.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function admin_init() {
135135
'options' => isset( $option['options'] ) ? $option['options'] : '',
136136
'std' => isset( $option['default'] ) ? $option['default'] : '',
137137
'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
138+
'type' => $type,
138139
);
139140
add_settings_field( $section . '[' . $option['name'] . ']', $option['label'], array( $this, 'callback_' . $type ), $section, $section, $args );
140141
}
@@ -155,13 +156,23 @@ function callback_text( $args ) {
155156

156157
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
157158
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
159+
$type = isset( $args['type'] ) ? $args['type'] : 'text';
158160

159-
$html = sprintf( '<input type="text" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
161+
$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 );
160162
$html .= sprintf( '<span class="description"> %s</span>', $args['desc'] );
161163

162164
echo $html;
163165
}
164166

167+
/**
168+
* Displays a url field for a settings field
169+
*
170+
* @param array $args settings field args
171+
*/
172+
function callback_url( $args ) {
173+
$this->callback_text( $args );
174+
}
175+
165176
/**
166177
* Displays a checkbox for a settings field
167178
*

0 commit comments

Comments
 (0)