PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.10.0.5
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.10.0.5
1.10.1.1 1.10.1 1.10.0.5 trunk 1.1.4 1.1.4.2 1.1.5 1.1.5.1 1.1.6 1.1.6.1 1.1.7 1.1.7.1 1.1.7.2 1.1.8 1.1.8.1 1.1.8.2 1.1.8.3 1.1.8.4 1.10.0.1 1.10.0.2 1.10.0.3 1.10.0.4 1.2.0 1.2.0.1 1.2.1 1.2.2 1.2.2.1 1.2.2.2 1.2.3 1.2.3.1 1.2.3.2 1.2.4 1.2.4.1 1.2.5 1.2.5.1 1.2.6 1.2.7 1.2.8 1.2.8.1 1.2.9 1.3.0 1.3.1 1.3.1.1 1.3.1.2 1.3.2 1.3.3 1.3.5 1.3.6 1.3.6.1 1.3.6.2 1.3.7.2 1.3.7.3 1.3.7.4 1.3.8 1.3.9.1 1.4.0.1 1.4.1.1 1.4.2 1.4.2.1 1.4.2.2 1.4.3 1.4.4 1.4.4.1 1.4.5 1.4.5.1 1.4.5.2 1.4.5.3 1.4.6 1.4.7.1 1.4.7.2 1.4.8.1 1.4.9 1.5.0.1 1.5.0.3 1.5.0.4 1.5.1 1.5.1.1 1.5.1.3 1.5.2.1 1.5.2.2 1.5.2.3 1.5.3 1.5.3.1 1.5.4.1 1.5.4.2 1.5.5 1.5.5.1 1.5.6 1.5.6.2 1.5.7 1.5.8.2 1.5.9.1 1.5.9.4 1.5.9.5 1.6.0.1 1.6.0.2 1.6.1 1.6.2.2 1.6.2.3 1.6.3.1 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.7 1.6.7.1 1.6.7.2 1.6.7.3 1.6.8 1.6.8.1 1.6.9 1.7.0 1.7.1.1 1.7.1.2 1.7.2 1.7.2.1 1.7.3 1.7.4 1.7.4.1 1.7.4.2 1.7.5.1 1.7.5.2 1.7.5.3 1.7.5.5 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.7.9.1 1.8.0.1 1.8.0.2 1.8.1.1 1.8.1.2 1.8.1.3 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.3.1 1.8.4 1.8.4.1 1.8.5.2 1.8.5.3 1.8.5.4 1.8.6.2 1.8.6.3 1.8.6.4 1.8.7.2 1.8.8.2 1.8.8.3 1.8.9.1 1.8.9.2 1.8.9.4 1.8.9.5 1.8.9.6 1.9.0.1 1.9.0.2 1.9.0.3 1.9.0.4 1.9.1.1 1.9.1.2 1.9.1.3 1.9.1.4 1.9.1.5 1.9.1.6 1.9.2.1 1.9.2.2 1.9.2.3 1.9.3.1 1.9.3.2 1.9.4.1 1.9.4.2 1.9.5 1.9.5.1 1.9.5.2 1.9.6 1.9.6.1 1.9.6.2 1.9.7.1 1.9.7.2 1.9.7.3 1.9.8.1 1.9.8.2 1.9.8.4 1.9.8.7 1.9.9.2 1.9.9.3 1.9.9.4
wpforms-lite / includes / admin / settings-api.php
wpforms-lite / includes / admin Last commit date
builder 2 weeks ago admin.php 2 weeks ago ajax-actions.php 8 months ago class-about.php 2 weeks ago class-editor.php 1 year ago class-menu.php 5 months ago class-notices.php 1 year ago class-review.php 5 months ago class-settings.php 9 months ago class-welcome.php 6 months ago settings-api.php 2 months ago
settings-api.php
735 lines
1 <?php
2 /**
3 * Settings API.
4 *
5 * @since 1.3.7
6 */
7
8 use WPForms\Admin\Education\Helpers as EducationHelpers;
9
10 /**
11 * Settings output wrapper.
12 *
13 * @since 1.3.9
14 *
15 * @param array $args Arguments.
16 *
17 * @return string
18 */
19 function wpforms_settings_output_field( array $args ): string {
20
21 // Define default callback for this field type.
22 $callback = ! empty( $args['type'] ) && function_exists( 'wpforms_settings_' . $args['type'] . '_callback' ) ? 'wpforms_settings_' . $args['type'] . '_callback' : 'wpforms_settings_missing_callback';
23
24 // Allow custom callback to be provided via arg.
25 if ( ! empty( $args['callback'] ) && function_exists( $args['callback'] ) ) {
26 $callback = $args['callback'];
27 }
28
29 // Store returned markup from callback.
30 $field = $callback( $args );
31
32 // Allow arg to bypass standard field wrap for custom display.
33 if ( ! empty( $args['wrap'] ) ) {
34 return $field;
35 }
36
37 // Default class names.
38 $class = [
39 'wpforms-setting-row',
40 "wpforms-setting-row-{$args['type']}",
41 'wpforms-clear',
42 ];
43
44 // Row attributes.
45 $wrapper_attributes = wpforms_html_attributes(
46 'wpforms-setting-row-' . wpforms_sanitize_key( $args['id'] ),
47 ! empty( $args['class'] ) ? array_merge( $class, (array) $args['class'] ) : $class,
48 ! empty( $args['data_attributes'] ) && is_array( $args['data_attributes'] ) ? $args['data_attributes'] : [],
49 ! empty( $args['is_hidden'] ) ? [ 'style' => 'display:none;' ] : []
50 );
51
52 // Build standard field markup and return.
53 $output = "<div {$wrapper_attributes}>";
54
55 if ( ! empty( $args['name'] ) && empty( $args['no_label'] ) ) {
56 $output .= '<span class="wpforms-setting-label">';
57 $output .= '<label for="wpforms-setting-' . wpforms_sanitize_key( $args['id'] ) . '">' . esc_html( $args['name'] );
58
59 // Add education badge, if needed.
60 // The badge should be added after the label text, but before the label closing tag.
61 if ( ! empty( $args['education_badge'] ) ) {
62 $output .= wp_kses( $args['education_badge'], [ 'span' => [ 'class' => [] ] ] );
63 }
64
65 $output .= '</label>';
66 $output .= '</span>';
67 }
68
69 $output .= '<span class="wpforms-setting-field">';
70 $output .= $field;
71
72 if ( ! empty( $args['desc_after'] ) ) {
73 $output .= '<div class="wpforms-clear">' . $args['desc_after'] . '</div>';
74 }
75
76 $output .= '</span>';
77 $output .= '</div>';
78
79 return $output;
80 }
81
82 /**
83 * Missing Callback.
84 *
85 * If a function is missing for settings, callbacks alert the user.
86 *
87 * @since 1.3.9
88 *
89 * @param array $args Arguments passed by the setting.
90 *
91 * @return string
92 */
93 function wpforms_settings_missing_callback( array $args ): string {
94
95 return sprintf(
96 /* translators: %s - ID of a setting. */
97 esc_html__( 'The callback function used for the %s setting is missing.', 'wpforms-lite' ),
98 '<strong>' . wpforms_sanitize_key( $args['id'] ) . '</strong>'
99 );
100 }
101
102 /**
103 * Settings content field callback.
104 *
105 * @since 1.3.9
106 *
107 * @param array $args Arguments.
108 *
109 * @return string
110 */
111 function wpforms_settings_content_callback( array $args ): string {
112
113 return ! empty( $args['content'] ) ? $args['content'] : '';
114 }
115
116 /**
117 * Settings license field callback.
118 *
119 * @since 1.3.9
120 *
121 * @param array $args Settings arguments.
122 *
123 * @return string
124 * @noinspection HtmlUnknownTarget
125 * @noinspection PhpUnusedParameterInspection
126 */
127 function wpforms_settings_license_callback( array $args ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
128
129 $output = '<p>' . esc_html__( 'You\'re using WPForms Lite - no license needed. Enjoy!', 'wpforms-lite' ) . ' 🙂</p>';
130 $output .=
131 '<p>' .
132 sprintf(
133 wp_kses( /* translators: %s - WPForms.com upgrade URL. */
134 __( 'To unlock more features consider <strong><a href="%s" target="_blank" rel="noopener noreferrer" class="wpforms-upgrade-modal">upgrading to PRO</a></strong>.', 'wpforms-lite' ),
135 [
136 'a' => [
137 'href' => [],
138 'class' => [],
139 'target' => [],
140 'rel' => [],
141 ],
142 'strong' => [],
143 ]
144 ),
145 esc_url( wpforms_admin_upgrade_link( 'settings-license', 'Upgrade to WPForms Pro text Link' ) )
146 ) .
147 '</p>';
148 $output .=
149 '<p class="discount-note">' .
150 wp_kses(
151 __( 'As a valued WPForms Lite user you receive <strong>50% off</strong>, automatically applied at checkout!', 'wpforms-lite' ),
152 [
153 'strong' => [],
154 ]
155 ) .
156 '</p>';
157
158 $output .= '<hr><p>' . esc_html__( 'Already purchased? Simply enter your license key below to enable WPForms PRO!', 'wpforms-lite' ) . '</p>';
159 $output .= '<p>';
160 $output .= '<input type="password" spellcheck="false" id="wpforms-settings-upgrade-license-key" placeholder="' . esc_attr__( 'Paste license key here', 'wpforms-lite' ) . '" value="">';
161 $output .= '<button class="wpforms-btn wpforms-btn-md wpforms-btn-blue" id="wpforms-settings-connect-btn">' . esc_html__( 'Verify Key', 'wpforms-lite' ) . '</button>';
162 $output .= '</p>';
163
164 /**
165 * Filter license settings HTML output.
166 *
167 * @since 1.7.9
168 *
169 * @param string $output HTML markup to be rendered in place of license settings.
170 */
171 return (string) apply_filters( 'wpforms_settings_license_output', $output );
172 }
173
174 /**
175 * Settings text input field callback.
176 *
177 * @since 1.3.9
178 * @since 1.10.0 Adds the ability to make text input readonly.
179 *
180 * @param array $args Settings arguments.
181 *
182 * @return string
183 */
184 function wpforms_settings_text_callback( array $args ): string {
185
186 if ( ! in_array( $args['type'], [ 'text', 'password' ], true ) ) {
187 $args['type'] = 'text';
188 }
189
190 $default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
191 $value = wpforms_setting( $args['id'], $default );
192 $id = wpforms_sanitize_key( $args['id'] );
193 $readonly = ! empty( $args['readonly'] ) ? ' readonly' : '';
194
195 $output = '<input type="' . esc_attr( $args['type'] ) . '" id="wpforms-setting-' . $id . '" name="' . $id . '" value="' . esc_attr( $value ) . ' " ' . $readonly . ' />';
196
197 if ( ! empty( $args['desc'] ) ) {
198 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
199 }
200
201 return $output;
202 }
203
204 /**
205 * Settings password input field callback.
206 *
207 * @since 1.8.4
208 *
209 * @param array $args Setting field arguments.
210 *
211 * @return string
212 */
213 function wpforms_settings_password_callback( array $args ): string {
214
215 return wpforms_settings_text_callback( $args );
216 }
217
218 /**
219 * Settings number input field callback.
220 *
221 * @since 1.5.3
222 *
223 * @param array $args Setting field arguments.
224 *
225 * @return string
226 * @noinspection HtmlUnknownAttribute
227 */
228 function wpforms_settings_number_callback( array $args ): string {
229
230 $default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
231 $id = 'wpforms-setting-' . wpforms_sanitize_key( $args['id'] );
232 $attr = [
233 'value' => wpforms_setting( $args['id'], $default ),
234 'name' => wpforms_sanitize_key( $args['id'] ),
235 ];
236 $data = ! empty( $args['data'] ) ? $args['data'] : [];
237
238 if ( ! empty( $args['attr'] ) ) {
239 $attr = array_merge( $attr, $args['attr'] );
240 }
241
242 $output = sprintf(
243 '<input type="number" %s>',
244 wpforms_html_attributes( $id, [], $data, $attr )
245 );
246
247 if ( ! empty( $args['desc'] ) ) {
248 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
249 }
250
251 return $output;
252 }
253
254 /**
255 * Settings select field callback.
256 *
257 * @since 1.3.9
258 *
259 * @param array $args Arguments.
260 *
261 * @return string
262 */
263 function wpforms_settings_select_callback( array $args ): string { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
264
265 $default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
266 $value = wpforms_setting( $args['id'], $default );
267 $id = wpforms_sanitize_key( $args['id'] );
268 $select_name = $id;
269 $class = ! empty( $args['choicesjs'] ) ? 'choicesjs-select' : '';
270 $choices = ! empty( $args['choicesjs'] );
271 $data = isset( $args['data'] ) ? (array) $args['data'] : [];
272 $attr = isset( $args['attr'] ) ? (array) $args['attr'] : [];
273
274 if ( $choices && ! empty( $args['search'] ) ) {
275 $data['search'] = 'true';
276 }
277
278 if ( ! empty( $args['placeholder'] ) ) {
279 $data['placeholder'] = $args['placeholder'];
280 }
281
282 $size_attr = '';
283
284 if ( $choices && ! empty( $args['multiple'] ) ) {
285 $attr[] = 'multiple';
286 $select_name = $id . '[]';
287 $size_attr = ' size="1"';
288 }
289
290 foreach ( $data as $name => $val ) {
291 $data[ $name ] = 'data-' . sanitize_html_class( $name ) . '="' . esc_attr( $val ) . '"';
292 }
293
294 $data = implode( ' ', $data );
295 $attr = implode( ' ', array_map( 'sanitize_html_class', $attr ) );
296
297 $output = $choices ? '<span class="choicesjs-select-wrap">' : '';
298 $output .= '<select id="wpforms-setting-' . $id . '" name="' . $select_name . '" class="' . $class . '"' . $data . $attr . $size_attr . '>';
299
300 foreach ( $args['options'] as $option => $name ) {
301 if ( empty( $args['selected'] ) ) {
302 $selected = selected( $value, $option, false );
303 } else {
304 $selected = is_array( $args['selected'] ) && in_array( $option, $args['selected'], true ) ? 'selected' : '';
305 }
306 $output .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
307 }
308
309 $output .= '</select>';
310 $output .= $choices ? '</span>' : '';
311
312 if ( ! empty( $args['desc'] ) ) {
313 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
314 }
315
316 return $output;
317 }
318
319 /**
320 * Settings checkbox field callback.
321 *
322 * @since 1.3.9
323 *
324 * @param array $args Arguments.
325 *
326 * @return string
327 */
328 function wpforms_settings_checkbox_callback( array $args ): string {
329
330 $value = wpforms_setting( $args['id'] );
331 $id = wpforms_sanitize_key( $args['id'] );
332 $checked = ! empty( $value ) ? checked( 1, $value, false ) : '';
333 $disabled = ! empty( $args['disabled'] ) ? ' disabled' : '';
334
335 $output = '<input type="checkbox" id="wpforms-setting-' . $id . '" name="' . $id . '" ' . $checked . $disabled . '>';
336
337 if ( ! empty( $args['desc'] ) ) {
338 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
339 }
340
341 if ( ! empty( $args['disabled_desc'] ) ) {
342 $output .= '<p class="disabled-desc">' . wp_kses_post( $args['disabled_desc'] ) . '</p>';
343 }
344
345 return $output;
346 }
347
348 /**
349 * Settings radio field callback.
350 *
351 * @since 1.3.9
352 *
353 * @param array $args Arguments.
354 *
355 * @return string
356 */
357 function wpforms_settings_radio_callback( array $args ): string {
358
359 $default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
360 $value = wpforms_setting( $args['id'], $default );
361 $id = wpforms_sanitize_key( $args['id'] );
362 $output = '';
363 $x = 1;
364
365 foreach ( $args['options'] as $option => $name ) {
366
367 $checked = checked( $value, $option, false );
368 $output .= '<span class="wpforms-settings-field-radio-wrapper">';
369 $output .= '<input type="radio" id="wpforms-setting-' . $id . '[' . $x . ']" name="' . $id . '" value="' . esc_attr( $option ) . '" ' . $checked . '>';
370 $output .= '<label for="wpforms-setting-' . $id . '[' . $x . ']" class="option-' . sanitize_html_class( $option ) . '">';
371 $output .= esc_html( $name );
372 $output .= '</label>';
373 $output .= '</span>';
374
375 ++$x;
376 }
377
378 if ( ! empty( $args['desc'] ) ) {
379 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
380 }
381
382 return $output;
383 }
384
385 /**
386 * Email template endpoint field callback.
387 *
388 * @since 1.8.5
389 *
390 * @param array $args Field arguments.
391 *
392 * @return string
393 */
394 function wpforms_settings_email_template_callback( array $args ): string {
395
396 $id = wpforms_sanitize_key( $args['id'] );
397 $is_pro = wpforms()->is_pro();
398 $output = '';
399 $x = 1;
400 $education_args = [
401 'name' => esc_html__( 'Email Templates', 'wpforms-lite' ),
402 'plural' => '1',
403 'action' => 'upgrade',
404 ];
405
406 foreach ( $args['options'] as $option => $attrs ) {
407 $checked = checked( $args['value'], $option, false );
408 $has_education = ! $is_pro && isset( $attrs['is_pro'] ) && $attrs['is_pro'];
409 $class = [ 'wpforms-settings-field-radio-wrapper', 'wpforms-card-image' ];
410 $data = [];
411
412 // Add class and data attributes for education modal, if needed.
413 if ( $has_education ) {
414 $class[] = 'education-modal'; // This class is used for JS.
415 $data = $education_args; // This data is used for JS.
416 }
417
418 $output .= '<span ' . wpforms_html_attributes( '', $class, $data ) . '>';
419 $output .= '<input type="radio" id="wpforms-setting-' . $id . '[' . $x . ']" name="' . $id . '" value="' . esc_attr( $option ) . '" ' . $checked . '>';
420 $output .= '<label for="wpforms-setting-' . $id . '[' . $x . ']" class="option-' . sanitize_html_class( $option ) . '">';
421 $output .= esc_html( $attrs['name'] );
422
423 // Add class and data attributes for education modal, if needed.
424 if ( $has_education ) {
425 $output .= EducationHelpers::get_badge( 'Pro' );
426 }
427
428 $output .= '<span class="wpforms-card-image-overlay">';
429 $output .= '<span class="wpforms-btn-choose wpforms-btn wpforms-btn-md wpforms-btn-orange">';
430 $output .= esc_html__( 'Choose', 'wpforms-lite' ) . '</span>';
431
432 // Only add the preview action button if provided.
433 if ( ! empty( $attrs['preview'] ) ) {
434 $output .= '<a href="' . esc_url( $attrs['preview'] ) . '" class="wpforms-btn-preview wpforms-btn wpforms-btn-md wpforms-btn-light-grey" target="_blank">';
435 $output .= esc_html__( 'Preview', 'wpforms-lite' );
436 $output .= '</a>';
437 }
438
439 $output .= '</span>';
440 $output .= '</label>';
441 $output .= '</span>';
442
443 ++$x;
444 }
445
446 if ( ! empty( $args['desc'] ) ) {
447 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
448 }
449
450 return $output;
451 }
452
453 /**
454 * Settings toggle field callback.
455 *
456 * @since 1.7.4
457 *
458 * @param array $args Arguments.
459 *
460 * @return string
461 */
462 function wpforms_settings_toggle_callback( array $args ): string { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
463
464 $value = ! empty( $args['value'] ) ? $args['value'] : wpforms_setting( $args['id'] );
465 $id = wpforms_sanitize_key( $args['id'] );
466 $class = ! empty( $args['control-class'] ) ? $args['control-class'] : '';
467 $class .= ! empty( $args['is-important'] ) ? ' wpforms-important' : '';
468 $input_attr = ! empty( $args['input-attr'] ) ? $args['input-attr'] : '';
469
470 $default_args = [
471 'control-class' => $class,
472 ];
473
474 $args = wp_parse_args( $args, $default_args );
475
476 $output = wpforms_panel_field_toggle_control(
477 $args,
478 'wpforms-setting-' . $id,
479 $id,
480 ! empty( $args['label'] ) ? $args['label'] : '',
481 $value,
482 $input_attr
483 );
484
485 $desc_on = ! empty( $args['desc'] ) ? $args['desc'] : '';
486 $desc_on = ! empty( $args['desc-on'] ) ? $args['desc-on'] : $desc_on;
487 $desc_off = ! empty( $args['desc-off'] ) ? $args['desc-off'] : '';
488
489 $output .= sprintf(
490 '<p class="desc desc-on wpforms-toggle-desc%1$s">%2$s</p>',
491 empty( $value ) && ! empty( $desc_off ) ? ' wpforms-hidden' : '',
492 wp_kses_post( $desc_on )
493 );
494
495 if ( ! empty( $desc_off ) ) {
496 $output .= sprintf(
497 '<p class="desc desc-off wpforms-toggle-desc%1$s">%2$s</p>',
498 empty( $value ) ? '' : ' wpforms-hidden',
499 wp_kses_post( $desc_off )
500 );
501 }
502
503 if ( ! empty( $args['disabled_desc'] ) ) {
504 $output .= '<p class="disabled-desc">' . wp_kses_post( $args['disabled_desc'] ) . '</p>';
505 }
506
507 return $output;
508 }
509
510 /**
511 * Settings image uploads field callback.
512 *
513 * @since 1.3.9
514 *
515 * @param array $args Arguments.
516 *
517 * @return string
518 */
519 function wpforms_settings_image_callback( array $args ): string {
520
521 $default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
522 $value = wpforms_setting( $args['id'], $default );
523 $id = wpforms_sanitize_key( $args['id'] );
524 $output = '';
525
526 if ( ! empty( $value ) ) {
527 $output .= '<img src="' . esc_url_raw( $value ) . '">';
528 }
529
530 $output .= '<input type="text" id="wpforms-setting-' . $id . '" name="' . $id . '" value="' . esc_url_raw( $value ) . '">';
531
532 // Show the remove button if specified.
533 if ( isset( $args['show_remove'] ) && $args['show_remove'] ) {
534 $output .= '<button class="wpforms-btn wpforms-btn-md wpforms-setting-remove-image">' . esc_html__( 'Remove Image', 'wpforms-lite' ) . '</button>';
535 }
536
537 $output .= '<button class="wpforms-btn wpforms-btn-md wpforms-btn-light-grey wpforms-setting-upload-image">' . esc_html__( 'Upload Image', 'wpforms-lite' ) . '</button>';
538
539 if ( ! empty( $args['desc'] ) ) {
540 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
541 }
542
543 return $output;
544 }
545
546 /**
547 * Settings color picker field callback.
548 *
549 * @since 1.3.9
550 *
551 * @param array $args Arguments.
552 *
553 * @return string
554 */
555 function wpforms_settings_color_callback( array $args ): string {
556
557 $default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
558 $value = wpforms_setting( $args['id'], $default );
559 $id = wpforms_sanitize_key( $args['id'] );
560 $data = isset( $args['data'] ) ? (array) $args['data'] : [];
561
562 foreach ( $data as $name => $val ) {
563 $data[ $name ] = 'data-' . sanitize_html_class( $name ) . '="' . esc_attr( $val ) . '"';
564 }
565
566 $data = implode( ' ', $data );
567
568 $output = '<input type="text" id="wpforms-setting-' . $id . '" class="wpforms-color-picker" name="' . $id . '" value="' . esc_attr( $value ) . '" ' . $data . '>';
569
570 if ( ! empty( $args['desc'] ) ) {
571 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
572 }
573
574 return $output;
575 }
576
577 /**
578 * Color scheme endpoint fieldset callback.
579 * This function will output a fieldset with color picker inputs.
580 *
581 * @since 1.8.5
582 *
583 * @param array $args Field arguments.
584 *
585 * @return string
586 */
587 function wpforms_settings_color_scheme_callback( array $args ): string {
588
589 $id = wpforms_sanitize_key( $args['id'] );
590 $value = wpforms_setting( $args['id'], [] );
591 $output = '';
592
593 foreach ( $args['colors'] as $color => $attrs ) {
594 $data = isset( $attrs['data'] ) ? (array) $attrs['data'] : [];
595 $default_value = isset( $data['fallback-color'] ) ? wpforms_sanitize_hex_color( $data['fallback-color'] ) : '';
596 $field_id = "{$id}-{$color}";
597 $field_value = isset( $value[ $color ] ) ? wpforms_sanitize_hex_color( $value[ $color ] ) : $default_value;
598 $input_attributes = wpforms_html_attributes(
599 "wpforms-setting-{$field_id}",
600 [ 'wpforms-color-picker' ],
601 $data,
602 [
603 'type' => 'text',
604 'name' => "{$id}[{$color}]",
605 'value' => esc_attr( $field_value ),
606 ]
607 );
608
609 $output .= "<input {$input_attributes}>";
610 $output .= '<label for="wpforms-setting-' . $field_id . '">';
611 $output .= esc_html( $attrs['name'] );
612 $output .= '</label>';
613 }
614
615 if ( ! empty( $args['desc'] ) ) {
616 $output .= '<p class="desc">' . wp_kses_post( $args['desc'] ) . '</p>';
617 }
618
619 return $output;
620 }
621
622 /**
623 * Settings providers field callback - this is for the Integrations tab.
624 *
625 * @since 1.3.9
626 *
627 * @param array $args Arguments.
628 *
629 * @return string
630 * @noinspection PhpUnusedParameterInspection
631 */
632 function wpforms_settings_providers_callback( array $args ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
633
634 $active = wpforms_get_providers_available();
635 $providers = wpforms_get_providers_options();
636
637 $output = '<div id="wpforms-settings-providers">';
638
639 ob_start();
640
641 /**
642 * Output settings providers.
643 *
644 * @since 1.3.9.1
645 *
646 * @param array $active Active providers.
647 * @param array $providers Providers options.
648 */
649 do_action( 'wpforms_settings_providers', $active, $providers );
650
651 $output .= ob_get_clean();
652 $output .= '</div>';
653
654 return $output;
655 }
656
657 /**
658 * Webhooks' endpoint field callback.
659 *
660 * @since 1.8.4
661 *
662 * @param array $args Field arguments.
663 *
664 * @return string
665 */
666 function wpforms_settings_webhook_endpoint_callback( array $args ): string {
667
668 if ( empty( $args['url'] ) ) {
669 return ''; // Early return if no URL is provided.
670 }
671
672 $provider = $args['provider'] ?? 'stripe';
673 $input_id = "wpforms-{$provider}-webhook-endpoint-url";
674 $copy_btn = '<a class="button button-secondary wpforms-copy-to-clipboard" data-clipboard-target="#' . esc_attr( $input_id ) . '" href="#" aria-label="' . esc_attr__( 'Copy webhook URL', 'wpforms-lite' ) . '"><span class="dashicons dashicons-admin-page"></span></a>';
675 $input_field = '<input type="text" disabled id="' . esc_attr( $input_id ) . '" value="' . esc_url( $args['url'] ) . '" />';
676
677 $output = sprintf(
678 '<div class="%1$s">%2$s %3$s</div>',
679 esc_attr( "wpforms-{$provider}-webhook-endpoint-url" ),
680 $input_field,
681 $copy_btn
682 );
683
684 if ( ! empty( $args['desc'] ) ) {
685 $output .= sprintf( '<p class="desc">%s</p>', wp_kses_post( $args['desc'] ) );
686 }
687
688 return $output;
689 }
690
691 /**
692 * Settings field columns callback.
693 *
694 * @since 1.5.8
695 *
696 * @param array $args Arguments passed by the setting.
697 *
698 * @return string
699 */
700 function wpforms_settings_columns_callback( array $args ): string {
701
702 if ( empty( $args['columns'] ) || ! is_array( $args['columns'] ) ) {
703 return '';
704 }
705
706 $output = '<div class="wpforms-setting-columns">';
707
708 foreach ( $args['columns'] as $column ) {
709
710 // Define default callback for this field type.
711 $callback = ! empty( $column['type'] ) ? 'wpforms_settings_' . $column['type'] . '_callback' : '';
712
713 // Allow custom callback to be provided via arg.
714 if ( ! empty( $column['callback'] ) ) {
715 $callback = $column['callback'];
716 }
717
718 $output .= '<div class="wpforms-setting-column">';
719
720 if ( ! empty( $column['name'] ) ) {
721 $output .= '<label><b>' . wp_kses_post( $column['name'] ) . '</b></label>';
722 }
723
724 if ( function_exists( $callback ) ) {
725 $output .= $callback( $column );
726 }
727
728 $output .= '</div>';
729 }
730
731 $output .= '</div>';
732
733 return $output;
734 }
735