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

3,419 lines 141.5 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 <input type="hidden" name="uwp_create_field_nonce" class="uwp_create_field_nonce" value="<?php echo wp_create_nonce( 'uwp_create_field_nonce' ); ?>"/>
1111 <ul class="core uwp-tabs-selected uwp_form_extras ps-0 list-group">
1112 <?php
1113 // Retrieve fields saved with form id 0.
1114 if ( $form_id === 1 ) {
1115 $where = 'AND ( form_id = 1 OR form_id = 0 )';
1116 } else {
1117 $where = $wpdb->prepare( 'AND form_id = %d', $form_id );
1118 }
1119
1120 $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM `' . $table_name . "` WHERE form_type = %s {$where} ORDER BY sort_order ASC", $form_type ) );
1121
1122 if ( ! empty( $fields ) ) {
1123 foreach ( $fields as $field ) {
1124 $result_str = $field;
1125 $field_type = $field->field_type;
1126 $field_type_key = $field->field_type_key;
1127 $field_ins_upd = 'display';
1128
1129 $this->form_field_adminhtml( $field_type, $result_str, $field_ins_upd, $field_type_key );
1130 }
1131 }
1132 ?>
1133 </ul>
1134 <?php
1135 }
1136
1137 public function form_field_adminhtml( $field_type, $result_str, $field_ins_upd = '', $field_type_key = '', $form_type = false ) {
1138 global $wpdb;
1139 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1140 $cf = $result_str;
1141 $cf_arr = $this->get_form_existing_fields( $form_type );
1142
1143 if ( ! is_object( $cf ) ) {
1144
1145 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $table_name . ' where id= %d', array( $cf ) ) );
1146
1147 } else {
1148 $field_info = $cf;
1149 $result_str = $cf->id;
1150 }
1151
1152 if ( ! $field_info ) {
1153 $field_info = ( isset( $cf_arr[ $field_type_key ] ) ) ? $cf_arr[ $field_type_key ] : null;
1154 }
1155
1156 $this->admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type );
1157 }
1158
1159 /**
1160 * @param $field_info
1161 * @param $field_type
1162 * @param string $field_type_key
1163 * @param string $field_ins_upd
1164 * @param $result_str
1165 * @param bool $form_type
1166 */
1167 public function admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type = false ) {
1168
1169 if ( ! $form_type ) {
1170 if ( ! isset( $field_info->form_type ) ) {
1171 $form_type = sanitize_text_field( $_REQUEST['tab'] );
1172 } else {
1173 $form_type = $field_info->form_type;
1174 }
1175 }
1176
1177 $cf_arr1 = $this->form_fields( $form_type );
1178 $cf_arr2 = $this->form_fields_predefined( $form_type );
1179 $cf_arr3 = $this->form_fields_custom( $form_type );
1180
1181 $cf_arr = $cf_arr1 + $cf_arr2 + $cf_arr3; // this way defaults can't be overwritten
1182
1183 $cf = ( isset( $cf_arr[ $field_type_key ] ) ) ? $cf_arr[ $field_type_key ] : '';
1184
1185 $field_info = stripslashes_deep( $field_info ); // strip slashes from labels
1186
1187 $field_site_title = '';
1188 if ( isset( $field_info->site_title ) ) {
1189 $field_site_title = $field_info->site_title;
1190 }
1191
1192 $field_display = $field_type == 'address' && $field_info->htmlvar_name == 'post' ? 'style="display:none"' : '';
1193
1194 if ( isset( $cf['field_icon'] ) && strpos( $cf['field_icon'], ' fa-' ) !== false ) {
1195 $field_icon = '<i class="' . esc_attr( $cf['field_icon'] ) . '" aria-hidden="true"></i>';
1196 } elseif ( isset( $cf['field_icon'] ) && $cf['field_icon'] ) {
1197 $field_icon = '<b style="background-image: url("' . esc_url( $cf['field_icon'] ) . '")"></b>';
1198 } else {
1199 $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
1200 }
1201
1202 if ( isset( $cf['site_title'] ) && $cf['site_title'] ) {
1203 $field_type_name = $cf['site_title'];
1204 } else {
1205 $field_type_name = $field_type;
1206 }
1207
1208 $htmlvar_name = isset( $field_info->htmlvar_name ) ? sanitize_text_field( $field_info->htmlvar_name ) : '';
1209 $can_delete = apply_filters( 'uwp_cfa_can_delete_field', true, $field_info, $form_type );
1210 $nonce = wp_create_nonce( 'custom_fields_' . $result_str );
1211
1212 ?>
1213 <li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>">
1214 <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);">
1215 <div class="flex-fill font-weight-bold fw-bold">
1216 <?php if ( $field_type == 'fieldset' ) { ?>
1217 <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
1218 <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
1219 <b><?php echo esc_html( __( 'Fieldset:', 'userswp' ) ); ?></b>
1220 <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( $field_site_title ) . ')'; ?></span>
1221 <?php } else { ?>
1222 <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1223 <b><?php echo esc_html( ' ' . $field_site_title ); ?></b>
1224 <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( ucfirst( $field_type_name ) ) . ')'; ?></span>
1225 <?php } ?>
1226 </div>
1227 <div class="dd-handle ui-sortable-handle">
1228 <?php if ( $can_delete ) { ?>
1229 <i class="far fa-trash-alt text-danger ml-2 ms-2"
1230 id="delete-<?php echo esc_attr( $result_str ); ?>"
1231 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>
1232 <?php } ?>
1233 <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
1234 </div>
1235
1236 <?php // store the form as a template. This saves a load of memory on page load. ?>
1237 <script type="text/template" class="dd-setting <?php echo 'dd-type-' . esc_attr( $field_type ); ?>">
1238 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
1239 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1240 <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
1241 <input type="hidden" name="field_type_key" id="field_type_key" value="<?php echo esc_attr( $field_type_key ); ?>"/>
1242 <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
1243 <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 ?>
1244
1245 <?php
1246 // data_type
1247 if ( has_filter( "uwp_builder_data_type_{$field_type}" ) ) {
1248
1249 echo apply_filters( "uwp_builder_data_type_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1250
1251 } else {
1252 $value = '';
1253 if ( isset( $field_info->data_type ) ) {
1254 $value = esc_attr( $field_info->data_type );
1255 } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
1256 $value = $cf['defaults']['data_type'];
1257 }
1258 ?>
1259 <input type="hidden" name="data_type" id="data_type" value="<?php echo esc_attr( $value ); ?>"/>
1260 <?php
1261 }
1262
1263 // site_title
1264 if ( has_filter( "uwp_builder_site_title_{$field_type}" ) ) {
1265
1266 echo apply_filters( "uwp_builder_site_title_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1267
1268 } else {
1269 $value = '';
1270 if ( isset( $field_info->site_title ) ) {
1271 $value = esc_attr( $field_info->site_title );
1272 } elseif ( isset( $cf['defaults']['site_title'] ) && $cf['defaults']['site_title'] ) {
1273 $value = $cf['defaults']['site_title'];
1274 }
1275
1276 echo aui()->input(
1277 array(
1278 'id' => 'site_title',
1279 'name' => 'site_title',
1280 'label_type' => 'top',
1281 'label' => esc_html__( 'Label', 'userswp' ) . uwp_help_tip( __( 'This will be the label for the field.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1282 'type' => 'text',
1283 // 'wrap_class' => geodir_advanced_toggle_class(),
1284 'value' => $value,
1285 )
1286 );
1287 }
1288
1289 // Input Label
1290 if ( has_filter( "uwp_builder_form_label_{$field_type}" ) ) {
1291
1292 echo apply_filters( "uwp_builder_form_label_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1293
1294 } else {
1295 $value = '';
1296 if ( isset( $field_info->form_label ) ) {
1297 $value = esc_attr( $field_info->form_label );
1298 } elseif ( isset( $cf['defaults']['form_label'] ) && $cf['defaults']['form_label'] ) {
1299 $value = $cf['defaults']['form_label'];
1300 }
1301
1302 echo aui()->input(
1303 array(
1304 'id' => 'form_label',
1305 'name' => 'form_label',
1306 'label_type' => 'top',
1307 '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
1308 'type' => 'text',
1309 'wrap_class' => uwp_advanced_toggle_class(),
1310 'value' => $value,
1311 )
1312 );
1313 }
1314
1315 // Input Description
1316 if ( has_filter( "uwp_builder_field_description_{$field_type}" ) ) {
1317
1318 echo apply_filters( "uwp_builder_field_description_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1319
1320 } else {
1321 $value = '';
1322 if ( isset( $field_info->help_text ) ) {
1323 $value = esc_attr( $field_info->help_text );
1324 } elseif ( isset( $cf['defaults']['help_text'] ) && $cf['defaults']['help_text'] ) {
1325 $value = $cf['defaults']['help_text'];
1326 }
1327 $tip_text = ! empty( $cf['help_text_tip'] ) ? esc_attr( $cf['help_text_tip'] ) : __( 'This will be displayed below the field in the form.', 'userswp' );
1328 echo aui()->input(
1329 array(
1330 'id' => 'help_text',
1331 'name' => 'help_text',
1332 'label_type' => 'top',
1333 'label' => esc_html__( 'Field Description', 'userswp' ) . uwp_help_tip( $tip_text ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1334 'type' => 'text',
1335 //'wrap_class' => uwp_advanced_toggle_class(),
1336 'value' => $value,
1337 )
1338 );
1339
1340 }
1341
1342 // htmlvar_name
1343 if ( has_filter( "uwp_builder_htmlvar_name_{$field_type}" ) ) {
1344
1345 echo apply_filters( "uwp_builder_htmlvar_name_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1346
1347 } else {
1348 $value = '';
1349 if ( isset( $field_info->htmlvar_name ) ) {
1350 $value = esc_attr( $field_info->htmlvar_name );
1351 } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
1352 $value = $cf['defaults']['htmlvar_name'];
1353 }
1354
1355 $extra_attributes = array();
1356 $class = '';
1357 if ( isset( $field_info->id ) && substr( $field_info->id, 0, 4 ) === 'new-' && empty( $field_info->single_use ) ) {
1358 } // New non single use predefined fields should have ability to change html_var
1359 elseif ( ! empty( $value ) && $value != 'uwp_' ) {
1360 $extra_attributes['readonly'] = 'readonly'; $class = 'bg-opacity-50 bg-gray'; }
1361
1362 $extra_attributes['maxlength'] = 50;
1363 $extra_attributes['pattern'] = '[a-zA-Z0-9]+';
1364
1365 echo aui()->input(
1366 array(
1367 'id' => 'htmlvar_name',
1368 'name' => 'htmlvar_name',
1369 'title' => __( 'Must not contain spaces or special characters', 'userswp' ),
1370 'label_type' => 'top',
1371 'label' => __( 'Key', 'userswp' ) . uwp_help_tip( __( 'This is a unique identifier used in the HTML, it MUST NOT contain spaces or special characters.', 'userswp' ) ),
1372 'type' => 'text',
1373 'wrap_class' => uwp_advanced_toggle_class(),
1374 'value' => $value ? preg_replace( '/uwp_/', '', $value, 1 ) : '',
1375 'extra_attributes' => $extra_attributes,
1376 'class' => $class,
1377 )
1378 );
1379
1380 }
1381
1382 // Placeholder text
1383 if ( has_filter( "uwp_builder_placeholder_value_{$field_type}" ) ) {
1384
1385 echo apply_filters( "uwp_builder_placeholder_value_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1386
1387 } else {
1388 $value = '';
1389 if ( isset( $field_info->placeholder_value ) ) {
1390 $value = esc_attr( $field_info->placeholder_value );
1391 } elseif ( isset( $cf['defaults']['placeholder_value'] ) && $cf['defaults']['placeholder_value'] ) {
1392 $value = $cf['defaults']['placeholder_value'];
1393 }
1394
1395 echo aui()->input(
1396 array(
1397 'id' => 'placeholder_value_' . esc_attr( $result_str ),
1398 'name' => 'placeholder_value',
1399 'title' => __( 'Enter placeholder text for this field.', 'userswp' ),
1400 'label_type' => 'top',
1401 'label' => esc_html__( 'Placeholder', 'userswp' ) . uwp_help_tip( __( 'Display placeholder text for this field.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1402 'type' => 'text',
1403 'wrap_class' => uwp_advanced_toggle_class(),
1404 'value' => $value,
1405 )
1406 );
1407
1408 }
1409
1410 // is_active
1411 if ( has_filter( "uwp_builder_is_active_{$field_type}" ) ) {
1412
1413 echo apply_filters( "uwp_builder_is_active_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1414
1415 } else {
1416 $value = '';
1417 if ( isset( $field_info->is_active ) ) {
1418 $value = esc_attr( $field_info->is_active );
1419 } elseif ( isset( $cf['defaults']['is_active'] ) && $cf['defaults']['is_active'] ) {
1420 $value = $cf['defaults']['is_active'];
1421 }
1422
1423 echo aui()->input(
1424 array(
1425 'id' => 'is_active',
1426 'name' => 'is_active',
1427 'type' => 'checkbox',
1428 'label_type' => 'horizontal',
1429 'label_col' => '4',
1430 'label' => __( 'Is active', 'userswp' ),
1431 'checked' => $value,
1432 'value' => '1',
1433 'with_hidden' => '',
1434 'switch' => 'md',
1435 'label_force_left' => true,
1436 'help_text' => uwp_help_tip( __( 'If no is selected then the field will not be displayed anywhere.', 'userswp' ) ),
1437 )
1438 );
1439
1440 }
1441
1442 // for_admin_use
1443 if ( has_filter( "uwp_builder_for_admin_use_{$field_type}" ) ) {
1444
1445 echo apply_filters( "uwp_builder_for_admin_use_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1446
1447 } else {
1448 $value = '';
1449 if ( isset( $field_info->for_admin_use ) ) {
1450 $value = esc_attr( $field_info->for_admin_use );
1451 } elseif ( isset( $cf['defaults']['for_admin_use'] ) && $cf['defaults']['for_admin_use'] ) {
1452 $value = $cf['defaults']['for_admin_use'];
1453 }
1454
1455 echo aui()->input(
1456 array(
1457 'id' => 'for_admin_use',
1458 'name' => 'for_admin_use',
1459 'type' => 'checkbox',
1460 'label_type' => 'horizontal',
1461 'label_col' => '4',
1462 'label' => __( 'For admin use only?', 'userswp' ),
1463 'checked' => $value,
1464 'value' => '1',
1465 'switch' => 'md',
1466 'label_force_left' => true,
1467 'help_text' => uwp_help_tip( __( 'If yes is selected then only site admin can see and edit this field.', 'userswp' ) ),
1468 // 'wrap_class' => uwp_advanced_toggle_class(),
1469 )
1470 );
1471
1472 }
1473
1474 // is_public
1475 if ( has_filter( "uwp_builder_is_public_{$field_type}" ) ) {
1476 echo apply_filters( "uwp_builder_is_public_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1477 } else {
1478 $value = '';
1479
1480 if ( isset( $field_info->is_public ) ) {
1481 $value = (int) $field_info->is_public;
1482 } elseif ( isset( $cf['defaults']['is_public'] ) && ( $cf['defaults']['is_public'] || $cf['defaults']['is_public'] === '0' || $cf['defaults']['is_public'] === 0 ) ) {
1483 $value = (int) $cf['defaults']['is_public'];
1484 }
1485
1486 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 true
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' => wp_slash( $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 <input type="hidden" name="uwp_create_field_nonce" class="uwp_create_field_nonce" value="<?php echo wp_create_nonce( 'uwp_create_field_nonce' ); ?>"/>
1856 <ul class="core uwp_form_extras uwp-tabs-selected ps-0 list-group ">
1857 <?php
1858
1859 $fields = $wpdb->get_results(
1860 $wpdb->prepare(
1861 'select * from ' . $extras_table_name . ' where form_type = %s AND form_id = %d order by sort_order asc',
1862 array( $form_type, $form_id )
1863 )
1864 );
1865
1866 if ( ! empty( $fields ) ) {
1867 foreach ( $fields as $field ) {
1868 $result_str = $field;
1869 $field_ins_upd = 'display';
1870 $this->register_field_adminhtml( $result_str, $field_ins_upd, false );
1871 }
1872 }
1873 ?>
1874 </ul>
1875 <?php
1876 }
1877
1878 public function register_field_adminhtml( $result_str, $field_ins_upd = '', $default = false, $request = array() ) {
1879 global $wpdb;
1880
1881 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1882 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1883
1884 $cf = $result_str;
1885 if ( ! is_object( $cf ) && ( is_int( $cf ) || ctype_digit( $cf ) ) ) {
1886 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( $cf ) ) );
1887 } elseif ( is_object( $cf ) ) {
1888 $result_str = $cf->id;
1889 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( (int) $cf->id ) ) );
1890 } else {
1891 $field_info = false;
1892 }
1893
1894 if ( isset( $request['field_type'] ) && $request['field_type'] != '' ) {
1895 $field_type = esc_attr( $request['field_type'] );
1896 } else {
1897 $field_type = $field_info->field_type;
1898 }
1899
1900 $field_site_name = '';
1901 if ( isset( $request['site_title'] ) ) {
1902 $field_site_name = $request['site_title'];
1903 }
1904
1905 if ( $field_info ) {
1906 $account_field_info = uwp_get_custom_field_info( $field_info->site_htmlvar_name );
1907 if ( isset( $account_field_info->site_title ) ) {
1908 if ( $account_field_info->field_type == 'fieldset' ) {
1909 $field_site_name = __( 'Fieldset:', 'userswp' ) . ' ' . $account_field_info->site_title;
1910 } else {
1911 $field_site_name = $account_field_info->site_title;
1912 }
1913 }
1914 $field_info = stripslashes_deep( $field_info ); // strip slashes
1915 }
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( $field_site_name ); ?></b>
1961 <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( ucfirst( $field_type ) ) . ')'; ?></span>
1962 </div>
1963 <div class="dd-handle ui-sortable-handle">
1964 <?php if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
1965 <i class="far fa-trash-alt text-danger ml-2 ms-2 c-pointer" id="delete-16"
1966 onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
1967 ></i>
1968 <?php } ?>
1969 <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
1970 </div>
1971 </div>
1972
1973 <div id="field_frm<?php echo esc_attr( $result_str ); ?>" class="field_frm" style="display:none;">
1974 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
1975 <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
1976 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1977 <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
1978 <input type="hidden" name="is_active" id="is_active" value="1"/>
1979 <ul class="widefat post fixed" style="width:100%;">
1980
1981 <input type="hidden" name="site_htmlvar_name" value="<?php echo esc_attr( $htmlvar_name ); ?>"/>
1982
1983 <li>
1984 <div class="uwp-input-wrap">
1985 <p><?php esc_html_e( 'No options available', 'userswp' ); ?></p>
1986 </div>
1987 </li>
1988
1989 <li>
1990 <div class="uwp-input-wrap">
1991 <?php if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
1992 <input type="button" class="button button-primary" name="save" id="save"
1993 value="<?php esc_attr_e( 'Save', 'userswp' ); ?>"
1994 onclick="save_field('<?php echo esc_js( $result_str ); ?>', 'register')"
1995 style="display: none;"/>
1996 <input type="button" name="delete"
1997 value="<?php esc_attr_e( 'Delete', 'userswp' ); ?>"
1998 onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
1999 class="button"/>
2000 <?php } ?>
2001
2002 </div>
2003 </li>
2004 </ul>
2005
2006 </div>
2007 </form>
2008 </li>
2009 <?php
2010 }
2011
2012 public function builder_extra_fields_smr( $output, $result_str, $cf, $field_info ) {
2013
2014 ob_start();
2015
2016 $value = '';
2017 if ( isset( $field_info->option_values ) ) {
2018 $value = esc_attr( $field_info->option_values );
2019 } elseif ( isset( $cf['defaults']['option_values'] ) && $cf['defaults']['option_values'] ) {
2020 $value = esc_attr( $cf['defaults']['option_values'] );
2021 }
2022
2023 $field_type = isset( $field_info->field_type ) ? $field_info->field_type : $cf['field_type'];
2024 $field_type_key = isset( $field_info->field_type_key ) ? $field_info->field_type_key : '';
2025 if ( ! $field_type_key ) {
2026 $field_type_key = isset( $_REQUEST['field_type_key'] ) ? esc_html( $_REQUEST['field_type_key'] ) : '';
2027 }
2028 ?>
2029 <div class="uwp-setting-name mb-3">
2030 <label for="option_values" class=" form-label">
2031 <?php
2032 $tip = __( 'Option Values should be separated by comma.', 'userswp' );
2033 if ( $field_type != 'multiselect' ) {
2034 $tip .= '<br/><small>' . __( 'If using for a tick filter place a / and then either a 1 for true or 0 for false', 'userswp' );
2035 $tip .= '<br/>' . __( 'eg: No Dogs Allowed/0,Dogs Allowed/1', 'userswp' ) . '</small>';
2036 }
2037 if ( $field_type == 'multiselect' || $field_type == 'select' ) {
2038 $tip .= '<br/><small>' . __( 'Like: Apple,Bannana,Pear,Peach', 'userswp' );
2039 $tip .= '<br/>' . __( 'Or you can show Selection/Value shown: Pets Allowed/Yes,Pets not Allowed/No', 'userswp' );
2040 $tip .= '<br/>' . __( '- If using OPTGROUP tag to grouping options, use {optgroup}OPTGROUP-LABEL|OPTION-1,OPTION-2{/optgroup}', 'userswp' );
2041 $tip .= '<br/>' . __( 'eg: {optgroup}Pets Allowed|No Dogs Allowed/0,Dogs Allowed/1{/optgroup},{optgroup}Sports|Cricket/Cricket,Football/Football,Hockey{/optgroup}', 'userswp' ) . '</small>';
2042 }
2043 ?>
2044 <?php
2045 echo uwp_help_tip( $tip ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2046 esc_html_e( 'Option Values :', 'userswp' );
2047 ?>
2048 </label>
2049 <div class="uwp-input-wrap">
2050
2051 <?php
2052 if ( isset( $field_type_key ) && $field_type_key == 'uwp_country' ) {
2053 // @todo here we should show a multiselect to either include or exclude countries
2054 echo aui()->alert(
2055 array(
2056 'type' => 'info',
2057 'content' => esc_html__( 'A full country list will be shown', 'userswp' ),
2058 )
2059 );
2060
2061 } elseif ( isset( $field_type_key ) && $field_type_key == 'uwp_language' ) {
2062 echo aui()->alert(
2063 array(
2064 'type' => 'info',
2065 'content' => esc_html__( 'Available translation languages list will be shown', 'userswp' ),
2066 )
2067 );
2068 } else {
2069 ?>
2070 <input type="text" name="option_values" id="option_values" class="form-control" value="<?php echo esc_attr( $value ); ?>"/>
2071 <?php } ?>
2072
2073 <br/>
2074
2075 </div>
2076 </div>
2077 <?php
2078
2079 $html = ob_get_clean();
2080
2081 return $output . $html;
2082 }
2083
2084 public function builder_extra_fields_datepicker( $output, $result_str, $cf, $field_info ) {
2085 ob_start();
2086 $extra = array();
2087 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2088 $extra = unserialize( $field_info->extra_fields );
2089 }
2090 ?>
2091 <div class="uwp-setting-name uwp-advanced-setting mb-3">
2092 <label for="date_format" class=" form-label">
2093 <?php
2094 echo uwp_help_tip( __( 'Select the date format.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2095 esc_html_e( 'Date Format :', 'userswp' );
2096 ?>
2097 </label>
2098 <div class="uwp-input-wrap" style="overflow:inherit;">
2099 <?php
2100 $date_formats = array(
2101 'm/d/Y',
2102 'd/m/Y',
2103 'Y/m/d',
2104 'm-d-Y',
2105 'd-m-Y',
2106 'Y-m-d',
2107 'F j, Y',
2108 );
2109
2110 $date_formats = apply_filters( 'uwp_date_formats', $date_formats );
2111 ?>
2112 <select name="extra[date_format]" id="date_format" class="aui-selectx2 form-select mw-100" >
2113 <?php
2114 foreach ( $date_formats as $format ) {
2115 $selected = false;
2116 if ( ! empty( $extra ) && esc_attr( $extra['date_format'] ) == $format ) {
2117 $selected = true;
2118 }
2119 echo '<option ' . selected( $selected, true, false ) . " value='" . esc_attr( $format ) . "'>" . esc_html( $format . ' (' . date_i18n( $format, time() ) . ')' ) . '</option>';
2120 }
2121 ?>
2122 </select>
2123
2124 </div>
2125 </div>
2126 <?php
2127
2128 $html = ob_get_clean();
2129
2130 return $output . $html;
2131 }
2132
2133 public function builder_extra_fields_password( $output, $result_str, $cf, $field_info ) {
2134 ob_start();
2135
2136 //confirm password field
2137 $extra = array();
2138 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2139 $extra = unserialize( $field_info->extra_fields );
2140 }
2141 $value = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '1';
2142 if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'password' ) {
2143
2144 echo '<div class="' . uwp_advanced_toggle_class() . '">';
2145 echo aui()->input(
2146 array(
2147 'id' => 'extra_confirm_password',
2148 'name' => 'extra[confirm_password]',
2149 'type' => 'checkbox',
2150 'label_type' => 'horizontal',
2151 'label_col' => '4',
2152 'label' => __( 'Display confirm password field', 'userswp' ),
2153 'checked' => $value,
2154 'value' => '1',
2155 'switch' => 'md',
2156 'label_force_left' => true,
2157 'help_text' => uwp_help_tip( __( 'Lets you display confirm password form field.', 'userswp' ) ),
2158 )
2159 );
2160 echo '</div>';
2161
2162 }
2163 $html = ob_get_clean();
2164
2165 return $output . $html;
2166 }
2167
2168 public function builder_extra_fields_email( $output, $result_str, $cf, $field_info ) {
2169 ob_start();
2170 //confirm email field
2171 $extra = array();
2172 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2173 $extra = unserialize( $field_info->extra_fields );
2174 }
2175 $value = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0';
2176
2177 if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'email' ) {
2178
2179 echo '<div class="' . uwp_advanced_toggle_class() . '">';
2180 echo aui()->input(
2181 array(
2182 'id' => 'extra_confirm_email',
2183 'name' => 'extra[confirm_email]',
2184 'type' => 'checkbox',
2185 'label_type' => 'horizontal',
2186 'label_col' => '4',
2187 'label' => __( 'Display confirm email field', 'userswp' ),
2188 'checked' => $value,
2189 'value' => '1',
2190 'switch' => 'md',
2191 'label_force_left' => true,
2192 'help_text' => uwp_help_tip( __( 'Lets you display confirm email form field.', 'userswp' ) ),
2193 )
2194 );
2195 echo '</div>';
2196
2197 }
2198 $html = ob_get_clean();
2199
2200 return $output . $html;
2201 }
2202
2203 public function builder_extra_fields_file( $output, $result_str, $cf, $field_info ) {
2204 ob_start();
2205
2206 $file_obj = new UsersWP_Files();
2207 $allowed_file_types = $file_obj->allowed_mime_types();
2208
2209 $extra_fields = isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ? maybe_unserialize( $field_info->extra_fields ) : '';
2210 $uwp_file_types = ! empty( $extra_fields ) && ! empty( $extra_fields['uwp_file_types'] ) ? $extra_fields['uwp_file_types'] : array( '*' );
2211 ?>
2212 <div class="uwp-setting-name uwp-advanced-setting mb-3">
2213 <label for="uwp_file_types" class="form-label">
2214 <?php
2215 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
2216 esc_html_e( 'Allowed file types :', 'userswp' );
2217 ?>
2218 </label>
2219 <div class="uwp-input-wrap">
2220 <select name="extra[uwp_file_types][]" id="uwp_file_types" multiple="multiple" class="aui-select2 form-select mw-100" >
2221 <option value="*" <?php selected( true, in_array( '*', $uwp_file_types ) ); ?>><?php esc_html_e( 'All types', 'userswp' ); ?></option>
2222 <?php foreach ( $allowed_file_types as $format => $types ) { ?>
2223 <optgroup
2224 label="<?php echo esc_attr( wp_sprintf( __( '%s formats', 'userswp' ), __( $format, 'userswp' ) ) ); ?>">
2225 <?php foreach ( $types as $ext => $type ) { ?>
2226 <option value="<?php echo esc_attr( $ext ); ?>" <?php selected( true, in_array( $ext, $uwp_file_types ) ); ?>><?php echo '.' . esc_html( $ext ); ?></option>
2227 <?php } ?>
2228 </optgroup>
2229 <?php } ?>
2230 </select>
2231 </div>
2232 </div>
2233 <?php
2234
2235 $html = ob_get_clean();
2236
2237 return $output . $html;
2238 }
2239
2240 public function builder_data_type_text( $output, $result_str, $cf, $field_info ) {
2241 ob_start();
2242
2243 $dt_value = '';
2244 if ( isset( $field_info->data_type ) ) {
2245 $dt_value = esc_attr( $field_info->data_type );
2246 } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
2247 $dt_value = $cf['defaults']['data_type'];
2248 }
2249
2250 // fix some values
2251 if ( $dt_value == 'VARCHAR' ) {
2252 $dt_value = 'XVARCHAR';
2253 }
2254
2255 echo aui()->select(
2256 array(
2257 'id' => 'data_type',
2258 'name' => 'data_type',
2259 'label_type' => 'top',
2260 'multiple' => false,
2261 'wrap_class' => uwp_advanced_toggle_class(),
2262 'class' => 'mw-100',
2263 'options' => array(
2264 'XVARCHAR' => __( 'CHARACTER', 'userswp' ),
2265 'INT' => __( 'NUMBER', 'userswp' ),
2266 'FLOAT' => __( 'DECIMAL', 'userswp' ),
2267 ),
2268 'label' => __( 'Data Type', 'userswp' ) . uwp_help_tip( __( 'Select Custom Field type', 'userswp' ) ),
2269 'value' => $dt_value,
2270 'extra_attributes' => array(
2271 'onchange' => "javascript:uwp_data_type_changed(this, '$result_str');",
2272 ),
2273 )
2274 );
2275
2276 $value = '';
2277 if ( isset( $field_info->decimal_point ) ) {
2278 $value = esc_attr( $field_info->decimal_point );
2279 } elseif ( isset( $cf['defaults']['decimal_point'] ) && $cf['defaults']['decimal_point'] ) {
2280 $value = $cf['defaults']['decimal_point'];
2281 }
2282
2283 echo aui()->select(
2284 array(
2285 'id' => 'decimal_point',
2286 'name' => 'decimal_point',
2287 'label_type' => 'top',
2288 'multiple' => false,
2289 'class' => ' mw-100',
2290 'options' => array(
2291 '' => __( 'Select', 'userswp' ),
2292 '1' => '1',
2293 '2' => '2',
2294 '3' => '3',
2295 '4' => '4',
2296 '5' => '5',
2297 '6' => '6',
2298 '7' => '7',
2299 '8' => '8',
2300 '9' => '9',
2301 '10' => '10',
2302 ),
2303 'label' => __( 'Decimal points', 'userswp' ) . uwp_help_tip( __( 'Decimals to display after point.', 'userswp' ) ),
2304 'value' => $value,
2305 'element_require' => '[%data_type%] == "FLOAT"',
2306 )
2307 );
2308
2309 $output = ob_get_clean();
2310
2311 return $output;
2312 }
2313
2314 public function advance_admin_custom_fields( $field_info, $cf ) {
2315 $hide_register_field = ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] === false ) ? "style='display:none;'" : '';
2316 $hide_register_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_field;
2317 $hide_user_sort = ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] === false ) ? "style='display:none;'" : '';
2318
2319 $value = 0;
2320 if ( isset( $field_info->is_register_field ) ) {
2321 $value = (int) $field_info->is_register_field;
2322 } elseif ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] ) {
2323 $value = ( $cf['defaults']['is_register_field'] ) ? 1 : 0;
2324 }
2325
2326 if ( isset( $field_info->htmlvar_name ) ) {
2327 $htmlvar_name = $field_info->htmlvar_name;
2328 } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
2329 $htmlvar_name = ( $cf['defaults']['htmlvar_name'] ) ? $cf['defaults']['htmlvar_name'] : '';
2330 }
2331
2332 //register only field
2333 $hide_register_only_field = ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] === false ) ? "style='display:none;'" : '';
2334 $hide_register_only_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_only_field;
2335 $register_only_value = 0;
2336 if ( isset( $field_info->is_register_only_field ) ) {
2337 $register_only_value = (int) $field_info->is_register_only_field;
2338 } elseif ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] ) {
2339 $register_only_value = ( $cf['defaults']['is_register_only_field'] ) ? 1 : 0;
2340 }
2341
2342 $user_sort_value = 0;
2343 if ( isset( $field_info->user_sort ) ) {
2344 $user_sort_value = (int) $field_info->user_sort;
2345 } elseif ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] ) {
2346 $user_sort_value = ( $cf['defaults']['user_sort'] ) ? 1 : 0;
2347 }
2348
2349 ?>
2350 <div <?php echo $hide_register_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name mb-3">
2351
2352 <?php
2353 $reg_only_fields = uwp_get_register_only_fields();
2354 if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2355 ?>
2356 <label for="is_register_field" class=" form-label">
2357 <?php
2358 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
2359 esc_html_e( 'Include this field in register form:', 'userswp' );
2360 ?>
2361 </label>
2362 <input type="hidden" name="is_register_field" value="1"/>
2363 <p><?php esc_html_e( 'This is mandatory register form field.', 'userswp' ); ?></p>
2364 <?php
2365 } else {
2366 echo aui()->input(
2367 array(
2368 'id' => 'is_register_field',
2369 'name' => 'is_register_field',
2370 'type' => 'checkbox',
2371 'label_type' => 'horizontal',
2372 'label_col' => '4',
2373 'label' => __( 'Include this field in register form', 'userswp' ),
2374 'checked' => $value,
2375 'value' => '1',
2376 'switch' => 'md',
2377 'label_force_left' => true,
2378 'help_text' => uwp_help_tip( __( 'Lets you use this field as register form field, set from register tab above.', 'userswp' ) ),
2379 )
2380 );
2381 }
2382 ?>
2383 </div>
2384
2385 <div <?php echo $hide_register_only_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-inconlyin-reg-form uwp-setting-name uwp-advanced-setting">
2386
2387
2388 <?php
2389 if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2390 ?>
2391 <label for="is_register_only_field" class="form-label">
2392 <?php
2393 echo uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2394 esc_html_e( 'Include this field ONLY in register form:', 'userswp' );
2395 ?>
2396 </label>
2397 <input type="hidden" name="is_register_only_field" class="form-control" value="1"/>
2398 <p><?php esc_html_e( 'This field is applicable only for register form.', 'userswp' ); ?></p>
2399 <?php
2400 } else {
2401 echo aui()->input(
2402 array(
2403 'id' => 'is_register_only_field',
2404 'name' => 'is_register_only_field',
2405 'type' => 'checkbox',
2406 'label_type' => 'horizontal',
2407 'label_col' => '4',
2408 'label' => __( 'Include this field ONLY in register form', 'userswp' ),
2409 'checked' => $register_only_value,
2410 'value' => '1',
2411 'switch' => 'md',
2412 'label_force_left' => true,
2413 'help_text' => uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ),
2414
2415 )
2416 );
2417
2418 }
2419 ?>
2420 </div>
2421
2422 <div <?php echo $hide_user_sort; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name uwp-advanced-setting">
2423 <?php
2424
2425 echo aui()->input(
2426 array(
2427 'id' => 'user_sort',
2428 'name' => 'user_sort',
2429 'type' => 'checkbox',
2430 'label_type' => 'horizontal',
2431 'label_col' => '4',
2432 'label' => __( 'Include this field in sorting options', 'userswp' ),
2433 'checked' => $user_sort_value,
2434 'value' => '1',
2435 'switch' => 'md',
2436 'label_force_left' => true,
2437 'help_text' => uwp_help_tip( __( 'Lets you use this field as sorting in the users listing page, set from user sorting tab above.', 'userswp' ) ),
2438
2439 )
2440 );
2441
2442 ?>
2443
2444 </div>
2445
2446 <?php
2447 }
2448
2449 public function return_empty_string() {
2450 return '';
2451 }
2452
2453 public function register_available_fields_head( $heading, $form_type ) {
2454 switch ( $form_type ) {
2455 case 'register':
2456 $heading = __( 'Available register form fields.', 'userswp' );
2457 break;
2458 }
2459
2460 return $heading;
2461 }
2462
2463 public function register_available_fields_note( $note, $form_type ) {
2464 switch ( $form_type ) {
2465 case 'register':
2466 $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' );
2467 break;
2468 }
2469
2470 return $note;
2471 }
2472
2473 public function register_selected_fields_head( $heading, $form_type ) {
2474 switch ( $form_type ) {
2475 case 'register':
2476 $heading = __( 'List of fields that will appear in the register form.', 'userswp' );
2477 break;
2478
2479 }
2480
2481 return $heading;
2482 }
2483
2484 public function register_selected_fields_note( $note, $form_type ) {
2485 switch ( $form_type ) {
2486 case 'register':
2487 $note = __( 'Click to expand and view field related settings. You may drag and drop to arrange fields order in register form.', 'userswp' );
2488 break;
2489
2490 }
2491
2492 return $note;
2493 }
2494
2495 /**
2496 * Handles the create custom field ajax request.
2497 *
2498 * @since 1.0.0
2499 * @package userswp
2500 * @return void
2501 */
2502 public function create_field() {
2503
2504 if ( ! current_user_can( 'manage_options' ) ) {
2505 wp_die( -1 );
2506 }
2507
2508 $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
2509 $field_type = isset( $_REQUEST['field_type'] ) ? sanitize_text_field( $_REQUEST['field_type'] ) : '';
2510 $field_type_key = isset( $_REQUEST['field_type_key'] ) ? sanitize_text_field( $_REQUEST['field_type_key'] ) : '';
2511 $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
2512 $field_id = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
2513 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 1;
2514
2515 $field_id = $field_id != '' ? trim( $field_id, '_' ) : $field_id;
2516
2517 $field_ids = array();
2518 if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
2519 foreach ( $_REQUEST['licontainer'] as $lic_id ) {
2520 $field_ids[] = sanitize_text_field( $lic_id );
2521 }
2522 }
2523
2524 /* ------- check nonce field ------- */
2525 if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2526 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_create_field_nonce' ) ) {
2527 return;
2528 }
2529 echo $this->set_field_order( $field_ids, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2530 }
2531
2532 /* ---- Show field form in admin ---- */
2533 if ( $field_type != '' && $field_id != '' && $field_action == 'new' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2534 $this->form_field_adminhtml( $field_type, $field_id, $field_action, $field_type_key, $form_type );
2535 }
2536
2537 /* ---- Delete field ---- */
2538 if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2539 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_delete_' . $field_id ) ) {
2540 return;
2541 }
2542
2543 echo $this->admin_form_field_delete( $field_id, true, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2544 }
2545
2546 /* ---- Save field ---- */
2547 if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2548 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_' . $field_id ) ) {
2549 return;
2550 }
2551
2552 foreach ( $_REQUEST as $pkey => $pval ) {
2553 if ( isset( $_REQUEST[ $pkey ] ) && is_array( $_REQUEST[ $pkey ] ) ) {
2554 $tags = 'skip_field';
2555 } else {
2556 $tags = '';
2557 }
2558
2559 if ( $tags != 'skip_field' && !empty( $_REQUEST[ $pkey ] ) ) {
2560 $_REQUEST[ $pkey ] = strip_tags( $_REQUEST[ $pkey ], $tags );
2561 }
2562 }
2563
2564 $return = $this->admin_form_field_save( $_REQUEST );
2565
2566 if ( is_int( $return ) ) {
2567 $lastid = $return;
2568 $this->form_field_adminhtml( $field_type, $lastid, 'submit', $field_type_key, $form_type );
2569 } else {
2570 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2571 }
2572 }
2573
2574 wp_die();
2575 }
2576
2577 public function set_field_order( $field_ids = array(), $form_id = 1 ) {
2578
2579 global $wpdb;
2580
2581 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2582
2583 $count = 0;
2584 if ( ! empty( $field_ids ) ) :
2585 $user_meta_info = false;
2586 foreach ( $field_ids as $id ) {
2587
2588 $cf = trim( $id, '_' );
2589
2590 $user_meta_info = $wpdb->query(
2591 $wpdb->prepare(
2592 'update ' . $table_name . ' set
2593 sort_order=%d
2594 where id= %d and form_id = %d',
2595 array( $count, $cf, $form_id )
2596 )
2597 );
2598 ++$count;
2599 }
2600
2601 return $user_meta_info;
2602 else :
2603 return false;
2604 endif;
2605 }
2606
2607 public function admin_form_field_delete( $field_id = '', $delete_meta = true, $form_id = 1 ) {
2608
2609 global $wpdb;
2610
2611 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2612 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2613 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2614
2615 if ( $field_id != '' ) {
2616 $cf = trim( $field_id, '_' );
2617
2618 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 ) ) ) ) {
2619
2620 $excluded_delete = array( 'email' );
2621 $excluded_delete = apply_filters( 'uwp_register_fields_exculde_delete', $excluded_delete );
2622
2623 if ( isset( $field->htmlvar_name ) && in_array( $field->htmlvar_name, $excluded_delete ) ) {
2624 return $field_id;
2625 }
2626
2627 // delete the meta column
2628 if ( isset( $field->htmlvar_name ) && $delete_meta ) {
2629 $register_forms = uwp_get_option( 'multiple_registration_forms' );
2630 $custom_fields = array();
2631
2632 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
2633 foreach ( $register_forms as $key => $register_form ) {
2634 $form_ids[] = (int) $register_form['id'];
2635 }
2636
2637 if ( isset( $form_ids ) && count( $form_ids ) > 0 ) {
2638 $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%d' );
2639 $form_ids_placeholder = implode( ', ', $form_ids_placeholder );
2640 $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 );
2641 $custom_fields = $wpdb->get_results( $query );
2642 }
2643 }
2644
2645 if ( isset( $custom_fields ) && ! empty( $custom_fields ) && count( $custom_fields ) > 1 ) {
2646 // Do not delete user meta column if field used in more than one form.
2647 } else {
2648 $col_name = sanitize_sql_orderby( $field->htmlvar_name );
2649 $wpdb->query( "ALTER TABLE `{$meta_table}` DROP COLUMN `{$col_name}`" );
2650 }
2651 }
2652
2653 $wpdb->query( $wpdb->prepare( 'delete from ' . $table_name . ' where id= %d AND form_id = %d', array( $cf, $form_id ) ) );
2654
2655 // Also delete register form field
2656 $wpdb->query( $wpdb->prepare( 'delete from ' . $extras_table_name . ' where site_htmlvar_name= %s AND form_id = %d ', array( $field->htmlvar_name, $form_id ) ) );
2657
2658 do_action( 'uwp_after_custom_field_deleted', $cf, $field );
2659
2660 return $field_id;
2661 } else {
2662 return 0;
2663 }
2664 } else {
2665 return 0;
2666 }
2667 }
2668
2669 public function admin_form_field_save( $request_field = array() ) {
2670
2671 global $wpdb;$wpdb->show_errors();
2672
2673 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2674
2675 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2676
2677 $old_html_variable = '';
2678
2679 $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
2680 $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : 1;
2681
2682 $user_meta_info = null;
2683
2684 // some servers fail if a POST value is VARCHAR so we change it.
2685 if ( isset( $request_field['data_type'] ) && $request_field['data_type'] == 'XVARCHAR' ) {
2686 $request_field['data_type'] = 'VARCHAR';
2687 }
2688
2689 $cf = trim( $result_str, '_' );
2690
2691 $cehhtmlvar_name = isset( $request_field['htmlvar_name'] ) ? $request_field['htmlvar_name'] : '';
2692 $form_type = $request_field['form_type'];
2693
2694 $old_html_variable_name = 'uwp_account_' . $cehhtmlvar_name;
2695 $check_old_html_variable = $wpdb->get_var(
2696 $wpdb->prepare(
2697 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2698 array( $cf, $old_html_variable_name, $form_type, $form_id )
2699 )
2700 );
2701
2702 $check_html_variable = $wpdb->get_var(
2703 $wpdb->prepare(
2704 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2705 array( $cf, $cehhtmlvar_name, $form_type, $form_id )
2706 )
2707 );
2708
2709 if ( ( ! $check_old_html_variable && ! $check_html_variable ) || $request_field['field_type'] == 'fieldset' ) {
2710
2711 if ( $cf != '' ) {
2712
2713 $user_meta_info = $wpdb->get_row(
2714 $wpdb->prepare(
2715 'select * from ' . $table_name . ' where id = %d',
2716 array( $cf )
2717 )
2718 );
2719
2720 }
2721
2722 if ( ! empty( $user_meta_info ) ) {
2723 $old_html_variable = $user_meta_info->htmlvar_name;
2724
2725 }
2726
2727 $site_title = sanitize_text_field( $request_field['site_title'] );
2728 $form_label = isset( $request_field['form_label'] ) ? sanitize_text_field( $request_field['form_label'] ) : '';
2729 $help_text = isset( $request_field['help_text'] ) ? sanitize_text_field( $request_field['help_text'] ) : '';
2730 $field_type = sanitize_text_field( $request_field['field_type'] );
2731 $data_type = sanitize_text_field( $request_field['data_type'] );
2732 $field_type_key = isset( $request_field['field_type_key'] ) ? sanitize_text_field( $request_field['field_type_key'] ) : $field_type;
2733 $htmlvar_name = isset( $request_field['htmlvar_name'] ) ? str_replace(
2734 array(
2735 '-',
2736 ' ',
2737 '"',
2738 "'",
2739 ),
2740 array( '_', '', '', '' ),
2741 sanitize_title_with_dashes( $request_field['htmlvar_name'] )
2742 ) : null;
2743 $default_value = isset( $request_field['default_value'] ) ? sanitize_text_field( $request_field['default_value'] ) : '';
2744 $sort_order = isset( $request_field['sort_order'] ) ? absint( $request_field['sort_order'] ) : '';
2745 $is_active = isset( $request_field['is_active'] ) ? absint( $request_field['is_active'] ) : 1;
2746 $placeholder_value = isset( $request_field['placeholder_value'] ) ? $request_field['placeholder_value'] : '';
2747 $for_admin_use = isset( $request_field['for_admin_use'] ) ? absint( $request_field['for_admin_use'] ) : 0;
2748 $is_required = isset( $request_field['is_required'] ) ? absint( $request_field['is_required'] ) : 0;
2749 $is_dummy = isset( $request_field['is_dummy'] ) ? absint( $request_field['is_dummy'] ) : 0;
2750 $is_public = isset( $request_field['is_public'] ) ? absint( $request_field['is_public'] ) : 0;
2751 $is_default = isset( $request_field['is_default'] ) ? absint( $request_field['is_default'] ) : 0;
2752 $is_register_field = isset( $request_field['is_register_field'] ) ? absint( $request_field['is_register_field'] ) : 0;
2753 $is_search_field = isset( $request_field['is_search_field'] ) ? absint( $request_field['is_search_field'] ) : 0;
2754 $is_register_only_field = isset( $request_field['is_register_only_field'] ) ? absint( $request_field['is_register_only_field'] ) : 0;
2755 $required_msg = isset( $request_field['required_msg'] ) ? sanitize_text_field( $request_field['required_msg'] ) : '';
2756 $css_class = isset( $request_field['css_class'] ) ? sanitize_text_field( $request_field['css_class'] ) : '';
2757 $field_icon = isset( $request_field['field_icon'] ) ? sanitize_text_field( $request_field['field_icon'] ) : '';
2758 $show_in = isset( $request_field['show_in'] ) ? $request_field['show_in'] : '';
2759 $user_roles = isset( $request_field['user_roles'] ) ? $request_field['user_roles'] : '';
2760 $decimal_point = isset( $request_field['decimal_point'] ) ? absint( $request_field['decimal_point'] ) : ''; // decimal point for DECIMAL data type
2761 $decimal_point = $decimal_point > 0 ? ( $decimal_point > 10 ? 10 : $decimal_point ) : '';
2762 $validation_pattern = isset( $request_field['validation_pattern'] ) ? sanitize_text_field( $request_field['validation_pattern'] ) : '';
2763 $validation_msg = isset( $request_field['validation_msg'] ) ? sanitize_text_field( $request_field['validation_msg'] ) : '';
2764 $user_sort = isset( $request_field['user_sort'] ) ? absint( $request_field['user_sort'] ) : 0;
2765
2766 if ( empty( $htmlvar_name ) ) {
2767 $htmlvar_name = sanitize_key(
2768 str_replace(
2769 array( '-', ' ', '"', "'" ),
2770 array(
2771 '_',
2772 '_',
2773 '',
2774 '',
2775 ),
2776 $request_field['site_title']
2777 )
2778 );
2779 if ( str_replace( '_', '', $htmlvar_name ) != '' ) {
2780 $htmlvar_name = substr( $htmlvar_name, 0, 50 );
2781 } else {
2782 $htmlvar_name = time();
2783 }
2784 }
2785
2786 if ( is_array( $show_in ) ) {
2787 $show_in = implode( ',', $request_field['show_in'] );
2788 $show_in = sanitize_text_field( $show_in );
2789 }
2790
2791 if ( is_array( $user_roles ) ) {
2792 $user_roles = implode( ',', $request_field['user_roles'] );
2793 $user_roles = sanitize_text_field( $user_roles );
2794 }
2795
2796 $option_values = '';
2797 if ( isset( $request_field['option_values'] ) ) {
2798 $option_values = $request_field['option_values'];
2799 }
2800
2801 if ( isset( $request_field['extra'] ) && ! empty( $request_field['extra'] ) ) {
2802 $extra_fields = $request_field['extra'];
2803 }
2804
2805 if ( $sort_order == '' ) {
2806
2807 $last_order = $wpdb->get_var( 'SELECT MAX(sort_order) as last_order FROM ' . $table_name );
2808
2809 $sort_order = (int) $last_order + 1;
2810 }
2811
2812 if ( ! empty( $user_meta_info ) ) {
2813
2814 $excluded = uwp_get_excluded_fields();
2815
2816 if ( ! in_array( $htmlvar_name, $excluded ) ) {
2817 // Create custom columns
2818 switch ( $field_type ) :
2819
2820 case 'checkbox':
2821 case 'multiselect':
2822 case 'select':
2823 $op_size = '500';
2824
2825 // only make the field as big as it needs to be.
2826 if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
2827 $option_values_arr = explode( ',', $option_values );
2828 if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
2829 $op_max = 0;
2830 foreach ( $option_values_arr as $op_val ) {
2831 if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
2832 $op_max = strlen( $op_val );
2833 }
2834 }
2835 if ( $op_max ) {
2836 $op_size = $op_max;
2837 }
2838 }
2839 } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
2840 if ( strlen( $option_values ) ) {
2841 $op_size = strlen( $option_values );
2842 }
2843 }
2844
2845 $meta_field_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . "`VARCHAR( $op_size ) NULL";
2846
2847 if ( $default_value != '' ) {
2848 $meta_field_add .= " DEFAULT '" . $default_value . "'";
2849 }
2850
2851 $alter_result = $wpdb->query( $meta_field_add );
2852 if ( $alter_result === false ) {
2853 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2854 }
2855
2856 if ( isset( $request_field['cat_display_type'] ) ) {
2857 $extra_fields = $request_field['cat_display_type'];
2858 }
2859
2860 if ( isset( $request_field['multi_display_type'] ) ) {
2861 $extra_fields = $request_field['multi_display_type'];
2862 }
2863
2864 break;
2865
2866 case 'textarea':
2867 case 'editor':
2868 case 'url':
2869 case 'file':
2870 $alter_result = $wpdb->query( 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` TEXT NULL' );
2871 if ( $alter_result === false ) {
2872 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2873 }
2874 if ( isset( $request_field['advanced_editor'] ) ) {
2875 $extra_fields = $request_field['advanced_editor'];
2876 }
2877
2878 break;
2879
2880 case 'fieldset':
2881 // Nothing happened for fieldset
2882 break;
2883
2884 default:
2885 if ( $data_type != 'VARCHAR' && $data_type != '' ) {
2886 if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
2887 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` DECIMAL(11, ' . (int) $decimal_point . ') NULL';
2888 } else {
2889 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` ' . $data_type . ' NULL';
2890 }
2891
2892 if ( is_numeric( $default_value ) && $default_value != '' ) {
2893 $default_value_add .= " DEFAULT '" . $default_value . "'";
2894 }
2895 } else {
2896 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` VARCHAR( 254 ) NULL';
2897 if ( $default_value != '' ) {
2898 $default_value_add .= " DEFAULT '" . $default_value . "'";
2899 }
2900 }
2901
2902 $alter_result = $wpdb->query( $default_value_add );
2903 if ( $alter_result === false ) {
2904 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2905 }
2906 break;
2907 endswitch;
2908 }
2909
2910 $extra_field_query = '';
2911 if ( ! empty( $extra_fields ) ) {
2912 $extra_field_query = serialize( $extra_fields );
2913 }
2914
2915 $wpdb->query(
2916 $wpdb->prepare(
2917 'update ' . $table_name . ' set
2918 form_type = %s,
2919 site_title = %s,
2920 form_label = %s,
2921 help_text = %s,
2922 field_type = %s,
2923 data_type = %s,
2924 decimal_point = %s,
2925 field_type_key = %s,
2926 htmlvar_name = %s,
2927 default_value = %s,
2928 sort_order = %s,
2929 is_active = %s,
2930 placeholder_value = %s,
2931 for_admin_use = %s,
2932 is_default = %s,
2933 is_required = %s,
2934 is_dummy = %s,
2935 is_public = %s,
2936 is_register_field = %s,
2937 is_search_field = %s,
2938 is_register_only_field = %s,
2939 required_msg = %s,
2940 css_class = %s,
2941 field_icon = %s,
2942 show_in = %s,
2943 user_roles = %s,
2944 option_values = %s,
2945 extra_fields = %s,
2946 validation_pattern = %s,
2947 validation_msg = %s,
2948 form_id = %d,
2949 user_sort = %s
2950 where id = %d',
2951 array(
2952 $form_type,
2953 $site_title,
2954 $form_label,
2955 $help_text,
2956 $field_type,
2957 $data_type,
2958 $decimal_point,
2959 $field_type_key,
2960 $htmlvar_name,
2961 $default_value,
2962 $sort_order,
2963 $is_active,
2964 $placeholder_value,
2965 $for_admin_use,
2966 $is_default,
2967 $is_required,
2968 $is_dummy,
2969 $is_public,
2970 $is_register_field,
2971 $is_search_field,
2972 $is_register_only_field,
2973 $required_msg,
2974 $css_class,
2975 $field_icon,
2976 $show_in,
2977 $user_roles,
2978 $option_values,
2979 $extra_field_query,
2980 $validation_pattern,
2981 $validation_msg,
2982 $form_id,
2983 $user_sort,
2984 $cf,
2985 )
2986 )
2987 );
2988
2989 $lastid = trim( $cf );
2990
2991 do_action( 'uwp_after_custom_fields_updated', $lastid );
2992
2993 } else {
2994
2995 switch ( $field_type ) :
2996
2997 case 'checkbox':
2998 $data_type = 'TINYINT';
2999
3000 $meta_field_add = $data_type . '( 1 ) NOT NULL ';
3001 if ( (int) $default_value === 1 ) {
3002 $meta_field_add .= " DEFAULT '1'";
3003 }
3004
3005 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3006 if ( $add_result === false ) {
3007 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3008 }
3009 break;
3010 case 'multiselect':
3011 case 'select':
3012 $data_type = 'VARCHAR';
3013 $op_size = '500';
3014
3015 // only make the field as big as it needs to be.
3016 if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
3017 $option_values_arr = explode( ',', $option_values );
3018
3019 if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
3020 $op_max = 0;
3021
3022 foreach ( $option_values_arr as $op_val ) {
3023 if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
3024 $op_max = strlen( $op_val );
3025 }
3026 }
3027
3028 if ( $op_max ) {
3029 $op_size = $op_max;
3030 }
3031 }
3032 } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
3033 if ( strlen( $option_values ) ) {
3034 $op_size = strlen( $option_values );
3035 }
3036
3037 if ( isset( $request_field['multi_display_type'] ) ) {
3038 $extra_fields = $request_field['multi_display_type'];
3039 }
3040 }
3041
3042 $meta_field_add = $data_type . "( $op_size ) NULL ";
3043 if ( $default_value != '' ) {
3044 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3045 }
3046
3047 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3048 if ( $add_result === false ) {
3049 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3050 }
3051 break;
3052 case 'textarea':
3053 case 'editor':
3054 case 'url':
3055 case 'file':
3056 $data_type = 'TEXT';
3057
3058 $meta_field_add = $data_type . ' NULL ';
3059
3060 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3061 if ( $add_result === false ) {
3062 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3063 }
3064
3065 break;
3066
3067 case 'datepicker':
3068 $data_type = 'DATE';
3069
3070 $meta_field_add = $data_type . ' NULL ';
3071
3072 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3073 if ( $add_result === false ) {
3074 return __( 'Column creation failed, you may have too many columns or the default value must have in valid date format.', 'userswp' );
3075 }
3076
3077 break;
3078
3079 case 'time':
3080 $data_type = 'TIME';
3081
3082 $meta_field_add = $data_type . ' NULL ';
3083
3084 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3085 if ( $add_result === false ) {
3086 return __( 'Column creation failed, you may have too many columns or the default value must have in valid time format.', 'userswp' );
3087 }
3088
3089 break;
3090
3091 default:
3092 if ( $data_type != 'VARCHAR' && $data_type != '' ) {
3093 $meta_field_add = $data_type . ' NULL ';
3094
3095 if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
3096 $meta_field_add = 'DECIMAL(11, ' . (int) $decimal_point . ') NULL ';
3097 }
3098
3099 if ( is_numeric( $default_value ) && $default_value != '' ) {
3100 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3101 }
3102 } else {
3103 $meta_field_add = ' VARCHAR( 254 ) NULL ';
3104
3105 if ( $default_value != '' ) {
3106 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3107 }
3108 }
3109
3110 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3111 if ( $add_result === false ) {
3112 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3113 }
3114 break;
3115 endswitch;
3116
3117 $extra_field_query = '';
3118 if ( ! empty( $extra_fields ) ) {
3119 $extra_field_query = serialize( $extra_fields );
3120 }
3121
3122 $wpdb->query(
3123 $wpdb->prepare(
3124 'insert into ' . $table_name . ' set
3125 form_type = %s,
3126 site_title = %s,
3127 form_label = %s,
3128 help_text = %s,
3129 field_type = %s,
3130 data_type = %s,
3131 decimal_point = %s,
3132 field_type_key = %s,
3133 htmlvar_name = %s,
3134 default_value = %s,
3135 sort_order = %d,
3136 is_active = %s,
3137 placeholder_value = %s,
3138 for_admin_use = %s,
3139 is_default = %s,
3140 is_required = %s,
3141 is_dummy = %s,
3142 is_public = %s,
3143 is_register_field = %s,
3144 is_search_field = %s,
3145 is_register_only_field = %s,
3146 required_msg = %s,
3147 css_class = %s,
3148 field_icon = %s,
3149 show_in = %s,
3150 user_roles = %s,
3151 option_values = %s,
3152 extra_fields = %s,
3153 validation_pattern = %s,
3154 validation_msg = %s,
3155 form_id = %d,
3156 user_sort = %s ',
3157 array(
3158 $form_type,
3159 $site_title,
3160 $form_label,
3161 $help_text,
3162 $field_type,
3163 $data_type,
3164 $decimal_point,
3165 $field_type_key,
3166 $htmlvar_name,
3167 $default_value,
3168 $sort_order,
3169 $is_active,
3170 $placeholder_value,
3171 $for_admin_use,
3172 $is_default,
3173 $is_required,
3174 $is_dummy,
3175 $is_public,
3176 $is_register_field,
3177 $is_search_field,
3178 $is_register_only_field,
3179 $required_msg,
3180 $css_class,
3181 $field_icon,
3182 $show_in,
3183 $user_roles,
3184 $option_values,
3185 $extra_field_query,
3186 $validation_pattern,
3187 $validation_msg,
3188 $form_id,
3189 $user_sort,
3190 )
3191 )
3192 );
3193
3194 $lastid = $wpdb->insert_id;
3195
3196 $lastid = trim( $lastid );
3197
3198 }
3199
3200 return (int) $lastid;
3201
3202 } else {
3203 return 'invalid_key';
3204 }
3205 }
3206
3207 public function register_ajax_handler() {
3208 if ( isset( $_REQUEST['create_field'] ) ) {
3209
3210 if ( ! current_user_can( 'manage_options' ) ) {
3211 wp_die( -1 );
3212 }
3213
3214 $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_text_field( $_REQUEST['form_id'] ) : 1;
3215 $field_id = isset( $_REQUEST['field_id'] ) ? trim( sanitize_text_field( $_REQUEST['field_id'] ), '_' ) : '';
3216 $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
3217
3218 /* ------- update order of fields ------- */
3219 if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['_wpnonce'] )) {
3220 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_create_field_nonce' ) ) {
3221 return;
3222 }
3223
3224 $field_ids = array();
3225 if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
3226 foreach ( $_REQUEST['licontainer'] as $lic_id ) {
3227 $field_ids[] = sanitize_text_field( $lic_id );
3228 }
3229 }
3230
3231 $return = uwp_form_extras_field_order( $field_ids, 'register', $form_id );
3232
3233 if ( is_array( $return ) ) {
3234 $return = json_encode( $return );
3235 }
3236
3237 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3238 }
3239
3240 /* ---- Show field form in admin ---- */
3241 if ( $field_action == 'new' ) {
3242 $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
3243 $fields = $this->register_fields( $form_type, $form_id );
3244
3245 $_REQUEST['site_field_id'] = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
3246 $_REQUEST['is_default'] = '0';
3247
3248 if ( ! empty( $fields ) ) {
3249 foreach ( $fields as $val ) {
3250 $val = stripslashes_deep( $val );
3251
3252 if ( $val['htmlvar_name'] == $_REQUEST['htmlvar_name'] ) {
3253 $_REQUEST['field_type'] = $val['field_type'];
3254 $_REQUEST['site_title'] = $val['site_title'];
3255 }
3256 }
3257 }
3258
3259 $htmlvar_name = isset( $_REQUEST['htmlvar_name'] ) ? sanitize_text_field( $_REQUEST['htmlvar_name'] ) : '';
3260
3261 $this->register_field_adminhtml( $htmlvar_name, $field_action, false, $_REQUEST );
3262 }
3263
3264 /* ---- Delete field ---- */
3265 if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) ) {
3266 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3267 return;
3268 }
3269
3270 echo $this->register_field_delete( $field_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3271 }
3272
3273 /* ---- Save field ---- */
3274 if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) ) {
3275 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3276 return;
3277 }
3278
3279 foreach ( $_REQUEST as $pkey => $pval ) {
3280 $tags = is_array( $_REQUEST[ $pkey ] ) ? 'skip_field' : '';
3281
3282 if ( $tags != 'skip_field' ) {
3283 $_REQUEST[ $pkey ] = strip_tags( sanitize_text_field( $_REQUEST[ $pkey ] ), $tags );
3284 }
3285 }
3286
3287 $return = $this->register_field_save( $_REQUEST );
3288
3289 if ( is_int( $return ) ) {
3290 $lastid = $return;
3291
3292 $this->register_field_adminhtml( $lastid, 'submit' );
3293 } else {
3294 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3295 }
3296 }
3297 }
3298 die();
3299 }
3300
3301 public function register_field_delete( $field_id = '' ) {
3302
3303 global $wpdb;
3304 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3305
3306 if ( $field_id != '' ) {
3307 $cf = trim( $field_id, '_' );
3308
3309 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $extras_table_name . ' WHERE id= %d ', array( $cf ) ) );
3310
3311 return $field_id;
3312
3313 } else {
3314 return 0;
3315 }
3316 }
3317
3318 public function register_field_save( $request_field = array() ) {
3319
3320 if ( ! current_user_can( 'manage_options' ) ) {
3321 wp_die( -1 );
3322 }
3323
3324 global $wpdb;
3325 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3326
3327 $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : '';
3328 $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
3329
3330 $cf = trim( $result_str, '_' );
3331
3332 /*-------- check duplicate validation --------*/
3333
3334 $site_htmlvar_name = isset( $request_field['site_htmlvar_name'] ) ? sanitize_text_field( $request_field['site_htmlvar_name'] ) : sanitize_text_field( $request_field['htmlvar_name'] );
3335 $form_type = $request_field['form_type'];
3336 $field_type = $request_field['field_type'];
3337
3338 $check_html_variable = $wpdb->get_var(
3339 $wpdb->prepare(
3340 'select site_htmlvar_name from ' . $extras_table_name . ' where id <> %d and site_htmlvar_name = %s and form_type = %s and form_id=%d',
3341 array( $cf, $site_htmlvar_name, $form_type, $form_id )
3342 )
3343 );
3344
3345 if ( ! $check_html_variable ) {
3346
3347 if ( $cf != '' ) {
3348
3349 $user_meta_info = $wpdb->get_row(
3350 $wpdb->prepare(
3351 'select * from ' . $extras_table_name . ' where id = %d',
3352 array( $cf )
3353 )
3354 );
3355
3356 }
3357
3358 if ( $form_type == '' ) {
3359 $form_type = 'register';
3360 }
3361
3362 $site_htmlvar_name = sanitize_text_field( $request_field['site_htmlvar_name'] );
3363 $field_id = ( isset( $request_field['field_id'] ) && $request_field['field_id'] ) ? str_replace( 'new', '', $request_field['field_id'] ) : '';
3364
3365 if ( ! empty( $user_meta_info ) ) {
3366
3367 $wpdb->query(
3368 $wpdb->prepare(
3369 'update ' . $extras_table_name . ' set
3370 form_type = %s,
3371 field_type = %s,
3372 site_htmlvar_name = %s,
3373 sort_order = %s,
3374 form_id = %d
3375 where id = %d',
3376 array(
3377 $form_type,
3378 $field_type,
3379 $site_htmlvar_name,
3380 $field_id,
3381 $form_id,
3382 $cf,
3383 )
3384 )
3385 );
3386
3387 $lastid = trim( $cf );
3388
3389 } else {
3390
3391 $wpdb->query(
3392 $wpdb->prepare(
3393 'insert into ' . $extras_table_name . ' set
3394 form_type = %s,
3395 field_type = %s,
3396 site_htmlvar_name = %s,
3397 sort_order = %s,
3398 form_id = %s',
3399 array(
3400 $form_type,
3401 $field_type,
3402 $site_htmlvar_name,
3403 $field_id,
3404 $form_id,
3405 )
3406 )
3407 );
3408 $lastid = $wpdb->insert_id;
3409 $lastid = trim( $lastid );
3410 }
3411
3412 return (int) $lastid;
3413
3414 } else {
3415 return 'invalid_key';
3416 }
3417 }
3418 }
3419