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

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

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