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