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

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

3,420 lines 141.4 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( uwp_ucwords( __( 'Fieldset:', 'userswp' ) ) ); ?></b>
1220 <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $field_site_title ) ) . ')'; ?></span>
1221 <?php } else { ?>
1222 <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1223 <b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_title ) ); ?></b>
1224 <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $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
1477 echo apply_filters( "uwp_builder_is_public_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1478
1479 } else {
1480 $value = '';
1481 if ( isset( $field_info->is_public ) ) {
1482 $value = esc_attr( $field_info->is_public );
1483 } elseif ( isset( $cf['defaults']['is_public'] ) && $cf['defaults']['is_public'] ) {
1484 $value = $cf['defaults']['is_public'];
1485 }
1486
1487 echo aui()->select(
1488 array(
1489 'id' => 'is_public',
1490 'name' => 'is_public',
1491 'label_type' => 'top',
1492 'multiple' => false,
1493 'class' => ' mw-100',
1494 'options' => array(
1495 '1' => __( 'Yes', 'userswp' ),
1496 '0' => __( 'No', 'userswp' ),
1497 '2' => __( 'Let User Decide', 'userswp' ),
1498 ),
1499 'label' => __( 'Is Public', 'userswp' ) . uwp_help_tip( __( 'If no is selected then the field will not be visible to other users.', 'userswp' ) ),
1500 'value' => $value,
1501 'wrap_class' => uwp_advanced_toggle_class(),
1502 )
1503 );
1504
1505 }
1506
1507 // default_value
1508 if ( has_filter( "uwp_builder_default_value_{$field_type}" ) ) {
1509
1510 echo apply_filters( "uwp_builder_default_value_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1511
1512 } else {
1513 $value = '';
1514 if ( isset( $field_info->default_value ) ) {
1515 $value = esc_attr( $field_info->default_value );
1516 } elseif ( isset( $cf['defaults']['default_value'] ) && $cf['defaults']['default_value'] ) {
1517 $value = $cf['defaults']['default_value'];
1518 }
1519
1520 // tip text
1521 if ( $field_type == 'checkbox' ) {
1522 $tip = __( 'Should the checkbox be checked by default?', 'userswp' );
1523 } elseif ( $field_type == 'email' ) {
1524 $tip = __( 'A default value for the field, usually blank. Ex: info@mysite.com', 'userswp' );
1525 } else {
1526 $tip = __( 'A default value for the field, usually blank. (for links this will be used as the link text)', 'userswp' );
1527 }
1528
1529 if ( $field_type == 'checkbox' ) {
1530 echo aui()->select(
1531 array(
1532 'id' => 'default_value',
1533 'name' => 'default_value',
1534 'label_type' => 'top',
1535 'multiple' => false,
1536 'class' => ' mw-100',
1537 'options' => array(
1538 '' => __( 'Unchecked', 'userswp' ),
1539 '1' => __( 'Checked', 'userswp' ),
1540 ),
1541 'label' => __( 'Default value', 'userswp' ) . uwp_help_tip( $tip ),
1542 'value' => $value,
1543 'wrap_class' => uwp_advanced_toggle_class(),
1544 )
1545 );
1546 } else {
1547 echo aui()->input(
1548 array(
1549 'id' => 'default_value',
1550 'name' => 'default_value',
1551 'label_type' => 'top',
1552 'label' => __( 'Default value', 'userswp' ) . uwp_help_tip( $tip ),
1553 'type' => 'text',
1554 'wrap_class' => uwp_advanced_toggle_class(),
1555 'value' => $value,
1556 'placeholder' => $field_type == 'email' ? __( 'info@mysite.com', 'userswp' ) : '',
1557 )
1558 );
1559 }
1560 }
1561
1562 // advanced_editor
1563 if ( has_filter( "uwp_builder_advanced_editor_{$field_type}" ) ) {
1564
1565 echo apply_filters( "uwp_builder_advanced_editor_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1566
1567 }
1568 ?>
1569 <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 ) : ''; ?>"/>
1570 <?php
1571
1572 // is_required
1573 if ( has_filter( "uwp_builder_is_required_{$field_type}" ) ) {
1574
1575 echo apply_filters( "uwp_builder_is_required_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1576
1577 } else {
1578 $value = '';
1579 if ( isset( $field_info->is_required ) ) {
1580 $value = esc_attr( $field_info->is_required );
1581 } elseif ( isset( $cf['defaults']['is_required'] ) && $cf['defaults']['is_required'] ) {
1582 $value = $cf['defaults']['is_required'];
1583 }
1584
1585 echo aui()->input(
1586 array(
1587 'id' => 'is_required',
1588 'name' => 'is_required',
1589 'type' => 'checkbox',
1590 'label_type' => 'horizontal',
1591 'label_col' => '4',
1592 'label' => __( 'Is required', 'userswp' ),
1593 'checked' => $value,
1594 'value' => '1',
1595 'switch' => 'md',
1596 'label_force_left' => true,
1597 'help_text' => uwp_help_tip( __( 'Select yes to set field as required', 'userswp' ) ),
1598 // 'wrap_class' => uwp_advanced_toggle_class(),
1599 )
1600 );
1601
1602 }
1603
1604 // required_msg
1605 if ( has_filter( "uwp_builder_required_msg_{$field_type}" ) ) {
1606
1607 echo apply_filters( "uwp_builder_required_msg_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1608
1609 } else {
1610 $value = '';
1611 if ( isset( $field_info->required_msg ) ) {
1612 $value = esc_attr( $field_info->required_msg );
1613 } elseif ( isset( $cf['defaults']['required_msg'] ) && $cf['defaults']['required_msg'] ) {
1614 $value = $cf['defaults']['required_msg'];
1615 }
1616
1617 echo aui()->input(
1618 array(
1619 'id' => 'required_msg',
1620 'name' => 'required_msg',
1621 'label_type' => 'top',
1622 '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' ) ),
1623 'type' => 'text',
1624 'wrap_class' => uwp_advanced_toggle_class(),
1625 'value' => $value,
1626 'element_require' => '[%is_required%:checked]',
1627 )
1628 );
1629
1630 }
1631
1632 // validation pattern
1633 if ( has_filter( "uwp_builder_validation_pattern_{$field_type}" ) ) {
1634
1635 echo apply_filters( "uwp_builder_validation_pattern_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1636
1637 }
1638
1639 // extra_fields
1640 if ( has_filter( "uwp_builder_extra_fields_{$field_type}" ) ) {
1641
1642 echo apply_filters( "uwp_builder_extra_fields_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1643
1644 }
1645
1646 // field_icon
1647 if ( has_filter( "uwp_builder_field_icon_{$field_type}" ) ) {
1648
1649 echo apply_filters( "uwp_builder_field_icon_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1650
1651 } else {
1652 $value = '';
1653 if ( isset( $field_info->field_icon ) ) {
1654 $value = esc_attr( $field_info->field_icon );
1655 } elseif ( isset( $cf['defaults']['field_icon'] ) && $cf['defaults']['field_icon'] ) {
1656 $value = $cf['defaults']['field_icon'];
1657 }
1658
1659 echo aui()->input(
1660 array(
1661 'id' => 'field_icon',
1662 'name' => 'field_icon',
1663 'label_type' => 'top',
1664 '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>' ) ),
1665 'type' => 'iconpicker',
1666 'wrap_class' => uwp_advanced_toggle_class(),
1667 'value' => $value,
1668 'extra_attributes' => defined( 'FAS_PRO' ) && FAS_PRO ? array(
1669 'data-fa-icons' => true,
1670 'data-bs-toggle' => 'tooltip',
1671 'data-bs-trigger' => 'focus',
1672 'title' => __( 'For pro icon variants (light, thin, duotone), paste the class here', 'userswp' ),
1673 ) : array(),
1674 )
1675 );
1676
1677 }
1678
1679 // css_class
1680 if ( has_filter( "uwp_builder_css_class_{$field_type}" ) ) {
1681
1682 echo apply_filters( "uwp_builder_css_class_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1683
1684 } else {
1685
1686 $value = '';
1687 if ( isset( $field_info->css_class ) ) {
1688 $value = esc_attr( $field_info->css_class );
1689 } elseif ( isset( $cf['defaults']['css_class'] ) && $cf['defaults']['css_class'] ) {
1690 $value = $cf['defaults']['css_class'];
1691 }
1692 $tip = __( 'Enter custom css class for field custom style.', 'userswp' );
1693 if ( $field_type == 'multiselect' ) {
1694 $tip .= __( '(Enter class `uwp-comma-list` to show list as comma separated)', 'userswp' );
1695 }
1696
1697 echo aui()->input(
1698 array(
1699 'id' => 'css_class',
1700 'name' => 'css_class',
1701 'label_type' => 'top',
1702 'label' => __( 'CSS class', 'userswp' ) . uwp_help_tip( $tip ),
1703 'type' => 'text',
1704 'wrap_class' => uwp_advanced_toggle_class(),
1705 'value' => $value,
1706 )
1707 );
1708
1709 }
1710
1711 // show_in
1712 if ( has_filter( "uwp_builder_show_in_{$field_type}" ) ) {
1713 echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1714 echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1715
1716 echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1717
1718 } else {
1719 $value = '';
1720 if ( isset( $field_info->show_in ) ) {
1721 $value = esc_attr( $field_info->show_in );
1722 } elseif ( isset( $cf['defaults']['show_in'] ) && $cf['defaults']['show_in'] ) {
1723 $value = esc_attr( $cf['defaults']['show_in'] );
1724 }
1725
1726 $show_in_locations = uwp_get_show_in_locations();
1727
1728 if ( $field_type == 'fieldset' ) {
1729 unset( $show_in_locations['[fieldset]'] );
1730 }
1731
1732 if ( ! in_array(
1733 $field_type,
1734 array(
1735 'text',
1736 'datepicker',
1737 'textarea',
1738 'time',
1739 'phone',
1740 'email',
1741 'select',
1742 'multiselect',
1743 'url',
1744 'html',
1745 'fieldset',
1746 'radio',
1747 'checkbox',
1748 'file',
1749 )
1750 ) ) {
1751 unset( $show_in_locations['[own_tab]'] );
1752 }
1753
1754 $show_in_values = $value ? explode( ',', $value ) : '';
1755
1756 echo aui()->select(
1757 array(
1758 'id' => 'show_in',
1759 'name' => 'show_in[]',
1760 'label_type' => 'top',
1761 'multiple' => true,
1762 'select2' => true,
1763 'class' => ' mw-100',
1764 'options' => $show_in_locations,
1765 'label' => __( 'Show in what locations?', 'userswp' ) . uwp_help_tip( __( 'Select in what locations you want to display this field.', 'userswp' ) ),
1766 'value' => $show_in_values,
1767 'placeholder' => __( 'Select locations', 'userswp' ),
1768 )
1769 );
1770
1771 }
1772
1773 do_action( 'uwp_admin_extra_custom_fields', $field_info, $cf );
1774 ?>
1775
1776
1777 <div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button">
1778
1779 <span class="text-left text-start float-left float-start">
1780 <?php UsersWP_Settings_Page::toggle_advanced_button( 'btn btn-outline-primary text-left text-start uwp-advanced-toggle', false ); ?>
1781 </span>
1782
1783 <a class=" btn btn-link text-muted" href="javascript:void(0);" onclick="uwp_tabs_close_settings(this); return false;"><?php _e( 'Close', 'userswp' ); ?></a>
1784 <a href='javascript:void(0);' type="button" class="btn btn-primary" id="save"
1785 onclick="save_field('<?php echo esc_attr( $result_str ); ?>');"><?php echo esc_attr( __( 'Save', 'userswp' ) ); ?></a>
1786 </div>
1787 </script>
1788 </div>
1789 </li>
1790 <?php
1791 }
1792
1793 /**
1794 * Add HTML5 validation pattern fields.
1795 *
1796 * @since 1.2.2.17
1797 *
1798 * @param string $output Html output.
1799 * @param string $result_str Result string.
1800 * @param array $cf Custom fields values.
1801 * @param object $field_info Extra fields information.
1802 * @return string $output.
1803 */
1804 public static function validation_pattern( $output, $result_str, $cf, $field_info ) {
1805 ob_start();
1806
1807 $value = '';
1808 if ( isset( $field_info->validation_pattern ) ) {
1809 $value = esc_attr( $field_info->validation_pattern );
1810 } elseif ( isset( $cf['defaults']['validation_pattern'] ) && $cf['defaults']['validation_pattern'] ) {
1811 $value = $cf['defaults']['validation_pattern'];
1812 }
1813
1814 echo aui()->input(
1815 array(
1816 'id' => 'validation_pattern',
1817 'name' => 'validation_pattern',
1818 'label_type' => 'top',
1819 'label' => __( 'Validation Pattern', 'userswp' ) . uwp_help_tip( __( 'Enter regex expression for HTML5 pattern validation.', 'userswp' ) ),
1820 'type' => 'text',
1821 'wrap_class' => uwp_advanced_toggle_class(),
1822 'value' => addslashes_gpc( $value ), // Keep slashes
1823 )
1824 );
1825
1826 $value = '';
1827 if ( isset( $field_info->validation_msg ) ) {
1828 $value = esc_attr( $field_info->validation_msg );
1829 } elseif ( isset( $cf['defaults']['validation_msg'] ) && $cf['defaults']['validation_msg'] ) {
1830 $value = $cf['defaults']['validation_msg'];
1831 }
1832
1833 echo aui()->input(
1834 array(
1835 'id' => 'validation_msg',
1836 'name' => 'validation_msg',
1837 'label_type' => 'top',
1838 'label' => __( 'Validation Message', 'userswp' ) . uwp_help_tip( __( 'Enter a extra validation message to show to the user if validation fails.', 'userswp' ) ),
1839 'type' => 'text',
1840 'wrap_class' => uwp_advanced_toggle_class(),
1841 'value' => $value,
1842 )
1843 );
1844
1845 $output = ob_get_clean();
1846
1847 return $output;
1848 }
1849
1850 public function register_selected_fields( $form_type ) {
1851 global $wpdb;
1852 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1853 $form_id = self::get_form_id()
1854 ?>
1855 <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
1856 <input type="hidden" name="uwp_create_field_nonce" class="uwp_create_field_nonce" value="<?php echo wp_create_nonce( 'uwp_create_field_nonce' ); ?>"/>
1857 <ul class="core uwp_form_extras uwp-tabs-selected ps-0 list-group ">
1858 <?php
1859
1860 $fields = $wpdb->get_results(
1861 $wpdb->prepare(
1862 'select * from ' . $extras_table_name . ' where form_type = %s AND form_id = %d order by sort_order asc',
1863 array( $form_type, $form_id )
1864 )
1865 );
1866
1867 if ( ! empty( $fields ) ) {
1868 foreach ( $fields as $field ) {
1869 $result_str = $field;
1870 $field_ins_upd = 'display';
1871 $this->register_field_adminhtml( $result_str, $field_ins_upd, false );
1872 }
1873 }
1874 ?>
1875 </ul>
1876 <?php
1877 }
1878
1879 public function register_field_adminhtml( $result_str, $field_ins_upd = '', $default = false, $request = array() ) {
1880 global $wpdb;
1881
1882 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1883 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1884
1885 $cf = $result_str;
1886 if ( ! is_object( $cf ) && ( is_int( $cf ) || ctype_digit( $cf ) ) ) {
1887 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( $cf ) ) );
1888 } elseif ( is_object( $cf ) ) {
1889 $result_str = $cf->id;
1890 $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( (int) $cf->id ) ) );
1891 } else {
1892 $field_info = false;
1893 }
1894
1895 if ( isset( $request['field_type'] ) && $request['field_type'] != '' ) {
1896 $field_type = esc_attr( $request['field_type'] );
1897 } else {
1898 $field_type = $field_info->field_type;
1899 }
1900
1901 $field_site_name = '';
1902 if ( isset( $request['site_title'] ) ) {
1903 $field_site_name = $request['site_title'];
1904 }
1905
1906 if ( $field_info ) {
1907 $account_field_info = uwp_get_custom_field_info( $field_info->site_htmlvar_name );
1908 if ( isset( $account_field_info->site_title ) ) {
1909 if ( $account_field_info->field_type == 'fieldset' ) {
1910 $field_site_name = __( 'Fieldset:', 'userswp' ) . ' ' . $account_field_info->site_title;
1911 } else {
1912 $field_site_name = $account_field_info->site_title;
1913 }
1914 }
1915 $field_info = stripslashes_deep( $field_info ); // strip slashes
1916 }
1917 $field_site_name = sanitize_title( $field_site_name );
1918
1919 if ( isset( $request['form_type'] ) ) {
1920 $form_type = esc_attr( $request['form_type'] );
1921 } else {
1922 $form_type = $field_info->form_type;
1923 }
1924
1925 if ( isset( $request['htmlvar_name'] ) && $request['htmlvar_name'] != '' ) {
1926 $htmlvar_name = esc_attr( $request['htmlvar_name'] );
1927 } else {
1928 $htmlvar_name = $field_info->site_htmlvar_name;
1929 }
1930
1931 if ( isset( $htmlvar_name ) ) {
1932 if ( ! is_object( $field_info ) ) {
1933 $field_info = new stdClass();
1934 }
1935 $field_info->field_icon = $wpdb->get_var(
1936 $wpdb->prepare( 'SELECT field_icon FROM ' . $table_name . ' WHERE htmlvar_name = %s', array( $htmlvar_name ) )
1937 );
1938 }
1939
1940 $icon = isset( $field_info->field_icon ) ? $field_info->field_icon : '';
1941 if ( uwp_is_fa_icon( $icon ) ) {
1942 $field_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>';
1943 } elseif ( uwp_is_icon_url( $icon ) ) {
1944 $field_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>';
1945 } elseif ( isset( $field_info->field_type ) && $field_info->field_type == 'fieldset' ) {
1946 $field_icon = '<i class="fas fa-arrows-alt-h" aria-hidden="true"></i>';
1947 } else {
1948 $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
1949 }
1950
1951 $no_actions = array( 'email' );
1952 $no_actions = apply_filters( 'uwp_register_fields_without_actions', $no_actions );
1953 ?>
1954 <li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>">
1955 <form>
1956 <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">
1957 <?php
1958 $nonce = wp_create_nonce( 'uwp_form_extras_nonce' . $result_str );
1959 ?>
1960 <div class=" flex-fill font-weight-bold fw-bold">
1961 <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1962 <b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_name ) ); ?></b>
1963 </div>
1964 <div class="dd-handle ui-sortable-handle">
1965 <?php if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
1966 <i class="far fa-trash-alt text-danger ml-2 ms-2 c-pointer" id="delete-16"
1967 onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
1968 ></i>
1969 <?php } ?>
1970 <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
1971 </div>
1972 </div>
1973
1974 <div id="field_frm<?php echo esc_attr( $result_str ); ?>" class="field_frm" style="display:none;">
1975 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
1976 <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
1977 <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1978 <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
1979 <input type="hidden" name="is_active" id="is_active" value="1"/>
1980 <ul class="widefat post fixed" style="width:100%;">
1981
1982 <input type="hidden" name="site_htmlvar_name" value="<?php echo esc_attr( $htmlvar_name ); ?>"/>
1983
1984 <li>
1985 <div class="uwp-input-wrap">
1986 <p><?php esc_html_e( 'No options available', 'userswp' ); ?></p>
1987 </div>
1988 </li>
1989
1990 <li>
1991 <div class="uwp-input-wrap">
1992 <?php if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
1993 <input type="button" class="button button-primary" name="save" id="save"
1994 value="<?php esc_attr_e( 'Save', 'userswp' ); ?>"
1995 onclick="save_field('<?php echo esc_js( $result_str ); ?>', 'register')"
1996 style="display: none;"/>
1997 <input type="button" name="delete"
1998 value="<?php esc_attr_e( 'Delete', 'userswp' ); ?>"
1999 onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
2000 class="button"/>
2001 <?php } ?>
2002
2003 </div>
2004 </li>
2005 </ul>
2006
2007 </div>
2008 </form>
2009 </li>
2010 <?php
2011 }
2012
2013 public function builder_extra_fields_smr( $output, $result_str, $cf, $field_info ) {
2014
2015 ob_start();
2016
2017 $value = '';
2018 if ( isset( $field_info->option_values ) ) {
2019 $value = esc_attr( $field_info->option_values );
2020 } elseif ( isset( $cf['defaults']['option_values'] ) && $cf['defaults']['option_values'] ) {
2021 $value = esc_attr( $cf['defaults']['option_values'] );
2022 }
2023
2024 $field_type = isset( $field_info->field_type ) ? $field_info->field_type : $cf['field_type'];
2025 $field_type_key = isset( $field_info->field_type_key ) ? $field_info->field_type_key : '';
2026 if ( ! $field_type_key ) {
2027 $field_type_key = isset( $_REQUEST['field_type_key'] ) ? esc_html( $_REQUEST['field_type_key'] ) : '';
2028 }
2029 ?>
2030 <div class="uwp-setting-name mb-3">
2031 <label for="option_values" class=" form-label">
2032 <?php
2033 $tip = __( 'Option Values should be separated by comma.', 'userswp' );
2034 if ( $field_type != 'multiselect' ) {
2035 $tip .= '<br/><small>' . __( 'If using for a tick filter place a / and then either a 1 for true or 0 for false', 'userswp' );
2036 $tip .= '<br/>' . __( 'eg: No Dogs Allowed/0,Dogs Allowed/1', 'userswp' ) . '</small>';
2037 }
2038 if ( $field_type == 'multiselect' || $field_type == 'select' ) {
2039 $tip .= '<br/><small>' . __( 'Like: Apple,Bannana,Pear,Peach', 'userswp' );
2040 $tip .= '<br/>' . __( 'Or you can show Selection/Value shown: Pets Allowed/Yes,Pets not Allowed/No', 'userswp' );
2041 $tip .= '<br/>' . __( '- If using OPTGROUP tag to grouping options, use {optgroup}OPTGROUP-LABEL|OPTION-1,OPTION-2{/optgroup}', 'userswp' );
2042 $tip .= '<br/>' . __( 'eg: {optgroup}Pets Allowed|No Dogs Allowed/0,Dogs Allowed/1{/optgroup},{optgroup}Sports|Cricket/Cricket,Football/Football,Hockey{/optgroup}', 'userswp' ) . '</small>';
2043 }
2044 ?>
2045 <?php
2046 echo uwp_help_tip( $tip ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2047 esc_html_e( 'Option Values :', 'userswp' );
2048 ?>
2049 </label>
2050 <div class="uwp-input-wrap">
2051
2052 <?php
2053 if ( isset( $field_type_key ) && $field_type_key == 'uwp_country' ) {
2054 // @todo here we should show a multiselect to either include or exclude countries
2055 echo aui()->alert(
2056 array(
2057 'type' => 'info',
2058 'content' => esc_html__( 'A full country list will be shown', 'userswp' ),
2059 )
2060 );
2061
2062 } elseif ( isset( $field_type_key ) && $field_type_key == 'uwp_language' ) {
2063 echo aui()->alert(
2064 array(
2065 'type' => 'info',
2066 'content' => esc_html__( 'Available translation languages list will be shown', 'userswp' ),
2067 )
2068 );
2069 } else {
2070 ?>
2071 <input type="text" name="option_values" id="option_values" class="form-control" value="<?php echo esc_attr( $value ); ?>"/>
2072 <?php } ?>
2073
2074 <br/>
2075
2076 </div>
2077 </div>
2078 <?php
2079
2080 $html = ob_get_clean();
2081
2082 return $output . $html;
2083 }
2084
2085 public function builder_extra_fields_datepicker( $output, $result_str, $cf, $field_info ) {
2086 ob_start();
2087 $extra = array();
2088 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2089 $extra = unserialize( $field_info->extra_fields );
2090 }
2091 ?>
2092 <div class="uwp-setting-name uwp-advanced-setting mb-3">
2093 <label for="date_format" class=" form-label">
2094 <?php
2095 echo uwp_help_tip( __( 'Select the date format.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2096 esc_html_e( 'Date Format :', 'userswp' );
2097 ?>
2098 </label>
2099 <div class="uwp-input-wrap" style="overflow:inherit;">
2100 <?php
2101 $date_formats = array(
2102 'm/d/Y',
2103 'd/m/Y',
2104 'Y/m/d',
2105 'm-d-Y',
2106 'd-m-Y',
2107 'Y-m-d',
2108 'F j, Y',
2109 );
2110
2111 $date_formats = apply_filters( 'uwp_date_formats', $date_formats );
2112 ?>
2113 <select name="extra[date_format]" id="date_format" class="aui-selectx2 form-select mw-100" >
2114 <?php
2115 foreach ( $date_formats as $format ) {
2116 $selected = false;
2117 if ( ! empty( $extra ) && esc_attr( $extra['date_format'] ) == $format ) {
2118 $selected = true;
2119 }
2120 echo '<option ' . selected( $selected, true, false ) . " value='" . esc_attr( $format ) . "'>" . esc_html( $format . ' (' . date_i18n( $format, time() ) . ')' ) . '</option>';
2121 }
2122 ?>
2123 </select>
2124
2125 </div>
2126 </div>
2127 <?php
2128
2129 $html = ob_get_clean();
2130
2131 return $output . $html;
2132 }
2133
2134 public function builder_extra_fields_password( $output, $result_str, $cf, $field_info ) {
2135 ob_start();
2136
2137 //confirm password field
2138 $extra = array();
2139 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2140 $extra = unserialize( $field_info->extra_fields );
2141 }
2142 $value = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '1';
2143 if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'password' ) {
2144
2145 echo '<div class="' . uwp_advanced_toggle_class() . '">';
2146 echo aui()->input(
2147 array(
2148 'id' => 'extra_confirm_password',
2149 'name' => 'extra[confirm_password]',
2150 'type' => 'checkbox',
2151 'label_type' => 'horizontal',
2152 'label_col' => '4',
2153 'label' => __( 'Display confirm password field', 'userswp' ),
2154 'checked' => $value,
2155 'value' => '1',
2156 'switch' => 'md',
2157 'label_force_left' => true,
2158 'help_text' => uwp_help_tip( __( 'Lets you display confirm password form field.', 'userswp' ) ),
2159 )
2160 );
2161 echo '</div>';
2162
2163 }
2164 $html = ob_get_clean();
2165
2166 return $output . $html;
2167 }
2168
2169 public function builder_extra_fields_email( $output, $result_str, $cf, $field_info ) {
2170 ob_start();
2171 //confirm email field
2172 $extra = array();
2173 if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2174 $extra = unserialize( $field_info->extra_fields );
2175 }
2176 $value = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0';
2177
2178 if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'email' ) {
2179
2180 echo '<div class="' . uwp_advanced_toggle_class() . '">';
2181 echo aui()->input(
2182 array(
2183 'id' => 'extra_confirm_email',
2184 'name' => 'extra[confirm_email]',
2185 'type' => 'checkbox',
2186 'label_type' => 'horizontal',
2187 'label_col' => '4',
2188 'label' => __( 'Display confirm email field', 'userswp' ),
2189 'checked' => $value,
2190 'value' => '1',
2191 'switch' => 'md',
2192 'label_force_left' => true,
2193 'help_text' => uwp_help_tip( __( 'Lets you display confirm email form field.', 'userswp' ) ),
2194 )
2195 );
2196 echo '</div>';
2197
2198 }
2199 $html = ob_get_clean();
2200
2201 return $output . $html;
2202 }
2203
2204 public function builder_extra_fields_file( $output, $result_str, $cf, $field_info ) {
2205 ob_start();
2206
2207 $file_obj = new UsersWP_Files();
2208 $allowed_file_types = $file_obj->allowed_mime_types();
2209
2210 $extra_fields = isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ? maybe_unserialize( $field_info->extra_fields ) : '';
2211 $uwp_file_types = ! empty( $extra_fields ) && ! empty( $extra_fields['uwp_file_types'] ) ? $extra_fields['uwp_file_types'] : array( '*' );
2212 ?>
2213 <div class="uwp-setting-name uwp-advanced-setting mb-3">
2214 <label for="uwp_file_types" class="form-label">
2215 <?php
2216 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
2217 esc_html_e( 'Allowed file types :', 'userswp' );
2218 ?>
2219 </label>
2220 <div class="uwp-input-wrap">
2221 <select name="extra[uwp_file_types][]" id="uwp_file_types" multiple="multiple" class="aui-select2 form-select mw-100" >
2222 <option value="*" <?php selected( true, in_array( '*', $uwp_file_types ) ); ?>><?php esc_html_e( 'All types', 'userswp' ); ?></option>
2223 <?php foreach ( $allowed_file_types as $format => $types ) { ?>
2224 <optgroup
2225 label="<?php echo esc_attr( wp_sprintf( __( '%s formats', 'userswp' ), __( $format, 'userswp' ) ) ); ?>">
2226 <?php foreach ( $types as $ext => $type ) { ?>
2227 <option value="<?php echo esc_attr( $ext ); ?>" <?php selected( true, in_array( $ext, $uwp_file_types ) ); ?>><?php echo '.' . esc_html( $ext ); ?></option>
2228 <?php } ?>
2229 </optgroup>
2230 <?php } ?>
2231 </select>
2232 </div>
2233 </div>
2234 <?php
2235
2236 $html = ob_get_clean();
2237
2238 return $output . $html;
2239 }
2240
2241 public function builder_data_type_text( $output, $result_str, $cf, $field_info ) {
2242 ob_start();
2243
2244 $dt_value = '';
2245 if ( isset( $field_info->data_type ) ) {
2246 $dt_value = esc_attr( $field_info->data_type );
2247 } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
2248 $dt_value = $cf['defaults']['data_type'];
2249 }
2250
2251 // fix some values
2252 if ( $dt_value == 'VARCHAR' ) {
2253 $dt_value = 'XVARCHAR';
2254 }
2255
2256 echo aui()->select(
2257 array(
2258 'id' => 'data_type',
2259 'name' => 'data_type',
2260 'label_type' => 'top',
2261 'multiple' => false,
2262 'wrap_class' => uwp_advanced_toggle_class(),
2263 'class' => 'mw-100',
2264 'options' => array(
2265 'XVARCHAR' => __( 'CHARACTER', 'userswp' ),
2266 'INT' => __( 'NUMBER', 'userswp' ),
2267 'FLOAT' => __( 'DECIMAL', 'userswp' ),
2268 ),
2269 'label' => __( 'Data Type', 'userswp' ) . uwp_help_tip( __( 'Select Custom Field type', 'userswp' ) ),
2270 'value' => $dt_value,
2271 'extra_attributes' => array(
2272 'onchange' => "javascript:uwp_data_type_changed(this, '$result_str');",
2273 ),
2274 )
2275 );
2276
2277 $value = '';
2278 if ( isset( $field_info->decimal_point ) ) {
2279 $value = esc_attr( $field_info->decimal_point );
2280 } elseif ( isset( $cf['defaults']['decimal_point'] ) && $cf['defaults']['decimal_point'] ) {
2281 $value = $cf['defaults']['decimal_point'];
2282 }
2283
2284 echo aui()->select(
2285 array(
2286 'id' => 'decimal_point',
2287 'name' => 'decimal_point',
2288 'label_type' => 'top',
2289 'multiple' => false,
2290 'class' => ' mw-100',
2291 'options' => array(
2292 '' => __( 'Select', 'userswp' ),
2293 '1' => '1',
2294 '2' => '2',
2295 '3' => '3',
2296 '4' => '4',
2297 '5' => '5',
2298 '6' => '6',
2299 '7' => '7',
2300 '8' => '8',
2301 '9' => '9',
2302 '10' => '10',
2303 ),
2304 'label' => __( 'Decimal points', 'userswp' ) . uwp_help_tip( __( 'Decimals to display after point.', 'userswp' ) ),
2305 'value' => $value,
2306 'element_require' => '[%data_type%] == "FLOAT"',
2307 )
2308 );
2309
2310 $output = ob_get_clean();
2311
2312 return $output;
2313 }
2314
2315 public function advance_admin_custom_fields( $field_info, $cf ) {
2316 $hide_register_field = ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] === false ) ? "style='display:none;'" : '';
2317 $hide_register_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_field;
2318 $hide_user_sort = ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] === false ) ? "style='display:none;'" : '';
2319
2320 $value = 0;
2321 if ( isset( $field_info->is_register_field ) ) {
2322 $value = (int) $field_info->is_register_field;
2323 } elseif ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] ) {
2324 $value = ( $cf['defaults']['is_register_field'] ) ? 1 : 0;
2325 }
2326
2327 if ( isset( $field_info->htmlvar_name ) ) {
2328 $htmlvar_name = $field_info->htmlvar_name;
2329 } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
2330 $htmlvar_name = ( $cf['defaults']['htmlvar_name'] ) ? $cf['defaults']['htmlvar_name'] : '';
2331 }
2332
2333 //register only field
2334 $hide_register_only_field = ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] === false ) ? "style='display:none;'" : '';
2335 $hide_register_only_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_only_field;
2336 $register_only_value = 0;
2337 if ( isset( $field_info->is_register_only_field ) ) {
2338 $register_only_value = (int) $field_info->is_register_only_field;
2339 } elseif ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] ) {
2340 $register_only_value = ( $cf['defaults']['is_register_only_field'] ) ? 1 : 0;
2341 }
2342
2343 $user_sort_value = 0;
2344 if ( isset( $field_info->user_sort ) ) {
2345 $user_sort_value = (int) $field_info->user_sort;
2346 } elseif ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] ) {
2347 $user_sort_value = ( $cf['defaults']['user_sort'] ) ? 1 : 0;
2348 }
2349
2350 ?>
2351 <div <?php echo $hide_register_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name mb-3">
2352
2353 <?php
2354 $reg_only_fields = uwp_get_register_only_fields();
2355 if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2356 ?>
2357 <label for="is_register_field" class=" form-label">
2358 <?php
2359 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
2360 esc_html_e( 'Include this field in register form:', 'userswp' );
2361 ?>
2362 </label>
2363 <input type="hidden" name="is_register_field" value="1"/>
2364 <p><?php esc_html_e( 'This is mandatory register form field.', 'userswp' ); ?></p>
2365 <?php
2366 } else {
2367 echo aui()->input(
2368 array(
2369 'id' => 'is_register_field',
2370 'name' => 'is_register_field',
2371 'type' => 'checkbox',
2372 'label_type' => 'horizontal',
2373 'label_col' => '4',
2374 'label' => __( 'Include this field in register form', 'userswp' ),
2375 'checked' => $value,
2376 'value' => '1',
2377 'switch' => 'md',
2378 'label_force_left' => true,
2379 'help_text' => uwp_help_tip( __( 'Lets you use this field as register form field, set from register tab above.', 'userswp' ) ),
2380 )
2381 );
2382 }
2383 ?>
2384 </div>
2385
2386 <div <?php echo $hide_register_only_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-inconlyin-reg-form uwp-setting-name uwp-advanced-setting">
2387
2388
2389 <?php
2390 if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2391 ?>
2392 <label for="is_register_only_field" class="form-label">
2393 <?php
2394 echo uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2395 esc_html_e( 'Include this field ONLY in register form:', 'userswp' );
2396 ?>
2397 </label>
2398 <input type="hidden" name="is_register_only_field" class="form-control" value="1"/>
2399 <p><?php esc_html_e( 'This field is applicable only for register form.', 'userswp' ); ?></p>
2400 <?php
2401 } else {
2402 echo aui()->input(
2403 array(
2404 'id' => 'is_register_only_field',
2405 'name' => 'is_register_only_field',
2406 'type' => 'checkbox',
2407 'label_type' => 'horizontal',
2408 'label_col' => '4',
2409 'label' => __( 'Include this field ONLY in register form', 'userswp' ),
2410 'checked' => $register_only_value,
2411 'value' => '1',
2412 'switch' => 'md',
2413 'label_force_left' => true,
2414 'help_text' => uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ),
2415
2416 )
2417 );
2418
2419 }
2420 ?>
2421 </div>
2422
2423 <div <?php echo $hide_user_sort; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name uwp-advanced-setting">
2424 <?php
2425
2426 echo aui()->input(
2427 array(
2428 'id' => 'user_sort',
2429 'name' => 'user_sort',
2430 'type' => 'checkbox',
2431 'label_type' => 'horizontal',
2432 'label_col' => '4',
2433 'label' => __( 'Include this field in sorting options', 'userswp' ),
2434 'checked' => $user_sort_value,
2435 'value' => '1',
2436 'switch' => 'md',
2437 'label_force_left' => true,
2438 'help_text' => uwp_help_tip( __( 'Lets you use this field as sorting in the users listing page, set from user sorting tab above.', 'userswp' ) ),
2439
2440 )
2441 );
2442
2443 ?>
2444
2445 </div>
2446
2447 <?php
2448 }
2449
2450 public function return_empty_string() {
2451 return '';
2452 }
2453
2454 public function register_available_fields_head( $heading, $form_type ) {
2455 switch ( $form_type ) {
2456 case 'register':
2457 $heading = __( 'Available register form fields.', 'userswp' );
2458 break;
2459 }
2460
2461 return $heading;
2462 }
2463
2464 public function register_available_fields_note( $note, $form_type ) {
2465 switch ( $form_type ) {
2466 case 'register':
2467 $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' );
2468 break;
2469 }
2470
2471 return $note;
2472 }
2473
2474 public function register_selected_fields_head( $heading, $form_type ) {
2475 switch ( $form_type ) {
2476 case 'register':
2477 $heading = __( 'List of fields that will appear in the register form.', 'userswp' );
2478 break;
2479
2480 }
2481
2482 return $heading;
2483 }
2484
2485 public function register_selected_fields_note( $note, $form_type ) {
2486 switch ( $form_type ) {
2487 case 'register':
2488 $note = __( 'Click to expand and view field related settings. You may drag and drop to arrange fields order in register form.', 'userswp' );
2489 break;
2490
2491 }
2492
2493 return $note;
2494 }
2495
2496 /**
2497 * Handles the create custom field ajax request.
2498 *
2499 * @since 1.0.0
2500 * @package userswp
2501 * @return void
2502 */
2503 public function create_field() {
2504
2505 if ( ! current_user_can( 'manage_options' ) ) {
2506 wp_die( -1 );
2507 }
2508
2509 $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
2510 $field_type = isset( $_REQUEST['field_type'] ) ? sanitize_text_field( $_REQUEST['field_type'] ) : '';
2511 $field_type_key = isset( $_REQUEST['field_type_key'] ) ? sanitize_text_field( $_REQUEST['field_type_key'] ) : '';
2512 $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
2513 $field_id = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
2514 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 1;
2515
2516 $field_id = $field_id != '' ? trim( $field_id, '_' ) : $field_id;
2517
2518 $field_ids = array();
2519 if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
2520 foreach ( $_REQUEST['licontainer'] as $lic_id ) {
2521 $field_ids[] = sanitize_text_field( $lic_id );
2522 }
2523 }
2524
2525 /* ------- check nonce field ------- */
2526 if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2527 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_create_field_nonce' ) ) {
2528 return;
2529 }
2530 echo $this->set_field_order( $field_ids, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2531 }
2532
2533 /* ---- Show field form in admin ---- */
2534 if ( $field_type != '' && $field_id != '' && $field_action == 'new' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2535 $this->form_field_adminhtml( $field_type, $field_id, $field_action, $field_type_key, $form_type );
2536 }
2537
2538 /* ---- Delete field ---- */
2539 if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2540 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_delete_' . $field_id ) ) {
2541 return;
2542 }
2543
2544 echo $this->admin_form_field_delete( $field_id, true, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2545 }
2546
2547 /* ---- Save field ---- */
2548 if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2549 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_' . $field_id ) ) {
2550 return;
2551 }
2552
2553 foreach ( $_REQUEST as $pkey => $pval ) {
2554 if ( isset( $_REQUEST[ $pkey ] ) && is_array( $_REQUEST[ $pkey ] ) ) {
2555 $tags = 'skip_field';
2556 } else {
2557 $tags = '';
2558 }
2559
2560 if ( $tags != 'skip_field' && !empty( $_REQUEST[ $pkey ] ) ) {
2561 $_REQUEST[ $pkey ] = strip_tags( $_REQUEST[ $pkey ], $tags );
2562 }
2563 }
2564
2565 $return = $this->admin_form_field_save( $_REQUEST );
2566
2567 if ( is_int( $return ) ) {
2568 $lastid = $return;
2569 $this->form_field_adminhtml( $field_type, $lastid, 'submit', $field_type_key, $form_type );
2570 } else {
2571 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2572 }
2573 }
2574
2575 wp_die();
2576 }
2577
2578 public function set_field_order( $field_ids = array(), $form_id = 1 ) {
2579
2580 global $wpdb;
2581
2582 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2583
2584 $count = 0;
2585 if ( ! empty( $field_ids ) ) :
2586 $user_meta_info = false;
2587 foreach ( $field_ids as $id ) {
2588
2589 $cf = trim( $id, '_' );
2590
2591 $user_meta_info = $wpdb->query(
2592 $wpdb->prepare(
2593 'update ' . $table_name . ' set
2594 sort_order=%d
2595 where id= %d and form_id = %d',
2596 array( $count, $cf, $form_id )
2597 )
2598 );
2599 ++$count;
2600 }
2601
2602 return $user_meta_info;
2603 else :
2604 return false;
2605 endif;
2606 }
2607
2608 public function admin_form_field_delete( $field_id = '', $delete_meta = true, $form_id = 1 ) {
2609
2610 global $wpdb;
2611
2612 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2613 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2614 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2615
2616 if ( $field_id != '' ) {
2617 $cf = trim( $field_id, '_' );
2618
2619 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 ) ) ) ) {
2620
2621 $excluded_delete = array( 'email' );
2622 $excluded_delete = apply_filters( 'uwp_register_fields_exculde_delete', $excluded_delete );
2623
2624 if ( isset( $field->htmlvar_name ) && in_array( $field->htmlvar_name, $excluded_delete ) ) {
2625 return $field_id;
2626 }
2627
2628 // delete the meta column
2629 if ( isset( $field->htmlvar_name ) && $delete_meta ) {
2630 $register_forms = uwp_get_option( 'multiple_registration_forms' );
2631 $custom_fields = array();
2632
2633 if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
2634 foreach ( $register_forms as $key => $register_form ) {
2635 $form_ids[] = (int) $register_form['id'];
2636 }
2637
2638 if ( isset( $form_ids ) && count( $form_ids ) > 0 ) {
2639 $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%d' );
2640 $form_ids_placeholder = implode( ', ', $form_ids_placeholder );
2641 $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 );
2642 $custom_fields = $wpdb->get_results( $query );
2643 }
2644 }
2645
2646 if ( isset( $custom_fields ) && ! empty( $custom_fields ) && count( $custom_fields ) > 1 ) {
2647 // Do not delete user meta column if field used in more than one form.
2648 } else {
2649 $col_name = sanitize_sql_orderby( $field->htmlvar_name );
2650 $wpdb->query( "ALTER TABLE `{$meta_table}` DROP COLUMN `{$col_name}`" );
2651 }
2652 }
2653
2654 $wpdb->query( $wpdb->prepare( 'delete from ' . $table_name . ' where id= %d AND form_id = %d', array( $cf, $form_id ) ) );
2655
2656 // Also delete register form field
2657 $wpdb->query( $wpdb->prepare( 'delete from ' . $extras_table_name . ' where site_htmlvar_name= %s AND form_id = %d ', array( $field->htmlvar_name, $form_id ) ) );
2658
2659 do_action( 'uwp_after_custom_field_deleted', $cf, $field );
2660
2661 return $field_id;
2662 } else {
2663 return 0;
2664 }
2665 } else {
2666 return 0;
2667 }
2668 }
2669
2670 public function admin_form_field_save( $request_field = array() ) {
2671
2672 global $wpdb;$wpdb->show_errors();
2673
2674 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2675
2676 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2677
2678 $old_html_variable = '';
2679
2680 $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
2681 $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : 1;
2682
2683 $user_meta_info = null;
2684
2685 // some servers fail if a POST value is VARCHAR so we change it.
2686 if ( isset( $request_field['data_type'] ) && $request_field['data_type'] == 'XVARCHAR' ) {
2687 $request_field['data_type'] = 'VARCHAR';
2688 }
2689
2690 $cf = trim( $result_str, '_' );
2691
2692 $cehhtmlvar_name = isset( $request_field['htmlvar_name'] ) ? $request_field['htmlvar_name'] : '';
2693 $form_type = $request_field['form_type'];
2694
2695 $old_html_variable_name = 'uwp_account_' . $cehhtmlvar_name;
2696 $check_old_html_variable = $wpdb->get_var(
2697 $wpdb->prepare(
2698 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2699 array( $cf, $old_html_variable_name, $form_type, $form_id )
2700 )
2701 );
2702
2703 $check_html_variable = $wpdb->get_var(
2704 $wpdb->prepare(
2705 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2706 array( $cf, $cehhtmlvar_name, $form_type, $form_id )
2707 )
2708 );
2709
2710 if ( ( ! $check_old_html_variable && ! $check_html_variable ) || $request_field['field_type'] == 'fieldset' ) {
2711
2712 if ( $cf != '' ) {
2713
2714 $user_meta_info = $wpdb->get_row(
2715 $wpdb->prepare(
2716 'select * from ' . $table_name . ' where id = %d',
2717 array( $cf )
2718 )
2719 );
2720
2721 }
2722
2723 if ( ! empty( $user_meta_info ) ) {
2724 $old_html_variable = $user_meta_info->htmlvar_name;
2725
2726 }
2727
2728 $site_title = sanitize_text_field( $request_field['site_title'] );
2729 $form_label = isset( $request_field['form_label'] ) ? sanitize_text_field( $request_field['form_label'] ) : '';
2730 $help_text = isset( $request_field['help_text'] ) ? sanitize_text_field( $request_field['help_text'] ) : '';
2731 $field_type = sanitize_text_field( $request_field['field_type'] );
2732 $data_type = sanitize_text_field( $request_field['data_type'] );
2733 $field_type_key = isset( $request_field['field_type_key'] ) ? sanitize_text_field( $request_field['field_type_key'] ) : $field_type;
2734 $htmlvar_name = isset( $request_field['htmlvar_name'] ) ? str_replace(
2735 array(
2736 '-',
2737 ' ',
2738 '"',
2739 "'",
2740 ),
2741 array( '_', '', '', '' ),
2742 sanitize_title_with_dashes( $request_field['htmlvar_name'] )
2743 ) : null;
2744 $default_value = isset( $request_field['default_value'] ) ? sanitize_text_field( $request_field['default_value'] ) : '';
2745 $sort_order = isset( $request_field['sort_order'] ) ? absint( $request_field['sort_order'] ) : '';
2746 $is_active = isset( $request_field['is_active'] ) ? absint( $request_field['is_active'] ) : 1;
2747 $placeholder_value = isset( $request_field['placeholder_value'] ) ? $request_field['placeholder_value'] : '';
2748 $for_admin_use = isset( $request_field['for_admin_use'] ) ? absint( $request_field['for_admin_use'] ) : 0;
2749 $is_required = isset( $request_field['is_required'] ) ? absint( $request_field['is_required'] ) : 0;
2750 $is_dummy = isset( $request_field['is_dummy'] ) ? absint( $request_field['is_dummy'] ) : 0;
2751 $is_public = isset( $request_field['is_public'] ) ? absint( $request_field['is_public'] ) : 0;
2752 $is_default = isset( $request_field['is_default'] ) ? absint( $request_field['is_default'] ) : 0;
2753 $is_register_field = isset( $request_field['is_register_field'] ) ? absint( $request_field['is_register_field'] ) : 0;
2754 $is_search_field = isset( $request_field['is_search_field'] ) ? absint( $request_field['is_search_field'] ) : 0;
2755 $is_register_only_field = isset( $request_field['is_register_only_field'] ) ? absint( $request_field['is_register_only_field'] ) : 0;
2756 $required_msg = isset( $request_field['required_msg'] ) ? sanitize_text_field( $request_field['required_msg'] ) : '';
2757 $css_class = isset( $request_field['css_class'] ) ? sanitize_text_field( $request_field['css_class'] ) : '';
2758 $field_icon = isset( $request_field['field_icon'] ) ? sanitize_text_field( $request_field['field_icon'] ) : '';
2759 $show_in = isset( $request_field['show_in'] ) ? $request_field['show_in'] : '';
2760 $user_roles = isset( $request_field['user_roles'] ) ? $request_field['user_roles'] : '';
2761 $decimal_point = isset( $request_field['decimal_point'] ) ? absint( $request_field['decimal_point'] ) : ''; // decimal point for DECIMAL data type
2762 $decimal_point = $decimal_point > 0 ? ( $decimal_point > 10 ? 10 : $decimal_point ) : '';
2763 $validation_pattern = isset( $request_field['validation_pattern'] ) ? sanitize_text_field( $request_field['validation_pattern'] ) : '';
2764 $validation_msg = isset( $request_field['validation_msg'] ) ? sanitize_text_field( $request_field['validation_msg'] ) : '';
2765 $user_sort = isset( $request_field['user_sort'] ) ? absint( $request_field['user_sort'] ) : 0;
2766
2767 if ( empty( $htmlvar_name ) ) {
2768 $htmlvar_name = sanitize_key(
2769 str_replace(
2770 array( '-', ' ', '"', "'" ),
2771 array(
2772 '_',
2773 '_',
2774 '',
2775 '',
2776 ),
2777 $request_field['site_title']
2778 )
2779 );
2780 if ( str_replace( '_', '', $htmlvar_name ) != '' ) {
2781 $htmlvar_name = substr( $htmlvar_name, 0, 50 );
2782 } else {
2783 $htmlvar_name = time();
2784 }
2785 }
2786
2787 if ( is_array( $show_in ) ) {
2788 $show_in = implode( ',', $request_field['show_in'] );
2789 $show_in = sanitize_text_field( $show_in );
2790 }
2791
2792 if ( is_array( $user_roles ) ) {
2793 $user_roles = implode( ',', $request_field['user_roles'] );
2794 $user_roles = sanitize_text_field( $user_roles );
2795 }
2796
2797 $option_values = '';
2798 if ( isset( $request_field['option_values'] ) ) {
2799 $option_values = $request_field['option_values'];
2800 }
2801
2802 if ( isset( $request_field['extra'] ) && ! empty( $request_field['extra'] ) ) {
2803 $extra_fields = $request_field['extra'];
2804 }
2805
2806 if ( $sort_order == '' ) {
2807
2808 $last_order = $wpdb->get_var( 'SELECT MAX(sort_order) as last_order FROM ' . $table_name );
2809
2810 $sort_order = (int) $last_order + 1;
2811 }
2812
2813 if ( ! empty( $user_meta_info ) ) {
2814
2815 $excluded = uwp_get_excluded_fields();
2816
2817 if ( ! in_array( $htmlvar_name, $excluded ) ) {
2818 // Create custom columns
2819 switch ( $field_type ) :
2820
2821 case 'checkbox':
2822 case 'multiselect':
2823 case 'select':
2824 $op_size = '500';
2825
2826 // only make the field as big as it needs to be.
2827 if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
2828 $option_values_arr = explode( ',', $option_values );
2829 if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
2830 $op_max = 0;
2831 foreach ( $option_values_arr as $op_val ) {
2832 if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
2833 $op_max = strlen( $op_val );
2834 }
2835 }
2836 if ( $op_max ) {
2837 $op_size = $op_max;
2838 }
2839 }
2840 } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
2841 if ( strlen( $option_values ) ) {
2842 $op_size = strlen( $option_values );
2843 }
2844 }
2845
2846 $meta_field_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . "`VARCHAR( $op_size ) NULL";
2847
2848 if ( $default_value != '' ) {
2849 $meta_field_add .= " DEFAULT '" . $default_value . "'";
2850 }
2851
2852 $alter_result = $wpdb->query( $meta_field_add );
2853 if ( $alter_result === false ) {
2854 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2855 }
2856
2857 if ( isset( $request_field['cat_display_type'] ) ) {
2858 $extra_fields = $request_field['cat_display_type'];
2859 }
2860
2861 if ( isset( $request_field['multi_display_type'] ) ) {
2862 $extra_fields = $request_field['multi_display_type'];
2863 }
2864
2865 break;
2866
2867 case 'textarea':
2868 case 'editor':
2869 case 'url':
2870 case 'file':
2871 $alter_result = $wpdb->query( 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` TEXT NULL' );
2872 if ( $alter_result === false ) {
2873 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2874 }
2875 if ( isset( $request_field['advanced_editor'] ) ) {
2876 $extra_fields = $request_field['advanced_editor'];
2877 }
2878
2879 break;
2880
2881 case 'fieldset':
2882 // Nothing happened for fieldset
2883 break;
2884
2885 default:
2886 if ( $data_type != 'VARCHAR' && $data_type != '' ) {
2887 if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
2888 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` DECIMAL(11, ' . (int) $decimal_point . ') NULL';
2889 } else {
2890 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` ' . $data_type . ' NULL';
2891 }
2892
2893 if ( is_numeric( $default_value ) && $default_value != '' ) {
2894 $default_value_add .= " DEFAULT '" . $default_value . "'";
2895 }
2896 } else {
2897 $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` VARCHAR( 254 ) NULL';
2898 if ( $default_value != '' ) {
2899 $default_value_add .= " DEFAULT '" . $default_value . "'";
2900 }
2901 }
2902
2903 $alter_result = $wpdb->query( $default_value_add );
2904 if ( $alter_result === false ) {
2905 return __( 'Column change failed, you may have too many columns.', 'userswp' );
2906 }
2907 break;
2908 endswitch;
2909 }
2910
2911 $extra_field_query = '';
2912 if ( ! empty( $extra_fields ) ) {
2913 $extra_field_query = serialize( $extra_fields );
2914 }
2915
2916 $wpdb->query(
2917 $wpdb->prepare(
2918 'update ' . $table_name . ' set
2919 form_type = %s,
2920 site_title = %s,
2921 form_label = %s,
2922 help_text = %s,
2923 field_type = %s,
2924 data_type = %s,
2925 decimal_point = %s,
2926 field_type_key = %s,
2927 htmlvar_name = %s,
2928 default_value = %s,
2929 sort_order = %s,
2930 is_active = %s,
2931 placeholder_value = %s,
2932 for_admin_use = %s,
2933 is_default = %s,
2934 is_required = %s,
2935 is_dummy = %s,
2936 is_public = %s,
2937 is_register_field = %s,
2938 is_search_field = %s,
2939 is_register_only_field = %s,
2940 required_msg = %s,
2941 css_class = %s,
2942 field_icon = %s,
2943 show_in = %s,
2944 user_roles = %s,
2945 option_values = %s,
2946 extra_fields = %s,
2947 validation_pattern = %s,
2948 validation_msg = %s,
2949 form_id = %d,
2950 user_sort = %s
2951 where id = %d',
2952 array(
2953 $form_type,
2954 $site_title,
2955 $form_label,
2956 $help_text,
2957 $field_type,
2958 $data_type,
2959 $decimal_point,
2960 $field_type_key,
2961 $htmlvar_name,
2962 $default_value,
2963 $sort_order,
2964 $is_active,
2965 $placeholder_value,
2966 $for_admin_use,
2967 $is_default,
2968 $is_required,
2969 $is_dummy,
2970 $is_public,
2971 $is_register_field,
2972 $is_search_field,
2973 $is_register_only_field,
2974 $required_msg,
2975 $css_class,
2976 $field_icon,
2977 $show_in,
2978 $user_roles,
2979 $option_values,
2980 $extra_field_query,
2981 $validation_pattern,
2982 $validation_msg,
2983 $form_id,
2984 $user_sort,
2985 $cf,
2986 )
2987 )
2988 );
2989
2990 $lastid = trim( $cf );
2991
2992 do_action( 'uwp_after_custom_fields_updated', $lastid );
2993
2994 } else {
2995
2996 switch ( $field_type ) :
2997
2998 case 'checkbox':
2999 $data_type = 'TINYINT';
3000
3001 $meta_field_add = $data_type . '( 1 ) NOT NULL ';
3002 if ( (int) $default_value === 1 ) {
3003 $meta_field_add .= " DEFAULT '1'";
3004 }
3005
3006 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3007 if ( $add_result === false ) {
3008 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3009 }
3010 break;
3011 case 'multiselect':
3012 case 'select':
3013 $data_type = 'VARCHAR';
3014 $op_size = '500';
3015
3016 // only make the field as big as it needs to be.
3017 if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
3018 $option_values_arr = explode( ',', $option_values );
3019
3020 if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
3021 $op_max = 0;
3022
3023 foreach ( $option_values_arr as $op_val ) {
3024 if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
3025 $op_max = strlen( $op_val );
3026 }
3027 }
3028
3029 if ( $op_max ) {
3030 $op_size = $op_max;
3031 }
3032 }
3033 } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
3034 if ( strlen( $option_values ) ) {
3035 $op_size = strlen( $option_values );
3036 }
3037
3038 if ( isset( $request_field['multi_display_type'] ) ) {
3039 $extra_fields = $request_field['multi_display_type'];
3040 }
3041 }
3042
3043 $meta_field_add = $data_type . "( $op_size ) NULL ";
3044 if ( $default_value != '' ) {
3045 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3046 }
3047
3048 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3049 if ( $add_result === false ) {
3050 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3051 }
3052 break;
3053 case 'textarea':
3054 case 'editor':
3055 case 'url':
3056 case 'file':
3057 $data_type = 'TEXT';
3058
3059 $meta_field_add = $data_type . ' NULL ';
3060
3061 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3062 if ( $add_result === false ) {
3063 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3064 }
3065
3066 break;
3067
3068 case 'datepicker':
3069 $data_type = 'DATE';
3070
3071 $meta_field_add = $data_type . ' NULL ';
3072
3073 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3074 if ( $add_result === false ) {
3075 return __( 'Column creation failed, you may have too many columns or the default value must have in valid date format.', 'userswp' );
3076 }
3077
3078 break;
3079
3080 case 'time':
3081 $data_type = 'TIME';
3082
3083 $meta_field_add = $data_type . ' NULL ';
3084
3085 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3086 if ( $add_result === false ) {
3087 return __( 'Column creation failed, you may have too many columns or the default value must have in valid time format.', 'userswp' );
3088 }
3089
3090 break;
3091
3092 default:
3093 if ( $data_type != 'VARCHAR' && $data_type != '' ) {
3094 $meta_field_add = $data_type . ' NULL ';
3095
3096 if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
3097 $meta_field_add = 'DECIMAL(11, ' . (int) $decimal_point . ') NULL ';
3098 }
3099
3100 if ( is_numeric( $default_value ) && $default_value != '' ) {
3101 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3102 }
3103 } else {
3104 $meta_field_add = ' VARCHAR( 254 ) NULL ';
3105
3106 if ( $default_value != '' ) {
3107 $meta_field_add .= " DEFAULT '" . $default_value . "'";
3108 }
3109 }
3110
3111 $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3112 if ( $add_result === false ) {
3113 return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3114 }
3115 break;
3116 endswitch;
3117
3118 $extra_field_query = '';
3119 if ( ! empty( $extra_fields ) ) {
3120 $extra_field_query = serialize( $extra_fields );
3121 }
3122
3123 $wpdb->query(
3124 $wpdb->prepare(
3125 'insert into ' . $table_name . ' set
3126 form_type = %s,
3127 site_title = %s,
3128 form_label = %s,
3129 help_text = %s,
3130 field_type = %s,
3131 data_type = %s,
3132 decimal_point = %s,
3133 field_type_key = %s,
3134 htmlvar_name = %s,
3135 default_value = %s,
3136 sort_order = %d,
3137 is_active = %s,
3138 placeholder_value = %s,
3139 for_admin_use = %s,
3140 is_default = %s,
3141 is_required = %s,
3142 is_dummy = %s,
3143 is_public = %s,
3144 is_register_field = %s,
3145 is_search_field = %s,
3146 is_register_only_field = %s,
3147 required_msg = %s,
3148 css_class = %s,
3149 field_icon = %s,
3150 show_in = %s,
3151 user_roles = %s,
3152 option_values = %s,
3153 extra_fields = %s,
3154 validation_pattern = %s,
3155 validation_msg = %s,
3156 form_id = %d,
3157 user_sort = %s ',
3158 array(
3159 $form_type,
3160 $site_title,
3161 $form_label,
3162 $help_text,
3163 $field_type,
3164 $data_type,
3165 $decimal_point,
3166 $field_type_key,
3167 $htmlvar_name,
3168 $default_value,
3169 $sort_order,
3170 $is_active,
3171 $placeholder_value,
3172 $for_admin_use,
3173 $is_default,
3174 $is_required,
3175 $is_dummy,
3176 $is_public,
3177 $is_register_field,
3178 $is_search_field,
3179 $is_register_only_field,
3180 $required_msg,
3181 $css_class,
3182 $field_icon,
3183 $show_in,
3184 $user_roles,
3185 $option_values,
3186 $extra_field_query,
3187 $validation_pattern,
3188 $validation_msg,
3189 $form_id,
3190 $user_sort,
3191 )
3192 )
3193 );
3194
3195 $lastid = $wpdb->insert_id;
3196
3197 $lastid = trim( $lastid );
3198
3199 }
3200
3201 return (int) $lastid;
3202
3203 } else {
3204 return 'invalid_key';
3205 }
3206 }
3207
3208 public function register_ajax_handler() {
3209 if ( isset( $_REQUEST['create_field'] ) ) {
3210
3211 if ( ! current_user_can( 'manage_options' ) ) {
3212 wp_die( -1 );
3213 }
3214
3215 $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_text_field( $_REQUEST['form_id'] ) : 1;
3216 $field_id = isset( $_REQUEST['field_id'] ) ? trim( sanitize_text_field( $_REQUEST['field_id'] ), '_' ) : '';
3217 $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
3218
3219 /* ------- update order of fields ------- */
3220 if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['_wpnonce'] )) {
3221 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_create_field_nonce' ) ) {
3222 return;
3223 }
3224
3225 $field_ids = array();
3226 if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
3227 foreach ( $_REQUEST['licontainer'] as $lic_id ) {
3228 $field_ids[] = sanitize_text_field( $lic_id );
3229 }
3230 }
3231
3232 $return = uwp_form_extras_field_order( $field_ids, 'register', $form_id );
3233
3234 if ( is_array( $return ) ) {
3235 $return = json_encode( $return );
3236 }
3237
3238 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3239 }
3240
3241 /* ---- Show field form in admin ---- */
3242 if ( $field_action == 'new' ) {
3243 $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
3244 $fields = $this->register_fields( $form_type, $form_id );
3245
3246 $_REQUEST['site_field_id'] = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
3247 $_REQUEST['is_default'] = '0';
3248
3249 if ( ! empty( $fields ) ) {
3250 foreach ( $fields as $val ) {
3251 $val = stripslashes_deep( $val );
3252
3253 if ( $val['htmlvar_name'] == $_REQUEST['htmlvar_name'] ) {
3254 $_REQUEST['field_type'] = $val['field_type'];
3255 $_REQUEST['site_title'] = $val['site_title'];
3256 }
3257 }
3258 }
3259
3260 $htmlvar_name = isset( $_REQUEST['htmlvar_name'] ) ? sanitize_text_field( $_REQUEST['htmlvar_name'] ) : '';
3261
3262 $this->register_field_adminhtml( $htmlvar_name, $field_action, false, $_REQUEST );
3263 }
3264
3265 /* ---- Delete field ---- */
3266 if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) ) {
3267 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3268 return;
3269 }
3270
3271 echo $this->register_field_delete( $field_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3272 }
3273
3274 /* ---- Save field ---- */
3275 if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) ) {
3276 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3277 return;
3278 }
3279
3280 foreach ( $_REQUEST as $pkey => $pval ) {
3281 $tags = is_array( $_REQUEST[ $pkey ] ) ? 'skip_field' : '';
3282
3283 if ( $tags != 'skip_field' ) {
3284 $_REQUEST[ $pkey ] = strip_tags( sanitize_text_field( $_REQUEST[ $pkey ] ), $tags );
3285 }
3286 }
3287
3288 $return = $this->register_field_save( $_REQUEST );
3289
3290 if ( is_int( $return ) ) {
3291 $lastid = $return;
3292
3293 $this->register_field_adminhtml( $lastid, 'submit' );
3294 } else {
3295 echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3296 }
3297 }
3298 }
3299 die();
3300 }
3301
3302 public function register_field_delete( $field_id = '' ) {
3303
3304 global $wpdb;
3305 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3306
3307 if ( $field_id != '' ) {
3308 $cf = trim( $field_id, '_' );
3309
3310 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $extras_table_name . ' WHERE id= %d ', array( $cf ) ) );
3311
3312 return $field_id;
3313
3314 } else {
3315 return 0;
3316 }
3317 }
3318
3319 public function register_field_save( $request_field = array() ) {
3320
3321 if ( ! current_user_can( 'manage_options' ) ) {
3322 wp_die( -1 );
3323 }
3324
3325 global $wpdb;
3326 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3327
3328 $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : '';
3329 $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
3330
3331 $cf = trim( $result_str, '_' );
3332
3333 /*-------- check duplicate validation --------*/
3334
3335 $site_htmlvar_name = isset( $request_field['site_htmlvar_name'] ) ? sanitize_text_field( $request_field['site_htmlvar_name'] ) : sanitize_text_field( $request_field['htmlvar_name'] );
3336 $form_type = $request_field['form_type'];
3337 $field_type = $request_field['field_type'];
3338
3339 $check_html_variable = $wpdb->get_var(
3340 $wpdb->prepare(
3341 'select site_htmlvar_name from ' . $extras_table_name . ' where id <> %d and site_htmlvar_name = %s and form_type = %s and form_id=%d',
3342 array( $cf, $site_htmlvar_name, $form_type, $form_id )
3343 )
3344 );
3345
3346 if ( ! $check_html_variable ) {
3347
3348 if ( $cf != '' ) {
3349
3350 $user_meta_info = $wpdb->get_row(
3351 $wpdb->prepare(
3352 'select * from ' . $extras_table_name . ' where id = %d',
3353 array( $cf )
3354 )
3355 );
3356
3357 }
3358
3359 if ( $form_type == '' ) {
3360 $form_type = 'register';
3361 }
3362
3363 $site_htmlvar_name = sanitize_text_field( $request_field['site_htmlvar_name'] );
3364 $field_id = ( isset( $request_field['field_id'] ) && $request_field['field_id'] ) ? str_replace( 'new', '', $request_field['field_id'] ) : '';
3365
3366 if ( ! empty( $user_meta_info ) ) {
3367
3368 $wpdb->query(
3369 $wpdb->prepare(
3370 'update ' . $extras_table_name . ' set
3371 form_type = %s,
3372 field_type = %s,
3373 site_htmlvar_name = %s,
3374 sort_order = %s,
3375 form_id = %d
3376 where id = %d',
3377 array(
3378 $form_type,
3379 $field_type,
3380 $site_htmlvar_name,
3381 $field_id,
3382 $form_id,
3383 $cf,
3384 )
3385 )
3386 );
3387
3388 $lastid = trim( $cf );
3389
3390 } else {
3391
3392 $wpdb->query(
3393 $wpdb->prepare(
3394 'insert into ' . $extras_table_name . ' set
3395 form_type = %s,
3396 field_type = %s,
3397 site_htmlvar_name = %s,
3398 sort_order = %s,
3399 form_id = %s',
3400 array(
3401 $form_type,
3402 $field_type,
3403 $site_htmlvar_name,
3404 $field_id,
3405 $form_id,
3406 )
3407 )
3408 );
3409 $lastid = $wpdb->insert_id;
3410 $lastid = trim( $lastid );
3411 }
3412
3413 return (int) $lastid;
3414
3415 } else {
3416 return 'invalid_key';
3417 }
3418 }
3419 }
3420