1 | <?php |
||||
2 | /** |
||||
3 | * Meta Box Gateway Config |
||||
4 | * |
||||
5 | * @author Pronamic <[email protected]> |
||||
6 | * @copyright 2005-2019 Pronamic |
||||
7 | * @license GPL-3.0-or-later |
||||
8 | * @package Pronamic\WordPress\Pay |
||||
9 | */ |
||||
10 | |||||
11 | use Pronamic\WordPress\Pay\Util; |
||||
12 | |||||
13 | $sections = $this->admin->gateway_settings->get_sections(); |
||||
14 | $fields = $this->admin->gateway_settings->get_fields(); |
||||
15 | |||||
16 | $sections_fields = array(); |
||||
17 | |||||
18 | foreach ( $sections as $id => $section ) { |
||||
19 | $sections_fields[ $id ] = array(); |
||||
20 | } |
||||
21 | |||||
22 | foreach ( $fields as $id => $field ) { |
||||
23 | $section = $field['section']; |
||||
24 | |||||
25 | $sections_fields[ $section ][ $id ] = $field; |
||||
26 | } |
||||
27 | |||||
28 | // Sections. |
||||
29 | $variant_id = get_post_meta( get_the_ID(), '_pronamic_gateway_id', true ); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
30 | |||||
31 | $options = array(); |
||||
32 | |||||
33 | global $pronamic_pay_providers; |
||||
34 | |||||
35 | bind_providers_and_gateways(); |
||||
36 | |||||
37 | ?> |
||||
38 | <div id="pronamic-pay-gateway-config-editor"> |
||||
39 | <table class="form-table"> |
||||
40 | <tr> |
||||
41 | <th scope="row"> |
||||
42 | <label for="pronamic_gateway_id"> |
||||
43 | <?php esc_html_e( 'Payment provider', 'pronamic_ideal' ); ?> |
||||
44 | </label> |
||||
45 | </th> |
||||
46 | <td> |
||||
47 | <select id="pronamic_gateway_id" name="_pronamic_gateway_id"> |
||||
48 | <option value=""></option> |
||||
49 | |||||
50 | <?php |
||||
51 | |||||
52 | foreach ( $pronamic_pay_providers as $provider ) { |
||||
53 | if ( isset( $provider['integrations'] ) && is_array( $provider['integrations'] ) ) { |
||||
54 | printf( '<optgroup label="%s">', esc_attr( $provider['name'] ) ); |
||||
55 | |||||
56 | foreach ( $provider['integrations'] as $integration ) { |
||||
57 | $id = $integration->get_id(); |
||||
58 | $name = $integration->get_name(); |
||||
59 | $classes = array(); |
||||
60 | $description = ''; |
||||
61 | $links = array(); |
||||
62 | |||||
63 | if ( isset( $integration->deprecated ) && $integration->deprecated ) { |
||||
64 | $classes[] = 'deprecated'; |
||||
65 | |||||
66 | /* translators: %s: Integration name */ |
||||
67 | $name = sprintf( __( '%s (obsoleted)', 'pronamic_ideal' ), $name ); |
||||
68 | |||||
69 | if ( $variant_id !== $id ) { |
||||
70 | continue; |
||||
71 | } |
||||
72 | } |
||||
73 | |||||
74 | // Dashboard links. |
||||
75 | $dashboards = $integration->get_dashboard_url(); |
||||
76 | |||||
77 | if ( 1 === count( $dashboards ) ) { |
||||
78 | $links[] = sprintf( |
||||
79 | '<a href="%s" title="%s">%2$s</a>', |
||||
80 | esc_attr( $dashboards[0] ), |
||||
81 | __( 'Dashboard', 'pronamic_ideal' ) |
||||
82 | ); |
||||
83 | } elseif ( count( $dashboards ) > 1 ) { |
||||
84 | $dashboard_urls = array(); |
||||
85 | |||||
86 | foreach ( $dashboards as $dashboard_name => $dashboard_url ) { |
||||
87 | $dashboard_urls[] = sprintf( |
||||
88 | '<a href="%s" title="%s">%2$s</a>', |
||||
89 | esc_attr( $dashboard_url ), |
||||
90 | esc_html( ucfirst( $dashboard_name ) ) |
||||
91 | ); |
||||
92 | } |
||||
93 | |||||
94 | $links[] = sprintf( |
||||
95 | '%s: %s', |
||||
96 | __( 'Dashboards', 'pronamic_ideal' ), |
||||
97 | strtolower( implode( ', ', $dashboard_urls ) ) |
||||
98 | ); |
||||
99 | } |
||||
100 | |||||
101 | // Product link. |
||||
102 | if ( $integration->get_product_url() ) { |
||||
103 | $links[] = sprintf( |
||||
104 | '<a href="%s" target="_blank" title="%s">%2$s</a>', |
||||
105 | $integration->get_product_url(), |
||||
106 | __( 'Product information', 'pronamic_ideal' ) |
||||
107 | ); |
||||
108 | } |
||||
109 | |||||
110 | $description = implode( ' | ', $links ); |
||||
111 | |||||
112 | printf( |
||||
113 | '<option data-gateway-description="%s" data-pronamic-pay-settings="%s" value="%s" %s class="%s">%s</option>', |
||||
114 | esc_attr( $description ), |
||||
115 | esc_attr( wp_json_encode( $integration->get_settings() ) ), |
||||
0 ignored issues
–
show
It seems like
wp_json_encode($integration->get_settings()) can also be of type false ; however, parameter $text of esc_attr() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
116 | esc_attr( $id ), |
||||
117 | selected( $variant_id, $id, false ), |
||||
118 | esc_attr( implode( ' ', $classes ) ), |
||||
119 | esc_attr( $name ) |
||||
120 | ); |
||||
121 | } |
||||
122 | |||||
123 | printf( '</optgroup>' ); |
||||
124 | } |
||||
125 | } |
||||
126 | |||||
127 | ?> |
||||
128 | </select> |
||||
129 | |||||
130 | <p id="pronamic-pay-gateway-description"></p> |
||||
131 | </td> |
||||
132 | </tr> |
||||
133 | </table> |
||||
134 | |||||
135 | <div class="pronamic-pay-tabs"> |
||||
136 | <ul class="pronamic-pay-tabs-items"></ul> |
||||
137 | |||||
138 | <?php foreach ( $sections as $id => $section ) : ?> |
||||
139 | |||||
140 | <?php |
||||
141 | |||||
142 | $classes = array(); |
||||
143 | if ( isset( $section['methods'] ) ) { |
||||
144 | $classes[] = 'pronamic-pay-tab'; |
||||
145 | $classes[] = 'pronamic-pay-cloack'; |
||||
146 | $classes[] = 'extra-settings'; |
||||
147 | |||||
148 | foreach ( $section['methods'] as $method ) { |
||||
149 | $classes[] = 'setting-' . $method; |
||||
150 | } |
||||
151 | } |
||||
152 | |||||
153 | ?> |
||||
154 | |||||
155 | <div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
||||
156 | <?php if ( ! empty( $section['title'] ) || ! empty( $section['description'] ) ) : ?> |
||||
157 | |||||
158 | <div class="pronamic-pay-tab-block gateway-config-section-header"> |
||||
159 | <?php if ( ! empty( $section['title'] ) ) : ?> |
||||
160 | |||||
161 | <h4 class="pronamic-pay-cloack"><?php echo esc_html( $section['title'] ); ?></h4> |
||||
162 | |||||
163 | <?php endif; ?> |
||||
164 | |||||
165 | <?php if ( ! empty( $section['description'] ) ) : ?> |
||||
166 | |||||
167 | <p> |
||||
168 | <?php |
||||
169 | |||||
170 | echo $section['description']; // WPCS: XSS ok. |
||||
171 | |||||
172 | ?> |
||||
173 | </p> |
||||
174 | |||||
175 | <?php endif; ?> |
||||
176 | </div> |
||||
177 | |||||
178 | <?php endif; ?> |
||||
179 | |||||
180 | <table class="form-table"> |
||||
181 | |||||
182 | <?php |
||||
183 | |||||
184 | foreach ( $sections_fields[ $id ] as $field ) : |
||||
185 | |||||
186 | $classes = array(); |
||||
187 | if ( isset( $field['methods'] ) ) { |
||||
188 | $classes[] = 'pronamic-pay-cloack'; |
||||
189 | $classes[] = 'extra-settings'; |
||||
190 | |||||
191 | foreach ( $field['methods'] as $method ) { |
||||
192 | $classes[] = 'setting-' . $method; |
||||
193 | } |
||||
194 | } |
||||
195 | |||||
196 | if ( isset( $field['group'] ) ) { |
||||
197 | $classes[] = $field['group']; |
||||
198 | } |
||||
199 | |||||
200 | if ( isset( $field['id'] ) ) { |
||||
201 | $id = $field['id']; |
||||
202 | } elseif ( isset( $field['meta_key'] ) ) { |
||||
203 | $id = $field['meta_key']; |
||||
204 | } else { |
||||
205 | $id = uniqid(); |
||||
206 | } |
||||
207 | |||||
208 | ?> |
||||
209 | <tr class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
||||
210 | |||||
211 | <?php if ( 'html' !== $field['type'] ) { ?> |
||||
212 | |||||
213 | <th scope="row"> |
||||
214 | <label for="<?php echo esc_attr( $id ); ?>"> |
||||
215 | <?php echo esc_html( $field['title'] ); ?> |
||||
216 | </label> |
||||
217 | |||||
218 | <?php |
||||
219 | |||||
220 | if ( isset( $field['tooltip'] ) && ! empty( $field['tooltip'] ) ) { |
||||
221 | printf( |
||||
222 | '<span class="dashicons dashicons-editor-help pronamic-pay-tip" title="%s"></span>', |
||||
223 | esc_attr( $field['tooltip'] ) |
||||
224 | ); |
||||
225 | } |
||||
226 | |||||
227 | ?> |
||||
228 | </th> |
||||
229 | |||||
230 | <?php } ?> |
||||
231 | |||||
232 | <td <?php if ( 'html' === $field['type'] ) : ?>colspan="2"<?php endif; ?>> |
||||
233 | <?php |
||||
234 | |||||
235 | $attributes = array(); |
||||
236 | $attributes['id'] = $id; |
||||
237 | $attributes['name'] = $id; |
||||
238 | |||||
239 | $classes = array(); |
||||
240 | if ( isset( $field['classes'] ) ) { |
||||
241 | $classes = $field['classes']; |
||||
242 | } |
||||
243 | |||||
244 | if ( isset( $field['readonly'] ) && $field['readonly'] ) { |
||||
245 | $attributes['readonly'] = 'readonly'; |
||||
246 | |||||
247 | $classes[] = 'readonly'; |
||||
248 | } |
||||
249 | |||||
250 | if ( isset( $field['size'] ) ) { |
||||
251 | $attributes['size'] = $field['size']; |
||||
252 | } |
||||
253 | |||||
254 | if ( in_array( $field['type'], array( 'text', 'password', 'textarea', 'select' ), true ) ) { |
||||
255 | $classes[] = 'pronamic-pay-form-control'; |
||||
256 | } |
||||
257 | |||||
258 | if ( in_array( $field['type'], array( 'textarea' ), true ) ) { |
||||
259 | $classes[] = 'pronamic-pay-form-control-lg'; |
||||
260 | } |
||||
261 | |||||
262 | if ( ! empty( $classes ) ) { |
||||
263 | $attributes['class'] = implode( ' ', $classes ); |
||||
264 | } |
||||
265 | |||||
266 | $value = ''; |
||||
267 | if ( isset( $field['meta_key'] ) ) { |
||||
268 | $attributes['name'] = $field['meta_key']; |
||||
269 | |||||
270 | $value = get_post_meta( get_the_ID(), $field['meta_key'], true ); |
||||
271 | } elseif ( isset( $field['value'] ) ) { |
||||
272 | $value = $field['value']; |
||||
273 | } |
||||
274 | |||||
275 | // Set default. |
||||
276 | if ( empty( $value ) && isset( $field['default'] ) ) { |
||||
277 | $value = $field['default']; |
||||
278 | } |
||||
279 | |||||
280 | switch ( $field['type'] ) { |
||||
281 | case 'text': |
||||
282 | case 'password': |
||||
283 | $attributes['type'] = $field['type']; |
||||
284 | $attributes['value'] = $value; |
||||
285 | |||||
286 | printf( |
||||
287 | '<input %s />', |
||||
288 | // @codingStandardsIgnoreStart |
||||
289 | Util::array_to_html_attributes( $attributes ) |
||||
290 | // @codingStandardsIgnoreEnd |
||||
291 | ); |
||||
292 | |||||
293 | break; |
||||
294 | case 'checkbox': |
||||
295 | $attributes['type'] = $field['type']; |
||||
296 | $attributes['value'] = '1'; |
||||
297 | |||||
298 | printf( |
||||
299 | '<input %s %s />', |
||||
300 | // @codingStandardsIgnoreStart |
||||
301 | Util::array_to_html_attributes( $attributes ), |
||||
302 | // @codingStandardsIgnoreEnd |
||||
303 | checked( $value, true, false ) |
||||
304 | ); |
||||
305 | |||||
306 | printf( ' ' ); |
||||
307 | |||||
308 | printf( |
||||
309 | '<label for="%s">%s</label>', |
||||
310 | esc_attr( $attributes['id'] ), |
||||
311 | esc_html( $field['label'] ) |
||||
312 | ); |
||||
313 | |||||
314 | break; |
||||
315 | case 'textarea': |
||||
316 | $attributes['rows'] = 4; |
||||
317 | $attributes['cols'] = 65; |
||||
318 | |||||
319 | printf( |
||||
320 | '<textarea %s />%s</textarea>', |
||||
321 | // @codingStandardsIgnoreStart |
||||
322 | Util::array_to_html_attributes( $attributes ), |
||||
323 | // @codingStandardsIgnoreEnd |
||||
324 | esc_textarea( $value ) |
||||
325 | ); |
||||
326 | |||||
327 | break; |
||||
328 | case 'file': |
||||
329 | $attributes['type'] = 'file'; |
||||
330 | |||||
331 | printf( |
||||
332 | '<input %s />', |
||||
333 | // @codingStandardsIgnoreStart |
||||
334 | Util::array_to_html_attributes( $attributes ) |
||||
335 | // @codingStandardsIgnoreEnd |
||||
336 | ); |
||||
337 | |||||
338 | break; |
||||
339 | case 'select': |
||||
340 | printf( |
||||
341 | '<select %s>%s</select>', |
||||
342 | // @codingStandardsIgnoreStart |
||||
343 | Util::array_to_html_attributes( $attributes ), |
||||
344 | Util::select_options_grouped( $field['options'], $value ) |
||||
345 | // @codingStandardsIgnoreEnd |
||||
346 | ); |
||||
347 | |||||
348 | break; |
||||
349 | case 'optgroup': |
||||
350 | printf( '<fieldset>' ); |
||||
351 | printf( '<legend class="screen-reader-text">%s</legend>', esc_html( $field['title'] ) ); |
||||
352 | |||||
353 | foreach ( $field['options'] as $key => $label ) { |
||||
354 | printf( |
||||
355 | '<label>%s %s</label><br />', |
||||
356 | sprintf( |
||||
357 | '<input type="radio" value="%s" name="%s" %s />', |
||||
358 | esc_attr( $key ), |
||||
359 | esc_attr( $attributes['name'] ), |
||||
360 | checked( $value, $key, false ) |
||||
361 | ), |
||||
362 | esc_html( $label ) |
||||
363 | ); |
||||
364 | } |
||||
365 | |||||
366 | break; |
||||
367 | } |
||||
368 | |||||
369 | if ( isset( $field['html'] ) ) { |
||||
370 | if ( 'description' !== $field['type'] && isset( $field['title'] ) && ! empty( $field['title'] ) ) { |
||||
371 | printf( |
||||
372 | '<strong>%s</strong><br>', |
||||
373 | esc_html( $field['title'] ) |
||||
374 | ); |
||||
375 | } |
||||
376 | |||||
377 | echo $field['html']; // WPCS: XSS ok. |
||||
378 | } |
||||
379 | |||||
380 | if ( isset( $field['description'] ) ) { |
||||
381 | printf( // WPCS: XSS ok. |
||||
382 | '<p class="pronamic-pay-description description">%s</p>', |
||||
383 | $field['description'] |
||||
384 | ); |
||||
385 | } |
||||
386 | |||||
387 | if ( isset( $field['callback'] ) ) { |
||||
388 | $callback = $field['callback']; |
||||
389 | |||||
390 | call_user_func( $callback, $field ); |
||||
391 | } |
||||
392 | |||||
393 | ?> |
||||
394 | |||||
395 | </td> |
||||
396 | </tr> |
||||
397 | |||||
398 | <?php endforeach; ?> |
||||
399 | |||||
400 | </table> |
||||
401 | </div> |
||||
402 | |||||
403 | <?php endforeach; ?> |
||||
404 | |||||
405 | </div> |
||||
406 | |||||
407 | <div style="clear:both;"></div> |
||||
408 | </div> |
||||
409 |