@@ -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 | ); |
@@ -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'; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | return $this->$property; |
61 | 61 | } |
62 | 62 | |
63 | - throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $property ); |
|
63 | + throw new Exception('Invalid ' . __CLASS__ . ' property: ' . $property); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return null|string |
72 | 72 | */ |
73 | - public function generateDescription( $paragraph = true ) |
|
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'])return; |
|
76 | 76 | |
77 | - $tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span'; |
|
77 | + $tag = (!!$paragraph || $paragraph == 'p') ? 'p' : 'span'; |
|
78 | 78 | |
79 | - return sprintf( '<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc'] ); |
|
79 | + return sprintf('<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc']); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function generateLabel() |
88 | 88 | { |
89 | - if( empty( $this->args['label'] ))return; |
|
89 | + if (empty($this->args['label']))return; |
|
90 | 90 | |
91 | 91 | $for = !!$this->args['id'] |
92 | 92 | ? " for=\"{$this->args['id']}\"" |
93 | 93 | : ''; |
94 | 94 | |
95 | - return sprintf( '<label%s>%s</label>', $for, $this->args['label'] ); |
|
95 | + return sprintf('<label%s>%s</label>', $for, $this->args['label']); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - protected function camelCase( $value ) |
|
112 | + protected function camelCase($value) |
|
113 | 113 | { |
114 | - $value = ucwords( str_replace( ['-', '_'], ' ', $value )); |
|
114 | + $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
115 | 115 | |
116 | - return lcfirst( str_replace( ' ', '', $value )); |
|
116 | + return lcfirst(str_replace(' ', '', $value)); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return array |
123 | 123 | */ |
124 | - protected function implodeAttributes( $defaults = [] ) |
|
124 | + protected function implodeAttributes($defaults = []) |
|
125 | 125 | { |
126 | - return $this->normalize( $defaults, 'implode' ); |
|
126 | + return $this->normalize($defaults, 'implode'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,24 +131,24 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return null|string |
133 | 133 | */ |
134 | - protected function implodeOptions( $method = 'select_option', $default = null ) |
|
134 | + protected function implodeOptions($method = 'select_option', $default = null) |
|
135 | 135 | { |
136 | 136 | $this->args['default'] ?: $this->args['default'] = $default; |
137 | 137 | |
138 | - $method = $this->camelCase( $method ); |
|
138 | + $method = $this->camelCase($method); |
|
139 | 139 | |
140 | - $method = method_exists( $this, $method ) |
|
140 | + $method = method_exists($this, $method) |
|
141 | 141 | ? $method |
142 | 142 | : 'selectOption'; |
143 | 143 | |
144 | 144 | $i = 0; |
145 | 145 | |
146 | - if( $method === 'singleInput' ) { |
|
146 | + if ($method === 'singleInput') { |
|
147 | 147 | |
148 | - if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return; |
|
148 | + if (!isset($this->args['options']) || empty($this->args['options']))return; |
|
149 | 149 | |
150 | 150 | // hack to make sure unset single checkbox values start at 1 instead of 0 |
151 | - if( key( $this->args['options'] ) === 0 ) { |
|
151 | + if (key($this->args['options']) === 0) { |
|
152 | 152 | $options = ['1' => $this->args['options'][0]]; |
153 | 153 | $this->args['options'] = $options; |
154 | 154 | } |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | return $this->singleInput(); |
157 | 157 | } |
158 | 158 | |
159 | - return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use ( &$i, $method ) { |
|
160 | - return $carry .= $this->$method( $key, $i++ ); |
|
159 | + return array_reduce(array_keys($this->args['options']), function($carry, $key) use (&$i, $method) { |
|
160 | + return $carry .= $this->$method($key, $i++); |
|
161 | 161 | }); |
162 | 162 | } |
163 | 163 | |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return array |
170 | 170 | */ |
171 | - protected function normalize( array $defaults = [], $implode = false ) |
|
171 | + protected function normalize(array $defaults = [], $implode = false) |
|
172 | 172 | { |
173 | - $args = $this->mergeAttributesWith( $defaults ); |
|
173 | + $args = $this->mergeAttributesWith($defaults); |
|
174 | 174 | |
175 | 175 | $normalize = new Normalize; |
176 | 176 | |
177 | - return ( $this->element && method_exists( $normalize, $this->element )) |
|
178 | - ? $normalize->{$this->element}( $args, $implode ) |
|
179 | - : ( !!$implode ? '' : [] ); |
|
177 | + return ($this->element && method_exists($normalize, $this->element)) |
|
178 | + ? $normalize->{$this->element}($args, $implode) |
|
179 | + : (!!$implode ? '' : []); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return array |
186 | 186 | */ |
187 | - protected function mergeAttributesWith( array $defaults ) |
|
187 | + protected function mergeAttributesWith(array $defaults) |
|
188 | 188 | { |
189 | 189 | // similar to array_merge except overwrite empty values |
190 | - foreach( $defaults as $key => $value ) { |
|
191 | - if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] ))continue; |
|
192 | - $this->args[ $key ] = $value; |
|
190 | + foreach ($defaults as $key => $value) { |
|
191 | + if (isset($this->args[$key]) && !empty($this->args[$key]))continue; |
|
192 | + $this->args[$key] = $value; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $attributes = $this->args['attributes']; |
196 | 196 | |
197 | 197 | // prioritize $attributes over $this->args, don't worry about duplicates |
198 | - return array_merge( $this->args, $attributes ); |
|
198 | + return array_merge($this->args, $attributes); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -207,22 +207,22 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return null|string |
209 | 209 | */ |
210 | - protected function multiInput( $optionKey, $number, $type = 'radio' ) |
|
210 | + protected function multiInput($optionKey, $number, $type = 'radio') |
|
211 | 211 | { |
212 | - $args = $this->multiInputArgs( $type, $optionKey, $number ); |
|
212 | + $args = $this->multiInputArgs($type, $optionKey, $number); |
|
213 | 213 | |
214 | - if( !$args )return; |
|
214 | + if (!$args)return; |
|
215 | 215 | |
216 | 216 | $attributes = ''; |
217 | 217 | |
218 | - foreach( $args['attributes'] as $key => $val ) { |
|
219 | - $attributes .= sprintf( '%s="%s" ', $key, $val ); |
|
218 | + foreach ($args['attributes'] as $key => $val) { |
|
219 | + $attributes .= sprintf('%s="%s" ', $key, $val); |
|
220 | 220 | } |
221 | 221 | |
222 | - return sprintf( '<li><label for="%s"><input %s%s/> %s</label></li>', |
|
222 | + return sprintf('<li><label for="%s"><input %s%s/> %s</label></li>', |
|
223 | 223 | $args['attributes']['id'], |
224 | 224 | $attributes, |
225 | - checked( $args['value'], $args['attributes']['value'], false ), |
|
225 | + checked($args['value'], $args['attributes']['value'], false), |
|
226 | 226 | $args['label'] |
227 | 227 | ); |
228 | 228 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return array|null |
238 | 238 | */ |
239 | - protected function multiInputArgs( $type, $optionName, $number ) |
|
239 | + protected function multiInputArgs($type, $optionName, $number) |
|
240 | 240 | { |
241 | 241 | $defaults = [ |
242 | 242 | 'class' => '', |
@@ -247,39 +247,39 @@ discard block |
||
247 | 247 | |
248 | 248 | $args = []; |
249 | 249 | |
250 | - $value = $this->args['options'][ $optionName ]; |
|
250 | + $value = $this->args['options'][$optionName]; |
|
251 | 251 | |
252 | - if( is_array( $value )) { |
|
252 | + if (is_array($value)) { |
|
253 | 253 | $args = $value; |
254 | 254 | } |
255 | 255 | |
256 | - if( is_string( $value )) { |
|
256 | + if (is_string($value)) { |
|
257 | 257 | $label = $value; |
258 | 258 | } |
259 | 259 | |
260 | - isset( $args['name'] ) ?: $args['name'] = $optionName; |
|
261 | - isset( $args['value'] ) ?: $args['value'] = $optionName; |
|
260 | + isset($args['name']) ?: $args['name'] = $optionName; |
|
261 | + isset($args['value']) ?: $args['value'] = $optionName; |
|
262 | 262 | |
263 | - $args = wp_parse_args( $args, $defaults ); |
|
263 | + $args = wp_parse_args($args, $defaults); |
|
264 | 264 | |
265 | - if( !isset( $label ) || $args['name'] === '' )return; |
|
265 | + if (!isset($label) || $args['name'] === '')return; |
|
266 | 266 | |
267 | 267 | $args['id'] = $this->args['id'] . "-{$number}"; |
268 | - $args['name'] = $this->args['name'] . ( $type === 'checkbox' && $this->multi ? '[]' : '' ); |
|
268 | + $args['name'] = $this->args['name'] . ($type === 'checkbox' && $this->multi ? '[]' : ''); |
|
269 | 269 | |
270 | - $args = array_filter( $args, function( $value ) { |
|
270 | + $args = array_filter($args, function($value) { |
|
271 | 271 | return $value !== ''; |
272 | 272 | }); |
273 | 273 | |
274 | - if( is_array( $this->args['value'] )) { |
|
275 | - if( in_array( $args['value'], $this->args['value'] )) { |
|
274 | + if (is_array($this->args['value'])) { |
|
275 | + if (in_array($args['value'], $this->args['value'])) { |
|
276 | 276 | $this->args['default'] = $args['value']; |
277 | 277 | } |
278 | 278 | } |
279 | - else if( $this->args['value'] ) { |
|
279 | + else if ($this->args['value']) { |
|
280 | 280 | $this->args['default'] = $this->args['value']; |
281 | 281 | } |
282 | - else if( $type == 'radio' && !$this->args['default'] ) { |
|
282 | + else if ($type == 'radio' && !$this->args['default']) { |
|
283 | 283 | $this->args['default'] = 0; |
284 | 284 | } |
285 | 285 | |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return null|string |
300 | 300 | */ |
301 | - protected function multiInputCheckbox( $optionKey, $number ) |
|
301 | + protected function multiInputCheckbox($optionKey, $number) |
|
302 | 302 | { |
303 | - return $this->multiInput( $optionKey, $number, 'checkbox' ); |
|
303 | + return $this->multiInput($optionKey, $number, 'checkbox'); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,12 +310,12 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - protected function selectOption( $optionKey ) |
|
313 | + protected function selectOption($optionKey) |
|
314 | 314 | { |
315 | - return sprintf( '<option value="%s"%s>%s</option>', |
|
315 | + return sprintf('<option value="%s"%s>%s</option>', |
|
316 | 316 | $optionKey, |
317 | - selected( $this->args['value'], $optionKey, false ), |
|
318 | - $this->args['options'][ $optionKey ] |
|
317 | + selected($this->args['value'], $optionKey, false), |
|
318 | + $this->args['options'][$optionKey] |
|
319 | 319 | ); |
320 | 320 | } |
321 | 321 | |
@@ -326,27 +326,27 @@ discard block |
||
326 | 326 | * |
327 | 327 | * @return null|string |
328 | 328 | */ |
329 | - protected function singleInput( $type = 'checkbox' ) |
|
329 | + protected function singleInput($type = 'checkbox') |
|
330 | 330 | { |
331 | - $optionKey = key( $this->args['options'] ); |
|
331 | + $optionKey = key($this->args['options']); |
|
332 | 332 | |
333 | - $args = $this->multiInputArgs( $type, $optionKey, 1 ); |
|
333 | + $args = $this->multiInputArgs($type, $optionKey, 1); |
|
334 | 334 | |
335 | - if( !$args )return; |
|
335 | + if (!$args)return; |
|
336 | 336 | |
337 | 337 | $atts = $this->normalize(); |
338 | - $atts = wp_parse_args( $args['attributes'], $atts ); |
|
338 | + $atts = wp_parse_args($args['attributes'], $atts); |
|
339 | 339 | |
340 | 340 | $attributes = ''; |
341 | 341 | |
342 | - foreach( $atts as $key => $val ) { |
|
343 | - $attributes .= sprintf( '%s="%s" ', $key, $val ); |
|
342 | + foreach ($atts as $key => $val) { |
|
343 | + $attributes .= sprintf('%s="%s" ', $key, $val); |
|
344 | 344 | } |
345 | 345 | |
346 | - return sprintf( '<label for="%s"><input %s%s/> %s</label>', |
|
346 | + return sprintf('<label for="%s"><input %s%s/> %s</label>', |
|
347 | 347 | $atts['id'], |
348 | 348 | $attributes, |
349 | - checked( $args['value'], $atts['value'], false ), |
|
349 | + checked($args['value'], $atts['value'], false), |
|
350 | 350 | $args['label'] |
351 | 351 | ); |
352 | 352 | } |
@@ -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 ); |
@@ -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 | } |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * @return mixed |
27 | 27 | * @throws Exception |
28 | 28 | */ |
29 | - public function __get( $property ) |
|
29 | + public function __get($property) |
|
30 | 30 | { |
31 | - switch( $property ) { |
|
31 | + switch ($property) { |
|
32 | 32 | case 'args'; |
33 | 33 | case 'dependencies'; |
34 | 34 | return $this->$property; |
35 | 35 | } |
36 | - throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property )); |
|
36 | + throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property)); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return mixed GeminiLabs\SiteReviews\Html\Fields\* |
44 | 44 | */ |
45 | - public function getField( array $args = [] ) |
|
45 | + public function getField(array $args = []) |
|
46 | 46 | { |
47 | - if( empty( $args )) { |
|
47 | + if (empty($args)) { |
|
48 | 48 | $args = $this->args; |
49 | 49 | } |
50 | 50 | |
51 | - $className = sprintf( 'GeminiLabs\Castor\Forms\Fields\%s', ucfirst( $args['type'] )); |
|
51 | + $className = sprintf('GeminiLabs\Castor\Forms\Fields\%s', ucfirst($args['type'])); |
|
52 | 52 | |
53 | - if( !class_exists( $className )) { |
|
54 | - throw new ReflectionException( "Class does not exist: {$className}" ); |
|
53 | + if (!class_exists($className)) { |
|
54 | + throw new ReflectionException("Class does not exist: {$className}"); |
|
55 | 55 | } |
56 | 56 | |
57 | - return (new $className( $args )); |
|
57 | + return (new $className($args)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return $this |
64 | 64 | */ |
65 | - public function normalize( array $args = [] ) |
|
65 | + public function normalize(array $args = []) |
|
66 | 66 | { |
67 | 67 | $defaults = [ |
68 | 68 | 'after' => '', |
@@ -86,23 +86,23 @@ discard block |
||
86 | 86 | 'value' => '', |
87 | 87 | ]; |
88 | 88 | |
89 | - $args = $atts = wp_parse_args( $args, $defaults ); |
|
89 | + $args = $atts = wp_parse_args($args, $defaults); |
|
90 | 90 | |
91 | - $args['attributes'] = $this->parseAttributes( $atts ); |
|
92 | - $args['id'] = $this->parseId( $atts ); |
|
93 | - $args['inline'] = $this->parseInline( $atts ); |
|
94 | - $args['type'] = $this->parseType( $atts ); |
|
95 | - $args['name'] = $this->parseName( $atts ); |
|
91 | + $args['attributes'] = $this->parseAttributes($atts); |
|
92 | + $args['id'] = $this->parseId($atts); |
|
93 | + $args['inline'] = $this->parseInline($atts); |
|
94 | + $args['type'] = $this->parseType($atts); |
|
95 | + $args['name'] = $this->parseName($atts); |
|
96 | 96 | $args['options'] = (array) $atts['options']; // make sure this is always an array |
97 | 97 | $args['path'] = $atts['name']; |
98 | - $args['prefix'] = $this->parsePrefix( $atts ); |
|
99 | - $args['value'] = $this->parseValue( $atts ); |
|
98 | + $args['prefix'] = $this->parsePrefix($atts); |
|
99 | + $args['value'] = $this->parseValue($atts); |
|
100 | 100 | |
101 | 101 | $this->args = $args; |
102 | - $this->dependencies = $this->getField( $args )->dependencies; |
|
102 | + $this->dependencies = $this->getField($args)->dependencies; |
|
103 | 103 | |
104 | 104 | $this->setDataDepends(); |
105 | - $this->checkForErrors( $atts ); |
|
105 | + $this->checkForErrors($atts); |
|
106 | 106 | |
107 | 107 | return $this; |
108 | 108 | } |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string|void |
116 | 116 | */ |
117 | - public function render( $print = true ) |
|
117 | + public function render($print = true) |
|
118 | 118 | { |
119 | - if( $this->args['render'] === false )return; |
|
119 | + if ($this->args['render'] === false)return; |
|
120 | 120 | |
121 | 121 | $field = $this->getField(); |
122 | 122 | |
@@ -125,16 +125,16 @@ discard block |
||
125 | 125 | |
126 | 126 | $renderedString = '%s'; |
127 | 127 | |
128 | - if( ( isset( $field->args['required'] ) && $field->args['required'] ) |
|
129 | - || ( isset( $field->args['attributes']['required'] ) || in_array( 'required', $field->args['attributes'] )) ) { |
|
128 | + if ((isset($field->args['required']) && $field->args['required']) |
|
129 | + || (isset($field->args['attributes']['required']) || in_array('required', $field->args['attributes']))) { |
|
130 | 130 | $class .= ' glsr-required'; |
131 | 131 | } |
132 | 132 | |
133 | - if( $field->args['type'] !== 'hidden' ) { |
|
134 | - $renderedString = sprintf( '<div class="%s">%%s</div>', $class ); |
|
133 | + if ($field->args['type'] !== 'hidden') { |
|
134 | + $renderedString = sprintf('<div class="%s">%%s</div>', $class); |
|
135 | 135 | } |
136 | 136 | |
137 | - $rendered = sprintf( $renderedString, |
|
137 | + $rendered = sprintf($renderedString, |
|
138 | 138 | $this->args['before'] . |
139 | 139 | $field->generateLabel() . |
140 | 140 | $field->render() . |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | $this->args['errors'] |
143 | 143 | ); |
144 | 144 | |
145 | - $rendered = apply_filters( 'castor/rendered/field', $rendered, $field->args['type'] ); |
|
145 | + $rendered = apply_filters('castor/rendered/field', $rendered, $field->args['type']); |
|
146 | 146 | |
147 | - if( !!$print && $print !== 'return' ) { |
|
147 | + if (!!$print && $print !== 'return') { |
|
148 | 148 | echo $rendered; |
149 | 149 | } |
150 | 150 | |
@@ -168,22 +168,22 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - protected function checkForErrors( array $atts ) |
|
171 | + protected function checkForErrors(array $atts) |
|
172 | 172 | { |
173 | 173 | $args = $this->args; |
174 | 174 | |
175 | - if( !array_key_exists( $atts['name'], $args['errors'] )) { |
|
175 | + if (!array_key_exists($atts['name'], $args['errors'])) { |
|
176 | 176 | $this->args['errors'] = ''; // set to an empty string |
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - $field_errors = $args['errors'][ $atts['name'] ]; |
|
180 | + $field_errors = $args['errors'][$atts['name']]; |
|
181 | 181 | |
182 | - $errors = array_reduce( $field_errors['errors'], function( $carry, $error ) { |
|
183 | - return $carry . sprintf( '<span>%s</span> ', $error ); |
|
182 | + $errors = array_reduce($field_errors['errors'], function($carry, $error) { |
|
183 | + return $carry . sprintf('<span>%s</span> ', $error); |
|
184 | 184 | }); |
185 | 185 | |
186 | - $this->args['errors'] = sprintf( '<span class="glsr-field-errors">%s</span>', $errors ); |
|
186 | + $this->args['errors'] = sprintf('<span class="glsr-field-errors">%s</span>', $errors); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return array |
193 | 193 | */ |
194 | - protected function parseAttributes( array $args ) |
|
194 | + protected function parseAttributes(array $args) |
|
195 | 195 | { |
196 | - if( empty( $args['attributes'] )) { |
|
196 | + if (empty($args['attributes'])) { |
|
197 | 197 | return []; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $attributes = (array) $args['attributes']; |
201 | 201 | |
202 | - foreach( $attributes as $key => $value ) { |
|
203 | - if( is_string( $key ))continue; |
|
204 | - unset( $attributes[ $key ] ); |
|
205 | - if( !isset( $attributes[ $value ] )) { |
|
206 | - $attributes[ $value ] = ''; |
|
202 | + foreach ($attributes as $key => $value) { |
|
203 | + if (is_string($key))continue; |
|
204 | + unset($attributes[$key]); |
|
205 | + if (!isset($attributes[$value])) { |
|
206 | + $attributes[$value] = ''; |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return null|string |
217 | 217 | */ |
218 | - protected function parseId( array $args ) |
|
218 | + protected function parseId(array $args) |
|
219 | 219 | { |
220 | - if( isset( $args['id'] ) && !$args['id'] )return; |
|
220 | + if (isset($args['id']) && !$args['id'])return; |
|
221 | 221 | |
222 | 222 | !$args['suffix'] ?: $args['suffix'] = "-{$args['suffix']}"; |
223 | 223 | |
224 | - return str_replace( ['[]','[',']','.'], ['','-','','-'], $this->parseName( $args ) . $args['suffix'] ); |
|
224 | + return str_replace(['[]', '[', ']', '.'], ['', '-', '', '-'], $this->parseName($args) . $args['suffix']); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return bool |
231 | 231 | */ |
232 | - protected function parseInline( array $args ) |
|
232 | + protected function parseInline(array $args) |
|
233 | 233 | { |
234 | - return false !== stripos( $args['type'], '_inline' ) |
|
234 | + return false !== stripos($args['type'], '_inline') |
|
235 | 235 | ? true |
236 | 236 | : $args['inline']; |
237 | 237 | } |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - protected function parseName( array $args ) |
|
244 | + protected function parseName(array $args) |
|
245 | 245 | { |
246 | 246 | $name = $args['name']; |
247 | - $prefix = $this->parsePrefix( $args ); |
|
247 | + $prefix = $this->parsePrefix($args); |
|
248 | 248 | |
249 | - if( $prefix === false ) { |
|
249 | + if ($prefix === false) { |
|
250 | 250 | return $name; |
251 | 251 | } |
252 | 252 | |
253 | - $paths = explode( '.', $name ); |
|
253 | + $paths = explode('.', $name); |
|
254 | 254 | |
255 | - return array_reduce( $paths, function( $result, $value ) { |
|
255 | + return array_reduce($paths, function($result, $value) { |
|
256 | 256 | return $result .= "[$value]"; |
257 | - }, $prefix ); |
|
257 | + }, $prefix); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return string|false |
264 | 264 | */ |
265 | - protected function parsePrefix( array $args ) |
|
265 | + protected function parsePrefix(array $args) |
|
266 | 266 | { |
267 | 267 | return $args['prefix']; |
268 | 268 | } |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return string |
274 | 274 | */ |
275 | - protected function parseType( array $args ) |
|
275 | + protected function parseType(array $args) |
|
276 | 276 | { |
277 | 277 | $type = $args['type']; |
278 | 278 | |
279 | - return false !== stripos( $type, '_inline' ) |
|
280 | - ? str_replace( '_inline', '', $type ) |
|
279 | + return false !== stripos($type, '_inline') |
|
280 | + ? str_replace('_inline', '', $type) |
|
281 | 281 | : $type; |
282 | 282 | } |
283 | 283 | |
@@ -286,18 +286,18 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return string |
288 | 288 | */ |
289 | - protected function parseValue( array $args ) |
|
289 | + protected function parseValue(array $args) |
|
290 | 290 | { |
291 | 291 | $default = $args['default']; |
292 | 292 | $name = $args['name']; |
293 | 293 | $prefix = $args['prefix']; |
294 | 294 | $value = $args['value']; |
295 | 295 | |
296 | - if( $default == ':placeholder' ) { |
|
296 | + if ($default == ':placeholder') { |
|
297 | 297 | $default = ''; |
298 | 298 | } |
299 | 299 | |
300 | - return ( !empty( $value ) || !$name || $prefix === false ) |
|
300 | + return (!empty($value) || !$name || $prefix === false) |
|
301 | 301 | ? $value |
302 | 302 | : $default; |
303 | 303 | } |
@@ -329,15 +329,15 @@ discard block |
||
329 | 329 | */ |
330 | 330 | protected function setDataDepends() |
331 | 331 | { |
332 | - if( !( $depends = $this->args['depends'] ))return; |
|
332 | + if (!($depends = $this->args['depends']))return; |
|
333 | 333 | |
334 | 334 | $name = $depends; |
335 | 335 | $value = true; |
336 | 336 | |
337 | - if( is_array( $depends )) { |
|
338 | - reset( $depends ); |
|
339 | - $name = key( $depends ); |
|
340 | - $value = $depends[ $name ]; |
|
337 | + if (is_array($depends)) { |
|
338 | + reset($depends); |
|
339 | + $name = key($depends); |
|
340 | + $value = $depends[$name]; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | $name = $this->parseName([ |
@@ -116,7 +116,9 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function render( $print = true ) |
118 | 118 | { |
119 | - if( $this->args['render'] === false )return; |
|
119 | + if( $this->args['render'] === false ) { |
|
120 | + return; |
|
121 | + } |
|
120 | 122 | |
121 | 123 | $field = $this->getField(); |
122 | 124 | |
@@ -200,7 +202,9 @@ discard block |
||
200 | 202 | $attributes = (array) $args['attributes']; |
201 | 203 | |
202 | 204 | foreach( $attributes as $key => $value ) { |
203 | - if( is_string( $key ))continue; |
|
205 | + if( is_string( $key )) { |
|
206 | + continue; |
|
207 | + } |
|
204 | 208 | unset( $attributes[ $key ] ); |
205 | 209 | if( !isset( $attributes[ $value ] )) { |
206 | 210 | $attributes[ $value ] = ''; |
@@ -217,7 +221,9 @@ discard block |
||
217 | 221 | */ |
218 | 222 | protected function parseId( array $args ) |
219 | 223 | { |
220 | - if( isset( $args['id'] ) && !$args['id'] )return; |
|
224 | + if( isset( $args['id'] ) && !$args['id'] ) { |
|
225 | + return; |
|
226 | + } |
|
221 | 227 | |
222 | 228 | !$args['suffix'] ?: $args['suffix'] = "-{$args['suffix']}"; |
223 | 229 | |
@@ -329,7 +335,9 @@ discard block |
||
329 | 335 | */ |
330 | 336 | protected function setDataDepends() |
331 | 337 | { |
332 | - if( !( $depends = $this->args['depends'] ))return; |
|
338 | + if( !( $depends = $this->args['depends'] )) { |
|
339 | + return; |
|
340 | + } |
|
333 | 341 | |
334 | 342 | $name = $depends; |
335 | 343 | $value = true; |