@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | { |
9 | 9 | protected $element = 'input'; |
10 | 10 | |
11 | - public function __construct( array $args = [] ) |
|
11 | + public function __construct(array $args = []) |
|
12 | 12 | { |
13 | - parent::__construct( $args ); |
|
13 | + parent::__construct($args); |
|
14 | 14 | |
15 | - if( count( $args['options'] ) > 1 ) { |
|
15 | + if (count($args['options']) > 1) { |
|
16 | 16 | $this->multi = true; |
17 | 17 | } |
18 | 18 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | { |
25 | 25 | $inline = $this->args['inline'] ? ' class="inline"' : ''; |
26 | 26 | |
27 | - if( $this->multi ) { |
|
28 | - return sprintf( '<ul%s>%s</ul>%s', |
|
27 | + if ($this->multi) { |
|
28 | + return sprintf('<ul%s>%s</ul>%s', |
|
29 | 29 | $inline, |
30 | - $this->implodeOptions( 'multi_input_checkbox' ), |
|
30 | + $this->implodeOptions('multi_input_checkbox'), |
|
31 | 31 | $this->generateDescription() |
32 | 32 | ); |
33 | 33 | } |
34 | 34 | |
35 | - return sprintf( '%s%s', |
|
36 | - $this->implodeOptions( 'single_input' ), |
|
35 | + return sprintf('%s%s', |
|
36 | + $this->implodeOptions('single_input'), |
|
37 | 37 | $this->generateDescription() |
38 | 38 | ); |
39 | 39 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( $default = null ) |
|
14 | + public function render($default = null) |
|
15 | 15 | { |
16 | 16 | $inline = $this->args['inline'] ? ' class="inline"' : ''; |
17 | 17 | |
18 | - return sprintf( '<ul%s>%s</ul>%s', |
|
18 | + return sprintf('<ul%s>%s</ul>%s', |
|
19 | 19 | $inline, |
20 | - $this->implodeOptions( 'multi_input', $default ), |
|
20 | + $this->implodeOptions('multi_input', $default), |
|
21 | 21 | $this->generateDescription() |
22 | 22 | ); |
23 | 23 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | */ |
12 | 12 | public function render() |
13 | 13 | { |
14 | - if( isset( $this->args['name'] )) { |
|
14 | + if (isset($this->args['name'])) { |
|
15 | 15 | $this->args['name'] = 'submit'; |
16 | 16 | } |
17 | 17 |
@@ -11,15 +11,15 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( array $defaults = [] ) |
|
14 | + public function render(array $defaults = []) |
|
15 | 15 | { |
16 | - $defaults = wp_parse_args( $defaults, [ |
|
16 | + $defaults = wp_parse_args($defaults, [ |
|
17 | 17 | 'type' => 'select', |
18 | 18 | ]); |
19 | 19 | |
20 | - return sprintf( '<select %s>%s</select>%s', |
|
21 | - $this->implodeAttributes( $defaults ), |
|
22 | - $this->implodeOptions( 'select_option' ), |
|
20 | + return sprintf('<select %s>%s</select>%s', |
|
21 | + $this->implodeAttributes($defaults), |
|
22 | + $this->implodeOptions('select_option'), |
|
23 | 23 | $this->generateDescription() |
24 | 24 | ); |
25 | 25 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | public function render() |
13 | 13 | { |
14 | - if( isset( $this->args['label'] )) { |
|
15 | - unset( $this->args['label'] ); |
|
14 | + if (isset($this->args['label'])) { |
|
15 | + unset($this->args['label']); |
|
16 | 16 | } |
17 | 17 | |
18 | - if( isset( $this->args['desc'] )) { |
|
19 | - unset( $this->args['desc'] ); |
|
18 | + if (isset($this->args['desc'])) { |
|
19 | + unset($this->args['desc']); |
|
20 | 20 | } |
21 | 21 | |
22 | - if( isset( $this->args['id'] )) { |
|
23 | - unset( $this->args['id'] ); |
|
22 | + if (isset($this->args['id'])) { |
|
23 | + unset($this->args['id']); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return parent::render([ |
@@ -11,16 +11,16 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( array $defaults = [] ) |
|
14 | + public function render(array $defaults = []) |
|
15 | 15 | { |
16 | - $defaults = wp_parse_args( $defaults, [ |
|
16 | + $defaults = wp_parse_args($defaults, [ |
|
17 | 17 | 'class' => 'large-text', |
18 | 18 | 'rows' => 3, |
19 | 19 | 'type' => 'textarea', |
20 | 20 | ]); |
21 | 21 | |
22 | - return sprintf( '<textarea %s>%s</textarea>%s', |
|
23 | - $this->implodeAttributes( $defaults ), |
|
22 | + return sprintf('<textarea %s>%s</textarea>%s', |
|
23 | + $this->implodeAttributes($defaults), |
|
24 | 24 | $this->args['value'], |
25 | 25 | $this->generateDescription() |
26 | 26 | ); |
@@ -72,7 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function generateDescription( $paragraph = true ) |
74 | 74 | { |
75 | - if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return; |
|
75 | + if( !isset( $this->args['desc'] ) || !$this->args['desc'] ) { |
|
76 | + return; |
|
77 | + } |
|
76 | 78 | |
77 | 79 | $tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span'; |
78 | 80 | |
@@ -86,7 +88,9 @@ discard block |
||
86 | 88 | */ |
87 | 89 | public function generateLabel() |
88 | 90 | { |
89 | - if( empty( $this->args['label'] ))return; |
|
91 | + if( empty( $this->args['label'] )) { |
|
92 | + return; |
|
93 | + } |
|
90 | 94 | |
91 | 95 | $for = !!$this->args['id'] |
92 | 96 | ? " for=\"{$this->args['id']}\"" |
@@ -145,7 +149,9 @@ discard block |
||
145 | 149 | |
146 | 150 | if( $method === 'singleInput' ) { |
147 | 151 | |
148 | - if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return; |
|
152 | + if( !isset( $this->args['options'] ) || empty( $this->args['options'] )) { |
|
153 | + return; |
|
154 | + } |
|
149 | 155 | |
150 | 156 | // hack to make sure unset single checkbox values start at 1 instead of 0 |
151 | 157 | if( key( $this->args['options'] ) === 0 ) { |
@@ -188,7 +194,9 @@ discard block |
||
188 | 194 | { |
189 | 195 | // similar to array_merge except overwrite empty values |
190 | 196 | foreach( $defaults as $key => $value ) { |
191 | - if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] ))continue; |
|
197 | + if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] )) { |
|
198 | + continue; |
|
199 | + } |
|
192 | 200 | $this->args[ $key ] = $value; |
193 | 201 | } |
194 | 202 | |
@@ -211,7 +219,9 @@ discard block |
||
211 | 219 | { |
212 | 220 | $args = $this->multiInputArgs( $type, $optionKey, $number ); |
213 | 221 | |
214 | - if( !$args )return; |
|
222 | + if( !$args ) { |
|
223 | + return; |
|
224 | + } |
|
215 | 225 | |
216 | 226 | $attributes = ''; |
217 | 227 | |
@@ -262,7 +272,9 @@ discard block |
||
262 | 272 | |
263 | 273 | $args = wp_parse_args( $args, $defaults ); |
264 | 274 | |
265 | - if( !isset( $label ) || $args['name'] === '' )return; |
|
275 | + if( !isset( $label ) || $args['name'] === '' ) { |
|
276 | + return; |
|
277 | + } |
|
266 | 278 | |
267 | 279 | $args['id'] = $this->args['id'] . "-{$number}"; |
268 | 280 | $args['name'] = $this->args['name'] . ( $type === 'checkbox' && $this->multi ? '[]' : '' ); |
@@ -275,11 +287,9 @@ discard block |
||
275 | 287 | if( in_array( $args['value'], $this->args['value'] )) { |
276 | 288 | $this->args['default'] = $args['value']; |
277 | 289 | } |
278 | - } |
|
279 | - else if( $this->args['value'] ) { |
|
290 | + } else if( $this->args['value'] ) { |
|
280 | 291 | $this->args['default'] = $this->args['value']; |
281 | - } |
|
282 | - else if( $type == 'radio' && !$this->args['default'] ) { |
|
292 | + } else if( $type == 'radio' && !$this->args['default'] ) { |
|
283 | 293 | $this->args['default'] = 0; |
284 | 294 | } |
285 | 295 | |
@@ -332,7 +342,9 @@ discard block |
||
332 | 342 | |
333 | 343 | $args = $this->multiInputArgs( $type, $optionKey, 1 ); |
334 | 344 | |
335 | - if( !$args )return; |
|
345 | + if( !$args ) { |
|
346 | + return; |
|
347 | + } |
|
336 | 348 | |
337 | 349 | $atts = $this->normalize(); |
338 | 350 | $atts = wp_parse_args( $args['attributes'], $atts ); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected $element; |
40 | 40 | |
41 | - public function __construct( array $args = [] ) |
|
41 | + public function __construct(array $args = []) |
|
42 | 42 | { |
43 | 43 | $this->args = $args; |
44 | 44 | } |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @return mixed |
50 | 50 | * @throws Exception |
51 | 51 | */ |
52 | - public function __get( $property ) |
|
52 | + public function __get($property) |
|
53 | 53 | { |
54 | - switch( $property ) { |
|
54 | + switch ($property) { |
|
55 | 55 | case 'args': |
56 | 56 | case 'dependencies': |
57 | 57 | case 'element': |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | case 'outside': |
60 | 60 | return $this->$property; |
61 | 61 | } |
62 | - throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property )); |
|
62 | + throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property)); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return null|string |
71 | 71 | */ |
72 | - public function generateDescription( $paragraph = true ) |
|
72 | + public function generateDescription($paragraph = true) |
|
73 | 73 | { |
74 | - if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return; |
|
74 | + if (!isset($this->args['desc']) || !$this->args['desc'])return; |
|
75 | 75 | |
76 | - $tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span'; |
|
76 | + $tag = (!!$paragraph || $paragraph == 'p') ? 'p' : 'span'; |
|
77 | 77 | |
78 | - return sprintf( '<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc'] ); |
|
78 | + return sprintf('<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc']); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function generateLabel() |
87 | 87 | { |
88 | - if( empty( $this->args['label'] ))return; |
|
88 | + if (empty($this->args['label']))return; |
|
89 | 89 | |
90 | 90 | $for = !!$this->args['id'] |
91 | 91 | ? " for=\"{$this->args['id']}\"" |
92 | 92 | : ''; |
93 | 93 | |
94 | - return sprintf( '<label%s>%s</label>', $for, $this->args['label'] ); |
|
94 | + return sprintf('<label%s>%s</label>', $for, $this->args['label']); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - protected function camelCase( $value ) |
|
111 | + protected function camelCase($value) |
|
112 | 112 | { |
113 | - $value = ucwords( str_replace( ['-', '_'], ' ', $value )); |
|
113 | + $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
114 | 114 | |
115 | - return lcfirst( str_replace( ' ', '', $value )); |
|
115 | + return lcfirst(str_replace(' ', '', $value)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - protected function implodeAttributes( $defaults = [] ) |
|
123 | + protected function implodeAttributes($defaults = []) |
|
124 | 124 | { |
125 | - return $this->normalize( $defaults, 'implode' ); |
|
125 | + return $this->normalize($defaults, 'implode'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,24 +130,24 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return null|string |
132 | 132 | */ |
133 | - protected function implodeOptions( $method = 'select_option', $default = null ) |
|
133 | + protected function implodeOptions($method = 'select_option', $default = null) |
|
134 | 134 | { |
135 | 135 | $this->args['default'] ?: $this->args['default'] = $default; |
136 | 136 | |
137 | - $method = $this->camelCase( $method ); |
|
137 | + $method = $this->camelCase($method); |
|
138 | 138 | |
139 | - $method = method_exists( $this, $method ) |
|
139 | + $method = method_exists($this, $method) |
|
140 | 140 | ? $method |
141 | 141 | : 'selectOption'; |
142 | 142 | |
143 | 143 | $i = 0; |
144 | 144 | |
145 | - if( $method === 'singleInput' ) { |
|
145 | + if ($method === 'singleInput') { |
|
146 | 146 | |
147 | - if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return; |
|
147 | + if (!isset($this->args['options']) || empty($this->args['options']))return; |
|
148 | 148 | |
149 | 149 | // hack to make sure unset single checkbox values start at 1 instead of 0 |
150 | - if( key( $this->args['options'] ) === 0 ) { |
|
150 | + if (key($this->args['options']) === 0) { |
|
151 | 151 | $options = ['1' => $this->args['options'][0]]; |
152 | 152 | $this->args['options'] = $options; |
153 | 153 | } |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | return $this->singleInput(); |
156 | 156 | } |
157 | 157 | |
158 | - return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use ( &$i, $method ) { |
|
159 | - return $carry .= $this->$method( $key, $i++ ); |
|
158 | + return array_reduce(array_keys($this->args['options']), function($carry, $key) use (&$i, $method) { |
|
159 | + return $carry .= $this->$method($key, $i++); |
|
160 | 160 | }); |
161 | 161 | } |
162 | 162 | |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - protected function normalize( array $defaults = [], $implode = false ) |
|
170 | + protected function normalize(array $defaults = [], $implode = false) |
|
171 | 171 | { |
172 | - $args = $this->mergeAttributesWith( $defaults ); |
|
172 | + $args = $this->mergeAttributesWith($defaults); |
|
173 | 173 | |
174 | 174 | $normalize = new Normalize; |
175 | 175 | |
176 | - return ( $this->element && method_exists( $normalize, $this->element )) |
|
177 | - ? $normalize->{$this->element}( $args, $implode ) |
|
178 | - : ( !!$implode ? '' : [] ); |
|
176 | + return ($this->element && method_exists($normalize, $this->element)) |
|
177 | + ? $normalize->{$this->element}($args, $implode) |
|
178 | + : (!!$implode ? '' : []); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return array |
185 | 185 | */ |
186 | - protected function mergeAttributesWith( array $defaults ) |
|
186 | + protected function mergeAttributesWith(array $defaults) |
|
187 | 187 | { |
188 | 188 | // similar to array_merge except overwrite empty values |
189 | - foreach( $defaults as $key => $value ) { |
|
190 | - if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] ))continue; |
|
191 | - $this->args[ $key ] = $value; |
|
189 | + foreach ($defaults as $key => $value) { |
|
190 | + if (isset($this->args[$key]) && !empty($this->args[$key]))continue; |
|
191 | + $this->args[$key] = $value; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $attributes = $this->args['attributes']; |
195 | 195 | |
196 | 196 | // prioritize $attributes over $this->args, don't worry about duplicates |
197 | - return array_merge( $this->args, $attributes ); |
|
197 | + return array_merge($this->args, $attributes); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -206,22 +206,22 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return null|string |
208 | 208 | */ |
209 | - protected function multiInput( $optionKey, $number, $type = 'radio' ) |
|
209 | + protected function multiInput($optionKey, $number, $type = 'radio') |
|
210 | 210 | { |
211 | - $args = $this->multiInputArgs( $type, $optionKey, $number ); |
|
211 | + $args = $this->multiInputArgs($type, $optionKey, $number); |
|
212 | 212 | |
213 | - if( !$args )return; |
|
213 | + if (!$args)return; |
|
214 | 214 | |
215 | 215 | $attributes = ''; |
216 | 216 | |
217 | - foreach( $args['attributes'] as $key => $val ) { |
|
218 | - $attributes .= sprintf( '%s="%s" ', $key, $val ); |
|
217 | + foreach ($args['attributes'] as $key => $val) { |
|
218 | + $attributes .= sprintf('%s="%s" ', $key, $val); |
|
219 | 219 | } |
220 | 220 | |
221 | - return sprintf( '<li><label for="%s"><input %s%s/> %s</label></li>', |
|
221 | + return sprintf('<li><label for="%s"><input %s%s/> %s</label></li>', |
|
222 | 222 | $args['attributes']['id'], |
223 | 223 | $attributes, |
224 | - checked( $args['value'], $args['attributes']['value'], false ), |
|
224 | + checked($args['value'], $args['attributes']['value'], false), |
|
225 | 225 | $args['label'] |
226 | 226 | ); |
227 | 227 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return array|null |
237 | 237 | */ |
238 | - protected function multiInputArgs( $type, $optionName, $number ) |
|
238 | + protected function multiInputArgs($type, $optionName, $number) |
|
239 | 239 | { |
240 | 240 | $defaults = [ |
241 | 241 | 'class' => '', |
@@ -246,39 +246,39 @@ discard block |
||
246 | 246 | |
247 | 247 | $args = []; |
248 | 248 | |
249 | - $value = $this->args['options'][ $optionName ]; |
|
249 | + $value = $this->args['options'][$optionName]; |
|
250 | 250 | |
251 | - if( is_array( $value )) { |
|
251 | + if (is_array($value)) { |
|
252 | 252 | $args = $value; |
253 | 253 | } |
254 | 254 | |
255 | - if( is_string( $value )) { |
|
255 | + if (is_string($value)) { |
|
256 | 256 | $label = $value; |
257 | 257 | } |
258 | 258 | |
259 | - isset( $args['name'] ) ?: $args['name'] = $optionName; |
|
260 | - isset( $args['value'] ) ?: $args['value'] = $optionName; |
|
259 | + isset($args['name']) ?: $args['name'] = $optionName; |
|
260 | + isset($args['value']) ?: $args['value'] = $optionName; |
|
261 | 261 | |
262 | - $args = wp_parse_args( $args, $defaults ); |
|
262 | + $args = wp_parse_args($args, $defaults); |
|
263 | 263 | |
264 | - if( !isset( $label ) || $args['name'] === '' )return; |
|
264 | + if (!isset($label) || $args['name'] === '')return; |
|
265 | 265 | |
266 | 266 | $args['id'] = $this->args['id'] . "-{$number}"; |
267 | - $args['name'] = $this->args['name'] . ( $type === 'checkbox' && $this->multi ? '[]' : '' ); |
|
267 | + $args['name'] = $this->args['name'] . ($type === 'checkbox' && $this->multi ? '[]' : ''); |
|
268 | 268 | |
269 | - $args = array_filter( $args, function( $value ) { |
|
269 | + $args = array_filter($args, function($value) { |
|
270 | 270 | return $value !== ''; |
271 | 271 | }); |
272 | 272 | |
273 | - if( is_array( $this->args['value'] )) { |
|
274 | - if( in_array( $args['value'], $this->args['value'] )) { |
|
273 | + if (is_array($this->args['value'])) { |
|
274 | + if (in_array($args['value'], $this->args['value'])) { |
|
275 | 275 | $this->args['default'] = $args['value']; |
276 | 276 | } |
277 | 277 | } |
278 | - else if( $this->args['value'] ) { |
|
278 | + else if ($this->args['value']) { |
|
279 | 279 | $this->args['default'] = $this->args['value']; |
280 | 280 | } |
281 | - else if( $type == 'radio' && !$this->args['default'] ) { |
|
281 | + else if ($type == 'radio' && !$this->args['default']) { |
|
282 | 282 | $this->args['default'] = 0; |
283 | 283 | } |
284 | 284 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return null|string |
299 | 299 | */ |
300 | - protected function multiInputCheckbox( $optionKey, $number ) |
|
300 | + protected function multiInputCheckbox($optionKey, $number) |
|
301 | 301 | { |
302 | - return $this->multiInput( $optionKey, $number, 'checkbox' ); |
|
302 | + return $this->multiInput($optionKey, $number, 'checkbox'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -309,12 +309,12 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return string |
311 | 311 | */ |
312 | - protected function selectOption( $optionKey ) |
|
312 | + protected function selectOption($optionKey) |
|
313 | 313 | { |
314 | - return sprintf( '<option value="%s"%s>%s</option>', |
|
314 | + return sprintf('<option value="%s"%s>%s</option>', |
|
315 | 315 | $optionKey, |
316 | - selected( $this->args['value'], $optionKey, false ), |
|
317 | - $this->args['options'][ $optionKey ] |
|
316 | + selected($this->args['value'], $optionKey, false), |
|
317 | + $this->args['options'][$optionKey] |
|
318 | 318 | ); |
319 | 319 | } |
320 | 320 | |
@@ -325,27 +325,27 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return null|string |
327 | 327 | */ |
328 | - protected function singleInput( $type = 'checkbox' ) |
|
328 | + protected function singleInput($type = 'checkbox') |
|
329 | 329 | { |
330 | - $optionKey = key( $this->args['options'] ); |
|
330 | + $optionKey = key($this->args['options']); |
|
331 | 331 | |
332 | - $args = $this->multiInputArgs( $type, $optionKey, 1 ); |
|
332 | + $args = $this->multiInputArgs($type, $optionKey, 1); |
|
333 | 333 | |
334 | - if( !$args )return; |
|
334 | + if (!$args)return; |
|
335 | 335 | |
336 | 336 | $atts = $this->normalize(); |
337 | - $atts = wp_parse_args( $args['attributes'], $atts ); |
|
337 | + $atts = wp_parse_args($args['attributes'], $atts); |
|
338 | 338 | |
339 | 339 | $attributes = ''; |
340 | 340 | |
341 | - foreach( $atts as $key => $val ) { |
|
342 | - $attributes .= sprintf( '%s="%s" ', $key, $val ); |
|
341 | + foreach ($atts as $key => $val) { |
|
342 | + $attributes .= sprintf('%s="%s" ', $key, $val); |
|
343 | 343 | } |
344 | 344 | |
345 | - return sprintf( '<label for="%s"><input %s%s/> %s</label>', |
|
345 | + return sprintf('<label for="%s"><input %s%s/> %s</label>', |
|
346 | 346 | $atts['id'], |
347 | 347 | $attributes, |
348 | - checked( $args['value'], $atts['value'], false ), |
|
348 | + checked($args['value'], $atts['value'], false), |
|
349 | 349 | $args['label'] |
350 | 350 | ); |
351 | 351 | } |
@@ -11,15 +11,15 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( array $defaults = [] ) |
|
14 | + public function render(array $defaults = []) |
|
15 | 15 | { |
16 | - $defaults = wp_parse_args( $defaults, [ |
|
16 | + $defaults = wp_parse_args($defaults, [ |
|
17 | 17 | 'class' => 'regular-text', |
18 | 18 | 'type' => 'text', |
19 | 19 | ]); |
20 | 20 | |
21 | - return sprintf( '<input %s/>%s', |
|
22 | - $this->implodeAttributes( $defaults ), |
|
21 | + return sprintf('<input %s/>%s', |
|
22 | + $this->implodeAttributes($defaults), |
|
23 | 23 | $this->generateDescription() |
24 | 24 | ); |
25 | 25 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected $normalize; |
35 | 35 | |
36 | - public function __construct( Field $field, Normalizer $normalize ) |
|
36 | + public function __construct(Field $field, Normalizer $normalize) |
|
37 | 37 | { |
38 | 38 | $this->args = []; |
39 | 39 | $this->dependencies = []; |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | * @return mixed |
49 | 49 | * @throws Exception |
50 | 50 | */ |
51 | - public function __get( $property ) |
|
51 | + public function __get($property) |
|
52 | 52 | { |
53 | - switch( $property ) { |
|
53 | + switch ($property) { |
|
54 | 54 | case 'args': |
55 | 55 | case 'dependencies': |
56 | 56 | case 'fields': |
57 | 57 | return $this->$property; |
58 | 58 | } |
59 | - throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property )); |
|
59 | + throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property)); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | * @return void |
67 | 67 | * @throws Exception |
68 | 68 | */ |
69 | - public function __set( $property, $value ) |
|
69 | + public function __set($property, $value) |
|
70 | 70 | { |
71 | - switch( $property ) { |
|
71 | + switch ($property) { |
|
72 | 72 | case 'args': |
73 | 73 | case 'dependencies': |
74 | 74 | case 'fields': |
75 | 75 | $this->$property = $value; |
76 | 76 | break; |
77 | 77 | default: |
78 | - throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property )); |
|
78 | + throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property)); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return Form |
86 | 86 | */ |
87 | - public function addField( array $args = [] ) |
|
87 | + public function addField(array $args = []) |
|
88 | 88 | { |
89 | - $field = $this->field->normalize( $args ); |
|
89 | + $field = $this->field->normalize($args); |
|
90 | 90 | |
91 | - if( $field->args['render'] !== false ) { |
|
91 | + if ($field->args['render'] !== false) { |
|
92 | 92 | $this->dependencies = array_unique( |
93 | - array_merge( $field->dependencies, $this->dependencies ) |
|
93 | + array_merge($field->dependencies, $this->dependencies) |
|
94 | 94 | ); |
95 | 95 | $this->fields[] = $field; |
96 | 96 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return Form |
105 | 105 | */ |
106 | - public function normalize( array $args = [] ) |
|
106 | + public function normalize(array $args = []) |
|
107 | 107 | { |
108 | 108 | $defaults = [ |
109 | 109 | 'action' => '', |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | 'enctype' => 'multipart/form-data', |
114 | 114 | 'method' => 'post', |
115 | 115 | 'nonce' => '', |
116 | - 'submit' => __( 'Submit', 'site-reviews' ), |
|
116 | + 'submit' => __('Submit', 'site-reviews'), |
|
117 | 117 | ]; |
118 | 118 | |
119 | - $this->args = array_merge( $defaults, $args ); |
|
119 | + $this->args = array_merge($defaults, $args); |
|
120 | 120 | |
121 | - $attributes = $this->normalize->form( $this->args, 'implode' ); |
|
121 | + $attributes = $this->normalize->form($this->args, 'implode'); |
|
122 | 122 | |
123 | 123 | $this->args['attributes'] = $attributes; |
124 | 124 | |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return string|void |
134 | 134 | */ |
135 | - public function render( $print = true ) |
|
135 | + public function render($print = true) |
|
136 | 136 | { |
137 | - $rendered = sprintf( '<form %s>%s%s</form>', |
|
137 | + $rendered = sprintf('<form %s>%s%s</form>', |
|
138 | 138 | $this->args['attributes'], |
139 | 139 | $this->generateFields(), |
140 | 140 | $this->generateSubmitButton() |
141 | 141 | ); |
142 | 142 | |
143 | - if( !!$print && $print !== 'return' ) { |
|
143 | + if (!!$print && $print !== 'return') { |
|
144 | 144 | echo $rendered; |
145 | 145 | } |
146 | 146 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $hiddenFields = ''; |
171 | 171 | |
172 | - $fields = array_reduce( $this->fields, function( $carry, $formField ) use ( &$hiddenFields ) { |
|
172 | + $fields = array_reduce($this->fields, function($carry, $formField) use (&$hiddenFields) { |
|
173 | 173 | |
174 | 174 | $stringLegend = '<legend class="screen-reader-text"><span>%s</span></legend>'; |
175 | 175 | $stringFieldset = '<fieldset%s>%s%s</fieldset>'; |
@@ -185,30 +185,30 @@ discard block |
||
185 | 185 | $rendered = $field->render(); |
186 | 186 | |
187 | 187 | // render hidden inputs outside the table |
188 | - if( $field->args['type'] === 'hidden' ) { |
|
188 | + if ($field->args['type'] === 'hidden') { |
|
189 | 189 | $hiddenFields .= $rendered; |
190 | 190 | return $carry; |
191 | 191 | } |
192 | 192 | |
193 | - $hiddenClass = $this->isFieldHidden( $formField ) ? 'hidden' : ''; |
|
193 | + $hiddenClass = $this->isFieldHidden($formField) ? 'hidden' : ''; |
|
194 | 194 | |
195 | - if( $multi ) { |
|
196 | - if( $depends = $formField->getDataDepends() ) { |
|
197 | - $depends = sprintf( ' data-depends=\'%s\'', json_encode( $depends )); |
|
195 | + if ($multi) { |
|
196 | + if ($depends = $formField->getDataDepends()) { |
|
197 | + $depends = sprintf(' data-depends=\'%s\'', json_encode($depends)); |
|
198 | 198 | } |
199 | 199 | |
200 | - $legend = $label ? sprintf( $stringLegend, $label ) : ''; |
|
201 | - $rendered = sprintf( $stringFieldset, $depends, $legend, $rendered ); |
|
200 | + $legend = $label ? sprintf($stringLegend, $label) : ''; |
|
201 | + $rendered = sprintf($stringFieldset, $depends, $legend, $rendered); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | $renderedField = $field->outside |
205 | - ? sprintf( $outsideRendered, $rendered ) |
|
206 | - : sprintf( $stringRendered, $hiddenClass, $label, $rendered ); |
|
205 | + ? sprintf($outsideRendered, $rendered) |
|
206 | + : sprintf($stringRendered, $hiddenClass, $label, $rendered); |
|
207 | 207 | |
208 | 208 | return $carry . $renderedField; |
209 | 209 | }); |
210 | 210 | |
211 | - return sprintf( '<table class="form-table"><tbody>%s</tbody></table>%s', $fields, $hiddenFields ); |
|
211 | + return sprintf('<table class="form-table"><tbody>%s</tbody></table>%s', $fields, $hiddenFields); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -220,19 +220,19 @@ discard block |
||
220 | 220 | { |
221 | 221 | $args = $this->args['submit']; |
222 | 222 | |
223 | - is_array( $args ) ?: $args = ['text' => $args ]; |
|
223 | + is_array($args) ?: $args = ['text' => $args]; |
|
224 | 224 | |
225 | 225 | $args = shortcode_atts([ |
226 | - 'text' => __( 'Save Changes', 'site-reviews' ), |
|
226 | + 'text' => __('Save Changes', 'site-reviews'), |
|
227 | 227 | 'type' => 'primary', |
228 | 228 | 'name' => 'submit', |
229 | 229 | 'wrap' => true, |
230 | 230 | 'other_attributes' => null, |
231 | - ], $args ); |
|
231 | + ], $args); |
|
232 | 232 | |
233 | - if( is_admin() ) { |
|
233 | + if (is_admin()) { |
|
234 | 234 | ob_start(); |
235 | - submit_button( $args['text'], $args['type'], $args['name'], $args['wrap'], $args['other_attributes'] ); |
|
235 | + submit_button($args['text'], $args['type'], $args['name'], $args['wrap'], $args['other_attributes']); |
|
236 | 236 | return ob_get_clean(); |
237 | 237 | } |
238 | 238 | } |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @return bool|null |
244 | 244 | */ |
245 | - protected function isFieldHidden( $field ) |
|
245 | + protected function isFieldHidden($field) |
|
246 | 246 | { |
247 | - if( !( $dependsOn = $field->getDataDepends() ))return; |
|
247 | + if (!($dependsOn = $field->getDataDepends()))return; |
|
248 | 248 | |
249 | - foreach( $this->fields as $formField ) { |
|
250 | - if( $dependsOn['name'] !== $formField->args['name'] )continue; |
|
249 | + foreach ($this->fields as $formField) { |
|
250 | + if ($dependsOn['name'] !== $formField->args['name'])continue; |
|
251 | 251 | |
252 | - if( is_array( $dependsOn['value'] )) { |
|
253 | - return !in_array( $formField->args['value'], $dependsOn['value'] ); |
|
252 | + if (is_array($dependsOn['value'])) { |
|
253 | + return !in_array($formField->args['value'], $dependsOn['value']); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return $dependsOn['value'] != $formField->args['value']; |
@@ -244,10 +244,14 @@ |
||
244 | 244 | */ |
245 | 245 | protected function isFieldHidden( $field ) |
246 | 246 | { |
247 | - if( !( $dependsOn = $field->getDataDepends() ))return; |
|
247 | + if( !( $dependsOn = $field->getDataDepends() )) { |
|
248 | + return; |
|
249 | + } |
|
248 | 250 | |
249 | 251 | foreach( $this->fields as $formField ) { |
250 | - if( $dependsOn['name'] !== $formField->args['name'] )continue; |
|
252 | + if( $dependsOn['name'] !== $formField->args['name'] ) { |
|
253 | + continue; |
|
254 | + } |
|
251 | 255 | |
252 | 256 | if( is_array( $dependsOn['value'] )) { |
253 | 257 | return !in_array( $formField->args['value'], $dependsOn['value'] ); |