-
Notifications
You must be signed in to change notification settings - Fork 2
/
form-fields.php
79 lines (76 loc) · 2.48 KB
/
form-fields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Text field for widget settings
*
* @param $name
* @param $text
* @param array $attributes
* @param string $value
*/
function wpbw_field_text( $name, $text, $attributes = array(), $value = '' ) {
$id = $attributes['id'];
$class = isset( $attributes['class'] ) ? $attributes['class'] : 'widefat';
$placeholder = isset( $attributes['placeholder'] ) ? $attributes['placeholder'] : '';
?>
<p>
<label for="<?php echo $id; ?>"><?php echo $text; ?></label>
<?php do_action( 'wpbw_field_before', $name ); ?>
<input class="<?php echo $class; ?>" id="<?php echo $id; ?>" name="<?php echo $name; ?>" type="text" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" />
<?php do_action( 'wpbw_field_after', $name ); ?>
</p>
<?php
}
/**
* Textarea field for widget settings
*
* @param $name
* @param $text
* @param array $attributes
* @param string $value
*/
function wpbw_field_textarea( $name, $text, $attributes = array(), $value = '' ) {
$id = $attributes['id'];
unset( $attributes['id'] );
$class = isset( $attributes['class'] ) ? $attributes['class'] : 'widefat';
unset( $attributes['class'] );
$html = '';
foreach ( $attributes as $key => $val ) {
$html .= sprintf( '%s="%s" ', $key, $val );
}
?>
<p>
<label for="<?php echo $id; ?>"><?php echo $text; ?></label>
<?php do_action( 'wpbw_field_before', $name ); ?>
<textarea class="<?php echo $class; ?>" id="<?php echo $id; ?>" name="<?php echo $name; ?>" <?php echo $html; ?>><?php echo $value; ?></textarea>
<?php do_action( 'wpbw_field_after', $name ); ?>
</p>
<?php
}
/**
* Select field for widget settings
*
* @param $name
* @param $text
* @param $options
* @param array $attributes
* @param string $value
*/
function wpbw_field_select( $name, $text, $options, $attributes = array(), $value = '' ) {
$id = $attributes['id'];
$class = isset( $attributes['class'] ) ? $attributes['class'] : '';
?>
<p>
<label for="<?php echo $id; ?>"><?php echo $text; ?></label>
<?php do_action( 'wpbw_field_before', $name ); ?>
<select name="<?php echo $name; ?>" id="<?php echo $id; ?>" class="<?php echo $class; ?>">
<?php foreach ( $options as $key => $option ): ?>
<?php $selected = ( $key == $value ) ? 'selected="selected"' : ''; ?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>>
<?php echo $option; ?>
</option>
<?php endforeach; ?>
</select>
<?php do_action( 'wpbw_field_after', $name ); ?>
</p>
<?php
}