PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.27
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.27
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.27, at admin/settings/class-formbuilder.php

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