PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.24
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.24
1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 All 173 releases
userswp / admin / settings / class-formbuilder.php

class-formbuilder.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.24, at admin/settings/class-formbuilder.php

3,462 lines 144.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The form builder functionality of the plugin.
4 *
5 * @link http://wpgeodirectory.com
6 * @since 1.0.0
7 *
8 * @package userswp
9 * @subpackage userswp/admin/settings
10 */
11
12 /**
13 * The form builder functionality of the plugin.
14 *
15 * @package userswp
16 * @subpackage userswp/admin/settings
17 * @author GeoDirectory Team <info@wpgeodirectory.com>
18 */
19 class UsersWP_Form_Builder {
20
21 public static function output( $tab = '' ) {
22
23 global $current_tab;
24
25 do_action( 'uwp_form_builder_start' );
26
27 // Get current tab/section
28 if ( $tab ) {
29 $current_tab = sanitize_title( $tab );
30 } else {
31 $current_tab = empty( $_GET['tab'] ) ? 'account' : sanitize_title( $_GET['tab'] );
32 }
33
34 $form = '';
35 if ( isset( $_GET['form'] ) && ! empty( $_GET['form'] ) ) {
36 $form = '&form=' . (int) $_GET['form'];
37 }
38
39 // Get tabs for the form builder page
40 $tabs = apply_filters(
41 'uwp_form_builder_tabs_array',
42 array(
43 'account' => __( 'Account', 'userswp' ),
44 'register' => __( 'Register', 'userswp' ),
45 )
46 );
47
48 ?>
49 <div class="wrap">
50 <nav class="nav-tab-wrapper uwp-nav-tab-wrapper">
51 <?php
52 foreach ( $tabs as $name => $label ) {
53 echo '<a href="' . esc_url( admin_url( 'admin.php?page=uwp_form_builder&tab=' . $name . $form ) ) . '" id="uwp-form-builder-' . esc_attr( $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
54 }
55 do_action( 'uwp_form_builder_tabs' );
56 ?>
57 </nav>
58 <h1 class="screen-reader-text"><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1>
59 <?php
60 do_action( 'uwp_form_builder_tabs_content', $current_tab, $tabs );
61 do_action( 'uwp_form_builder_tabs_' . $current_tab, $tabs );
62 do_action( 'uwp_extra_form_builder_content', $current_tab, $tabs );
63 ?>
64 </div>
65 <?php
66 }
67
68 public function uwp_form_builder( $default_tab = 'account' ) {
69 ob_start();
70 $form_type = ( isset( $_GET['tab'] ) && $_GET['tab'] != '' ) ? sanitize_text_field( $_GET['tab'] ) : $default_tab;
71 ?>
72 <div class="uwp-settings-wrap bsui">
73
74
75 <div class="container-fluid p-0 mt-3">
76
77
78 <?php
79 if($form_type != 'user-sorting') {
80 ?>
81 <div class="row">
82 <div class="col-12">
83 <div class="card border-0 shadow-sm mb-3 px-0 mw-100">
84 <div class="card-body">
85 <?php do_action( 'uwp_before_form_builder_content', $default_tab ); ?>
86 </div>
87 </div>
88 </div>
89 </div>
90 <?php
91 }
92 ?>
93
94 <div id="uwp_form_builder_container" class="row">
95 <div class="col-md-6">
96
97 <!-- required for tabs to work -->
98 <ul class="nav nav-tabs d-none " role="tablist">
99 <li class="nav-item" role="presentation">
100 <a class="nav-link active" id="uwp-fields-tab" data-toggle="tab" href="#uwp-available-fields" role="tab" aria-controls="home" aria-selected="true">1</a>
101 </li>
102 <li class="nav-item" role="presentation">
103 <a class="nav-link" id="uwp-field-settings-tab" data-toggle="tab" href="#uwp-field-settings" role="tab" aria-controls="profile" aria-selected="false">2</a>
104 </li>
105 </ul>
106 <!-- required for tabs to work -->
107
108 <div class="tab-content sticky-top" style="top: 40px;">
109
110 <div class="side-sortables side-sortables tab-pane fade show active card p-0 mw-100 w-100 border-0 shadow-sm" id="uwp-available-fields" role="tabpanel">
111 <div class="card border-0 shadow-sm mb-4 px-0 mw-100">
112 <div class="card-header bg-white">
113 <h3 class="h5 mb-0 text-dark py-0">
114 <span><?php echo apply_filters( 'uwp_form_builder_available_fields_head', __( 'Add new form field', 'userswp' ), $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
115 </h3>
116 </div>
117 <div class="card-body">
118 <p>
119 <?php
120 $note = sprintf( __( 'Click on any box below to add a field of that type on %s form. You must use a fieldset to group your fields.', 'userswp' ), $form_type );
121 echo apply_filters( 'uwp_form_builder_available_fields_note', $note, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
122 ?>
123 </p>
124 <?php do_action( 'uwp_before_available_fields', $default_tab ); ?>
125
126 <h4 class="h6 text-muted"><?php esc_html_e( 'Standard Fields', 'userswp' ); ?></h4>
127 <div id="uwp-form-builder-tab" class="uwp-tabs-panel mb-4">
128 <?php do_action( 'uwp_manage_available_fields', $form_type ); ?>
129 </div>
130
131 <?php
132 $predefined_fields = apply_filters( 'uwp_predefined_fields_tabs', array( 'account', 'profile-tabs' ) );
133 if ( in_array( $form_type, $predefined_fields ) ) {
134 ?>
135 <h4 class="h6 text-muted"><?php esc_html_e( 'Predefined Fields', 'userswp' ); ?></h4>
136 <div id="uwp-form-builder-tab-predefined" class="uwp-tabs-panel mb-4">
137 <?php do_action( 'uwp_manage_available_fields_predefined', $form_type ); ?>
138 </div>
139 <?php }
140
141 $custom_fields = apply_filters( 'uwp_custom_fields_tabs', array( 'account', 'profile-tabs' ) );
142 $fields = $this->form_fields_custom( $form_type );
143 if ( in_array( $form_type, $custom_fields ) && $fields ) { ?>
144 <h4 class="h6 text-muted"><?php esc_html_e( 'Custom Fields', 'userswp' ); ?></h4>
145 <div id="uwp-form-builder-tab-custom" class="uwp-tabs-panel">
146 <?php do_action( 'uwp_manage_available_fields_custom', $form_type ); ?>
147 </div>
148 <?php }
149
150 do_action( 'uwp_after_available_fields', $default_tab );
151 ?>
152 </div>
153 </div>
154 </div>
155
156
157 <div class="side-sortables side-sortables tab-pane fade card p-0 mw-100 w-100 border-0 shadow-sm" id="uwp-field-settings" role="tabpanel">
158 <div class="card border-0 shadow-sm mb-4 px-0 mw-100">
159 <div class="card-header bg-white d-flex justify-content-between">
160 <h3 class="h5 mb-0 text-dark py-0">
161 <span><?php echo apply_filters( 'uwp_form_builder_available_fields_settings_head', __( 'Field Settings', 'userswp' ), $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
162 </h3>
163 <?php
164 global $aui_bs5;
165 if ( $aui_bs5 ) {
166 ?>
167 <button type="button" class="btn-close align-self-center" aria-label="Close" onclick="uwp_tabs_close_settings(this);"></button>
168 <?php } else { ?>
169 <button type="button" class="close" aria-label="Close" onclick="uwp_tabs_close_settings(this);">
170 <span aria-hidden="true">&times;</span>
171 </button>
172 <?php } ?>
173 </div>
174
175 <form></form> <!-- required as chrome removes first empty form -->
176 <form class="uwp-form-settings-form">
177 <div class="card-body scrollbars-ios" style="max-height: 70vh; overflow-y:auto;">
178 </div>
179 </form>
180
181 <div class="card-footer text-right text-end">
182
183 </div>
184 </div>
185 </div>
186 </div>
187 </div>
188
189 <div class="col-md-6 uwp-side-sortables" id="uwp-selected-fields">
190 <div class="card border-0 shadow-sm mb-4 px-0 mw-100">
191 <div class="card-header bg-white">
192 <h3 class="h5 mb-0 text-dark py-0">
193 <span>
194 <?php
195 $title = __( 'List of fields that will appear in the account form.', 'userswp' );
196 echo apply_filters( 'uwp_form_builder_selected_fields_head', $title, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
197 </span>
198 </h3>
199 </div>
200 <div class="card-body">
201 <p>
202 <?php
203 $note = sprintf( __( 'Click to expand and view field related settings. You may drag and drop to arrange fields order on %s form too.', 'userswp' ), $form_type );
204 echo apply_filters( 'uwp_form_builder_selected_fields_note', $note, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
205 </p>
206 <div id="uwp-form-builder-tab-selected" class="uwp-tabs-panel">
207 <div class="field_row_main">
208 <?php do_action( 'uwp_manage_selected_fields', $form_type ); ?>
209 </div>
210 </div>
211 </div>
212 </div>
213 </div>
214
215 </div>
216
217 </div>
218 </div>
219 <?php
220 echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
221 }
222
223 public function display_before_available_fields( $tab = '' ) {
224 global $wpdb;
225
226 if ( empty( $tab ) || $tab == 'account' ) {
227 $form_type = 'account';
228 $type = 'predefined';
229 ?>
230 <h3 class="h6 text-muted">
231 <span>
232 <?php
233 echo apply_filters( 'uwp_form_builder_available_fields_head', __( 'Existing Fields', 'userswp' ), $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
234
235 $note = sprintf( __( 'Click on field to add it to the form. Existing fields are most used fields in all other forms.', 'userswp' ), $form_type );
236 $note_text = apply_filters( 'uwp_form_builder_existing_fields_note', $note, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
237 echo uwp_help_tip( $note_text );
238 ?>
239 </span>
240 </h3>
241
242
243 <div class="inside mb-4">
244 <div id="uwp-form-builder-tab-existing" class="uwp-tabs-panel">
245 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
246 <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
247 <ul class="corex uwp-tabs-selected uwp_form_extras row row-cols-2 px-2">
248 <?php
249 $form_id = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
250 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
251 $existing_fields = $wpdb->get_results( 'select htmlvar_name from ' . $table_name . " where form_type ='" . $form_type . "' AND form_id = " . $form_id );
252
253 $existing_field_ids = array();
254 if ( ! empty( $existing_fields ) ) {
255 foreach ( $existing_fields as $existing_field ) {
256 $existing_field_ids[] = $existing_field->htmlvar_name;
257 }
258 }
259
260 $fields = $this->get_form_existing_fields( $form_type, 'array' );
261
262 if ( ! empty( $fields ) ) {
263 foreach ( $fields as $id => $field ) {
264 $display = '';
265 if ( in_array( $field['htmlvar_name'], $existing_field_ids ) ) {
266 $display = 'display:none;';
267 }
268
269 $style = 'style="' . $display . '"';
270 ?>
271 <li class="uwp-tooltip-wrap col px-1 " <?php echo esc_attr( $style ); ?>>
272 <a id="uwp-<?php echo esc_attr( $field['htmlvar_name'] ); ?>"
273 data-field-custom-type="<?php echo esc_attr( $type ); ?>"
274 data-field-type-key="<?php echo esc_attr( $field['htmlvar_name'] ); ?>"
275 data-field-type="<?php echo esc_attr( $field['field_type'] ); ?>"
276 class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
277 href="javascript:void(0);">
278
279 <?php
280 if ( isset( $field['field_icon'] ) && strpos( $field['field_icon'], ' fa-' ) !== false ) {
281 echo '<i class="' . esc_attr( $field['field_icon'] ) . '" aria-hidden="true"></i>';
282 } elseif ( isset( $field['field_icon'] ) && $field['field_icon'] ) {
283 echo '<b style="background-image: url("' . esc_url( $field['field_icon'] ) . '")"></b>';
284 } else {
285 echo '<i class="fas fa-cog" aria-hidden="true"></i>';
286 }
287
288 echo ' ' . esc_attr( $field['site_title'] );
289
290 if ( isset( $field['help_text'] ) && $field['help_text'] ) {
291 echo uwp_help_tip( $field['help_text'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
292 }
293 ?>
294 </a>
295 </li>
296 <?php
297 }
298 }
299 ?>
300 </ul>
301 </div>
302 </div>
303 <?php
304 }
305 }
306
307 public function get_form_existing_fields( $type = '', $output = '' ) {
308
309 global $wpdb;
310 $custom_fields = array();
311 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
312 $register_forms = uwp_get_option( 'multiple_registration_forms' );
313 if ( 'array' == $output ) {
314 $output = ARRAY_A;
315 } else {
316 $output = OBJECT;
317 }
318 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
319 foreach ( $register_forms as $key => $register_form ) {
320 $form_ids[] = (int) $register_form['id'];
321 }
322
323 if ( isset( $form_ids ) && count( $form_ids ) > 0 ) {
324 $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%s' );
325 $form_ids_placeholder = implode( ', ', $form_ids_placeholder );
326 $query = 'SELECT * FROM ' . $table_name . " WHERE form_type = 'account' AND form_id IN (" . $form_ids_placeholder . ') ORDER BY sort_order ASC';
327 $custom_fields = $wpdb->get_results( $wpdb->prepare( $query, $form_ids ), $output );
328 }
329 }
330
331 $custom_fields = uwp_get_unique_custom_fields( $custom_fields );
332
333 return apply_filters( 'uwp_form_existing_fields', $custom_fields, $type );
334 }
335
336 public function multiple_registration_form( $tab = '' ) {
337
338 $alert_content = wp_kses(
339 sprintf(
340 /* translators: %1$s: URL to add user type, %2$s: Add User Type button text */
341 '%s <a href="%s" class="btn btn-primary btn-sm text-decoration-none ms-auto" role="button">%s</a>',
342 __( 'Add different user types to create custom registration forms with unique roles and redirects.', 'userswp' ),
343 admin_url( 'admin.php?page=uwp_user_types&form=add' ),
344 __( 'Add User Type', 'userswp' )
345 ),
346 array(
347 'a' => array(
348 'href' => array(),
349 'class' => array(),
350 'role' => array(),
351 ),
352 )
353 );
354
355 $maybe_add_user_type = aui()->alert(
356 array(
357 'type' => 'dark',
358 'class' => 'd-flex align-items-center mb-0',
359 'content' => $alert_content,
360 'dismissible' => false,
361 )
362 );
363
364 if ( ! empty( $tab ) && $tab == 'account' ) {
365 $current_form = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
366 $register_tab = admin_url( 'admin.php?page=uwp_form_builder&tab=account' );
367 $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
368
369
370
371 ?>
372 <?php if ( ! empty( $register_forms ) && is_array( $register_forms ) ) { ?>
373 <form class="uwp_user_type_form" id="uwp_user_type_form" method="POST">
374 <input type="hidden" name="manage_field_form_id" class="manage_field_form_id" id="manage_field_form_id" value="<?php echo esc_attr( $current_form ); ?>">
375 <?php do_action( 'uwp_user_type_form_before', $current_form, $tab ); ?>
376
377 <div class="d-flex align-items-center">
378 <label class="form-label h1"><i class="fas fa-user me-3 iconbox border-0 fill rounded-circle transition-all btn-translucent-info iconsmallmedium"></i>
379 <?php _e( 'Select user type', 'userswp' ); ?></label>
380 <div class="ms-3 col-6">
381 <select onChange="window.location.replace(jQuery(this).val());"
382 name="form_select" id="multiple_registration_select"
383 class="form-select form-select-lgx">
384 <?php
385 foreach ( $register_forms as $form ) :
386 $form_id = ! empty( $form['id'] ) ? $form['id'] : '';
387 $form_title = ! empty( $form['title'] ) ? sanitize_title_with_dashes( $form['title'] ) : '';
388 $option_text = sprintf(
389 /* translators: %1$s: Form title, %2$s: Form ID */
390 __( '%1$s - #%2$s', 'userswp' ),
391 $form_title,
392 $form_id
393 );
394 $option_value = esc_url( add_query_arg( 'form', $form_id, $register_tab ) );
395 ?>
396 <option <?php selected( $current_form, $form_id ); ?> value="<?php echo esc_attr( $option_value ); ?>">
397 <?php echo esc_html( $option_text ); ?>
398 </option>
399 <?php endforeach; ?>
400 </select>
401 </div>
402 </div>
403
404 <?php do_action( 'uwp_user_type_form_after', $current_form, $tab ); ?>
405 </form>
406 <?php
407 }else {
408 echo $maybe_add_user_type;
409 }
410
411 }
412
413 if ( ! empty( $tab ) && $tab == 'register' ) {
414 $current_form = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
415
416 $register_tab = admin_url( 'admin.php?page=uwp_form_builder&tab=register' );
417 $register_forms = uwp_get_option( 'multiple_registration_forms' );
418 ?>
419 <input type="hidden" name="manage_field_form_id" class="manage_field_form_id" id="manage_field_form_id"
420 value="<?php echo esc_attr( $current_form ); ?>">
421 <?php
422 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
423 ?>
424 <div class="d-flex align-items-center">
425 <label class="form-label h1"><i class="fas fa-user me-3 iconbox border-0 fill rounded-circle transition-all btn-translucent-info iconsmallmedium"></i>
426 <?php _e( 'Select user type', 'userswp' ); ?></label>
427 <div class="ms-3 col-6">
428 <select onChange="window.location.replace(jQuery(this).val());"
429 name="multiple-registration-select" id="multiple_registration_select"
430 class="form-select aui-select2x">
431 <?php
432 foreach ( $register_forms as $key => $forms ) {
433 $form_id = ! empty( $forms['id'] ) ? $forms['id'] : '';
434 $form_title = ! empty( $forms['title'] ) ? sanitize_title_with_dashes( $forms['title'] ) : '';
435 ?>
436 <option <?php selected( $current_form, $form_id ); ?> value="<?php echo esc_attr( $register_tab . '&form=' . $form_id ); ?>"><?php echo esc_html( wp_sprintf( __( '%1$s - #%2$s', 'userswp' ), $form_title, $form_id ) ); ?></option>
437 <?php } ?>
438 </select>
439 </select>
440 </div>
441 </div>
442 <?php
443 }else {
444 echo $maybe_add_user_type;
445 }
446
447 }
448
449 if ( ! empty( $tab ) && $tab == 'profile-tabs' ) {
450 $current_form = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
451
452 $register_tab = admin_url( 'admin.php?page=uwp_form_builder&tab=profile-tabs' );
453 $register_forms = uwp_get_option( 'multiple_registration_forms' );
454 ?>
455 <input type="hidden" name="manage_field_form_id" class="manage_field_form_id" id="manage_field_form_id"
456 value="<?php echo esc_attr( $current_form ); ?>">
457 <?php
458 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
459 ?>
460 <div class="d-flex align-items-center">
461 <label class="form-label h1"><i class="fas fa-user me-3 iconbox border-0 fill rounded-circle transition-all btn-translucent-info iconsmallmedium"></i>
462 <?php _e( 'Select user type', 'userswp' ); ?></label>
463 <div class="ms-3 col-6">
464 <select onChange="window.location.replace(jQuery(this).val());"
465 name="multiple-registration-select" id="multiple_registration_select"
466 class="form-select">
467 <?php
468 foreach ( $register_forms as $key => $forms ) {
469 $form_id = ! empty( $forms['id'] ) ? $forms['id'] : '';
470 $form_title = ! empty( $forms['title'] ) ? $forms['title'] : '';
471 ?>
472 <option <?php selected( $current_form, $form_id ); ?>
473 value="<?php echo esc_attr( $register_tab . '&form=' . $form_id ); ?>"><?php echo esc_html( wp_sprintf( __( '%1$s - #%2$s', 'userswp' ), $form_title, $form_id ) ); ?></option>
474 <?php } ?>
475 </select>
476 </div>
477 </div>
478 <?php } else {
479 echo $maybe_add_user_type;
480 }
481 }
482 }
483
484 public function manage_available_fields_predefined( $form_type ) {
485 switch ( $form_type ) {
486 case 'account':
487 $this->custom_available_fields( 'predefined', $form_type );
488 break;
489 }
490 }
491
492 public function custom_available_fields( $type, $form_type ) {
493 ?>
494 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
495 <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
496 <?php
497 if ( $type == 'predefined' ) {
498 $fields = $this->form_fields_predefined( $form_type );
499 } elseif ( $type == 'custom' ) {
500 $fields = $this->form_fields_custom( $form_type );
501 } else {
502 $fields = $this->form_fields( $form_type );
503 ?>
504 <ul class="row row-cols-1 px-2 mb-0">
505 <li class="uwp-tooltip-wrapx col px-1">
506 <a id="uwp-fieldset"
507 class="uwp-draggable-form-itemsx uwp-fieldset btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
508 href="javascript:void(0);"
509 data-field-custom-type=""
510 data-field-type="fieldset"
511 data-field-type-key="fieldset">
512 <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
513 <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
514 <?php
515 esc_html_e( 'Fieldset (section separator)', 'userswp' );
516 echo uwp_help_tip( __( 'This adds a section separator with a title.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
517 ?>
518 </a>
519 </li>
520 </ul>
521
522 <?php
523 }
524
525 if ( ! empty( $fields ) ) {
526 ?>
527 <ul class="row row-cols-2 px-2 mb-0">
528 <?php
529 foreach ( $fields as $id => $field ) {
530 ?>
531 <li class="uwp-tooltip-wrapx col px-1">
532 <a id="uwp-<?php echo esc_attr( $id ); ?>"
533 data-field-custom-type="<?php echo esc_attr( $type ); ?>"
534 data-field-type-key="<?php echo esc_attr( $id ); ?>"
535 data-field-type="<?php echo esc_attr( $field['field_type'] ); ?>"
536 class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
537 href="javascript:void(0);">
538
539 <?php
540 if ( isset( $field['field_icon'] ) && strpos( $field['field_icon'], ' fa-' ) !== false ) {
541 echo '<i class="' . esc_attr( $field['field_icon'] ) . '" aria-hidden="true"></i>';
542 } elseif ( isset( $field['field_icon'] ) && $field['field_icon'] ) {
543 echo '<b style="background-image: url("' . esc_url( $field['field_icon'] ) . '")"></b>';
544 } else {
545 echo '<i class="fas fa-cog" aria-hidden="true"></i>';
546 }
547
548 echo ' ' . esc_attr( $field['site_title'] );
549
550 if ( isset( $field['help_text'] ) && $field['help_text'] ) {
551 echo uwp_help_tip( $field['help_text'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
552 }
553 ?>
554 </a>
555 </li>
556 <?php
557 }
558 } else {
559 esc_html_e( 'There are no custom fields here yet.', 'userswp' );
560 }
561 ?>
562 </ul>
563
564 <?php
565 }
566
567 public function form_fields_predefined( $type = '' ) {
568 $custom_fields = array();
569
570 // Country
571 $custom_fields['uwp_country'] = array(
572 'field_type' => 'select',
573 'class' => 'uwp-country',
574 'field_icon' => 'fas fa-map-marker-alt',
575 'site_title' => __( 'Country', 'userswp' ),
576 'help_text' => __( 'Adds a input for Country field.', 'userswp' ),
577 'defaults' => array(
578 'admin_title' => 'Country',
579 'site_title' => 'Country',
580 'htmlvar_name' => 'uwp_country',
581 'is_active' => 1,
582 'default_value' => '',
583 'is_required' => 0,
584 'option_values' => '',
585 'required_msg' => '',
586 'field_icon' => 'fas fa-map-marker-alt',
587 'css_class' => '',
588 ),
589 );
590
591 // Gender
592 $custom_fields['gender'] = array(
593 'field_type' => 'select',
594 'class' => 'uwp-gender',
595 'field_icon' => 'fas fa-user',
596 'site_title' => __( 'Gender', 'userswp' ),
597 'help_text' => __( 'Adds a input for Gender field.', 'userswp' ),
598 'defaults' => array(
599 'admin_title' => 'Gender',
600 'site_title' => 'Gender',
601 'htmlvar_name' => 'gender',
602 'is_active' => 1,
603 'default_value' => '',
604 'is_required' => 0,
605 'option_values' => __( 'Male,Female,Other', 'userswp' ),
606 'required_msg' => '',
607 'field_icon' => 'fas fa-user',
608 'css_class' => '',
609 ),
610 );
611
612 $custom_fields['dob'] = array(
613 'field_type' => 'datepicker',
614 'class' => 'uwp-dob',
615 'field_icon' => 'fas fa-birthday-cake',
616 'site_title' => __( 'Date of birth', 'userswp' ),
617 'help_text' => __( 'Adds a date input for users to enter their date of birth.', 'userswp' ),
618 'defaults' => array(
619 'data_type' => 'DATE',
620 'admin_title' => __( 'Date of birth', 'userswp' ),
621 'site_title' => __( 'Date of birth', 'userswp' ),
622 'form_label' => __( 'Enter your date of birth.', 'userswp' ),
623 'htmlvar_name' => 'dob',
624 'is_active' => true,
625 'for_admin_use' => false,
626 'default_value' => '',
627 'is_required' => false,
628 'validation_pattern' => '',
629 'validation_msg' => '',
630 'required_msg' => '',
631 'field_icon' => 'fas fa-birthday-cake',
632 'css_class' => '',
633 'extra_fields' => array(
634 'date_range' => 'c-100:c+0',
635 ),
636 ),
637 );
638
639 // Mobile
640 $custom_fields['mobile'] = array(
641 'field_type' => 'phone',
642 'class' => 'uwp-mobile',
643 'field_icon' => 'fas fa-mobile-alt',
644 'site_title' => __( 'Mobile', 'userswp' ),
645 'help_text' => __( 'Adds a input for Mobile field.', 'userswp' ),
646 'defaults' => array(
647 'admin_title' => 'Mobile',
648 'site_title' => 'Mobile',
649 'htmlvar_name' => 'mobile',
650 'is_active' => 1,
651 'default_value' => '',
652 'is_required' => 0,
653 'required_msg' => '',
654 'field_icon' => 'fas fa-mobile-alt',
655 'css_class' => '',
656 ),
657 );
658
659 $custom_fields['register_gdpr'] = array(
660 'field_type' => 'checkbox',
661 'class' => 'uwp-register-gdpr',
662 'field_icon' => 'fas fa-file',
663 'site_title' => __( 'GDPR Policy Page', 'userswp' ),
664 'help_text' => __( 'Adds Register GDPR page.', 'userswp' ),
665 'defaults' => array(
666 'admin_title' => 'GDPR Policy',
667 'site_title' => 'GDPR Policy',
668 'form_label' => __( 'GDPR Policy', 'userswp' ),
669 'htmlvar_name' => 'register_gdpr',
670 'is_active' => 1,
671 'default_value' => '',
672 'is_required' => 1,
673 'required_msg' => '',
674 'field_icon' => 'fas fa-file',
675 'css_class' => 'btn-register-gdpr',
676 ),
677 );
678
679 $custom_fields['register_tos'] = array(
680 'field_type' => 'checkbox',
681 'class' => 'uwp-register-tos',
682 'field_icon' => 'fas fa-file',
683 'site_title' => __( 'Terms & Conditions', 'userswp' ),
684 'help_text' => __( 'Adds Register TOS page.', 'userswp' ),
685 'help_text_tip' => __( 'This will show next to the checkbox, to add a link to the TOS page, use format: %%link_start%% View TOS %%link_end%%', 'userswp' ),
686 'defaults' => array(
687 'admin_title' => 'Terms & Conditions',
688 'site_title' => 'Terms & Conditions',
689 'form_label' => __( 'Terms & Conditions', 'userswp' ),
690 'htmlvar_name' => 'register_tos',
691 'is_active' => 1,
692 'default_value' => '',
693 'is_required' => 1,
694 'required_msg' => '',
695 'field_icon' => 'fas fa-file',
696 'css_class' => 'btn-register-tos',
697 ),
698 );
699
700 // Website
701 $custom_fields['user_url'] = array(
702 'field_type' => 'url',
703 'class' => 'uwp-website',
704 'field_icon' => 'fas fa-link',
705 'site_title' => __( 'Website', 'userswp' ),
706 'help_text' => __( 'Let users enter their website url.', 'userswp' ),
707 'defaults' => array(
708 'admin_title' => 'Website',
709 'site_title' => 'Website',
710 'form_label' => __( 'Website', 'userswp' ),
711 'htmlvar_name' => 'user_url',
712 'is_active' => 1,
713 'default_value' => '',
714 'is_required' => 0,
715 'required_msg' => '',
716 'field_icon' => 'fas fa-link',
717 'css_class' => 'btn-website',
718 ),
719 );
720
721 // Facebook
722 $custom_fields['facebook'] = array(
723 'field_type' => 'url',
724 'class' => 'uwp-facebook',
725 'field_icon' => 'fab fa-facebook-square',
726 'site_title' => __( 'Facebook', 'userswp' ),
727 'help_text' => __( 'Let users enter their facebook url.', 'userswp' ),
728 'defaults' => array(
729 'admin_title' => 'Facebook',
730 'site_title' => 'Facebook',
731 'form_label' => __( 'Facebook url', 'userswp' ),
732 'htmlvar_name' => 'facebook',
733 'is_active' => 1,
734 'default_value' => '',
735 'is_required' => 0,
736 'required_msg' => '',
737 'field_icon' => 'fab fa-facebook-f',
738 'css_class' => 'btn-facebook',
739 ),
740 );
741
742 // Twitter
743 $custom_fields['twitter'] = array(
744 'field_type' => 'url',
745 'class' => 'uwp-twitter',
746 'field_icon' => 'fab fa-twitter-square',
747 'site_title' => __( 'Twitter', 'userswp' ),
748 'help_text' => __( 'Let users enter their twitter url.', 'userswp' ),
749 'defaults' => array(
750 'admin_title' => 'Twitter',
751 'site_title' => 'Twitter',
752 'form_label' => __( 'Twitter url', 'userswp' ),
753 'htmlvar_name' => 'twitter',
754 'is_active' => 1,
755 'default_value' => '',
756 'is_required' => 0,
757 'required_msg' => '',
758 'field_icon' => 'fab fa-twitter',
759 'css_class' => 'btn-twitter',
760 ),
761 );
762
763 // Instagram
764 $custom_fields['instagram'] = array(
765 'field_type' => 'url',
766 'class' => 'uwp-instagram',
767 'field_icon' => 'fab fa-instagram',
768 'site_title' => __( 'Instagram', 'userswp' ),
769 'help_text' => __( 'Let users enter their instagram url.', 'userswp' ),
770 'defaults' => array(
771 'admin_title' => 'Instagram',
772 'site_title' => 'Instagram',
773 'form_label' => __( 'Instagram url', 'userswp' ),
774 'htmlvar_name' => 'instagram',
775 'is_active' => 1,
776 'default_value' => '',
777 'is_required' => 0,
778 'required_msg' => '',
779 'field_icon' => 'fab fa-instagram',
780 'css_class' => 'btn-instagram',
781 ),
782 );
783
784 // Linkedin
785 $custom_fields['linkedin'] = array(
786 'field_type' => 'url',
787 'class' => 'uwp-linkedin',
788 'field_icon' => 'fab fa-linkedin',
789 'site_title' => __( 'Linkedin', 'userswp' ),
790 'help_text' => __( 'Let users enter their linkedin url.', 'userswp' ),
791 'defaults' => array(
792 'admin_title' => 'Linkedin',
793 'site_title' => 'Linkedin',
794 'form_label' => __( 'Linkedin url', 'userswp' ),
795 'htmlvar_name' => 'linkedin',
796 'is_active' => 1,
797 'default_value' => '',
798 'is_required' => 0,
799 'required_msg' => '',
800 'field_icon' => 'fab fa-linkedin-in',
801 'css_class' => 'btn-linkedin',
802 ),
803 );
804
805 // Flickr
806 $custom_fields['flickr'] = array(
807 'field_type' => 'url',
808 'class' => 'uwp-flickr',
809 'field_icon' => 'fab fa-flickr',
810 'site_title' => __( 'Flickr', 'userswp' ),
811 'help_text' => __( 'Let users enter their Flickr url.', 'userswp' ),
812 'defaults' => array(
813 'admin_title' => 'Flickr',
814 'site_title' => 'Flickr',
815 'form_label' => __( 'Flickr url', 'userswp' ),
816 'htmlvar_name' => 'flickr',
817 'is_active' => 1,
818 'default_value' => '',
819 'is_required' => 0,
820 'required_msg' => '',
821 'field_icon' => 'fab fa-flickr',
822 'css_class' => 'btn-flickr',
823 ),
824 );
825
826 // GitHub
827 $custom_fields['github'] = array(
828 'field_type' => 'url',
829 'class' => 'uwp-github',
830 'field_icon' => 'fab fa-github-square',
831 'site_title' => __( 'GitHub', 'userswp' ),
832 'help_text' => __( 'Let users enter their GitHub url.', 'userswp' ),
833 'defaults' => array(
834 'admin_title' => 'GitHub',
835 'site_title' => 'GitHub',
836 'form_label' => __( 'GitHub url', 'userswp' ),
837 'htmlvar_name' => 'github',
838 'is_active' => 1,
839 'default_value' => '',
840 'is_required' => 0,
841 'required_msg' => '',
842 'field_icon' => 'fab fa-github-alt',
843 'css_class' => 'btn-github',
844 ),
845 );
846
847 // YouTube
848 $custom_fields['youtube'] = array(
849 'field_type' => 'url',
850 'class' => 'uwp-youtube',
851 'field_icon' => 'fab fa-youtube-square',
852 'site_title' => __( 'YouTube', 'userswp' ),
853 'help_text' => __( 'Let users enter their YouTube url.', 'userswp' ),
854 'defaults' => array(
855 'admin_title' => 'YouTube',
856 'site_title' => 'YouTube',
857 'form_label' => __( 'YouTube url', 'userswp' ),
858 'htmlvar_name' => 'youtube',
859 'is_active' => 1,
860 'default_value' => '',
861 'is_required' => 0,
862 'required_msg' => '',
863 'field_icon' => 'fab fa-youtube',
864 'css_class' => 'btn-youtube',
865 ),
866 );
867
868 // WordPress
869 $custom_fields['wordpress'] = array(
870 'field_type' => 'url',
871 'class' => 'uwp-wordpress',
872 'field_icon' => 'fab fa-wordpress-simple',
873 'site_title' => __( 'WordPress', 'userswp' ),
874 'help_text' => __( 'Let users enter their WordPress profile url.', 'userswp' ),
875 'defaults' => array(
876 'admin_title' => 'WordPress',
877 'site_title' => 'WordPress',
878 'form_label' => __( 'WordPress url', 'userswp' ),
879 'htmlvar_name' => 'wordpress',
880 'is_active' => 1,
881 'default_value' => '',
882 'is_required' => 0,
883 'required_msg' => '',
884 'field_icon' => 'fab fa-wordpress-simple',
885 'css_class' => 'btn-wordpress',
886 ),
887 );
888
889 // Language
890 $custom_fields['uwp_language'] = array(
891 'field_type' => 'select',
892 'class' => 'uwp-language',
893 'field_icon' => 'fas fa-language',
894 'site_title' => __( 'Select Language', 'userswp' ),
895 'help_text' => __( 'Adds a input for user language selection.', 'userswp' ),
896 'defaults' => array(
897 'admin_title' => 'Select Language',
898 'site_title' => 'Select Language',
899 'form_label' => __( 'Site Language', 'userswp' ),
900 'htmlvar_name' => 'uwp_language',
901 'is_active' => 1,
902 'default_value' => 'site-default',
903 'is_required' => 0,
904 'option_values' => '',
905 'required_msg' => '',
906 'field_icon' => 'fas fa-language',
907 'css_class' => '',
908 ),
909 );
910
911 return apply_filters( 'uwp_form_fields_predefined', $custom_fields, $type );
912 }
913
914 public function form_fields_custom( $type = '' ) {
915 $custom_fields = array();
916
917 return apply_filters( 'uwp_form_fields_custom', $custom_fields, $type );
918 }
919
920 public function form_fields( $type = '' ) {
921
922 $custom_fields = array(
923 'text' => array(
924 'field_type' => 'text',
925 'class' => 'uwp-text',
926 'field_icon' => 'fas fa-minus',
927 'site_title' => __( 'Text', 'userswp' ),
928 'help_text' => __( 'Add any sort of text field, text or numbers', 'userswp' ),
929 ),
930 'datepicker' => array(
931 'field_type' => 'datepicker',
932 'class' => 'uwp-datepicker',
933 'field_icon' => 'fas fa-calendar-alt',
934 'site_title' => __( 'Date', 'userswp' ),
935 'help_text' => __( 'Adds a date picker.', 'userswp' ),
936 ),
937 'textarea' => array(
938 'field_type' => 'textarea',
939 'class' => 'uwp-textarea',
940 'field_icon' => 'fas fa-bars',
941 'site_title' => __( 'Textarea', 'userswp' ),
942 'help_text' => __( 'Adds a textarea', 'userswp' ),
943 ),
944 'time' => array(
945 'field_type' => 'time',
946 'class' => 'uwp-time',
947 'field_icon' => 'far fa-clock',
948 'site_title' => __( 'Time', 'userswp' ),
949 'help_text' => __( 'Adds a time picker', 'userswp' ),
950 ),
951 'checkbox' => array(
952 'field_type' => 'checkbox',
953 'class' => 'uwp-checkbox',
954 'field_icon' => 'far fa-check-square',
955 'site_title' => __( 'Checkbox', 'userswp' ),
956 'help_text' => __( 'Adds a checkbox', 'userswp' ),
957 ),
958 'phone' => array(
959 'field_type' => 'phone',
960 'class' => 'uwp-phone',
961 'field_icon' => 'fas fa-phone',
962 'site_title' => __( 'Phone', 'userswp' ),
963 'help_text' => __( 'Adds a phone input', 'userswp' ),
964 ),
965 'radio' => array(
966 'field_type' => 'radio',
967 'class' => 'uwp-radio',
968 'field_icon' => 'far fa-dot-circle',
969 'site_title' => __( 'Radio', 'userswp' ),
970 'help_text' => __( 'Adds a radio input', 'userswp' ),
971 ),
972 'email' => array(
973 'field_type' => 'email',
974 'class' => 'uwp-email',
975 'field_icon' => 'far fa-envelope',
976 'site_title' => __( 'Email', 'userswp' ),
977 'help_text' => __( 'Adds a email input', 'userswp' ),
978 ),
979 'select' => array(
980 'field_type' => 'select',
981 'field_icon' => 'far fa-caret-square-down',
982 'site_title' => __( 'Select', 'userswp' ),
983 'help_text' => __( 'Adds a select input', 'userswp' ),
984 ),
985 'multiselect' => array(
986 'field_type' => 'multiselect',
987 'class' => 'uwp-multiselect',
988 'field_icon' => 'far fa-caret-square-down',
989 'site_title' => __( 'Multi Select', 'userswp' ),
990 'help_text' => __( 'Adds a multiselect input', 'userswp' ),
991 ),
992 'url' => array(
993 'field_type' => 'url',
994 'class' => 'uwp-url',
995 'field_icon' => 'fas fa-link',
996 'site_title' => __( 'URL', 'userswp' ),
997 'help_text' => __( 'Adds a url input', 'userswp' ),
998 ),
999 'editor' => array(
1000 'field_type' => 'editor',
1001 'class' => 'uwp-html',
1002 'field_icon' => 'fas fa-code',
1003 'site_title' => __( 'HTML', 'userswp' ),
1004 'help_text' => __( 'Adds a wysiwyg editor input', 'userswp' ),
1005 ),
1006 'file' => array(
1007 'field_type' => 'file',
1008 'class' => 'uwp-file',
1009 'field_icon' => 'fas fa-file',
1010 'site_title' => __( 'File Upload', 'userswp' ),
1011 'help_text' => __( 'Adds a file input', 'userswp' ),
1012 ),
1013 );
1014
1015 return apply_filters( 'uwp_form_fields', $custom_fields, $type );
1016 }
1017
1018 public function manage_available_fields_custom( $form_type ) {
1019 switch ( $form_type ) {
1020 case 'account':
1021 $this->custom_available_fields( 'custom', $form_type );
1022 break;
1023 }
1024 }
1025
1026 public function manage_available_fields( $form_type ) {
1027 switch ( $form_type ) {
1028 case 'account':
1029 $this->custom_available_fields( '', $form_type );
1030 break;
1031 case 'register':
1032 $this->register_available_fields( $form_type );
1033 break;
1034 }
1035 }
1036
1037 public function register_available_fields( $form_type ) {
1038 global $wpdb;
1039
1040 $form_id = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
1041
1042 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1043
1044 $existing_fields = $wpdb->get_results( 'select site_htmlvar_name from ' . $extras_table_name . " where form_type ='" . $form_type . "' AND form_id = " . $form_id );
1045
1046 $existing_field_ids = array();
1047 if ( ! empty( $existing_fields ) ) {
1048 foreach ( $existing_fields as $existing_field ) {
1049 $existing_field_ids[] = $existing_field->site_htmlvar_name;
1050 }
1051 }
1052 ?>
1053 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1054 <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
1055 <ul class="row row-cols-1 px-2 mb-0">
1056 <?php
1057
1058 $fields = $this->register_fields( $form_type, $form_id );
1059
1060 if ( ! empty( $fields ) ) {
1061 foreach ( $fields as $field ) {
1062 $field = stripslashes_deep( $field ); // strip slashes
1063
1064 $fieldset_width = '';
1065 if ( $field['field_type'] == 'fieldset' ) {
1066 $fieldset_width = 'width:100%;';
1067 }
1068
1069 $display = '';
1070 if ( in_array( $field['htmlvar_name'], $existing_field_ids ) ) {
1071 $display = 'display:none;';
1072 }
1073
1074 $style = 'style="' . $display . $fieldset_width . '"';
1075 ?>
1076 <li <?php echo $style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="col px-1" >
1077
1078 <a id="uwp-<?php echo esc_attr( $field['htmlvar_name'] ); ?>"
1079 class="uwp-draggable-form-itemsx uwp-<?php echo esc_attr( $field['field_type'] ); ?> btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
1080 href="javascript:void(0);" data-field-type="<?php echo esc_attr( $field['field_type'] ); ?>">
1081
1082 <?php
1083 if ( $icon = uwp_get_field_icon( $field['field_icon'] ) ) {
1084 echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1085 } else {
1086 echo '<i class="fas fa-cog" aria-hidden="true"></i>';
1087 }
1088 ?>
1089
1090 <?php echo esc_attr( $field['site_title'] ); ?>
1091
1092 </a>
1093 </li>
1094
1095
1096 <?php
1097 }
1098 }
1099 ?>
1100 </ul>
1101 <?php
1102 }
1103
1104 public function register_fields( $form_type, $form_id = 1 ) {
1105
1106 global $wpdb;
1107
1108 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1109 $fields = $wpdb->get_results(
1110 $wpdb->prepare(
1111 'select field_type, site_title, htmlvar_name, field_icon from ' . $table_name . ' where form_type = %s and is_register_field = %s and form_id = %d order by sort_order asc',
1112 array(
1113 'account',
1114 '1',
1115 $form_id,
1116 )
1117 ),
1118 ARRAY_A
1119 );
1120
1121 return apply_filters( 'uwp_register_fields', $fields, $form_type );
1122 }
1123
1124 public function manage_selected_fields( $form_type ) {
1125 switch ( $form_type ) {
1126 case 'account':
1127 $this->custom_selected_fields( $form_type );
1128 break;
1129 case 'register':
1130 $this->register_selected_fields( $form_type );
1131 break;
1132 }
1133 }
1134
1135 public function custom_selected_fields( $form_type ) {
1136
1137 global $wpdb;
1138 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1139 $form_id = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
1140 ?>
1141 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1142 <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
1143 <ul class="core uwp-tabs-selected uwp_form_extras ps-0 list-group">
1144 <?php
1145 $fields = $wpdb->get_results(
1146 $wpdb->prepare(
1147 'SELECT * FROM ' . $table_name . ' WHERE form_type = %s AND form_id = %s ORDER BY sort_order ASC',
1148 array(
1149 $form_type,
1150 $form_id,
1151 )
1152 )
1153 );
1154
1155 if ( ! empty( $fields ) ) {
1156 foreach ( $fields as $field ) {
1157 $result_str = $field;
1158 $field_type = $field->field_type;
1159 $field_type_key = $field->field_type_key;
1160 $field_ins_upd = 'display';
1161
1162 $this->form_field_adminhtml( $field_type, $result_str, $field_ins_upd, $field_type_key );
1163 }
1164 }
1165 ?>
1166 </ul>
1167 <?php
1168 }
1169
1170 public function form_field_adminhtml( $field_type, $result_str, $field_ins_upd = '', $field_type_key = '', $form_type = false ) {
1171 global $wpdb;
1172 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1173 $cf = $result_str;
1174 $cf_arr = $this->get_form_existing_fields( $form_type );
1175
1176 if ( ! is_object( $cf ) ) {
1177
1178 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $table_name . ' where id= %d', array( $cf ) ) );
1179
1180 } else {
1181 $field_info = $cf;
1182 $result_str = $cf->id;
1183 }
1184
1185 if ( ! $field_info ) {
1186 $field_info = ( isset( $cf_arr[ $field_type_key ] ) ) ? $cf_arr[ $field_type_key ] : null;
1187 }
1188
1189 $this->admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type );
1190 }
1191
1192 /**
1193 * @param $field_info
1194 * @param $field_type
1195 * @param string $field_type_key
1196 * @param string $field_ins_upd
1197 * @param $result_str
1198 * @param bool $form_type
1199 */
1200 public function admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type = false ) {
1201
1202 if ( ! $form_type ) {
1203 if ( ! isset( $field_info->form_type ) ) {
1204 $form_type = sanitize_text_field( $_REQUEST['tab'] );
1205 } else {
1206 $form_type = $field_info->form_type;
1207 }
1208 }
1209
1210 $cf_arr1 = $this->form_fields( $form_type );
1211 $cf_arr2 = $this->form_fields_predefined( $form_type );
1212 $cf_arr3 = $this->form_fields_custom( $form_type );
1213
1214 $cf_arr = $cf_arr1 + $cf_arr2 + $cf_arr3; // this way defaults can't be overwritten
1215
1216 $cf = ( isset( $cf_arr[ $field_type_key ] ) ) ? $cf_arr[ $field_type_key ] : '';
1217
1218 $field_info = stripslashes_deep( $field_info ); // strip slashes from labels
1219
1220 $field_site_title = '';
1221 if ( isset( $field_info->site_title ) ) {
1222 $field_site_title = $field_info->site_title;
1223 }
1224
1225 $field_display = $field_type == 'address' && $field_info->htmlvar_name == 'post' ? 'style="display:none"' : '';
1226
1227 if ( isset( $cf['field_icon'] ) && strpos( $cf['field_icon'], ' fa-' ) !== false ) {
1228 $field_icon = '<i class="' . esc_attr( $cf['field_icon'] ) . '" aria-hidden="true"></i>';
1229 } elseif ( isset( $cf['field_icon'] ) && $cf['field_icon'] ) {
1230 $field_icon = '<b style="background-image: url("' . esc_url( $cf['field_icon'] ) . '")"></b>';
1231 } else {
1232 $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
1233 }
1234
1235 if ( isset( $cf['site_title'] ) && $cf['site_title'] ) {
1236 $field_type_name = $cf['site_title'];
1237 } else {
1238 $field_type_name = $field_type;
1239 }
1240
1241 $htmlvar_name = isset( $field_info->htmlvar_name ) ? sanitize_text_field( $field_info->htmlvar_name ) : '';
1242
1243 ?>
1244 <li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>">
1245 <div class="title title<?php echo esc_attr( $result_str ); ?> uwp-fieldset hover-shadow dd-form d-flex justify-content-between rounded c-pointer list-group-item border rounded-smx text-start bg-light " onclick="uwp_tabs_item_settings(this);">
1246 <?php
1247 $nonce = wp_create_nonce( 'custom_fields_' . $result_str );
1248 if ( $field_type == 'fieldset' ) {
1249 ?>
1250 <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
1251 <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
1252 <b><?php echo esc_html( uwp_ucwords( __( 'Fieldset:', 'userswp' ) ) ); ?></b>
1253 <span class="field-type"><?php echo ' (' . esc_html( uwp_ucwords( $field_site_title ) ) . ')'; ?></span>
1254 <?php
1255 } else {
1256
1257 ?>
1258 <div class=" flex-fill font-weight-bold fw-bold">
1259 <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1260 <b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_title ) ); ?></b>
1261 <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $field_type_name ) ) . ')'; ?></span>
1262 </div>
1263 <div class="dd-handle ui-sortable-handle">
1264 <?php
1265 $can_delete = apply_filters( 'uwp_cfa_can_delete_field', true, $field_info, $form_type );
1266 if ( $can_delete ){ ?>
1267 <i class="far fa-trash-alt text-danger ml-2 ms-2" id="delete-16"
1268 onclick="delete_field('<?php echo esc_attr( $result_str ); ?>', '<?php echo esc_attr( wp_create_nonce( 'custom_fields_delete_' . $result_str ) ); ?>', '<?php echo esc_attr($htmlvar_name); ?>');event.stopPropagation();return false;"></i>
1269 <?php } ?>
1270 <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
1271 </div>
1272
1273 <?php
1274 }
1275 ?>
1276
1277
1278 <?php // store the form as a template. This saves a load of memory on page load. ?>
1279 <script type="text/template" class="dd-setting <?php echo 'dd-type-'.esc_attr($field_type);?>">
1280 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
1281 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1282 <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
1283 <input type="hidden" name="field_type_key" id="field_type_key"
1284 value="<?php echo esc_attr( $field_type_key ); ?>"/>
1285 <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
1286 <input type="hidden" name="is_active" id="is_active" value="1"/>
1287
1288 <input type="hidden" name="is_default"
1289 value="<?php echo isset( $field_info->is_default ) ? esc_attr( $field_info->is_default ) : ''; ?>"/><?php // show in sidebar value ?>
1290
1291
1292 <?php
1293 // data_type
1294 if ( has_filter( "uwp_builder_data_type_{$field_type}" ) ) {
1295
1296 echo apply_filters( "uwp_builder_data_type_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1297
1298 } else {
1299 $value = '';
1300 if ( isset( $field_info->data_type ) ) {
1301 $value = esc_attr( $field_info->data_type );
1302 } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
1303 $value = $cf['defaults']['data_type'];
1304 }
1305 ?>
1306 <input type="hidden" name="data_type" id="data_type" value="<?php echo esc_attr($value); ?>"/>
1307 <?php
1308 }
1309
1310 // site_title
1311 if ( has_filter( "uwp_builder_site_title_{$field_type}" ) ) {
1312
1313 echo apply_filters( "uwp_builder_site_title_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1314
1315 } else {
1316 $value = '';
1317 if ( isset( $field_info->site_title ) ) {
1318 $value = esc_attr( $field_info->site_title );
1319 } elseif ( isset( $cf['defaults']['site_title'] ) && $cf['defaults']['site_title'] ) {
1320 $value = $cf['defaults']['site_title'];
1321 }
1322
1323 echo aui()->input(
1324 array(
1325 'id' => 'site_title',
1326 'name' => 'site_title',
1327 'label_type' => 'top',
1328 'label' => esc_html__( 'Label', 'userswp' ) . uwp_help_tip( __( 'This will be the label for the field.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1329 'type' => 'text',
1330 // 'wrap_class' => geodir_advanced_toggle_class(),
1331 'value' => $value,
1332 )
1333 );
1334 }
1335
1336 // Input Label
1337 if ( has_filter( "uwp_builder_form_label_{$field_type}" ) ) {
1338
1339 echo apply_filters( "uwp_builder_form_label_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1340
1341 } else {
1342 $value = '';
1343 if ( isset( $field_info->form_label ) ) {
1344 $value = esc_attr( $field_info->form_label );
1345 } elseif ( isset( $cf['defaults']['form_label'] ) && $cf['defaults']['form_label'] ) {
1346 $value = $cf['defaults']['form_label'];
1347 }
1348
1349 echo aui()->input(
1350 array(
1351 'id' => 'form_label',
1352 'name' => 'form_label',
1353 'label_type' => 'top',
1354 'label' => esc_html__( 'Form Label: (Optional)', 'userswp' ) . uwp_help_tip( __( 'If your form label is different, then you can fill this field. Ex: You would like to display "What is your age?" in Form Field but would like to display "DOB" in site. In such cases "What is your age?" should be entered here and "DOB" should be entered in previous field. Note: If this field not filled, then the previous field will be used in Form.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1355 'type' => 'text',
1356 'wrap_class' => uwp_advanced_toggle_class(),
1357 'value' => $value,
1358 )
1359 );
1360 }
1361
1362 // Input Description
1363 if ( has_filter( "uwp_builder_field_description_{$field_type}" ) ) {
1364
1365 echo apply_filters( "uwp_builder_field_description_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1366
1367 } else {
1368 $value = '';
1369 if ( isset( $field_info->help_text ) ) {
1370 $value = esc_attr( $field_info->help_text );
1371 } elseif ( isset( $cf['defaults']['help_text'] ) && $cf['defaults']['help_text'] ) {
1372 $value = $cf['defaults']['help_text'];
1373 }
1374 $tip_text = !empty($cf['help_text_tip']) ? esc_attr($cf['help_text_tip']) : __( 'This will be displayed below the field in the form.', 'userswp' );
1375 echo aui()->input(
1376 array(
1377 'id' => 'help_text',
1378 'name' => 'help_text',
1379 'label_type' => 'top',
1380 'label' => esc_html__( 'Field Description', 'userswp' ) . uwp_help_tip( $tip_text ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1381 'type' => 'text',
1382 //'wrap_class' => uwp_advanced_toggle_class(),
1383 'value' => $value,
1384 )
1385 );
1386
1387 }
1388
1389
1390 // htmlvar_name
1391 if ( has_filter( "uwp_builder_htmlvar_name_{$field_type}" ) ) {
1392
1393 echo apply_filters( "uwp_builder_htmlvar_name_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1394
1395 } else {
1396 $value = '';
1397 if ( isset( $field_info->htmlvar_name ) ) {
1398 $value = esc_attr( $field_info->htmlvar_name );
1399 } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
1400 $value = $cf['defaults']['htmlvar_name'];
1401 }
1402
1403 $extra_attributes = array();
1404 $class = '';
1405 if(isset($field_info->id) && substr( $field_info->id, 0, 4 ) === "new-" && empty($field_info->single_use)){} // New non single use predefined fields should have ability to change html_var
1406 elseif ( ! empty( $value ) && $value != 'uwp_' ) { $extra_attributes['readonly'] = 'readonly'; $class = 'bg-opacity-50 bg-gray'; }
1407
1408 $extra_attributes['maxlength'] = 50;
1409 $extra_attributes['pattern'] = "[a-zA-Z0-9]+";
1410
1411 echo aui()->input(
1412 array(
1413 'id' => 'htmlvar_name',
1414 'name' => 'htmlvar_name',
1415 'title' => __( 'Must not contain spaces or special characters', 'userswp' ),
1416 'label_type' => 'top',
1417 'label' => __('Key','userswp') . uwp_help_tip( __( 'This is a unique identifier used in the HTML, it MUST NOT contain spaces or special characters.', 'userswp' )),
1418 'type' => 'text',
1419 'wrap_class' => uwp_advanced_toggle_class(),
1420 'value' => $value ? preg_replace( '/uwp_/', '', $value, 1 ) : '',
1421 'extra_attributes' => $extra_attributes,
1422 'class' => $class,
1423 )
1424 );
1425
1426 }
1427
1428 // Placeholder text
1429 if ( has_filter( "uwp_builder_placeholder_value_{$field_type}" ) ) {
1430
1431 echo apply_filters( "uwp_builder_placeholder_value_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1432
1433 } else {
1434 $value = '';
1435 if ( isset( $field_info->placeholder_value ) ) {
1436 $value = esc_attr( $field_info->placeholder_value );
1437 } elseif ( isset( $cf['defaults']['placeholder_value'] ) && $cf['defaults']['placeholder_value'] ) {
1438 $value = $cf['defaults']['placeholder_value'];
1439 }
1440
1441 echo aui()->input(
1442 array(
1443 'id' => 'placeholder_value_'.esc_attr($result_str),
1444 'name' => 'placeholder_value',
1445 'title' => __( 'Enter placeholder text for this field.', 'userswp' ),
1446 'label_type' => 'top',
1447 'label' => esc_html__( 'Placeholder', 'userswp' ) . uwp_help_tip( __( 'Display placeholder text for this field.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1448 'type' => 'text',
1449 'wrap_class' => uwp_advanced_toggle_class(),
1450 'value' => $value,
1451 )
1452 );
1453
1454 }
1455
1456 // is_active
1457 if ( has_filter( "uwp_builder_is_active_{$field_type}" ) ) {
1458
1459 echo apply_filters( "uwp_builder_is_active_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1460
1461 } else {
1462 $value = '';
1463 if ( isset( $field_info->is_active ) ) {
1464 $value = esc_attr( $field_info->is_active );
1465 } elseif ( isset( $cf['defaults']['is_active'] ) && $cf['defaults']['is_active'] ) {
1466 $value = $cf['defaults']['is_active'];
1467 }
1468
1469 echo aui()->input(
1470 array(
1471 'id' => 'is_active',
1472 'name' => 'is_active',
1473 'type' => 'checkbox',
1474 'label_type' => 'horizontal',
1475 'label_col' => '4',
1476 'label' => __( 'Is active', 'userswp' ) ,
1477 'checked' => $value,
1478 'value' => '1',
1479 'switch' => 'md',
1480 'label_force_left' => true,
1481 'help_text' => uwp_help_tip( __( 'If no is selected then the field will not be displayed anywhere.', 'userswp' ) ),
1482 )
1483 );
1484
1485 }
1486
1487 // for_admin_use
1488 if ( has_filter( "uwp_builder_for_admin_use_{$field_type}" ) ) {
1489
1490 echo apply_filters( "uwp_builder_for_admin_use_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1491
1492 } else {
1493 $value = '';
1494 if ( isset( $field_info->for_admin_use ) ) {
1495 $value = esc_attr( $field_info->for_admin_use );
1496 } elseif ( isset( $cf['defaults']['for_admin_use'] ) && $cf['defaults']['for_admin_use'] ) {
1497 $value = $cf['defaults']['for_admin_use'];
1498 }
1499
1500
1501 echo aui()->input(
1502 array(
1503 'id' => 'for_admin_use',
1504 'name' => 'for_admin_use',
1505 'type' => 'checkbox',
1506 'label_type' => 'horizontal',
1507 'label_col' => '4',
1508 'label' => __( 'For admin use only?', 'userswp' ) ,
1509 'checked' => $value,
1510 'value' => '1',
1511 'switch' => 'md',
1512 'label_force_left' => true,
1513 'help_text' => uwp_help_tip( __( 'If yes is selected then only site admin can see and edit this field.', 'userswp' ) ),
1514 // 'wrap_class' => uwp_advanced_toggle_class(),
1515 )
1516 );
1517
1518 }
1519
1520 // is_public
1521 if ( has_filter( "uwp_builder_is_public_{$field_type}" ) ) {
1522
1523 echo apply_filters( "uwp_builder_is_public_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1524
1525 } else {
1526 $value = '';
1527 if ( isset( $field_info->is_public ) ) {
1528 $value = esc_attr( $field_info->is_public );
1529 } elseif ( isset( $cf['defaults']['is_public'] ) && $cf['defaults']['is_public'] ) {
1530 $value = $cf['defaults']['is_public'];
1531 }
1532
1533 echo aui()->select(
1534 array(
1535 'id' => 'is_public',
1536 'name' => 'is_public',
1537 'label_type' => 'top',
1538 'multiple' => false,
1539 'class' => ' mw-100',
1540 'options' => array(
1541 '1' => __( 'Yes', 'userswp' ),
1542 '0' => __( 'No', 'userswp' ),
1543 '2' => __( 'Let User Decide', 'userswp' ),
1544 ),
1545 'label' => __('Is Public','userswp') . uwp_help_tip(__( 'If no is selected then the field will not be visible to other users.', 'userswp' ) ) ,
1546 'value' => $value ,
1547 'wrap_class' => uwp_advanced_toggle_class(),
1548 )
1549 );
1550
1551 }
1552
1553 // default_value
1554 if ( has_filter( "uwp_builder_default_value_{$field_type}" ) ) {
1555
1556 echo apply_filters( "uwp_builder_default_value_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1557
1558 } else {
1559 $value = '';
1560 if ( isset( $field_info->default_value ) ) {
1561 $value = esc_attr( $field_info->default_value );
1562 } elseif ( isset( $cf['defaults']['default_value'] ) && $cf['defaults']['default_value'] ) {
1563 $value = $cf['defaults']['default_value'];
1564 }
1565
1566
1567 // tip text
1568 if ( $field_type == 'checkbox' ) {
1569 $tip = __( 'Should the checkbox be checked by default?', 'userswp' );
1570 } else if ( $field_type == 'email' ) {
1571 $tip = __( 'A default value for the field, usually blank. Ex: info@mysite.com', 'userswp' );
1572 } else {
1573 $tip = __( 'A default value for the field, usually blank. (for links this will be used as the link text)', 'userswp' );
1574 }
1575
1576 if ( $field_type == 'checkbox' ) {
1577 echo aui()->select(
1578 array(
1579 'id' => 'default_value',
1580 'name' => 'default_value',
1581 'label_type' => 'top',
1582 'multiple' => false,
1583 'class' => ' mw-100',
1584 'options' => array(
1585 '' => __( 'Unchecked', 'userswp' ),
1586 '1' => __( 'Checked', 'userswp' ),
1587 ),
1588 'label' => __('Default value','userswp') . uwp_help_tip( $tip ) ,
1589 'value' => $value ,
1590 'wrap_class' => uwp_advanced_toggle_class(),
1591 )
1592 );
1593 } else {
1594 echo aui()->input(
1595 array(
1596 'id' => 'default_value',
1597 'name' => 'default_value',
1598 'label_type' => 'top',
1599 'label' => __('Default value','userswp') . uwp_help_tip( $tip ) ,
1600 'type' => 'text',
1601 'wrap_class' => uwp_advanced_toggle_class(),
1602 'value' => $value,
1603 'placeholder' => $field_type == 'email' ? __( 'info@mysite.com', 'userswp' ) : ''
1604 )
1605 );
1606 }
1607
1608 }
1609
1610 // advanced_editor
1611 if ( has_filter( "uwp_builder_advanced_editor_{$field_type}" ) ) {
1612
1613 echo apply_filters( "uwp_builder_advanced_editor_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1614
1615 }
1616 ?>
1617 <input type="hidden" readonly="readonly" name="sort_order" id="sort_order"
1618 value="<?php if ( isset( $field_info->sort_order ) ) {
1619 echo esc_attr( $field_info->sort_order );
1620 } ?>"/>
1621 <?php
1622
1623 // is_required
1624 if ( has_filter( "uwp_builder_is_required_{$field_type}" ) ) {
1625
1626 echo apply_filters( "uwp_builder_is_required_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1627
1628 } else {
1629 $value = '';
1630 if ( isset( $field_info->is_required ) ) {
1631 $value = esc_attr( $field_info->is_required );
1632 } elseif ( isset( $cf['defaults']['is_required'] ) && $cf['defaults']['is_required'] ) {
1633 $value = $cf['defaults']['is_required'];
1634 }
1635
1636 echo aui()->input(
1637 array(
1638 'id' => 'is_required',
1639 'name' => 'is_required',
1640 'type' => 'checkbox',
1641 'label_type' => 'horizontal',
1642 'label_col' => '4',
1643 'label' => __( 'Is required', 'userswp' ) ,
1644 'checked' => $value,
1645 'value' => '1',
1646 'switch' => 'md',
1647 'label_force_left' => true,
1648 'help_text' => uwp_help_tip( __( 'Select yes to set field as required', 'userswp' ) ),
1649 // 'wrap_class' => uwp_advanced_toggle_class(),
1650 )
1651 );
1652
1653 }
1654
1655 // required_msg
1656 if ( has_filter( "uwp_builder_required_msg_{$field_type}" ) ) {
1657
1658 echo apply_filters( "uwp_builder_required_msg_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1659
1660 } else {
1661 $value = '';
1662 if ( isset( $field_info->required_msg ) ) {
1663 $value = esc_attr( $field_info->required_msg );
1664 } elseif ( isset( $cf['defaults']['required_msg'] ) && $cf['defaults']['required_msg'] ) {
1665 $value = $cf['defaults']['required_msg'];
1666 }
1667
1668 echo aui()->input(
1669 array(
1670 'id' => 'required_msg',
1671 'name' => 'required_msg',
1672 'label_type' => 'top',
1673 'label' => __('Required message','userswp') . uwp_help_tip( __( 'Enter text for the error message if the field is required and has not fulfilled the requirements.', 'userswp' ) ) ,
1674 'type' => 'text',
1675 'wrap_class' => uwp_advanced_toggle_class(),
1676 'value' => $value,
1677 'element_require' => '[%is_required%:checked]'
1678 )
1679 );
1680
1681 }
1682
1683 // validation pattern
1684 if ( has_filter( "uwp_builder_validation_pattern_{$field_type}" ) ) {
1685
1686 echo apply_filters( "uwp_builder_validation_pattern_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1687
1688 }
1689
1690 // extra_fields
1691 if ( has_filter( "uwp_builder_extra_fields_{$field_type}" ) ) {
1692
1693 echo apply_filters( "uwp_builder_extra_fields_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1694
1695 }
1696
1697 // field_icon
1698 if ( has_filter( "uwp_builder_field_icon_{$field_type}" ) ) {
1699
1700 echo apply_filters( "uwp_builder_field_icon_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1701
1702 } else {
1703 $value = '';
1704 if ( isset( $field_info->field_icon ) ) {
1705 $value = esc_attr( $field_info->field_icon );
1706 } elseif ( isset( $cf['defaults']['field_icon'] ) && $cf['defaults']['field_icon'] ) {
1707 $value = $cf['defaults']['field_icon'];
1708 }
1709
1710 echo aui()->input(
1711 array(
1712 'id' => 'field_icon',
1713 'name' => 'field_icon',
1714 'label_type' => 'top',
1715 'label' => __('Icon','userswp') . uwp_help_tip( sprintf( __( 'Upload icon using media and enter its url path, or enter %sfont awesome%s class eg:"fas fa-home"', 'userswp' ), '<a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank" >', '</a>' ) ),
1716 'type' => 'iconpicker',
1717 'wrap_class' => uwp_advanced_toggle_class(),
1718 'value' => $value,
1719 'extra_attributes' => defined('FAS_PRO') && FAS_PRO ? array(
1720 'data-fa-icons' => true,
1721 'data-bs-toggle' => "tooltip",
1722 'data-bs-trigger' => "focus",
1723 'title' => __('For pro icon variants (light, thin, duotone), paste the class here','userswp'),
1724 ) : array(),
1725 )
1726 );
1727
1728 }
1729
1730 // css_class
1731 if ( has_filter( "uwp_builder_css_class_{$field_type}" ) ) {
1732
1733 echo apply_filters( "uwp_builder_css_class_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1734
1735 } else {
1736
1737 $value = '';
1738 if ( isset( $field_info->css_class ) ) {
1739 $value = esc_attr( $field_info->css_class );
1740 } elseif ( isset( $cf['defaults']['css_class'] ) && $cf['defaults']['css_class'] ) {
1741 $value = $cf['defaults']['css_class'];
1742 }
1743 $tip = __( 'Enter custom css class for field custom style.', 'userswp' );
1744 if ( $field_type == 'multiselect' ) {
1745 $tip .= __( '(Enter class `uwp-comma-list` to show list as comma separated)', 'userswp' );
1746 }
1747
1748 echo aui()->input(
1749 array(
1750 'id' => 'css_class',
1751 'name' => 'css_class',
1752 'label_type' => 'top',
1753 'label' => __('CSS class','userswp') . uwp_help_tip( $tip ) ,
1754 'type' => 'text',
1755 'wrap_class' => uwp_advanced_toggle_class(),
1756 'value' => $value,
1757 )
1758 );
1759
1760 }
1761
1762 // show_in
1763 if ( has_filter( "uwp_builder_show_in_{$field_type}" ) ) {
1764
1765 echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1766
1767 } else {
1768 $value = '';
1769 if ( isset( $field_info->show_in ) ) {
1770 $value = esc_attr( $field_info->show_in );
1771 } elseif ( isset( $cf['defaults']['show_in'] ) && $cf['defaults']['show_in'] ) {
1772 $value = esc_attr( $cf['defaults']['show_in'] );
1773 }
1774
1775
1776 $show_in_locations = uwp_get_show_in_locations();
1777
1778 if ( $field_type == 'fieldset' ) {
1779 unset( $show_in_locations['[fieldset]'] );
1780 }
1781
1782 if ( ! in_array( $field_type, array(
1783 'text',
1784 'datepicker',
1785 'textarea',
1786 'time',
1787 'phone',
1788 'email',
1789 'select',
1790 'multiselect',
1791 'url',
1792 'html',
1793 'fieldset',
1794 'radio',
1795 'checkbox',
1796 'file'
1797 ) ) ) {
1798 unset( $show_in_locations['[own_tab]'] );
1799 }
1800
1801
1802 $show_in_values = $value ? explode( ',', $value ) : '';
1803
1804 echo aui()->select(
1805 array(
1806 'id' => 'show_in',
1807 'name' => 'show_in[]',
1808 'label_type' => 'top',
1809 'multiple' => true,
1810 'select2' => true,
1811 'class' => ' mw-100',
1812 'options' => $show_in_locations,
1813 'label' => __('Show in what locations?','userswp') . uwp_help_tip( __( 'Select in what locations you want to display this field.', 'userswp' )),
1814 'value' => $show_in_values,
1815 'placeholder' => __( 'Select locations', 'userswp' ),
1816 )
1817 );
1818
1819 }
1820
1821 do_action( 'uwp_admin_extra_custom_fields', $field_info, $cf ); ?>
1822
1823
1824 <div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button">
1825
1826 <span class="text-left text-start float-left float-start">
1827 <?php UsersWP_Settings_Page::toggle_advanced_button('btn btn-outline-primary text-left text-start uwp-advanced-toggle', false); ?>
1828 </span>
1829
1830 <a class=" btn btn-link text-muted" href="javascript:void(0);" onclick="uwp_tabs_close_settings(this); return false;"><?php _e("Close","userswp");?></a>
1831 <a href='javascript:void(0);' type="button" class="btn btn-primary" id="save"
1832 onclick="save_field('<?php echo esc_attr( $result_str ); ?>');return false;"><?php echo esc_attr( __( 'Save', 'userswp' ) ); ?></a>
1833 </div>
1834
1835 </script>
1836
1837
1838 </div>
1839
1840 </li>
1841 <?php
1842 }
1843
1844 /**
1845 * Add HTML5 validation pattern fields.
1846 *
1847 * @since 1.2.2.17
1848 *
1849 * @param string $output Html output.
1850 * @param string $result_str Result string.
1851 * @param array $cf Custom fields values.
1852 * @param object $field_info Extra fields information.
1853 * @return string $output.
1854 */
1855 public static function validation_pattern( $output, $result_str, $cf, $field_info ) {
1856 ob_start();
1857
1858 $value = '';
1859 if ( isset( $field_info->validation_pattern ) ) {
1860 $value = esc_attr( $field_info->validation_pattern );
1861 } elseif ( isset( $cf['defaults']['validation_pattern'] ) && $cf['defaults']['validation_pattern'] ) {
1862 $value = $cf['defaults']['validation_pattern'];
1863 }
1864
1865 echo aui()->input(
1866 array(
1867 'id' => 'validation_pattern',
1868 'name' => 'validation_pattern',
1869 'label_type' => 'top',
1870 'label' => __('Validation Pattern','userswp') . uwp_help_tip( __( 'Enter regex expression for HTML5 pattern validation.', 'userswp' )),
1871 'type' => 'text',
1872 'wrap_class' => uwp_advanced_toggle_class(),
1873 'value' => addslashes_gpc( $value ), // Keep slashes
1874 )
1875 );
1876
1877
1878 $value = '';
1879 if ( isset( $field_info->validation_msg ) ) {
1880 $value = esc_attr( $field_info->validation_msg );
1881 } elseif ( isset( $cf['defaults']['validation_msg'] ) && $cf['defaults']['validation_msg'] ) {
1882 $value = $cf['defaults']['validation_msg'];
1883 }
1884
1885 echo aui()->input(
1886 array(
1887 'id' => 'validation_msg',
1888 'name' => 'validation_msg',
1889 'label_type' => 'top',
1890 'label' => __('Validation Message','userswp') . uwp_help_tip( __( 'Enter a extra validation message to show to the user if validation fails.', 'userswp' )),
1891 'type' => 'text',
1892 'wrap_class' => uwp_advanced_toggle_class(),
1893 'value' => $value,
1894 )
1895 );
1896
1897
1898 $output = ob_get_clean();
1899
1900 return $output;
1901 }
1902
1903 public function register_selected_fields( $form_type ) {
1904 global $wpdb;
1905 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1906 $form_id = ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : 1;
1907 ?>
1908 <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
1909 <ul class="core uwp_form_extras uwp-tabs-selected ps-0 list-group "><?php
1910
1911 $fields = $wpdb->get_results(
1912 $wpdb->prepare(
1913 'select * from ' . $extras_table_name . ' where form_type = %s AND form_id = %d order by sort_order asc',
1914 array( $form_type, $form_id )
1915 )
1916 );
1917
1918 if ( ! empty( $fields ) ) {
1919 foreach ( $fields as $field ) {
1920 $result_str = $field;
1921 $field_ins_upd = 'display';
1922 $this->register_field_adminhtml( $result_str, $field_ins_upd, false );
1923 }
1924 }
1925 ?>
1926 </ul>
1927 <?php
1928 }
1929
1930 public function register_field_adminhtml( $result_str, $field_ins_upd = '', $default = false, $request = array() ) {
1931 global $wpdb;
1932
1933 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1934 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1935
1936 $cf = $result_str;
1937 if ( ! is_object( $cf ) && ( is_int( $cf ) || ctype_digit( $cf ) ) ) {
1938 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( $cf ) ) );
1939 } elseif ( is_object( $cf ) ) {
1940 $result_str = $cf->id;
1941 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( (int) $cf->id ) ) );
1942 } else {
1943 $field_info = false;
1944 }
1945
1946 if ( isset( $request['field_type'] ) && $request['field_type'] != '' ) {
1947 $field_type = esc_attr( $request['field_type'] );
1948 } else {
1949 $field_type = $field_info->field_type;
1950 }
1951
1952 $field_site_name = '';
1953 if ( isset( $request['site_title'] ) ) {
1954 $field_site_name = $request['site_title'];
1955 }
1956
1957 if ( $field_info ) {
1958 $account_field_info = uwp_get_custom_field_info( $field_info->site_htmlvar_name );
1959 if ( isset( $account_field_info->site_title ) ) {
1960 if ( $account_field_info->field_type == 'fieldset' ) {
1961 $field_site_name = __( 'Fieldset:', 'userswp' ) . ' ' . $account_field_info->site_title;
1962 } else {
1963 $field_site_name = $account_field_info->site_title;
1964 }
1965 }
1966 $field_info = stripslashes_deep( $field_info ); // strip slashes
1967 }
1968 $field_site_name = sanitize_title( $field_site_name );
1969
1970 if ( isset( $request['form_type'] ) ) {
1971 $form_type = esc_attr( $request['form_type'] );
1972 } else {
1973 $form_type = $field_info->form_type;
1974 }
1975
1976 if ( isset( $request['htmlvar_name'] ) && $request['htmlvar_name'] != '' ) {
1977 $htmlvar_name = esc_attr( $request['htmlvar_name'] );
1978 } else {
1979 $htmlvar_name = $field_info->site_htmlvar_name;
1980 }
1981
1982 if ( isset( $htmlvar_name ) ) {
1983 if ( ! is_object( $field_info ) ) {
1984 $field_info = new stdClass();
1985 }
1986 $field_info->field_icon = $wpdb->get_var(
1987 $wpdb->prepare( 'SELECT field_icon FROM ' . $table_name . ' WHERE htmlvar_name = %s', array( $htmlvar_name ) )
1988 );
1989 }
1990
1991 $icon = isset( $field_info->field_icon ) ? $field_info->field_icon : '';
1992 if ( uwp_is_fa_icon( $icon ) ) {
1993 $field_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>';
1994 } elseif ( uwp_is_icon_url( $icon ) ) {
1995 $field_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>';
1996 } elseif ( isset( $field_info->field_type ) && $field_info->field_type == 'fieldset' ) {
1997 $field_icon = '<i class="fas fa-arrows-alt-h" aria-hidden="true"></i>';
1998 } else {
1999 $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
2000 }
2001 ?>
2002 <li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>">
2003 <form>
2004 <div class="title title<?php echo esc_attr( $result_str ); ?> uwp-fieldset hover-shadow dd-form d-flex justify-content-between rounded list-group-item border rounded-smx text-start bg-light">
2005 <?php
2006 $nonce = wp_create_nonce( 'uwp_form_extras_nonce' . $result_str );
2007 ?>
2008 <div class=" flex-fill font-weight-bold fw-bold">
2009 <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
2010 <b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_name ) ); ?></b>
2011 </div>
2012 <div class="dd-handle ui-sortable-handle">
2013 <?php
2014 $no_actions = array( 'username', 'email' );
2015 $no_actions = apply_filters( 'uwp_register_fields_without_actions', $no_actions );
2016 if ( isset($htmlvar_name) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
2017 <i class="far fa-trash-alt text-danger ml-2 ms-2 c-pointer" id="delete-16"
2018 onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
2019 ></i>
2020 <?php } ?>
2021 <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
2022 </div>
2023
2024
2025
2026 </div>
2027
2028 <div id="field_frm<?php echo esc_attr( $result_str ); ?>" class="field_frm"
2029 style="display:none;">
2030 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
2031 <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
2032 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
2033 <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
2034 <input type="hidden" name="is_active" id="is_active" value="1"/>
2035 <ul class="widefat post fixed" style="width:100%;">
2036
2037 <input type="hidden" name="site_htmlvar_name" value="<?php echo esc_attr( $htmlvar_name ); ?>"/>
2038
2039 <li>
2040 <div class="uwp-input-wrap">
2041 <p><?php esc_html_e( 'No options available', 'userswp' ); ?></p>
2042 </div>
2043 </li>
2044
2045 <li>
2046 <div class="uwp-input-wrap">
2047 <?php
2048 $no_actions = array( 'username', 'email' );
2049 $no_actions = apply_filters( 'uwp_register_fields_without_actions', $no_actions );
2050 if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) {
2051 ?>
2052 <input type="button" class="button button-primary" name="save" id="save"
2053 value="<?php esc_attr_e( 'Save', 'userswp' ); ?>"
2054 onclick="save_field('<?php echo esc_js( $result_str ); ?>', 'register')"
2055 style="display: none;"/>
2056 <input type="button" name="delete"
2057 value="<?php esc_attr_e( 'Delete', 'userswp' ); ?>"
2058 onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
2059 class="button"/>
2060 <?php } ?>
2061
2062 </div>
2063 </li>
2064 </ul>
2065
2066 </div>
2067
2068
2069 </form>
2070
2071 </li>
2072 <?php
2073 }
2074
2075 public function builder_extra_fields_smr( $output, $result_str, $cf, $field_info ) {
2076
2077 ob_start();
2078
2079 $value = '';
2080 if ( isset( $field_info->option_values ) ) {
2081 $value = esc_attr( $field_info->option_values );
2082 } elseif ( isset( $cf['defaults']['option_values'] ) && $cf['defaults']['option_values'] ) {
2083 $value = esc_attr( $cf['defaults']['option_values'] );
2084 }
2085
2086 $field_type = isset( $field_info->field_type ) ? $field_info->field_type : $cf['field_type'];
2087 $field_type_key = isset( $field_info->field_type_key ) ? $field_info->field_type_key : '';
2088 if ( ! $field_type_key ) {
2089 $field_type_key = isset( $_REQUEST['field_type_key'] ) ? esc_html( $_REQUEST['field_type_key'] ) : '';
2090 }
2091 ?>
2092 <li class="uwp-setting-name">
2093 <label for="option_values" class="uwp-tooltip-wrap">
2094 <?php
2095 $tip = __( 'Option Values should be separated by comma.', 'userswp' );
2096 if ( $field_type != 'multiselect' ) {
2097 $tip .= '<br/><small>' . __( 'If using for a tick filter place a / and then either a 1 for true or 0 for false', 'userswp' );
2098 $tip .= '<br/>' . __( 'eg: No Dogs Allowed/0,Dogs Allowed/1', 'userswp' ) . '</small>';
2099 }
2100 if ( $field_type == 'multiselect' || $field_type == 'select' ) {
2101 $tip .= '<br/><small>' . __( 'Like: Apple,Bannana,Pear,Peach', 'userswp' );
2102 $tip .= '<br/>' . __( 'Or you can show Selection/Value shown: Pets Allowed/Yes,Pets not Allowed/No', 'userswp' );
2103 $tip .= '<br/>' . __( '- If using OPTGROUP tag to grouping options, use {optgroup}OPTGROUP-LABEL|OPTION-1,OPTION-2{/optgroup}', 'userswp' );
2104 $tip .= '<br/>' . __( 'eg: {optgroup}Pets Allowed|No Dogs Allowed/0,Dogs Allowed/1{/optgroup},{optgroup}Sports|Cricket/Cricket,Football/Football,Hockey{/optgroup}', 'userswp' ) . '</small>';
2105 }
2106 ?>
2107 <?php
2108 echo uwp_help_tip( $tip ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2109 esc_html_e( 'Option Values :', 'userswp' );
2110 ?>
2111 </label>
2112 <div class="uwp-input-wrap">
2113
2114 <?php
2115 if ( isset( $field_type_key ) && $field_type_key == 'uwp_country' ) {
2116
2117 // @todo here we should show a multiselect to either include or exclude countries
2118 esc_html_e( 'A full country list will be shown', 'userswp' );
2119 } elseif ( isset( $field_type_key ) && $field_type_key == 'uwp_language' ) {
2120 esc_html_e( 'Available translation languages list will be shown', 'userswp' );
2121 } else {
2122 ?>
2123 <input type="text" name="option_values" id="option_values" value="<?php echo esc_attr( $value ); ?>"/>
2124 <?php } ?>
2125
2126 <br/>
2127
2128 </div>
2129 </li>
2130 <?php
2131
2132 $html = ob_get_clean();
2133
2134 return $output . $html;
2135 }
2136
2137 public function builder_extra_fields_datepicker( $output, $result_str, $cf, $field_info ) {
2138 ob_start();
2139 $extra = array();
2140 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2141 $extra = unserialize( $field_info->extra_fields );
2142 }
2143 ?>
2144 <li class="uwp-setting-name uwp-advanced-setting">
2145 <label for="date_format" class="uwp-tooltip-wrap">
2146 <?php
2147 echo uwp_help_tip( __( 'Select the date format.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2148 esc_html_e( 'Date Format :', 'userswp' );
2149 ?>
2150 </label>
2151 <div class="uwp-input-wrap" style="overflow:inherit;">
2152 <?php
2153 $date_formats = array(
2154 'm/d/Y',
2155 'd/m/Y',
2156 'Y/m/d',
2157 'm-d-Y',
2158 'd-m-Y',
2159 'Y-m-d',
2160 'F j, Y',
2161 );
2162
2163 $date_formats = apply_filters( 'uwp_date_formats', $date_formats );
2164 ?>
2165 <select name="extra[date_format]" id="date_format" class="aui-select2">
2166 <?php
2167 foreach ( $date_formats as $format ) {
2168 $selected = false;
2169 if ( ! empty( $extra ) && esc_attr( $extra['date_format'] ) == $format ) {
2170 $selected = true;
2171 }
2172 echo '<option ' . selected( $selected, true, false ) . " value='" . esc_attr( $format ) . "'>" . esc_html( $format . ' (' . date_i18n( $format, time() ) . ')' ) . '</option>';
2173 }
2174 ?>
2175 </select>
2176
2177 </div>
2178 </li>
2179 <?php
2180
2181 $html = ob_get_clean();
2182
2183 return $output . $html;
2184 }
2185
2186 public function builder_extra_fields_password( $output, $result_str, $cf, $field_info ) {
2187 ob_start();
2188
2189 //confirm password field
2190 $extra = array();
2191 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2192 $extra = unserialize( $field_info->extra_fields );
2193 }
2194 $value = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '1';
2195 if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'password' ) {
2196
2197 echo '<div class="'.uwp_advanced_toggle_class().'">';
2198 echo aui()->input(
2199 array(
2200 'id' => 'extra_confirm_password',
2201 'name' => 'extra[confirm_password]',
2202 'type' => 'checkbox',
2203 'label_type' => 'horizontal',
2204 'label_col' => '4',
2205 'label' => __('Display confirm password field', 'userswp'),
2206 'checked' => $value,
2207 'value' => '1',
2208 'switch' => 'md',
2209 'label_force_left' => true,
2210 'help_text' => uwp_help_tip(__('Lets you display confirm password form field.', 'userswp')),
2211 )
2212 );
2213 echo '</div>';
2214
2215 }
2216 $html = ob_get_clean();
2217
2218 return $output . $html;
2219 }
2220
2221 public function builder_extra_fields_email( $output, $result_str, $cf, $field_info ) {
2222 ob_start();
2223 //confirm email field
2224 $extra = array();
2225 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2226 $extra = unserialize( $field_info->extra_fields );
2227 }
2228 $value = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0';
2229
2230 if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'email' ) {
2231
2232 echo '<div class="'.uwp_advanced_toggle_class().'">';
2233 echo aui()->input(
2234 array(
2235 'id' => 'extra_confirm_email',
2236 'name' => 'extra[confirm_email]',
2237 'type' => 'checkbox',
2238 'label_type' => 'horizontal',
2239 'label_col' => '4',
2240 'label' => __('Display confirm email field', 'userswp'),
2241 'checked' => $value,
2242 'value' => '1',
2243 'switch' => 'md',
2244 'label_force_left' => true,
2245 'help_text' => uwp_help_tip(__('Lets you display confirm email form field.', 'userswp')),
2246 )
2247 );
2248 echo '</div>';
2249
2250 }
2251 $html = ob_get_clean();
2252
2253 return $output . $html;
2254 }
2255
2256 public function builder_extra_fields_file( $output, $result_str, $cf, $field_info ) {
2257 ob_start();
2258
2259 $file_obj = new UsersWP_Files();
2260 $allowed_file_types = $file_obj->allowed_mime_types();
2261
2262 $extra_fields = isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ? maybe_unserialize( $field_info->extra_fields ) : '';
2263 $uwp_file_types = ! empty( $extra_fields ) && ! empty( $extra_fields['uwp_file_types'] ) ? $extra_fields['uwp_file_types'] : array( '*' );
2264 ?>
2265 <li class="uwp-setting-name uwp-advanced-setting">
2266 <label for="uwp_file_types" class="uwp-tooltip-wrap">
2267 <?php
2268 echo uwp_help_tip( __( 'Select file types to allowed for file uploading. (Select multiple file types by holding down "Ctrl" key.)', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2269 esc_html_e( 'Allowed file types :', 'userswp' );
2270 ?>
2271 </label>
2272 <div class="uwp-input-wrap">
2273 <select name="extra[uwp_file_types][]" id="uwp_file_types" multiple="multiple" class="aui-select2"
2274 style="height:100px;width:90%;">
2275 <option value="*" <?php selected( true, in_array( '*', $uwp_file_types ) ); ?>><?php esc_html_e( 'All types', 'userswp' ); ?></option>
2276 <?php foreach ( $allowed_file_types as $format => $types ) { ?>
2277 <optgroup
2278 label="<?php echo esc_attr( wp_sprintf( __( '%s formats', 'userswp' ), __( $format, 'userswp' ) ) ); ?>">
2279 <?php foreach ( $types as $ext => $type ) { ?>
2280 <option value="<?php echo esc_attr( $ext ); ?>" <?php selected( true, in_array( $ext, $uwp_file_types ) ); ?>><?php echo '.' . esc_html( $ext ); ?></option>
2281 <?php } ?>
2282 </optgroup>
2283 <?php } ?>
2284 </select>
2285 </div>
2286 </li>
2287 <?php
2288
2289 $html = ob_get_clean();
2290
2291 return $output . $html;
2292 }
2293
2294 public function builder_data_type_text( $output, $result_str, $cf, $field_info ) {
2295 ob_start();
2296
2297 $dt_value = '';
2298 if ( isset( $field_info->data_type ) ) {
2299 $dt_value = esc_attr( $field_info->data_type );
2300 } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
2301 $dt_value = $cf['defaults']['data_type'];
2302 }
2303
2304 // fix some values
2305 if ( $dt_value == 'VARCHAR' ) {
2306 $dt_value = 'XVARCHAR';
2307 }
2308
2309 echo aui()->select(
2310 array(
2311 'id' => "data_type",
2312 'name' => "data_type",
2313 'label_type' => 'top',
2314 'multiple' => false,
2315 'wrap_class' => uwp_advanced_toggle_class(),
2316 'class' => 'mw-100',
2317 'options' => array(
2318 'XVARCHAR' => __( 'CHARACTER', 'userswp' ),
2319 'INT' => __( 'NUMBER', 'userswp' ),
2320 'FLOAT' => __( 'DECIMAL', 'userswp' ),
2321 ),
2322 'label' => __('Data Type','userswp').uwp_help_tip( __( 'Select Custom Field type', 'userswp' )),
2323 'value' => $dt_value,
2324 'extra_attributes' => array(
2325 'onchange' => "javascript:uwp_data_type_changed(this, '$result_str');"
2326 )
2327 )
2328 );
2329
2330
2331 $value = '';
2332 if ( isset( $field_info->decimal_point ) ) {
2333 $value = esc_attr( $field_info->decimal_point );
2334 } elseif ( isset( $cf['defaults']['decimal_point'] ) && $cf['defaults']['decimal_point'] ) {
2335 $value = $cf['defaults']['decimal_point'];
2336 }
2337
2338 echo aui()->select(
2339 array(
2340 'id' => 'decimal_point',
2341 'name' => 'decimal_point',
2342 'label_type' => 'top',
2343 'multiple' => false,
2344 'class' => ' mw-100',
2345 'options' => array(
2346 '' => __( 'Select', 'userswp' ),
2347 '1' => '1',
2348 '2' => '2',
2349 '3' => '3',
2350 '4' => '4',
2351 '5' => '5',
2352 '6' => '6',
2353 '7' => '7',
2354 '8' => '8',
2355 '9' => '9',
2356 '10' => '10',
2357 ),
2358 'label' => __('Decimal points','userswp') . uwp_help_tip( __( 'Decimals to display after point.', 'userswp' )),
2359 'value' => $value,
2360 'element_require' => '[%data_type%] == "FLOAT"'
2361 )
2362 );
2363
2364
2365 $output = ob_get_clean();
2366
2367 return $output;
2368 }
2369
2370 public function advance_admin_custom_fields( $field_info, $cf ) {
2371 $hide_register_field = ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] === false ) ? "style='display:none;'" : '';
2372 $hide_register_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_field;
2373 $hide_user_sort = ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] === false ) ? "style='display:none;'" : '';
2374
2375 $value = 0;
2376 if ( isset( $field_info->is_register_field ) ) {
2377 $value = (int) $field_info->is_register_field;
2378 } elseif ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] ) {
2379 $value = ( $cf['defaults']['is_register_field'] ) ? 1 : 0;
2380 }
2381
2382 if ( isset( $field_info->htmlvar_name ) ) {
2383 $htmlvar_name = $field_info->htmlvar_name;
2384 } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
2385 $htmlvar_name = ( $cf['defaults']['htmlvar_name'] ) ? $cf['defaults']['htmlvar_name'] : '';
2386 }
2387
2388 //register only field
2389 $hide_register_only_field = ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] === false ) ? "style='display:none;'" : '';
2390 $hide_register_only_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_only_field;
2391 $register_only_value = 0;
2392 if ( isset( $field_info->is_register_only_field ) ) {
2393 $register_only_value = (int) $field_info->is_register_only_field;
2394 } elseif ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] ) {
2395 $register_only_value = ( $cf['defaults']['is_register_only_field'] ) ? 1 : 0;
2396 }
2397
2398 $user_sort_value = 0;
2399 if ( isset( $field_info->user_sort ) ) {
2400 $user_sort_value = (int) $field_info->user_sort;
2401 } elseif ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] ) {
2402 $user_sort_value = ( $cf['defaults']['user_sort'] ) ? 1 : 0;
2403 }
2404
2405 ?>
2406 <div <?php echo $hide_register_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name">
2407
2408 <?php
2409 $reg_only_fields = uwp_get_register_only_fields();
2410 if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2411 ?>
2412 <label for="is_register_field" class="uwp-tooltip-wrap">
2413 <?php
2414 echo uwp_help_tip( __( 'Lets you use this field as register form field, set from register tab above.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2415 esc_html_e( 'Include this field in register form:', 'userswp' ); ?>
2416 </label>
2417 <input type="hidden" name="is_register_field" value="1"/>
2418 <p><?php esc_html_e( 'This is mandatory register form field.', 'userswp' ); ?></p>
2419 <?php
2420 } else {
2421 echo aui()->input(
2422 array(
2423 'id' => 'is_register_field',
2424 'name' => 'is_register_field',
2425 'type' => 'checkbox',
2426 'label_type' => 'horizontal',
2427 'label_col' => '4',
2428 'label' => __( 'Include this field in register form', 'userswp' ) ,
2429 'checked' => $value,
2430 'value' => '1',
2431 'switch' => 'md',
2432 'label_force_left' => true,
2433 'help_text' => uwp_help_tip( __( 'Lets you use this field as register form field, set from register tab above.', 'userswp' ) ),
2434 )
2435 );
2436 } ?>
2437 </div>
2438
2439 <div <?php echo $hide_register_only_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-inconlyin-reg-form uwp-setting-name uwp-advanced-setting">
2440
2441
2442 <?php
2443 if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2444 ?>
2445 <label for="is_register_only_field" class="uwp-tooltip-wrap">
2446 <?php
2447 echo uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2448 esc_html_e( 'Include this field ONLY in register form:', 'userswp' ); ?>
2449 </label>
2450 <input type="hidden" name="is_register_only_field" value="1"/>
2451 <p><?php esc_html_e( 'This field is applicable only for register form.', 'userswp' ); ?></p>
2452 <?php
2453 } else {
2454 echo aui()->input(
2455 array(
2456 'id' => 'is_register_only_field',
2457 'name' => 'is_register_only_field',
2458 'type' => 'checkbox',
2459 'label_type' => 'horizontal',
2460 'label_col' => '4',
2461 'label' => __('Include this field ONLY in register form', 'userswp'),
2462 'checked' => $register_only_value,
2463 'value' => '1',
2464 'switch' => 'md',
2465 'label_force_left' => true,
2466 'help_text' => uwp_help_tip(__('Lets you use this field as register ONLY form field.', 'userswp')),
2467
2468 )
2469 );
2470
2471 }?>
2472 </div>
2473
2474 <div <?php echo $hide_user_sort; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name uwp-advanced-setting">
2475 <?php
2476
2477 echo aui()->input(
2478 array(
2479 'id' => 'user_sort',
2480 'name' => 'user_sort',
2481 'type' => 'checkbox',
2482 'label_type' => 'horizontal',
2483 'label_col' => '4',
2484 'label' => __('Include this field in sorting options', 'userswp'),
2485 'checked' => $user_sort_value,
2486 'value' => '1',
2487 'switch' => 'md',
2488 'label_force_left' => true,
2489 'help_text' => uwp_help_tip(__('Lets you use this field as sorting in the users listing page, set from user sorting tab above.', 'userswp')),
2490
2491 )
2492 );
2493
2494 ?>
2495
2496 </div>
2497
2498 <?php
2499 }
2500
2501 public function return_empty_string() {
2502 return '';
2503 }
2504
2505 public function register_available_fields_head( $heading, $form_type ) {
2506 switch ( $form_type ) {
2507 case 'register':
2508 $heading = __( 'Available register form fields.', 'userswp' );
2509 break;
2510 }
2511
2512 return $heading;
2513 }
2514
2515 public function register_available_fields_note( $note, $form_type ) {
2516 switch ( $form_type ) {
2517 case 'register':
2518 $note = __( "Click on any box below to make it appear in register form. To make a field available here, go to account tab and expand any field from selected fields panel and tick the checkbox saying 'Include this field in register form'.", 'userswp' );
2519 break;
2520 }
2521
2522 return $note;
2523 }
2524
2525 public function register_selected_fields_head( $heading, $form_type ) {
2526 switch ( $form_type ) {
2527 case 'register':
2528 $heading = __( 'List of fields that will appear in the register form.', 'userswp' );
2529 break;
2530
2531 }
2532
2533 return $heading;
2534 }
2535
2536 public function register_selected_fields_note( $note, $form_type ) {
2537 switch ( $form_type ) {
2538 case 'register':
2539 $note = __( 'Click to expand and view field related settings. You may drag and drop to arrange fields order in register form.', 'userswp' );
2540 break;
2541
2542 }
2543
2544 return $note;
2545 }
2546
2547 /**
2548 * Handles the create custom field ajax request.
2549 *
2550 * @since 1.0.0
2551 * @package userswp
2552 * @return void
2553 */
2554 public function create_field() {
2555
2556 if ( ! current_user_can( 'manage_options' ) ) {
2557 wp_die( -1 );
2558 }
2559
2560 $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
2561 $field_type = isset( $_REQUEST['field_type'] ) ? sanitize_text_field( $_REQUEST['field_type'] ) : '';
2562 $field_type_key = isset( $_REQUEST['field_type_key'] ) ? sanitize_text_field( $_REQUEST['field_type_key'] ) : '';
2563 $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
2564 $field_id = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
2565 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 1;
2566
2567 $field_id = $field_id != '' ? trim( $field_id, '_' ) : $field_id;
2568
2569 $field_ids = array();
2570 if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
2571 foreach ( $_REQUEST['licontainer'] as $lic_id ) {
2572 $field_ids[] = sanitize_text_field( $lic_id );
2573 }
2574 }
2575
2576 /* ------- check nonce field ------- */
2577 if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2578 echo $this->set_field_order( $field_ids, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2579 }
2580
2581 /* ---- Show field form in admin ---- */
2582 if ( $field_type != '' && $field_id != '' && $field_action == 'new' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2583 $this->form_field_adminhtml( $field_type, $field_id, $field_action, $field_type_key, $form_type );
2584 }
2585
2586 /* ---- Delete field ---- */
2587 if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2588 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_delete_' . $field_id ) ) {
2589 return;
2590 }
2591
2592 echo $this->admin_form_field_delete( $field_id, true, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2593 }
2594
2595 /* ---- Save field ---- */
2596 if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2597 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_' . $field_id ) ) {
2598 return;
2599 }
2600
2601 foreach ( $_REQUEST as $pkey => $pval ) {
2602 if ( isset( $_REQUEST[ $pkey ] ) && is_array( $_REQUEST[ $pkey ] ) ) {
2603 $tags = 'skip_field';
2604 } else {
2605 $tags = '';
2606 }
2607
2608 if ( $tags != 'skip_field' ) {
2609 $_REQUEST[ $pkey ] = strip_tags( $_REQUEST[ $pkey ], $tags );
2610 }
2611 }
2612
2613 $return = $this->admin_form_field_save( $_REQUEST );
2614
2615 if ( is_int( $return ) ) {
2616 $lastid = $return;
2617 $this->form_field_adminhtml( $field_type, $lastid, 'submit', $field_type_key, $form_type );
2618 } else {
2619 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2620 }
2621 }
2622
2623 wp_die();
2624 }
2625
2626 public function set_field_order( $field_ids = array(), $form_id = 1 ) {
2627
2628 global $wpdb;
2629
2630 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2631
2632 $count = 0;
2633 if ( ! empty( $field_ids ) ) :
2634 $user_meta_info = false;
2635 foreach ( $field_ids as $id ) {
2636
2637 $cf = trim( $id, '_' );
2638
2639 $user_meta_info = $wpdb->query(
2640 $wpdb->prepare(
2641 'update ' . $table_name . ' set
2642 sort_order=%d
2643 where id= %d and form_id = %d',
2644 array( $count, $cf, $form_id )
2645 )
2646 );
2647 ++$count;
2648 }
2649
2650 return $user_meta_info;
2651 else :
2652 return false;
2653 endif;
2654 }
2655
2656 public function admin_form_field_delete( $field_id = '', $delete_meta = true, $form_id = 1 ) {
2657
2658 global $wpdb;
2659
2660 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2661 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2662 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2663
2664 if ( $field_id != '' ) {
2665 $cf = trim( $field_id, '_' );
2666
2667 if ( $field = $wpdb->get_row( $wpdb->prepare( 'select id, htmlvar_name from ' . $table_name . ' where id= %d AND form_id = %d', array( $cf, $form_id ) ) ) ) {
2668
2669 $excluded_delete = array( 'username', 'email' );
2670 if ( isset( $field->htmlvar_name ) && in_array( $field->htmlvar_name, $excluded_delete ) ) {
2671 return $field_id;
2672 }
2673
2674 // delete the meta column
2675 if ( isset( $field->htmlvar_name ) && $delete_meta ) {
2676 $register_forms = uwp_get_option( 'multiple_registration_forms' );
2677 $custom_fields = array();
2678
2679 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
2680 foreach ( $register_forms as $key => $register_form ) {
2681 $form_ids[] = (int) $register_form['id'];
2682 }
2683
2684 if ( isset( $form_ids ) && count( $form_ids ) > 0 ) {
2685 $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%d' );
2686 $form_ids_placeholder = implode( ', ', $form_ids_placeholder );
2687 $query = $wpdb->prepare( 'SELECT id FROM ' . $table_name . " WHERE form_type = 'account' AND htmlvar_name = '" . $field->htmlvar_name . "' AND form_id IN (" . $form_ids_placeholder . ') ORDER BY sort_order ASC', $form_ids );
2688 $custom_fields = $wpdb->get_results( $query );
2689 }
2690 }
2691
2692 if ( isset( $custom_fields ) && ! empty( $custom_fields ) && count( $custom_fields ) > 1 ) {
2693 // Do not delete user meta column if field used in more than one form.
2694 } else {
2695 $col_name = sanitize_sql_orderby( $field->htmlvar_name );
2696 $wpdb->query( "ALTER TABLE `{$meta_table}` DROP COLUMN `{$col_name}`" );
2697 }
2698 }
2699
2700 $wpdb->query( $wpdb->prepare( 'delete from ' . $table_name . ' where id= %d AND form_id = %d', array( $cf, $form_id ) ) );
2701
2702 // Also delete register form field
2703 $wpdb->query( $wpdb->prepare( 'delete from ' . $extras_table_name . ' where site_htmlvar_name= %s AND form_id = %d ', array( $field->htmlvar_name, $form_id ) ) );
2704
2705 do_action( 'uwp_after_custom_field_deleted', $cf, $field );
2706
2707 return $field_id;
2708 } else {
2709 return 0;
2710 }
2711 } else {
2712 return 0;
2713 }
2714 }
2715
2716 public function admin_form_field_save( $request_field = array() ) {
2717
2718 global $wpdb;$wpdb->show_errors();
2719
2720 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2721
2722 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2723
2724 $old_html_variable = '';
2725
2726 $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
2727 $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : 1;
2728
2729 $user_meta_info = null;
2730
2731 // some servers fail if a POST value is VARCHAR so we change it.
2732 if ( isset( $request_field['data_type'] ) && $request_field['data_type'] == 'XVARCHAR' ) {
2733 $request_field['data_type'] = 'VARCHAR';
2734 }
2735
2736 $cf = trim( $result_str, '_' );
2737
2738 $cehhtmlvar_name = isset( $request_field['htmlvar_name'] ) ? $request_field['htmlvar_name'] : '';
2739 $form_type = $request_field['form_type'];
2740
2741 $old_html_variable_name = 'uwp_account_' . $cehhtmlvar_name;
2742 $check_old_html_variable = $wpdb->get_var(
2743 $wpdb->prepare(
2744 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2745 array( $cf, $old_html_variable_name, $form_type, $form_id )
2746 )
2747 );
2748
2749 $check_html_variable = $wpdb->get_var(
2750 $wpdb->prepare(
2751 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2752 array( $cf, $cehhtmlvar_name, $form_type, $form_id )
2753 )
2754 );
2755
2756 if ( ( ! $check_old_html_variable && ! $check_html_variable ) || $request_field['field_type'] == 'fieldset' ) {
2757
2758 if ( $cf != '' ) {
2759
2760 $user_meta_info = $wpdb->get_row(
2761 $wpdb->prepare(
2762 'select * from ' . $table_name . ' where id = %d',
2763 array( $cf )
2764 )
2765 );
2766
2767 }
2768
2769 if ( ! empty( $user_meta_info ) ) {
2770 $old_html_variable = $user_meta_info->htmlvar_name;
2771
2772 }
2773
2774 $site_title = sanitize_text_field( $request_field['site_title'] );
2775 $form_label = isset( $request_field['form_label'] ) ? sanitize_text_field( $request_field['form_label'] ) : '';
2776 $help_text = isset( $request_field['help_text'] ) ? sanitize_text_field( $request_field['help_text'] ) : '';
2777 $field_type = sanitize_text_field( $request_field['field_type'] );
2778 $data_type = sanitize_text_field( $request_field['data_type'] );
2779 $field_type_key = isset( $request_field['field_type_key'] ) ? sanitize_text_field( $request_field['field_type_key'] ) : $field_type;
2780 $htmlvar_name = isset( $request_field['htmlvar_name'] ) ? str_replace(
2781 array(
2782 '-',
2783 ' ',
2784 '"',
2785 "'",
2786 ),
2787 array( '_', '', '', '' ),
2788 sanitize_title_with_dashes( $request_field['htmlvar_name'] )
2789 ) : null;
2790 $default_value = isset( $request_field['default_value'] ) ? sanitize_text_field( $request_field['default_value'] ) : '';
2791 $sort_order = isset( $request_field['sort_order'] ) ? absint( $request_field['sort_order'] ) : '';
2792 $is_active = isset( $request_field['is_active'] ) ? absint( $request_field['is_active'] ) : 1;
2793 $placeholder_value = isset( $request_field['placeholder_value'] ) ? $request_field['placeholder_value'] : '';
2794 $for_admin_use = isset( $request_field['for_admin_use'] ) ? absint( $request_field['for_admin_use'] ) : 0;
2795 $is_required = isset( $request_field['is_required'] ) ? absint( $request_field['is_required'] ) : 0;
2796 $is_dummy = isset( $request_field['is_dummy'] ) ? absint( $request_field['is_dummy'] ) : 0;
2797 $is_public = isset( $request_field['is_public'] ) ? absint( $request_field['is_public'] ) : 0;
2798 $is_default = isset( $request_field['is_default'] ) ? absint( $request_field['is_default'] ) : 0;
2799 $is_register_field = isset( $request_field['is_register_field'] ) ? absint( $request_field['is_register_field'] ) : 0;
2800 $is_search_field = isset( $request_field['is_search_field'] ) ? absint( $request_field['is_search_field'] ) : 0;
2801 $is_register_only_field = isset( $request_field['is_register_only_field'] ) ? absint( $request_field['is_register_only_field'] ) : 0;
2802 $required_msg = isset( $request_field['required_msg'] ) ? sanitize_text_field( $request_field['required_msg'] ) : '';
2803 $css_class = isset( $request_field['css_class'] ) ? sanitize_text_field( $request_field['css_class'] ) : '';
2804 $field_icon = isset( $request_field['field_icon'] ) ? sanitize_text_field( $request_field['field_icon'] ) : '';
2805 $show_in = isset( $request_field['show_in'] ) ? $request_field['show_in'] : '';
2806 $user_roles = isset( $request_field['user_roles'] ) ? $request_field['user_roles'] : '';
2807 $decimal_point = isset( $request_field['decimal_point'] ) ? absint( $request_field['decimal_point'] ) : ''; // decimal point for DECIMAL data type
2808 $decimal_point = $decimal_point > 0 ? ( $decimal_point > 10 ? 10 : $decimal_point ) : '';
2809 $validation_pattern = isset( $request_field['validation_pattern'] ) ? sanitize_text_field( $request_field['validation_pattern'] ) : '';
2810 $validation_msg = isset( $request_field['validation_msg'] ) ? sanitize_text_field( $request_field['validation_msg'] ) : '';
2811 $user_sort = isset( $request_field['user_sort'] ) ? absint( $request_field['user_sort'] ) : 0;
2812
2813 if ( empty( $htmlvar_name ) ) {
2814 $htmlvar_name = sanitize_key(
2815 str_replace(
2816 array( '-', ' ', '"', "'" ),
2817 array(
2818 '_',
2819 '_',
2820 '',
2821 '',
2822 ),
2823 $request_field['site_title']
2824 )
2825 );
2826 if ( str_replace( '_', '', $htmlvar_name ) != '' ) {
2827 $htmlvar_name = substr( $htmlvar_name, 0, 50 );
2828 } else {
2829 $htmlvar_name = time();
2830 }
2831 }
2832
2833 if ( is_array( $show_in ) ) {
2834 $show_in = implode( ',', $request_field['show_in'] );
2835 $show_in = sanitize_text_field( $show_in );
2836 }
2837
2838 if ( is_array( $user_roles ) ) {
2839 $user_roles = implode( ',', $request_field['user_roles'] );
2840 $user_roles = sanitize_text_field( $user_roles );
2841 }
2842
2843 $option_values = '';
2844 if ( isset( $request_field['option_values'] ) ) {
2845 $option_values = $request_field['option_values'];
2846 }
2847
2848 if ( isset( $request_field['extra'] ) && ! empty( $request_field['extra'] ) ) {
2849 $extra_fields = $request_field['extra'];
2850 }
2851
2852 if ( $sort_order == '' ) {
2853
2854 $last_order = $wpdb->get_var( 'SELECT MAX(sort_order) as last_order FROM ' . $table_name );
2855
2856 $sort_order = (int) $last_order + 1;
2857 }
2858
2859 if ( ! empty( $user_meta_info ) ) {
2860
2861 $excluded = uwp_get_excluded_fields();
2862
2863 if ( ! in_array( $htmlvar_name, $excluded ) ) {
2864 // Create custom columns
2865 switch ( $field_type ) :
2866
2867 case 'checkbox':
2868 case 'multiselect':
2869 case 'select':
2870 $op_size = '500';
2871
2872 // only make the field as big as it needs to be.
2873 if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
2874 $option_values_arr = explode( ',', $option_values );
2875 if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
2876 $op_max = 0;
2877 foreach ( $option_values_arr as $op_val ) {
2878 if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
2879 $op_max = strlen( $op_val );
2880 }
2881 }
2882 if ( $op_max ) {
2883 $op_size = $op_max;
2884 }
2885 }
2886 } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
2887 if ( strlen( $option_values ) ) {
2888 $op_size = strlen( $option_values );
2889 }
2890 }
2891
2892 $meta_field_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . "`VARCHAR( $op_size ) NULL";
2893
2894 if ( $default_value != '' ) {
2895 $meta_field_add .= " DEFAULT '" . $default_value . "'";
2896 }
2897
2898 $alter_result = $wpdb->query( $meta_field_add );
2899 if ( $alter_result === false ) {
2900 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2901 }
2902
2903 if ( isset( $request_field['cat_display_type'] ) ) {
2904 $extra_fields = $request_field['cat_display_type'];
2905 }
2906
2907 if ( isset( $request_field['multi_display_type'] ) ) {
2908 $extra_fields = $request_field['multi_display_type'];
2909 }
2910
2911 break;
2912
2913 case 'textarea':
2914 case 'editor':
2915 case 'url':
2916 case 'file':
2917 $alter_result = $wpdb->query( 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` TEXT NULL' );
2918 if ( $alter_result === false ) {
2919 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2920 }
2921 if ( isset( $request_field['advanced_editor'] ) ) {
2922 $extra_fields = $request_field['advanced_editor'];
2923 }
2924
2925 break;
2926
2927 case 'fieldset':
2928 // Nothing happened for fieldset
2929 break;
2930
2931 default:
2932 if ( $data_type != 'VARCHAR' && $data_type != '' ) {
2933 if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
2934 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` DECIMAL(11, ' . (int) $decimal_point . ') NULL';
2935 } else {
2936 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` ' . $data_type . ' NULL';
2937 }
2938
2939 if ( is_numeric( $default_value ) && $default_value != '' ) {
2940 $default_value_add .= " DEFAULT '" . $default_value . "'";
2941 }
2942 } else {
2943 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` VARCHAR( 254 ) NULL';
2944 if ( $default_value != '' ) {
2945 $default_value_add .= " DEFAULT '" . $default_value . "'";
2946 }
2947 }
2948
2949 $alter_result = $wpdb->query( $default_value_add );
2950 if ( $alter_result === false ) {
2951 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2952 }
2953 break;
2954 endswitch;
2955 }
2956
2957 $extra_field_query = '';
2958 if ( ! empty( $extra_fields ) ) {
2959 $extra_field_query = serialize( $extra_fields );
2960 }
2961
2962 $wpdb->query(
2963 $wpdb->prepare(
2964 'update ' . $table_name . ' set
2965 form_type = %s,
2966 site_title = %s,
2967 form_label = %s,
2968 help_text = %s,
2969 field_type = %s,
2970 data_type = %s,
2971 decimal_point = %s,
2972 field_type_key = %s,
2973 htmlvar_name = %s,
2974 default_value = %s,
2975 sort_order = %s,
2976 is_active = %s,
2977 placeholder_value = %s,
2978 for_admin_use = %s,
2979 is_default = %s,
2980 is_required = %s,
2981 is_dummy = %s,
2982 is_public = %s,
2983 is_register_field = %s,
2984 is_search_field = %s,
2985 is_register_only_field = %s,
2986 required_msg = %s,
2987 css_class = %s,
2988 field_icon = %s,
2989 show_in = %s,
2990 user_roles = %s,
2991 option_values = %s,
2992 extra_fields = %s,
2993 validation_pattern = %s,
2994 validation_msg = %s,
2995 form_id = %d,
2996 user_sort = %s
2997 where id = %d',
2998 array(
2999 $form_type,
3000 $site_title,
3001 $form_label,
3002 $help_text,
3003 $field_type,
3004 $data_type,
3005 $decimal_point,
3006 $field_type_key,
3007 $htmlvar_name,
3008 $default_value,
3009 $sort_order,
3010 $is_active,
3011 $placeholder_value,
3012 $for_admin_use,
3013 $is_default,
3014 $is_required,
3015 $is_dummy,
3016 $is_public,
3017 $is_register_field,
3018 $is_search_field,
3019 $is_register_only_field,
3020 $required_msg,
3021 $css_class,
3022 $field_icon,
3023 $show_in,
3024 $user_roles,
3025 $option_values,
3026 $extra_field_query,
3027 $validation_pattern,
3028 $validation_msg,
3029 $form_id,
3030 $user_sort,
3031 $cf,
3032 )
3033 )
3034 );
3035
3036 $lastid = trim( $cf );
3037
3038 do_action( 'uwp_after_custom_fields_updated', $lastid );
3039
3040 } else {
3041
3042 switch ( $field_type ) :
3043
3044 case 'checkbox':
3045 $data_type = 'TINYINT';
3046
3047 $meta_field_add = $data_type . '( 1 ) NOT NULL ';
3048 if ( (int) $default_value === 1 ) {
3049 $meta_field_add .= " DEFAULT '1'";
3050 }
3051
3052 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3053 if ( $add_result === false ) {
3054 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3055 }
3056 break;
3057 case 'multiselect':
3058 case 'select':
3059 $data_type = 'VARCHAR';
3060 $op_size = '500';
3061
3062 // only make the field as big as it needs to be.
3063 if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
3064 $option_values_arr = explode( ',', $option_values );
3065
3066 if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
3067 $op_max = 0;
3068
3069 foreach ( $option_values_arr as $op_val ) {
3070 if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
3071 $op_max = strlen( $op_val );
3072 }
3073 }
3074
3075 if ( $op_max ) {
3076 $op_size = $op_max;
3077 }
3078 }
3079 } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
3080 if ( strlen( $option_values ) ) {
3081 $op_size = strlen( $option_values );
3082 }
3083
3084 if ( isset( $request_field['multi_display_type'] ) ) {
3085 $extra_fields = $request_field['multi_display_type'];
3086 }
3087 }
3088
3089 $meta_field_add = $data_type . "( $op_size ) NULL ";
3090 if ( $default_value != '' ) {
3091 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3092 }
3093
3094 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3095 if ( $add_result === false ) {
3096 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3097 }
3098 break;
3099 case 'textarea':
3100 case 'editor':
3101 case 'url':
3102 case 'file':
3103 $data_type = 'TEXT';
3104
3105 $meta_field_add = $data_type . ' NULL ';
3106
3107 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3108 if ( $add_result === false ) {
3109 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3110 }
3111
3112 break;
3113
3114 case 'datepicker':
3115 $data_type = 'DATE';
3116
3117 $meta_field_add = $data_type . ' NULL ';
3118
3119 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3120 if ( $add_result === false ) {
3121 return __( 'Column creation failed, you may have too many columns or the default value must have in valid date format.', 'userswp' );
3122 }
3123
3124 break;
3125
3126 case 'time':
3127 $data_type = 'TIME';
3128
3129 $meta_field_add = $data_type . ' NULL ';
3130
3131 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3132 if ( $add_result === false ) {
3133 return __( 'Column creation failed, you may have too many columns or the default value must have in valid time format.', 'userswp' );
3134 }
3135
3136 break;
3137
3138 default:
3139 if ( $data_type != 'VARCHAR' && $data_type != '' ) {
3140 $meta_field_add = $data_type . ' NULL ';
3141
3142 if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
3143 $meta_field_add = 'DECIMAL(11, ' . (int) $decimal_point . ') NULL ';
3144 }
3145
3146 if ( is_numeric( $default_value ) && $default_value != '' ) {
3147 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3148 }
3149 } else {
3150 $meta_field_add = ' VARCHAR( 254 ) NULL ';
3151
3152 if ( $default_value != '' ) {
3153 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3154 }
3155 }
3156
3157 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3158 if ( $add_result === false ) {
3159 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3160 }
3161 break;
3162 endswitch;
3163
3164 $extra_field_query = '';
3165 if ( ! empty( $extra_fields ) ) {
3166 $extra_field_query = serialize( $extra_fields );
3167 }
3168
3169 $wpdb->query(
3170 $wpdb->prepare(
3171 'insert into ' . $table_name . ' set
3172 form_type = %s,
3173 site_title = %s,
3174 form_label = %s,
3175 help_text = %s,
3176 field_type = %s,
3177 data_type = %s,
3178 decimal_point = %s,
3179 field_type_key = %s,
3180 htmlvar_name = %s,
3181 default_value = %s,
3182 sort_order = %d,
3183 is_active = %s,
3184 placeholder_value = %s,
3185 for_admin_use = %s,
3186 is_default = %s,
3187 is_required = %s,
3188 is_dummy = %s,
3189 is_public = %s,
3190 is_register_field = %s,
3191 is_search_field = %s,
3192 is_register_only_field = %s,
3193 required_msg = %s,
3194 css_class = %s,
3195 field_icon = %s,
3196 show_in = %s,
3197 user_roles = %s,
3198 option_values = %s,
3199 extra_fields = %s,
3200 validation_pattern = %s,
3201 validation_msg = %s,
3202 form_id = %d,
3203 user_sort = %s ',
3204 array(
3205 $form_type,
3206 $site_title,
3207 $form_label,
3208 $help_text,
3209 $field_type,
3210 $data_type,
3211 $decimal_point,
3212 $field_type_key,
3213 $htmlvar_name,
3214 $default_value,
3215 $sort_order,
3216 $is_active,
3217 $placeholder_value,
3218 $for_admin_use,
3219 $is_default,
3220 $is_required,
3221 $is_dummy,
3222 $is_public,
3223 $is_register_field,
3224 $is_search_field,
3225 $is_register_only_field,
3226 $required_msg,
3227 $css_class,
3228 $field_icon,
3229 $show_in,
3230 $user_roles,
3231 $option_values,
3232 $extra_field_query,
3233 $validation_pattern,
3234 $validation_msg,
3235 $form_id,
3236 $user_sort,
3237 )
3238 )
3239 );
3240
3241 $lastid = $wpdb->insert_id;
3242
3243 $lastid = trim( $lastid );
3244
3245 }
3246
3247 return (int) $lastid;
3248
3249 } else {
3250 return 'invalid_key';
3251 }
3252 }
3253
3254 public function register_ajax_handler() {
3255 if ( isset( $_REQUEST['create_field'] ) ) {
3256
3257 if ( ! current_user_can( 'manage_options' ) ) {
3258 wp_die( -1 );
3259 }
3260
3261 $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_text_field( $_REQUEST['form_id'] ) : 1;
3262 $field_id = isset( $_REQUEST['field_id'] ) ? trim( sanitize_text_field( $_REQUEST['field_id'] ), '_' ) : '';
3263 $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
3264
3265 /* ------- check nonce field ------- */
3266 if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' ) {
3267 $field_ids = array();
3268 if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
3269 foreach ( $_REQUEST['licontainer'] as $lic_id ) {
3270 $field_ids[] = sanitize_text_field( $lic_id );
3271 }
3272 }
3273
3274 $return = uwp_form_extras_field_order( $field_ids, 'register', $form_id );
3275
3276 if ( is_array( $return ) ) {
3277 $return = json_encode( $return );
3278 }
3279
3280 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3281 }
3282
3283 /* ---- Show field form in admin ---- */
3284 if ( $field_action == 'new' ) {
3285 $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
3286 $fields = $this->register_fields( $form_type, $form_id );
3287
3288 $_REQUEST['site_field_id'] = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
3289 $_REQUEST['is_default'] = '0';
3290
3291 if ( ! empty( $fields ) ) {
3292 foreach ( $fields as $val ) {
3293 $val = stripslashes_deep( $val );
3294
3295 if ( $val['htmlvar_name'] == $_REQUEST['htmlvar_name'] ) {
3296 $_REQUEST['field_type'] = $val['field_type'];
3297 $_REQUEST['site_title'] = $val['site_title'];
3298 }
3299 }
3300 }
3301
3302 $htmlvar_name = isset( $_REQUEST['htmlvar_name'] ) ? sanitize_text_field( $_REQUEST['htmlvar_name'] ) : '';
3303
3304 $this->register_field_adminhtml( $htmlvar_name, $field_action, false, $_REQUEST );
3305 }
3306
3307 /* ---- Delete field ---- */
3308 if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) ) {
3309 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3310 return;
3311 }
3312
3313 echo $this->register_field_delete( $field_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3314 }
3315
3316 /* ---- Save field ---- */
3317 if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) ) {
3318 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3319 return;
3320 }
3321
3322 foreach ( $_REQUEST as $pkey => $pval ) {
3323 $tags = is_array( $_REQUEST[ $pkey ] ) ? 'skip_field' : '';
3324
3325 if ( $tags != 'skip_field' ) {
3326 $_REQUEST[ $pkey ] = strip_tags( sanitize_text_field( $_REQUEST[ $pkey ] ), $tags );
3327 }
3328 }
3329
3330 $return = $this->register_field_save( $_REQUEST );
3331
3332 if ( is_int( $return ) ) {
3333 $lastid = $return;
3334
3335 $this->register_field_adminhtml( $lastid, 'submit' );
3336 } else {
3337 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3338 }
3339 }
3340 }
3341 die();
3342 }
3343
3344 public function register_field_delete( $field_id = '' ) {
3345
3346 global $wpdb;
3347 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3348
3349 if ( $field_id != '' ) {
3350 $cf = trim( $field_id, '_' );
3351
3352 $wpdb->query( $wpdb->prepare( 'delete from ' . $extras_table_name . ' where id= %d ', array( $cf ) ) );
3353
3354 return $field_id;
3355
3356 } else {
3357 return 0;
3358 }
3359 }
3360
3361 public function register_field_save( $request_field = array() ) {
3362
3363 if ( ! current_user_can( 'manage_options' ) ) {
3364 wp_die( -1 );
3365 }
3366
3367 global $wpdb;
3368 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3369
3370 $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : '';
3371 $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
3372
3373 $cf = trim( $result_str, '_' );
3374
3375 /*-------- check duplicate validation --------*/
3376
3377 $site_htmlvar_name = isset( $request_field['site_htmlvar_name'] ) ? sanitize_text_field( $request_field['site_htmlvar_name'] ) : sanitize_text_field( $request_field['htmlvar_name'] );
3378 $form_type = $request_field['form_type'];
3379 $field_type = $request_field['field_type'];
3380
3381 $check_html_variable = $wpdb->get_var(
3382 $wpdb->prepare(
3383 'select site_htmlvar_name from ' . $extras_table_name . ' where id <> %d and site_htmlvar_name = %s and form_type = %s and form_id=%d',
3384 array( $cf, $site_htmlvar_name, $form_type, $form_id )
3385 )
3386 );
3387
3388 if ( ! $check_html_variable ) {
3389
3390 if ( $cf != '' ) {
3391
3392 $user_meta_info = $wpdb->get_row(
3393 $wpdb->prepare(
3394 'select * from ' . $extras_table_name . ' where id = %d',
3395 array( $cf )
3396 )
3397 );
3398
3399 }
3400
3401 if ( $form_type == '' ) {
3402 $form_type = 'register';
3403 }
3404
3405 $site_htmlvar_name = sanitize_text_field( $request_field['site_htmlvar_name'] );
3406 $field_id = ( isset( $request_field['field_id'] ) && $request_field['field_id'] ) ? str_replace( 'new', '', $request_field['field_id'] ) : '';
3407
3408 if ( ! empty( $user_meta_info ) ) {
3409
3410 $wpdb->query(
3411 $wpdb->prepare(
3412 'update ' . $extras_table_name . ' set
3413 form_type = %s,
3414 field_type = %s,
3415 site_htmlvar_name = %s,
3416 sort_order = %s,
3417 form_id = %d
3418 where id = %d',
3419 array(
3420 $form_type,
3421 $field_type,
3422 $site_htmlvar_name,
3423 $field_id,
3424 $form_id,
3425 $cf,
3426 )
3427 )
3428 );
3429
3430 $lastid = trim( $cf );
3431
3432 } else {
3433
3434 $wpdb->query(
3435 $wpdb->prepare(
3436 'insert into ' . $extras_table_name . ' set
3437 form_type = %s,
3438 field_type = %s,
3439 site_htmlvar_name = %s,
3440 sort_order = %s,
3441 form_id = %s',
3442 array(
3443 $form_type,
3444 $field_type,
3445 $site_htmlvar_name,
3446 $field_id,
3447 $form_id,
3448 )
3449 )
3450 );
3451 $lastid = $wpdb->insert_id;
3452 $lastid = trim( $lastid );
3453 }
3454
3455 return (int) $lastid;
3456
3457 } else {
3458 return 'invalid_key';
3459 }
3460 }
3461 }
3462