PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.34
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.34
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 1.0.23 All 172 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.34, at admin/settings/class-formbuilder.php

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