|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YIKES Inc. Easy Mailchimp Forms Plugin. |
|
4
|
|
|
* |
|
5
|
|
|
* @package YIKES\EasyForms |
|
6
|
|
|
* @author Freddie Mixell |
|
7
|
|
|
* @license GPL2 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace YIKES\EasyForms\Field; |
|
11
|
|
|
|
|
12
|
|
|
use YIKES\EasyForms\Exception\MustExtend; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class BaseInput |
|
16
|
|
|
* |
|
17
|
|
|
* @since %VERSION% |
|
18
|
|
|
* @package YIKES\EasyForms |
|
19
|
|
|
*/ |
|
20
|
|
|
class BaseInput extends BaseField { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Field ID. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $field_id; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Field's classes |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
private $classes = []; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Field placeholder. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $placeholder; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Field name. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $name; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Field value. |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
private $value; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Construct Field |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $id Fields ID. |
|
|
|
|
|
|
61
|
|
|
* @param array $classes Field and label classes. |
|
62
|
|
|
* @param string $placeholder Fields placeholder. |
|
63
|
|
|
* @param string $name Field name. |
|
|
|
|
|
|
64
|
|
|
*/ |
|
65
|
|
|
public function __construct( $classes, $placeholder, $label, $value, $description, $merge, $form_id, $hidden, $required ) { |
|
66
|
|
|
$this->classes = $classes; |
|
67
|
|
|
$this->placeholder = $placeholder; |
|
68
|
|
|
$this->label = $label; |
|
|
|
|
|
|
69
|
|
|
$this->value = $value; |
|
70
|
|
|
$this->description = $description['description']; |
|
|
|
|
|
|
71
|
|
|
$this->show_desc = $description['show_description']; |
|
|
|
|
|
|
72
|
|
|
$this->desc_above = $description['description_above']; |
|
|
|
|
|
|
73
|
|
|
$this->merge = $merge; |
|
|
|
|
|
|
74
|
|
|
$this->form_id = $form_id; |
|
|
|
|
|
|
75
|
|
|
$this->hidden = $hidden; |
|
|
|
|
|
|
76
|
|
|
$this->required = $required; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
const TYPE = 'text'; |
|
80
|
|
|
const REQUIRED = false; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get Field Type |
|
84
|
|
|
* |
|
85
|
|
|
* @return string $field['type'] |
|
86
|
|
|
*/ |
|
87
|
|
|
public function get_type() { |
|
88
|
|
|
return static::TYPE; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function get_placeholder() { |
|
92
|
|
|
return $this->placeholder; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function field_classes() { |
|
96
|
|
|
return $this->classes['field_classes']; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function label_classes() { |
|
100
|
|
|
if ( true === static::REQUIRED ) { |
|
101
|
|
|
$this->classes['label_classes'][] = 'yikes-mailchimp-field-required'; |
|
102
|
|
|
} |
|
103
|
|
|
return $this->classes['label_classes']; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function get_required() { |
|
107
|
|
|
if ( true === static::REQUIRED ) { |
|
108
|
|
|
return true; |
|
109
|
|
|
} |
|
110
|
|
|
return $this->required; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function get_name() { |
|
114
|
|
|
return $this->merge; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function get_id() { |
|
118
|
|
|
return 'yikes-easy-mc-form-' . $this->form_id . '-' . $this->merge; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function get_value() { |
|
122
|
|
|
return $this->value; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Render the field. |
|
127
|
|
|
* |
|
128
|
|
|
* @since %VERSION% |
|
129
|
|
|
*/ |
|
130
|
|
|
public function render() { |
|
131
|
|
|
|
|
132
|
|
|
?> |
|
133
|
|
|
<label for="<?= esc_attr( $this->get_id() ); ?>" class="<?= esc_html( implode( ' ' , $this->label_classes() ) ); ?>" <?= esc_html( implode( ' ' , $this->label['props'] ) ); ?> > |
|
134
|
|
|
|
|
135
|
|
|
<!-- dictate label visibility --> |
|
136
|
|
|
<?php if ( ! isset( $this->label['hide-label'] ) ) { ?> |
|
137
|
|
|
<span class="<?= esc_attr( $this->merge ) . '-label'; ?>"> |
|
138
|
|
|
<?= esc_html( apply_filters( 'yikes-mailchimp-'. $this->merge .'-label' , esc_attr( $this->label['value'] ), $this->form_id ) ); ?> |
|
139
|
|
|
</span> |
|
140
|
|
|
<?php } |
|
141
|
|
|
|
|
142
|
|
|
if ( $this->show_desc === true && $this->desc_above === true ) : |
|
143
|
|
|
?> |
|
144
|
|
|
|
|
145
|
|
|
<p class="form-field-description" id="form-field-description-<?= esc_attr( $this->merge ); ?>"> |
|
146
|
|
|
<?= esc_html( apply_filters( 'yikes-mailchimp-' . $this->merge . '-description', $this->description, $this->form_id ) ); ?> |
|
147
|
|
|
</p> |
|
148
|
|
|
|
|
149
|
|
|
<?php |
|
150
|
|
|
endif; |
|
151
|
|
|
?> |
|
152
|
|
|
<input type="<?= esc_attr( $this->get_type() ); ?>" |
|
153
|
|
|
class="<?= esc_attr( implode( ' ' , $this->field_classes() ) ); ?>" |
|
154
|
|
|
name="<?= esc_attr( $this->get_name() ); ?>" |
|
155
|
|
|
placeholder="<?= esc_attr( $this->get_placeholder() ); ?>" |
|
156
|
|
|
id="<?= esc_attr( $this->get_id() ); ?>" |
|
157
|
|
|
value="<?= esc_attr( $this->get_value() ); ?>" |
|
158
|
|
|
<?php if ( true === $this->get_required() ) : ?> |
|
159
|
|
|
required="required" |
|
160
|
|
|
<?php endif; ?> |
|
161
|
|
|
<?php if ( true === $this->hidden ) : ?> |
|
162
|
|
|
style="display:none;" |
|
163
|
|
|
<?php endif; ?> |
|
164
|
|
|
/> |
|
165
|
|
|
<?php |
|
166
|
|
|
if ( $this->show_desc === true && $this->desc_above === false ) { ?> |
|
167
|
|
|
<p class="form-field-description" id="form-field-description-<?= esc_attr( $this->merge ); ?>"><?= esc_html( $this->description ); ?></p> |
|
168
|
|
|
<?php |
|
169
|
|
|
} |
|
170
|
|
|
?> |
|
171
|
|
|
</label> |
|
172
|
|
|
<?php |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.