| 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 |
// Get tabs for the form builder page |
| 35 |
$tabs = apply_filters( 'uwp_form_builder_tabs_array', array( |
| 36 |
'account' => __( 'Account', 'userswp' ), |
| 37 |
'register' => __( 'Register', 'userswp' ), |
| 38 |
) ); |
| 39 |
|
| 40 |
?> |
| 41 |
<div class="wrap"> |
| 42 |
<nav class="nav-tab-wrapper uwp-nav-tab-wrapper"> |
| 43 |
<?php |
| 44 |
foreach ( $tabs as $name => $label ) { |
| 45 |
echo '<a href="' . admin_url( 'admin.php?page=uwp_form_builder&tab=' . $name ) . '" id="uwp-form-builder-'. $name . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
| 46 |
} |
| 47 |
do_action( 'uwp_form_builder_tabs' ); |
| 48 |
?> |
| 49 |
</nav> |
| 50 |
<h1 class="screen-reader-text"><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1> |
| 51 |
<?php |
| 52 |
do_action( 'uwp_form_builder_tabs_content', $current_tab, $tabs); |
| 53 |
do_action( 'uwp_form_builder_tabs_' . $current_tab, $tabs ); |
| 54 |
do_action('uwp_extra_form_builder_content', $current_tab, $tabs); |
| 55 |
?> |
| 56 |
</div> |
| 57 |
<?php |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
public function uwp_form_builder($default_tab = 'account') |
| 62 |
{ |
| 63 |
ob_start(); |
| 64 |
$form_type = (isset($_REQUEST['tab']) && $_REQUEST['tab'] != '') ? sanitize_text_field($_REQUEST['tab']) : $default_tab; |
| 65 |
?> |
| 66 |
<div class="uwp-panel-heading"> |
| 67 |
<h3><?php echo apply_filters('uwp_form_builder_panel_head', ''); ?></h3> |
| 68 |
</div> |
| 69 |
|
| 70 |
<div id="uwp_form_builder_container" class="clearfix"> |
| 71 |
<div class="uwp-form-builder-frame"> |
| 72 |
<div class="uwp-side-sortables" id="uwp-available-fields"> |
| 73 |
<h3 class="hndle"> |
| 74 |
<span> |
| 75 |
<?php echo apply_filters('uwp_form_builder_available_fields_head', __('Add new form field', 'userswp'), $form_type); ?> |
| 76 |
</span> |
| 77 |
</h3> |
| 78 |
|
| 79 |
<p> |
| 80 |
<?php |
| 81 |
$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); |
| 82 |
echo apply_filters('uwp_form_builder_available_fields_note', $note, $form_type); |
| 83 |
?> |
| 84 |
</p> |
| 85 |
|
| 86 |
<h3> |
| 87 |
<?php _e('Standard Field', 'userswp'); ?> |
| 88 |
</h3> |
| 89 |
|
| 90 |
<div class="inside"> |
| 91 |
<div id="uwp-form-builder-tab" class="uwp-tabs-panel"> |
| 92 |
<?php do_action('uwp_manage_available_fields', $form_type); ?> |
| 93 |
</div> |
| 94 |
</div> |
| 95 |
|
| 96 |
<h3> |
| 97 |
<?php _e('Predefined Fields', 'userswp'); ?> |
| 98 |
</h3> |
| 99 |
|
| 100 |
<div class="inside"> |
| 101 |
<div id="uwp-form-builder-tab-predefined" class="uwp-tabs-panel"> |
| 102 |
<?php do_action('uwp_manage_available_fields_predefined', $form_type); ?> |
| 103 |
</div> |
| 104 |
</div> |
| 105 |
|
| 106 |
<h3> |
| 107 |
<?php _e('Custom Fields', 'userswp'); ?> |
| 108 |
</h3> |
| 109 |
|
| 110 |
<div class="inside"> |
| 111 |
<div id="uwp-form-builder-tab-custom" class="uwp-tabs-panel"> |
| 112 |
<?php do_action('uwp_manage_available_fields_custom', $form_type); ?> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
|
| 116 |
</div> |
| 117 |
|
| 118 |
|
| 119 |
<div class="uwp-side-sortables" id="uwp-selected-fields"> |
| 120 |
|
| 121 |
<h3 class="hndle"> |
| 122 |
<span> |
| 123 |
<?php |
| 124 |
$title = __('List of fields those will appear on add new listing form', 'userswp'); |
| 125 |
echo apply_filters('uwp_form_builder_selected_fields_head', $title, $form_type); ?> |
| 126 |
</span> |
| 127 |
</h3> |
| 128 |
|
| 129 |
<p> |
| 130 |
<?php |
| 131 |
$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); |
| 132 |
echo apply_filters('uwp_form_builder_selected_fields_note', $note, $form_type); ?> |
| 133 |
</p> |
| 134 |
|
| 135 |
<div class="inside"> |
| 136 |
<div id="uwp-form-builder-tab-selected" class="uwp-tabs-panel"> |
| 137 |
<div class="field_row_main"> |
| 138 |
<?php do_action('uwp_manage_selected_fields', $form_type); ?> |
| 139 |
</div> |
| 140 |
</div> |
| 141 |
</div> |
| 142 |
|
| 143 |
</div> |
| 144 |
|
| 145 |
</div> |
| 146 |
</div> |
| 147 |
|
| 148 |
<?php |
| 149 |
$output = ob_get_clean(); |
| 150 |
|
| 151 |
echo $output; |
| 152 |
} |
| 153 |
|
| 154 |
public function custom_available_fields($type = '', $form_type) |
| 155 |
{ |
| 156 |
?> |
| 157 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/> |
| 158 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields"> |
| 159 |
<?php |
| 160 |
if ($type == 'predefined') { |
| 161 |
$fields = $this->form_fields_predefined($form_type); |
| 162 |
}elseif ($type == 'custom') { |
| 163 |
$fields = $this->form_fields_custom($form_type); |
| 164 |
} else { |
| 165 |
$fields = $this->form_fields($form_type); |
| 166 |
?> |
| 167 |
<ul class="full"> |
| 168 |
<li class="uwp-tooltip-wrap"> |
| 169 |
<a id="uwp-fieldset" |
| 170 |
class="uwp-draggable-form-items uwp-fieldset" |
| 171 |
href="javascript:void(0);" |
| 172 |
data-field-custom-type="" |
| 173 |
data-field-type="fieldset" |
| 174 |
data-field-type-key="fieldset"> |
| 175 |
|
| 176 |
<i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i> |
| 177 |
<i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i> |
| 178 |
<?php _e('Fieldset (section separator)', 'userswp'); ?> |
| 179 |
|
| 180 |
<span class="uwp-help-tip uwp-help-tip-no-margin dashicons dashicons-editor-help" title="<?php _e('This adds a section separator with a title.', 'userswp'); ?>"></span> |
| 181 |
</a> |
| 182 |
</li> |
| 183 |
</ul> |
| 184 |
|
| 185 |
<?php |
| 186 |
} |
| 187 |
|
| 188 |
if (!empty($fields)) { |
| 189 |
?> |
| 190 |
<ul> |
| 191 |
<?php |
| 192 |
foreach ($fields as $id => $field) { |
| 193 |
?> |
| 194 |
<li class="uwp-tooltip-wrap"> |
| 195 |
<a id="uwp-<?php echo $id; ?>" |
| 196 |
data-field-custom-type="<?php echo $type; ?>" |
| 197 |
data-field-type-key="<?php echo $id; ?>" |
| 198 |
data-field-type="<?php echo $field['field_type']; ?>" |
| 199 |
class="uwp-draggable-form-items <?php echo $field['class']; ?>" |
| 200 |
href="javascript:void(0);"> |
| 201 |
|
| 202 |
<?php if (isset($field['icon']) && strpos($field['icon'], ' fa-') !== false) { |
| 203 |
echo '<i class="' . $field['icon'] . '" aria-hidden="true"></i>'; |
| 204 |
} elseif (isset($field['icon']) && $field['icon']) { |
| 205 |
echo '<b style="background-image: url("' . $field['icon'] . '")"></b>'; |
| 206 |
} else { |
| 207 |
echo '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 208 |
} ?> |
| 209 |
<?php echo $field['name']; ?> |
| 210 |
|
| 211 |
<?php if (isset($field['description']) && $field['description']) { ?> |
| 212 |
<span class="uwp-help-tip uwp-help-tip-no-margin dashicons dashicons-editor-help" title="<?php echo $field['description'] ?>"></span> |
| 213 |
<?php } ?> |
| 214 |
</a> |
| 215 |
</li> |
| 216 |
<?php |
| 217 |
} |
| 218 |
} else { |
| 219 |
_e('There are no custom fields here yet.', 'userswp'); |
| 220 |
} |
| 221 |
?> |
| 222 |
</ul> |
| 223 |
|
| 224 |
<?php |
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
public function form_fields_predefined($type = '') { |
| 229 |
$custom_fields = array(); |
| 230 |
|
| 231 |
// Country |
| 232 |
$custom_fields['uwp_country'] = array( // The key value should be unique and not contain any spaces. |
| 233 |
'field_type' => 'select', |
| 234 |
'class' => 'uwp-country', |
| 235 |
'icon' => 'fas fa-map-marker-alt', |
| 236 |
'name' => __('Country', 'userswp'), |
| 237 |
'description' => __('Adds a input for Country field.', 'userswp'), |
| 238 |
'defaults' => array( |
| 239 |
'admin_title' => 'Country', |
| 240 |
'site_title' => 'Country', |
| 241 |
'htmlvar_name' => 'uwp_country', |
| 242 |
'is_active' => 1, |
| 243 |
'default_value' => '', |
| 244 |
'is_required' => 0, |
| 245 |
'option_values' => '', |
| 246 |
'required_msg' => '', |
| 247 |
'field_icon' => 'fas fa-map-marker-alt', |
| 248 |
'css_class' => '' |
| 249 |
) |
| 250 |
); |
| 251 |
|
| 252 |
// Gender |
| 253 |
$custom_fields['gender'] = array( // The key value should be unique and not contain any spaces. |
| 254 |
'field_type' => 'select', |
| 255 |
'class' => 'uwp-gender', |
| 256 |
'icon' => 'fas fa-user', |
| 257 |
'name' => __('Gender', 'userswp'), |
| 258 |
'description' => __('Adds a input for Gender field.', 'userswp'), |
| 259 |
'defaults' => array( |
| 260 |
'admin_title' => 'Gender', |
| 261 |
'site_title' => 'Gender', |
| 262 |
'htmlvar_name' => 'gender', |
| 263 |
'is_active' => 1, |
| 264 |
'default_value' => '', |
| 265 |
'is_required' => 0, |
| 266 |
'option_values' => __('Select Gender/,Male,Female,Other', 'userswp'), |
| 267 |
'required_msg' => '', |
| 268 |
'field_icon' => 'fas fa-user', |
| 269 |
'css_class' => '' |
| 270 |
) |
| 271 |
); |
| 272 |
|
| 273 |
$custom_fields['dob'] = array( // The key value should be unique and not contain any spaces. |
| 274 |
'field_type' => 'datepicker', |
| 275 |
'class' => 'uwp-dob', |
| 276 |
'icon' => 'fas fa-birthday-cake', |
| 277 |
'name' => __( 'Date of birth', 'userswp' ), |
| 278 |
'description' => __( 'Adds a date input for users to enter their date of birth.', 'userswp' ), |
| 279 |
'defaults' => array( |
| 280 |
'data_type' => 'DATE', |
| 281 |
'admin_title' => __( 'Date of birth', 'userswp' ), |
| 282 |
'site_title' => __( 'Date of birth', 'userswp' ), |
| 283 |
'form_label' => __( 'Enter your date of birth.', 'userswp' ), |
| 284 |
'htmlvar_name' => 'dob', |
| 285 |
'is_active' => true, |
| 286 |
'for_admin_use' => false, |
| 287 |
'default_value' => '', |
| 288 |
'is_required' => false, |
| 289 |
'validation_pattern' => '', |
| 290 |
'validation_msg' => '', |
| 291 |
'required_msg' => '', |
| 292 |
'field_icon' => 'fas fa-birthday-cake', |
| 293 |
'css_class' => '', |
| 294 |
'cat_sort' => true, |
| 295 |
'cat_filter' => true, |
| 296 |
'extra_fields' => array( |
| 297 |
'date_range' => 'c-100:c+0' |
| 298 |
) |
| 299 |
) |
| 300 |
); |
| 301 |
|
| 302 |
// Mobile |
| 303 |
$custom_fields['mobile'] = array( // The key value should be unique and not contain any spaces. |
| 304 |
'field_type' => 'phone', |
| 305 |
'class' => 'uwp-mobile', |
| 306 |
'icon' => 'fas fa-mobile-alt', |
| 307 |
'name' => __('Mobile', 'userswp'), |
| 308 |
'description' => __('Adds a input for Mobile field.', 'userswp'), |
| 309 |
'defaults' => array( |
| 310 |
'admin_title' => 'Mobile', |
| 311 |
'site_title' => 'Mobile', |
| 312 |
'htmlvar_name' => 'mobile', |
| 313 |
'is_active' => 1, |
| 314 |
'default_value' => '', |
| 315 |
'is_required' => 0, |
| 316 |
'required_msg' => '', |
| 317 |
'field_icon' => 'fas fa-mobile-alt', |
| 318 |
'css_class' => '' |
| 319 |
) |
| 320 |
); |
| 321 |
|
| 322 |
// Website |
| 323 |
$custom_fields['website'] = array( // The key value should be unique and not contain any spaces. |
| 324 |
'field_type' => 'url', |
| 325 |
'class' => 'uwp-website', |
| 326 |
'icon' => 'fas fa-link', |
| 327 |
'name' => __('Website', 'userswp'), |
| 328 |
'description' => __('Let users enter their website url.', 'userswp'), |
| 329 |
'defaults' => array( |
| 330 |
'admin_title' => 'Website', |
| 331 |
'site_title' => 'Website', |
| 332 |
'form_label' => __( 'Website', 'userswp' ), |
| 333 |
'htmlvar_name' => 'user_url', |
| 334 |
'is_active' => 1, |
| 335 |
'default_value' => '', |
| 336 |
'is_required' => 0, |
| 337 |
'required_msg' => '', |
| 338 |
'field_icon' => 'fas fa-link', |
| 339 |
'css_class' => 'btn-website' |
| 340 |
) |
| 341 |
); |
| 342 |
|
| 343 |
// Facebook |
| 344 |
$custom_fields['facebook'] = array( // The key value should be unique and not contain any spaces. |
| 345 |
'field_type' => 'url', |
| 346 |
'class' => 'uwp-facebook', |
| 347 |
'icon' => 'fab fa-facebook-square', |
| 348 |
'name' => __('Facebook', 'userswp'), |
| 349 |
'description' => __('Let users enter their facebook url.', 'userswp'), |
| 350 |
'defaults' => array( |
| 351 |
'admin_title' => 'Facebook', |
| 352 |
'site_title' => 'Facebook', |
| 353 |
'form_label' => __( 'Facebook url', 'userswp' ), |
| 354 |
'htmlvar_name' => 'facebook', |
| 355 |
'is_active' => 1, |
| 356 |
'default_value' => '', |
| 357 |
'is_required' => 0, |
| 358 |
'required_msg' => '', |
| 359 |
'field_icon' => 'fab fa-facebook-f', |
| 360 |
'css_class' => 'btn-facebook' |
| 361 |
) |
| 362 |
); |
| 363 |
|
| 364 |
// Twitter |
| 365 |
$custom_fields['twitter'] = array( // The key value should be unique and not contain any spaces. |
| 366 |
'field_type' => 'url', |
| 367 |
'class' => 'uwp-twitter', |
| 368 |
'icon' => 'fab fa-twitter-square', |
| 369 |
'name' => __('Twitter', 'userswp'), |
| 370 |
'description' => __('Let users enter their twitter url.', 'userswp'), |
| 371 |
'defaults' => array( |
| 372 |
'admin_title' => 'Twitter', |
| 373 |
'site_title' => 'Twitter', |
| 374 |
'form_label' => __( 'Twitter url', 'userswp' ), |
| 375 |
'htmlvar_name' => 'twitter', |
| 376 |
'is_active' => 1, |
| 377 |
'default_value' => '', |
| 378 |
'is_required' => 0, |
| 379 |
'required_msg' => '', |
| 380 |
'field_icon' => 'fab fa-twitter', |
| 381 |
'css_class' => 'btn-twitter' |
| 382 |
) |
| 383 |
); |
| 384 |
|
| 385 |
// Instagram |
| 386 |
$custom_fields['instagram'] = array( // The key value should be unique and not contain any spaces. |
| 387 |
'field_type' => 'url', |
| 388 |
'class' => 'uwp-instagram', |
| 389 |
'icon' => 'fab fa-instagram', |
| 390 |
'name' => __('Instagram', 'userswp'), |
| 391 |
'description' => __('Let users enter their instagram url.', 'userswp'), |
| 392 |
'defaults' => array( |
| 393 |
'admin_title' => 'Instagram', |
| 394 |
'site_title' => 'Instagram', |
| 395 |
'form_label' => __( 'Instagram url', 'userswp' ), |
| 396 |
'htmlvar_name' => 'instagram', |
| 397 |
'is_active' => 1, |
| 398 |
'default_value' => '', |
| 399 |
'is_required' => 0, |
| 400 |
'required_msg' => '', |
| 401 |
'field_icon' => 'fab fa-instagram', |
| 402 |
'css_class' => 'btn-instagram' |
| 403 |
) |
| 404 |
); |
| 405 |
|
| 406 |
// Linkedin |
| 407 |
$custom_fields['linkedin'] = array( // The key value should be unique and not contain any spaces. |
| 408 |
'field_type' => 'url', |
| 409 |
'class' => 'uwp-linkedin', |
| 410 |
'icon' => 'fab fa-linkedin', |
| 411 |
'name' => __('Linkedin', 'userswp'), |
| 412 |
'description' => __('Let users enter their linkedin url.', 'userswp'), |
| 413 |
'defaults' => array( |
| 414 |
'admin_title' => 'Linkedin', |
| 415 |
'site_title' => 'Linkedin', |
| 416 |
'form_label' => __( 'Linkedin url', 'userswp' ), |
| 417 |
'htmlvar_name' => 'linkedin', |
| 418 |
'is_active' => 1, |
| 419 |
'default_value' => '', |
| 420 |
'is_required' => 0, |
| 421 |
'required_msg' => '', |
| 422 |
'field_icon' => 'fab fa-linkedin-in', |
| 423 |
'css_class' => 'btn-linkedin' |
| 424 |
) |
| 425 |
); |
| 426 |
|
| 427 |
|
| 428 |
// Flickr |
| 429 |
$custom_fields['flickr'] = array( // The key value should be unique and not contain any spaces. |
| 430 |
'field_type' => 'url', |
| 431 |
'class' => 'uwp-flickr', |
| 432 |
'icon' => 'fab fa-flickr', |
| 433 |
'name' => __('Flickr', 'userswp'), |
| 434 |
'description' => __('Let users enter their Flickr url.', 'userswp'), |
| 435 |
'defaults' => array( |
| 436 |
'admin_title' => 'Flickr', |
| 437 |
'site_title' => 'Flickr', |
| 438 |
'form_label' => __( 'Flickr url', 'userswp' ), |
| 439 |
'htmlvar_name' => 'flickr', |
| 440 |
'is_active' => 1, |
| 441 |
'default_value' => '', |
| 442 |
'is_required' => 0, |
| 443 |
'required_msg' => '', |
| 444 |
'field_icon' => 'fab fa-flickr', |
| 445 |
'css_class' => 'btn-flickr' |
| 446 |
) |
| 447 |
); |
| 448 |
|
| 449 |
// GitHub |
| 450 |
$custom_fields['github'] = array( // The key value should be unique and not contain any spaces. |
| 451 |
'field_type' => 'url', |
| 452 |
'class' => 'uwp-github', |
| 453 |
'icon' => 'fab fa-github-square', |
| 454 |
'name' => __('GitHub', 'userswp'), |
| 455 |
'description' => __('Let users enter their GitHub url.', 'userswp'), |
| 456 |
'defaults' => array( |
| 457 |
'admin_title' => 'GitHub', |
| 458 |
'site_title' => 'GitHub', |
| 459 |
'form_label' => __( 'GitHub url', 'userswp' ), |
| 460 |
'htmlvar_name' => 'github', |
| 461 |
'is_active' => 1, |
| 462 |
'default_value' => '', |
| 463 |
'is_required' => 0, |
| 464 |
'required_msg' => '', |
| 465 |
'field_icon' => 'fab fa-github-alt', |
| 466 |
'css_class' => 'btn-github' |
| 467 |
) |
| 468 |
); |
| 469 |
|
| 470 |
// YouTube |
| 471 |
$custom_fields['youtube'] = array( // The key value should be unique and not contain any spaces. |
| 472 |
'field_type' => 'url', |
| 473 |
'class' => 'uwp-youtube', |
| 474 |
'icon' => 'fab fa-youtube-square', |
| 475 |
'name' => __('YouTube', 'userswp'), |
| 476 |
'description' => __('Let users enter their YouTube url.', 'userswp'), |
| 477 |
'defaults' => array( |
| 478 |
'admin_title' => 'YouTube', |
| 479 |
'site_title' => 'YouTube', |
| 480 |
'form_label' => __( 'YouTube url', 'userswp' ), |
| 481 |
'htmlvar_name' => 'youtube', |
| 482 |
'is_active' => 1, |
| 483 |
'default_value' => '', |
| 484 |
'is_required' => 0, |
| 485 |
'required_msg' => '', |
| 486 |
'field_icon' => 'fab fa-youtube', |
| 487 |
'css_class' => 'btn-youtube' |
| 488 |
) |
| 489 |
); |
| 490 |
|
| 491 |
// WordPress |
| 492 |
$custom_fields['wordpress'] = array( // The key value should be unique and not contain any spaces. |
| 493 |
'field_type' => 'url', |
| 494 |
'class' => 'uwp-wordpress', |
| 495 |
'icon' => 'fab fa-wordpress-simple', |
| 496 |
'name' => __('WordPress', 'userswp'), |
| 497 |
'description' => __('Let users enter their WordPress profile url.', 'userswp'), |
| 498 |
'defaults' => array( |
| 499 |
'admin_title' => 'WordPress', |
| 500 |
'site_title' => 'WordPress', |
| 501 |
'form_label' => __( 'WordPress url', 'userswp' ), |
| 502 |
'htmlvar_name' => 'wordpress', |
| 503 |
'is_active' => 1, |
| 504 |
'default_value' => '', |
| 505 |
'is_required' => 0, |
| 506 |
'required_msg' => '', |
| 507 |
'field_icon' => 'fab fa-wordpress-simple', |
| 508 |
'css_class' => 'btn-wordpress' |
| 509 |
) |
| 510 |
); |
| 511 |
|
| 512 |
|
| 513 |
return apply_filters('uwp_form_fields_predefined', $custom_fields, $type); |
| 514 |
} |
| 515 |
|
| 516 |
public function form_fields_custom($type = '') { |
| 517 |
$custom_fields = array(); |
| 518 |
return apply_filters('uwp_form_fields_custom', $custom_fields, $type); |
| 519 |
} |
| 520 |
|
| 521 |
public function form_fields($type = '') { |
| 522 |
|
| 523 |
$custom_fields = array( |
| 524 |
'text' => array( |
| 525 |
'field_type' => 'text', |
| 526 |
'class' => 'uwp-text', |
| 527 |
'icon' => 'fas fa-minus', |
| 528 |
'name' => __('Text', 'userswp'), |
| 529 |
'description' => __('Add any sort of text field, text or numbers', 'userswp') |
| 530 |
), |
| 531 |
'datepicker' => array( |
| 532 |
'field_type' => 'datepicker', |
| 533 |
'class' => 'uwp-datepicker', |
| 534 |
'icon' => 'fas fa-calendar-alt', |
| 535 |
'name' => __('Date', 'userswp'), |
| 536 |
'description' => __('Adds a date picker.', 'userswp') |
| 537 |
), |
| 538 |
'textarea' => array( |
| 539 |
'field_type' => 'textarea', |
| 540 |
'class' => 'uwp-textarea', |
| 541 |
'icon' => 'fas fa-bars', |
| 542 |
'name' => __('Textarea', 'userswp'), |
| 543 |
'description' => __('Adds a textarea', 'userswp') |
| 544 |
), |
| 545 |
'time' => array( |
| 546 |
'field_type' => 'time', |
| 547 |
'class' => 'uwp-time', |
| 548 |
'icon' => 'far fa-clock', |
| 549 |
'name' => __('Time', 'userswp'), |
| 550 |
'description' => __('Adds a time picker', 'userswp') |
| 551 |
), |
| 552 |
'checkbox' => array( |
| 553 |
'field_type' => 'checkbox', |
| 554 |
'class' => 'uwp-checkbox', |
| 555 |
'icon' => 'far fa-check-square', |
| 556 |
'name' => __('Checkbox', 'userswp'), |
| 557 |
'description' => __('Adds a checkbox', 'userswp') |
| 558 |
), |
| 559 |
'phone' => array( |
| 560 |
'field_type' => 'phone', |
| 561 |
'class' => 'uwp-phone', |
| 562 |
'icon' => 'fas fa-phone', |
| 563 |
'name' => __('Phone', 'userswp'), |
| 564 |
'description' => __('Adds a phone input', 'userswp') |
| 565 |
), |
| 566 |
'radio' => array( |
| 567 |
'field_type' => 'radio', |
| 568 |
'class' => 'uwp-radio', |
| 569 |
'icon' => 'far fa-dot-circle', |
| 570 |
'name' => __('Radio', 'userswp'), |
| 571 |
'description' => __('Adds a radio input', 'userswp') |
| 572 |
), |
| 573 |
'email' => array( |
| 574 |
'field_type' => 'email', |
| 575 |
'class' => 'uwp-email', |
| 576 |
'icon' => 'far fa-envelope', |
| 577 |
'name' => __('Email', 'userswp'), |
| 578 |
'description' => __('Adds a email input', 'userswp') |
| 579 |
), |
| 580 |
'select' => array( |
| 581 |
'field_type' => 'select', |
| 582 |
'class' => 'uwp-select', |
| 583 |
'icon' => 'far fa-caret-square-down', |
| 584 |
'name' => __('Select', 'userswp'), |
| 585 |
'description' => __('Adds a select input', 'userswp') |
| 586 |
), |
| 587 |
'multiselect' => array( |
| 588 |
'field_type' => 'multiselect', |
| 589 |
'class' => 'uwp-multiselect', |
| 590 |
'icon' => 'far fa-caret-square-down', |
| 591 |
'name' => __('Multi Select', 'userswp'), |
| 592 |
'description' => __('Adds a multiselect input', 'userswp') |
| 593 |
), |
| 594 |
'url' => array( |
| 595 |
'field_type' => 'url', |
| 596 |
'class' => 'uwp-url', |
| 597 |
'icon' => 'fas fa-link', |
| 598 |
'name' => __('URL', 'userswp'), |
| 599 |
'description' => __('Adds a url input', 'userswp') |
| 600 |
), |
| 601 |
'file' => array( |
| 602 |
'field_type' => 'file', |
| 603 |
'class' => 'uwp-file', |
| 604 |
'icon' => 'fas fa-file', |
| 605 |
'name' => __('File Upload', 'userswp'), |
| 606 |
'description' => __('Adds a file input', 'userswp') |
| 607 |
) |
| 608 |
); |
| 609 |
|
| 610 |
return apply_filters('uwp_form_fields', $custom_fields, $type); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
public function manage_available_fields_predefined($form_type) { |
| 615 |
switch ($form_type) { |
| 616 |
case 'account': |
| 617 |
$this->custom_available_fields('predefined', $form_type); |
| 618 |
break; |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
public function manage_available_fields_custom($form_type) { |
| 623 |
switch ($form_type) { |
| 624 |
case 'account': |
| 625 |
$this->custom_available_fields('custom', $form_type); |
| 626 |
break; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
public function manage_available_fields($form_type) { |
| 631 |
switch ($form_type) { |
| 632 |
case 'account': |
| 633 |
$this->custom_available_fields('', $form_type); |
| 634 |
break; |
| 635 |
case 'register': |
| 636 |
$this->register_available_fields($form_type); |
| 637 |
break; |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
public function manage_selected_fields($form_type) { |
| 642 |
switch ($form_type) { |
| 643 |
case 'account': |
| 644 |
$this->custom_selected_fields($form_type); |
| 645 |
break; |
| 646 |
case 'register': |
| 647 |
$this->register_selected_fields($form_type); |
| 648 |
break; |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
public function custom_selected_fields($form_type) |
| 653 |
{ |
| 654 |
|
| 655 |
global $wpdb; |
| 656 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 657 |
?> |
| 658 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/> |
| 659 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields"> |
| 660 |
<ul class="core uwp-tabs-selected uwp_form_extras"> |
| 661 |
<?php |
| 662 |
$fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s ORDER BY sort_order ASC", array($form_type))); |
| 663 |
|
| 664 |
if (!empty($fields)) { |
| 665 |
foreach ($fields as $field) { |
| 666 |
//$result_str = $field->id; |
| 667 |
$result_str = $field; |
| 668 |
$field_type = $field->field_type; |
| 669 |
$field_type_key = $field->field_type_key; |
| 670 |
$field_ins_upd = 'display'; |
| 671 |
|
| 672 |
$this->form_field_adminhtml($field_type, $result_str, $field_ins_upd, $field_type_key); |
| 673 |
} |
| 674 |
} |
| 675 |
?></ul> |
| 676 |
<?php |
| 677 |
|
| 678 |
} |
| 679 |
|
| 680 |
/** |
| 681 |
* @param $field_info |
| 682 |
* @param $field_type |
| 683 |
* @param string $field_type_key |
| 684 |
* @param string $field_ins_upd |
| 685 |
* @param $result_str |
| 686 |
* @param bool $form_type |
| 687 |
*/ |
| 688 |
public function admin_form_field_html($field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type = false) { |
| 689 |
|
| 690 |
if (!$form_type) { |
| 691 |
if (!isset($field_info->form_type)) { |
| 692 |
$form_type = sanitize_text_field($_REQUEST['tab']); |
| 693 |
} else { |
| 694 |
$form_type = $field_info->form_type; |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
$cf_arr1 = $this->form_fields($form_type); |
| 699 |
$cf_arr2 = $this->form_fields_predefined($form_type); |
| 700 |
$cf_arr3 = $this->form_fields_custom($form_type); |
| 701 |
|
| 702 |
$cf_arr = $cf_arr1 + $cf_arr2 + $cf_arr3; // this way defaults can't be overwritten |
| 703 |
|
| 704 |
$cf = (isset($cf_arr[$field_type_key])) ? $cf_arr[$field_type_key] : ''; |
| 705 |
|
| 706 |
$field_info = stripslashes_deep($field_info); // strip slashes from labels |
| 707 |
|
| 708 |
$field_site_title = ''; |
| 709 |
if (isset($field_info->site_title)) |
| 710 |
$field_site_title = $field_info->site_title; |
| 711 |
|
| 712 |
$default = isset($field_info->is_default) ? $field_info->is_default : ''; |
| 713 |
|
| 714 |
$field_display = $field_type == 'address' && $field_info->htmlvar_name == 'post' ? 'style="display:none"' : ''; |
| 715 |
|
| 716 |
if (isset($cf['icon']) && strpos($cf['icon'], ' fa-') !== false) { |
| 717 |
$field_icon = '<i class="' . $cf['icon'] . '" aria-hidden="true"></i>'; |
| 718 |
}elseif (isset($cf['icon']) && $cf['icon']) { |
| 719 |
$field_icon = '<b style="background-image: url("' . $cf['icon'] . '")"></b>'; |
| 720 |
} else { |
| 721 |
$field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 722 |
} |
| 723 |
|
| 724 |
if (isset($cf['name']) && $cf['name']) { |
| 725 |
$field_type_name = $cf['name']; |
| 726 |
} else { |
| 727 |
$field_type_name = $field_type; |
| 728 |
} |
| 729 |
|
| 730 |
?> |
| 731 |
<li class="text li-settings" id="licontainer_<?php echo $result_str; ?>"> |
| 732 |
<i class="fas fa-caret-down toggle-arrow" aria-hidden="true" onclick="uwp_show_hide(this);"></i> |
| 733 |
<div class="title title<?php echo $result_str; ?> uwp-fieldset"> |
| 734 |
<?php |
| 735 |
$nonce = wp_create_nonce('custom_fields_' . $result_str); |
| 736 |
if ($field_type == 'fieldset') { |
| 737 |
?> |
| 738 |
<i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i> |
| 739 |
<i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i> |
| 740 |
<b><?php echo uwp_ucwords(__('Fieldset:', 'userswp')); ?></b> |
| 741 |
<span class="field-type"><?php echo ' ('.uwp_ucwords($field_site_title).')';?></span> |
| 742 |
<?php |
| 743 |
} else {echo $field_icon; |
| 744 |
?> |
| 745 |
<b><?php echo uwp_ucwords(' ' . $field_site_title ); ?></b> |
| 746 |
<span class="field-type"><?php echo ' ('.uwp_ucwords($field_type_name).')';?></span> |
| 747 |
<?php |
| 748 |
} |
| 749 |
?> |
| 750 |
</div> |
| 751 |
|
| 752 |
<form> |
| 753 |
<div id="field_frm<?php echo $result_str; ?>" class="field_frm" |
| 754 |
style="display:<?php if ($field_ins_upd == 'submit') { |
| 755 |
echo 'block;'; |
| 756 |
} else { |
| 757 |
echo 'none;'; |
| 758 |
} ?>"> |
| 759 |
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr($nonce); ?>"/> |
| 760 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/> |
| 761 |
<input type="hidden" name="field_type" id="field_type" value="<?php echo $field_type; ?>"/> |
| 762 |
<input type="hidden" name="field_type_key" id="field_type_key" value="<?php echo $field_type_key; ?>"/> |
| 763 |
<input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr($result_str); ?>"/> |
| 764 |
<input type="hidden" name="is_active" id="is_active" value="1"/> |
| 765 |
|
| 766 |
<input type="hidden" name="is_default" value="<?php echo isset($field_info->is_default) ? $field_info->is_default : ''; ?>" /><?php // show in sidebar value?> |
| 767 |
|
| 768 |
<ul class="widefat post fixed" style="width:100%;"> |
| 769 |
|
| 770 |
<?php |
| 771 |
// data_type |
| 772 |
if (has_filter("uwp_builder_data_type_{$field_type}")) { |
| 773 |
|
| 774 |
echo apply_filters("uwp_builder_data_type_{$field_type}", '', $result_str, $cf, $field_info); |
| 775 |
|
| 776 |
} else { |
| 777 |
$value = ''; |
| 778 |
if (isset($field_info->data_type)) { |
| 779 |
$value = esc_attr($field_info->data_type); |
| 780 |
}elseif (isset($cf['defaults']['data_type']) && $cf['defaults']['data_type']) { |
| 781 |
$value = $cf['defaults']['data_type']; |
| 782 |
} |
| 783 |
?> |
| 784 |
<input type="hidden" name="data_type" id="data_type" value="<?php echo $value; ?>"/> |
| 785 |
<?php |
| 786 |
} |
| 787 |
|
| 788 |
// site_title |
| 789 |
if (has_filter("uwp_builder_site_title_{$field_type}")) { |
| 790 |
|
| 791 |
echo apply_filters("uwp_builder_site_title_{$field_type}", '', $result_str, $cf, $field_info); |
| 792 |
|
| 793 |
} else { |
| 794 |
$value = ''; |
| 795 |
if (isset($field_info->site_title)) { |
| 796 |
$value = esc_attr($field_info->site_title); |
| 797 |
}elseif (isset($cf['defaults']['site_title']) && $cf['defaults']['site_title']) { |
| 798 |
$value = $cf['defaults']['site_title']; |
| 799 |
} |
| 800 |
?> |
| 801 |
<li class="uwp-setting-name"> |
| 802 |
<label for="site_title" class="uwp-tooltip-wrap"> |
| 803 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('This will be the label for the field.', 'userswp'); ?>"></span> |
| 804 |
<?php _e('Field Label:', 'userswp'); ?> |
| 805 |
</label> |
| 806 |
<div class="uwp-input-wrap"> |
| 807 |
<input type="text" name="site_title" id="site_title" |
| 808 |
value="<?php echo $value; ?>"/> |
| 809 |
</div> |
| 810 |
</li> |
| 811 |
<?php |
| 812 |
} |
| 813 |
|
| 814 |
// Input Label |
| 815 |
if (has_filter("uwp_builder_form_label_{$field_type}")) { |
| 816 |
|
| 817 |
echo apply_filters("uwp_builder_form_label_{$field_type}", '', $result_str, $cf, $field_info); |
| 818 |
|
| 819 |
} else { |
| 820 |
$value = ''; |
| 821 |
if (isset($field_info->form_label)) { |
| 822 |
$value = esc_attr($field_info->form_label); |
| 823 |
}elseif (isset($cf['defaults']['form_label']) && $cf['defaults']['form_label']) { |
| 824 |
$value = $cf['defaults']['form_label']; |
| 825 |
} |
| 826 |
?> |
| 827 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 828 |
<label for="form_label" class="uwp-tooltip-wrap"> |
| 829 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('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'); ?>"></span> |
| 830 |
<?php _e('Form Label: (Optional)', 'userswp'); ?> |
| 831 |
</label> |
| 832 |
<div class="uwp-input-wrap"> |
| 833 |
<input type="text" name="form_label" id="form_label" |
| 834 |
value="<?php echo $value; ?>"/> |
| 835 |
</div> |
| 836 |
</li> |
| 837 |
<?php |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
// htmlvar_name |
| 842 |
if(has_filter("uwp_builder_htmlvar_name_{$field_type}")){ |
| 843 |
|
| 844 |
echo apply_filters("uwp_builder_htmlvar_name_{$field_type}",'',$result_str,$cf,$field_info); |
| 845 |
|
| 846 |
}else{ |
| 847 |
$value = ''; |
| 848 |
if (isset($field_info->htmlvar_name)) { |
| 849 |
$value = esc_attr($field_info->htmlvar_name); |
| 850 |
}elseif(isset($cf['defaults']['htmlvar_name']) && $cf['defaults']['htmlvar_name']){ |
| 851 |
$value = $cf['defaults']['htmlvar_name']; |
| 852 |
} |
| 853 |
?> |
| 854 |
<li class="uwp-setting-name"> |
| 855 |
<label for="htmlvar_name" class="uwp-tooltip-wrap"> |
| 856 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('This is a unique identifier used in the HTML, it MUST NOT contain spaces or special characters.', 'userswp'); ?>"></span> |
| 857 |
<?php _e('Field Key :', 'userswp');?> |
| 858 |
</label> |
| 859 |
<div class="uwp-input-wrap"> |
| 860 |
<input type="text" name="htmlvar_name" id="htmlvar_name" pattern="[a-zA-Z0-9]+" title="<?php _e('Must not contain spaces or special characters', 'userswp');?>" |
| 861 |
value="<?php if ($value) { |
| 862 |
echo preg_replace('/uwp_'.$form_type.'_/', '', $value, 1); |
| 863 |
}?>" <?php if ( ! empty( $value ) && $value != '' ) { echo 'readonly="readonly"'; } ?> /> |
| 864 |
</div> |
| 865 |
</li> |
| 866 |
<?php |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
// is_active |
| 871 |
if (has_filter("uwp_builder_is_active_{$field_type}")) { |
| 872 |
|
| 873 |
echo apply_filters("uwp_builder_is_active_{$field_type}", '', $result_str, $cf, $field_info); |
| 874 |
|
| 875 |
} else { |
| 876 |
$value = ''; |
| 877 |
if (isset($field_info->is_active)) { |
| 878 |
$value = esc_attr($field_info->is_active); |
| 879 |
}elseif (isset($cf['defaults']['is_active']) && $cf['defaults']['is_active']) { |
| 880 |
$value = $cf['defaults']['is_active']; |
| 881 |
} |
| 882 |
?> |
| 883 |
<li <?php echo $field_display; ?> class="uwp-setting-name"> |
| 884 |
<label for="is_active" class="uwp-tooltip-wrap"> |
| 885 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('If no is selected then the field will not be displayed anywhere.', 'userswp'); ?>"></span> |
| 886 |
<?php _e('Is active :', 'userswp'); ?> |
| 887 |
</label> |
| 888 |
<div class="uwp-input-wrap"> |
| 889 |
<input type="hidden" name="is_active" value="0" /> |
| 890 |
<input type="checkbox" name="is_active" value="1" <?php checked( $value, 1, true );?> /> |
| 891 |
</div> |
| 892 |
</li> |
| 893 |
<?php |
| 894 |
} |
| 895 |
|
| 896 |
// for_admin_use |
| 897 |
if (isset($field_info->is_default) && $field_info->is_default == '1') { |
| 898 |
// do nothing for default fields |
| 899 |
} else { |
| 900 |
if (has_filter("uwp_builder_for_admin_use_{$field_type}")) { |
| 901 |
|
| 902 |
echo apply_filters("uwp_builder_for_admin_use_{$field_type}", '', $result_str, $cf, $field_info); |
| 903 |
|
| 904 |
} else { |
| 905 |
$value = ''; |
| 906 |
if (isset($field_info->for_admin_use)) { |
| 907 |
$value = esc_attr($field_info->for_admin_use); |
| 908 |
}elseif (isset($cf['defaults']['for_admin_use']) && $cf['defaults']['for_admin_use']) { |
| 909 |
$value = $cf['defaults']['for_admin_use']; |
| 910 |
} |
| 911 |
?> |
| 912 |
<li <?php echo $field_display; ?> class="uwp-setting-name uwp-advanced-setting"> |
| 913 |
<label for="for_admin_use" class="uwp-tooltip-wrap"> |
| 914 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('If yes is selected then only site admin can see and edit this field.', 'userswp'); ?>"></span> |
| 915 |
<?php _e('For admin use only? :', 'userswp'); ?> |
| 916 |
</label> |
| 917 |
<div class="uwp-input-wrap"> |
| 918 |
<input type="hidden" name="for_admin_use" value="0" /> |
| 919 |
<input type="checkbox" name="for_admin_use" value="1" <?php checked( $value, 1, true );?> /> |
| 920 |
</div> |
| 921 |
</li> |
| 922 |
<?php |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
// is_public |
| 928 |
if (isset($field_info->is_default) && $field_info->is_default == '1') { |
| 929 |
// do nothing for default fields |
| 930 |
} else { |
| 931 |
if ( has_filter( "uwp_builder_is_public_{$field_type}" ) ) { |
| 932 |
|
| 933 |
echo apply_filters( "uwp_builder_is_public_{$field_type}", '', $result_str, $cf, $field_info ); |
| 934 |
|
| 935 |
} else { |
| 936 |
$value = ''; |
| 937 |
if ( isset( $field_info->is_public ) ) { |
| 938 |
$value = esc_attr( $field_info->is_public ); |
| 939 |
} elseif ( isset( $cf['defaults']['is_public'] ) && $cf['defaults']['is_public'] ) { |
| 940 |
$value = $cf['defaults']['is_public']; |
| 941 |
} |
| 942 |
?> |
| 943 |
<li <?php echo $field_display; ?> class="uwp-setting-name uwp-advanced-setting"> |
| 944 |
<label for="is_public" class="uwp-tooltip-wrap"> |
| 945 |
<span class="uwp-help-tip dashicons dashicons-editor-help" |
| 946 |
title="<?php _e( 'If no is selected then the field will not be visible to other users.', 'userswp' ); ?>"></span> |
| 947 |
<?php _e( 'Is Public :', 'userswp' ); ?> |
| 948 |
</label> |
| 949 |
<div class="uwp-input-wrap"> |
| 950 |
<?php |
| 951 |
if ( ! $value ) { |
| 952 |
$value = "1"; |
| 953 |
} |
| 954 |
?> |
| 955 |
|
| 956 |
<select name="is_public" class="aui-select2"> |
| 957 |
<option value="1" <?php selected( $value, "1" ); ?>><?php echo __( "Yes", "userswp" ) ?></option> |
| 958 |
<option value="0" <?php selected( $value, "0" ); ?>><?php echo __( "No", "userswp" ) ?></option> |
| 959 |
<option value="2" <?php selected( $value, "2" ); ?>><?php echo __( "Let User Decide", "userswp" ) ?></option> |
| 960 |
</select> |
| 961 |
|
| 962 |
</div> |
| 963 |
</li> |
| 964 |
<?php |
| 965 |
} |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
// default_value |
| 970 |
if (has_filter("uwp_builder_default_value_{$field_type}")) { |
| 971 |
|
| 972 |
echo apply_filters("uwp_builder_default_value_{$field_type}", '', $result_str, $cf, $field_info); |
| 973 |
|
| 974 |
} else { |
| 975 |
$value = ''; |
| 976 |
if (isset($field_info->default_value)) { |
| 977 |
$value = esc_attr($field_info->default_value); |
| 978 |
}elseif (isset($cf['defaults']['default_value']) && $cf['defaults']['default_value']) { |
| 979 |
$value = $cf['defaults']['default_value']; |
| 980 |
} |
| 981 |
?> |
| 982 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 983 |
<label for="default_value" class="uwp-tooltip-wrap"> |
| 984 |
<?php |
| 985 |
if ($field_type == 'checkbox') { |
| 986 |
$tip = __('Should the checkbox be checked by default?', 'userswp'); |
| 987 |
} else if ($field_type == 'email') { |
| 988 |
$tip = __('A default value for the field, usually blank. Ex: info@mysite.com', 'userswp'); |
| 989 |
} else { |
| 990 |
$tip = __('A default value for the field, usually blank. (for "link" this will be used as the link text)', 'userswp'); |
| 991 |
} |
| 992 |
?> |
| 993 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php echo $tip; ?>"></span> |
| 994 |
<?php _e('Default value :', 'userswp'); ?> |
| 995 |
</label> |
| 996 |
<div class="uwp-input-wrap"> |
| 997 |
<?php if ($field_type == 'checkbox') { ?> |
| 998 |
<select name="default_value" id="default_value" class="aui-select2"> |
| 999 |
<option value=""><?php _e('Unchecked', 'userswp'); ?></option> |
| 1000 |
<option value="1" <?php selected(true, (int) $value === 1); ?>><?php _e('Checked', 'userswp'); ?></option> |
| 1001 |
</select> |
| 1002 |
<?php } else if ($field_type == 'email') { ?> |
| 1003 |
<input type="email" name="default_value" placeholder="<?php _e('info@mysite.com', 'userswp'); ?>" id="default_value" value="<?php echo esc_attr($value); ?>" /><br/> |
| 1004 |
<?php } else { ?> |
| 1005 |
<input type="text" name="default_value" id="default_value" value="<?php echo esc_attr($value); ?>" /><br/> |
| 1006 |
<?php } ?> |
| 1007 |
</div> |
| 1008 |
</li> |
| 1009 |
<?php |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
// advanced_editor |
| 1014 |
if (has_filter("uwp_builder_advanced_editor_{$field_type}")) { |
| 1015 |
|
| 1016 |
echo apply_filters("uwp_builder_advanced_editor_{$field_type}", '', $result_str, $cf, $field_info); |
| 1017 |
|
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
?> |
| 1022 |
<input type="hidden" readonly="readonly" name="sort_order" id="sort_order" value="<?php if (isset($field_info->sort_order)) { echo esc_attr($field_info->sort_order); } ?>"/> |
| 1023 |
<?php |
| 1024 |
|
| 1025 |
// is_required |
| 1026 |
if (has_filter("uwp_builder_is_required_{$field_type}")) { |
| 1027 |
|
| 1028 |
echo apply_filters("uwp_builder_is_required_{$field_type}", '', $result_str, $cf, $field_info); |
| 1029 |
|
| 1030 |
} else { |
| 1031 |
$value = ''; |
| 1032 |
if (isset($field_info->is_required)) { |
| 1033 |
$value = esc_attr($field_info->is_required); |
| 1034 |
}elseif (isset($cf['defaults']['is_required']) && $cf['defaults']['is_required']) { |
| 1035 |
$value = $cf['defaults']['is_required']; |
| 1036 |
} |
| 1037 |
?> |
| 1038 |
<li class="uwp-setting-name"> |
| 1039 |
<label for="is_required" class="uwp-tooltip-wrap"> |
| 1040 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Select yes to set field as required', 'userswp'); ?>"></span> |
| 1041 |
<?php _e('Is required :', 'userswp'); ?> |
| 1042 |
</label> |
| 1043 |
|
| 1044 |
<div class="uwp-input-wrap"> |
| 1045 |
<input type="hidden" name="is_required" value="0" /> |
| 1046 |
<input type="checkbox" name="is_required" value="1" <?php checked( $value, 1, true );?> /> |
| 1047 |
</div> |
| 1048 |
|
| 1049 |
</li> |
| 1050 |
|
| 1051 |
<?php |
| 1052 |
} |
| 1053 |
|
| 1054 |
// required_msg |
| 1055 |
if (has_filter("uwp_builder_required_msg_{$field_type}")) { |
| 1056 |
|
| 1057 |
echo apply_filters("uwp_builder_required_msg_{$field_type}", '', $result_str, $cf, $field_info); |
| 1058 |
|
| 1059 |
} else { |
| 1060 |
$value = ''; |
| 1061 |
if (isset($field_info->required_msg)) { |
| 1062 |
$value = esc_attr($field_info->required_msg); |
| 1063 |
}elseif (isset($cf['defaults']['required_msg']) && $cf['defaults']['required_msg']) { |
| 1064 |
$value = $cf['defaults']['required_msg']; |
| 1065 |
} |
| 1066 |
?> |
| 1067 |
<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)) {echo "style='display:none;'"; }?>> |
| 1068 |
<label for="required_msg" class="uwp-tooltip-wrap"> |
| 1069 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Enter text for the error message if the field is required and has not fulfilled the requirements.', 'userswp'); ?>"></span> |
| 1070 |
<?php _e('Required message:', 'userswp'); ?> |
| 1071 |
</label> |
| 1072 |
<div class="uwp-input-wrap"> |
| 1073 |
<input type="text" name="required_msg" id="required_msg" |
| 1074 |
value="<?php echo esc_attr($value); ?>"/> |
| 1075 |
</div> |
| 1076 |
</li> |
| 1077 |
<?php |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
// required_msg |
| 1082 |
if (has_filter("uwp_builder_validation_pattern_{$field_type}")) { |
| 1083 |
|
| 1084 |
echo apply_filters("uwp_builder_validation_pattern_{$field_type}", '', $result_str, $cf, $field_info); |
| 1085 |
|
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
// extra_fields |
| 1090 |
if (has_filter("uwp_builder_extra_fields_{$field_type}")) { |
| 1091 |
|
| 1092 |
echo apply_filters("uwp_builder_extra_fields_{$field_type}", '', $result_str, $cf, $field_info); |
| 1093 |
|
| 1094 |
} |
| 1095 |
|
| 1096 |
|
| 1097 |
// field_icon |
| 1098 |
if (has_filter("uwp_builder_field_icon_{$field_type}")) { |
| 1099 |
|
| 1100 |
echo apply_filters("uwp_builder_field_icon_{$field_type}", '', $result_str, $cf, $field_info); |
| 1101 |
|
| 1102 |
} else { |
| 1103 |
$value = ''; |
| 1104 |
if (isset($field_info->field_icon)) { |
| 1105 |
$value = esc_attr($field_info->field_icon); |
| 1106 |
}elseif (isset($cf['defaults']['field_icon']) && $cf['defaults']['field_icon']) { |
| 1107 |
$value = $cf['defaults']['field_icon']; |
| 1108 |
} |
| 1109 |
?> |
| 1110 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 1111 |
|
| 1112 |
<label for="field_icon" class="uwp-tooltip-wrap"> |
| 1113 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title='<?php echo 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>'); ?>'></span> |
| 1114 |
<?php _e('Upload icon :', 'userswp'); ?> |
| 1115 |
</label> |
| 1116 |
<div class="uwp-input-wrap"> |
| 1117 |
<input type="text" name="field_icon" id="field_icon" |
| 1118 |
value="<?php echo $value; ?>"/> |
| 1119 |
</div> |
| 1120 |
|
| 1121 |
</li> |
| 1122 |
<?php |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
// css_class |
| 1127 |
if (has_filter("uwp_builder_css_class_{$field_type}")) { |
| 1128 |
|
| 1129 |
echo apply_filters("uwp_builder_css_class_{$field_type}", '', $result_str, $cf, $field_info); |
| 1130 |
|
| 1131 |
} else { |
| 1132 |
?> |
| 1133 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 1134 |
|
| 1135 |
<?php |
| 1136 |
$value = ''; |
| 1137 |
if (isset($field_info->css_class)) { |
| 1138 |
$value = esc_attr($field_info->css_class); |
| 1139 |
}elseif (isset($cf['defaults']['css_class']) && $cf['defaults']['css_class']) { |
| 1140 |
$value = $cf['defaults']['css_class']; |
| 1141 |
} |
| 1142 |
$tip = __('Enter custom css class for field custom style.', 'userswp'); |
| 1143 |
if ($field_type == 'multiselect') { $tip .= __('(Enter class `uwp-comma-list` to show list as comma separated)', 'userswp'); } |
| 1144 |
?> |
| 1145 |
|
| 1146 |
<label for="css_class" class="uwp-tooltip-wrap"> |
| 1147 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php echo $tip; ?>"></span> |
| 1148 |
<?php _e('CSS class :', 'userswp'); ?> |
| 1149 |
</label> |
| 1150 |
<div class="uwp-input-wrap"> |
| 1151 |
<input type="text" name="css_class" id="css_class" |
| 1152 |
value="<?php echo $value;?>"/> |
| 1153 |
</div> |
| 1154 |
|
| 1155 |
</li> |
| 1156 |
<?php |
| 1157 |
} |
| 1158 |
|
| 1159 |
// show_in |
| 1160 |
if (has_filter("uwp_builder_show_in_{$field_type}")) { |
| 1161 |
|
| 1162 |
echo apply_filters("uwp_builder_show_in_{$field_type}", '', $result_str, $cf, $field_info); |
| 1163 |
|
| 1164 |
} else { |
| 1165 |
$value = ''; |
| 1166 |
if (isset($field_info->show_in)) { |
| 1167 |
$value = esc_attr($field_info->show_in); |
| 1168 |
}elseif (isset($cf['defaults']['show_in']) && $cf['defaults']['show_in']) { |
| 1169 |
$value = esc_attr($cf['defaults']['show_in']); |
| 1170 |
} |
| 1171 |
?> |
| 1172 |
<li class="uwp-setting-name"> |
| 1173 |
<label for="show_in" class="uwp-tooltip-wrap"> |
| 1174 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Select in what locations you want to display this field.', 'userswp'); ?>"></span> |
| 1175 |
<?php _e('Show in what locations?:', 'userswp'); ?> |
| 1176 |
</label> |
| 1177 |
<div class="uwp-input-wrap"> |
| 1178 |
|
| 1179 |
<?php |
| 1180 |
|
| 1181 |
$show_in_locations = uwp_get_show_in_locations(); |
| 1182 |
|
| 1183 |
if ($field_type == 'fieldset') { |
| 1184 |
unset($show_in_locations['[fieldset]']); |
| 1185 |
} |
| 1186 |
|
| 1187 |
if (!in_array($field_type, array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) { |
| 1188 |
unset($show_in_locations['[own_tab]']); |
| 1189 |
} |
| 1190 |
?> |
| 1191 |
|
| 1192 |
<select multiple="multiple" name="show_in[]" |
| 1193 |
style="min-width:300px;" |
| 1194 |
class="aui-select2" |
| 1195 |
data-placeholder="<?php _e('Select locations', 'userswp'); ?>"> |
| 1196 |
<?php |
| 1197 |
|
| 1198 |
$show_in_values = explode(',', $value); |
| 1199 |
|
| 1200 |
foreach ($show_in_locations as $key => $val) { |
| 1201 |
$selected = ''; |
| 1202 |
|
| 1203 |
if (is_array($show_in_values) && in_array($key, $show_in_values)) { |
| 1204 |
$selected = 'selected'; |
| 1205 |
} |
| 1206 |
|
| 1207 |
?> |
| 1208 |
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $val; ?></option> |
| 1209 |
<?php |
| 1210 |
} |
| 1211 |
?> |
| 1212 |
</select> |
| 1213 |
</div> |
| 1214 |
</li> |
| 1215 |
<?php |
| 1216 |
} |
| 1217 |
|
| 1218 |
do_action('uwp_admin_extra_custom_fields', $field_info, $cf);?> |
| 1219 |
|
| 1220 |
<li> |
| 1221 |
|
| 1222 |
<label for="save" class="uwp-tooltip-wrap"> |
| 1223 |
</label> |
| 1224 |
<div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button"> |
| 1225 |
<input type="button" class="button button-primary" name="save" id="save" value="<?php echo esc_attr(__('Save', 'userswp')); ?>" |
| 1226 |
onclick="save_field('<?php echo esc_attr($result_str); ?>')"/> |
| 1227 |
<?php if (!$default): ?> |
| 1228 |
<a class="item-delete submitdelete deletion" id="delete-16" href="javascript:void(0);" onclick="delete_field('<?php echo esc_attr($result_str); ?>', '<?php echo $nonce; ?>')"><?php _e("Remove","userswp");?></a> |
| 1229 |
<?php endif; ?> |
| 1230 |
<?php UsersWP_Settings_Page::toggle_advanced_button();?> |
| 1231 |
</div> |
| 1232 |
</li> |
| 1233 |
</ul> |
| 1234 |
</div> |
| 1235 |
</form> |
| 1236 |
</li> |
| 1237 |
<?php |
| 1238 |
} |
| 1239 |
|
| 1240 |
public function form_field_adminhtml($field_type, $result_str, $field_ins_upd = '', $field_type_key = '', $form_type = false) |
| 1241 |
{ |
| 1242 |
global $wpdb; |
| 1243 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 1244 |
$cf = $result_str; |
| 1245 |
if (!is_object($cf)) { |
| 1246 |
|
| 1247 |
$field_info = $wpdb->get_row($wpdb->prepare("select * from " . $table_name . " where id= %d", array($cf))); |
| 1248 |
|
| 1249 |
} else { |
| 1250 |
$field_info = $cf; |
| 1251 |
$result_str = $cf->id; |
| 1252 |
} |
| 1253 |
|
| 1254 |
$this->admin_form_field_html($field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type); |
| 1255 |
|
| 1256 |
} |
| 1257 |
|
| 1258 |
|
| 1259 |
public function admin_form_field_save($request_field = array()) |
| 1260 |
{ |
| 1261 |
|
| 1262 |
global $wpdb; |
| 1263 |
|
| 1264 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 1265 |
|
| 1266 |
$meta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; |
| 1267 |
|
| 1268 |
$old_html_variable = ''; |
| 1269 |
|
| 1270 |
$result_str = isset($request_field['field_id']) ? trim($request_field['field_id']) : ''; |
| 1271 |
|
| 1272 |
$user_meta_info = null; |
| 1273 |
|
| 1274 |
// some servers fail if a POST value is VARCHAR so we change it. |
| 1275 |
if (isset($request_field['data_type']) && $request_field['data_type'] == 'XVARCHAR') { |
| 1276 |
$request_field['data_type'] = 'VARCHAR'; |
| 1277 |
} |
| 1278 |
|
| 1279 |
$cf = trim($result_str, '_'); |
| 1280 |
|
| 1281 |
$cehhtmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : ''; |
| 1282 |
$form_type = $request_field['form_type']; |
| 1283 |
|
| 1284 |
$old_html_variable_name = 'uwp_account_' . $cehhtmlvar_name; |
| 1285 |
$check_old_html_variable = $wpdb->get_var( |
| 1286 |
$wpdb->prepare( |
| 1287 |
"select htmlvar_name from " . $table_name . " where id <> %d and htmlvar_name = %s and form_type = %s ", |
| 1288 |
array($cf,$old_html_variable_name , $form_type) |
| 1289 |
) |
| 1290 |
); |
| 1291 |
|
| 1292 |
$check_html_variable = $wpdb->get_var( |
| 1293 |
$wpdb->prepare( |
| 1294 |
"select htmlvar_name from " . $table_name . " where id <> %d and htmlvar_name = %s and form_type = %s ", |
| 1295 |
array($cf, $cehhtmlvar_name, $form_type) |
| 1296 |
) |
| 1297 |
); |
| 1298 |
|
| 1299 |
|
| 1300 |
if ((!$check_old_html_variable && !$check_html_variable) || $request_field['field_type'] == 'fieldset') { |
| 1301 |
|
| 1302 |
if ($cf != '') { |
| 1303 |
|
| 1304 |
$user_meta_info = $wpdb->get_row( |
| 1305 |
$wpdb->prepare( |
| 1306 |
"select * from " . $table_name . " where id = %d", |
| 1307 |
array($cf) |
| 1308 |
) |
| 1309 |
); |
| 1310 |
|
| 1311 |
} |
| 1312 |
|
| 1313 |
if (!empty($user_meta_info)) { |
| 1314 |
$old_html_variable = $user_meta_info->htmlvar_name; |
| 1315 |
|
| 1316 |
} |
| 1317 |
|
| 1318 |
$site_title = sanitize_text_field($request_field['site_title']); |
| 1319 |
$form_label = isset($request_field['form_label']) ? sanitize_text_field($request_field['form_label']) : ''; |
| 1320 |
$field_type = sanitize_text_field($request_field['field_type']); |
| 1321 |
$data_type = sanitize_text_field($request_field['data_type']); |
| 1322 |
$field_type_key = isset($request_field['field_type_key']) ? sanitize_text_field($request_field['field_type_key']) : $field_type; |
| 1323 |
$htmlvar_name = isset( $request_field['htmlvar_name'] ) ? str_replace(array('-',' ','"',"'"), array('_','','',''), sanitize_title_with_dashes( $request_field['htmlvar_name'] ) ) : null; |
| 1324 |
$default_value = isset($request_field['default_value']) ? sanitize_text_field($request_field['default_value']) : ''; |
| 1325 |
$sort_order = isset($request_field['sort_order']) ? absint($request_field['sort_order']) : ''; |
| 1326 |
$is_active = isset($request_field['is_active']) ? absint($request_field['is_active']) : 1; |
| 1327 |
$for_admin_use = isset($request_field['for_admin_use']) ? absint($request_field['for_admin_use']) : 0; |
| 1328 |
$is_required = isset($request_field['is_required']) ? absint($request_field['is_required']) : 0; |
| 1329 |
$is_dummy = isset($request_field['is_dummy']) ? absint($request_field['is_dummy']) : 0; |
| 1330 |
$is_public = isset($request_field['is_public']) ? absint($request_field['is_public']) : 0; |
| 1331 |
$is_default = isset($request_field['is_default']) ? absint($request_field['is_default']) : 0; |
| 1332 |
$is_register_field = isset($request_field['is_register_field']) ? absint($request_field['is_register_field']) : 0; |
| 1333 |
$is_search_field = isset($request_field['is_search_field']) ? absint($request_field['is_search_field']) : 0; |
| 1334 |
$is_register_only_field = isset($request_field['is_register_only_field']) ? absint($request_field['is_register_only_field']) : 0; |
| 1335 |
$required_msg = isset($request_field['required_msg']) ? sanitize_text_field($request_field['required_msg']) : ''; |
| 1336 |
$css_class = isset($request_field['css_class']) ? sanitize_text_field($request_field['css_class']) : ''; |
| 1337 |
$field_icon = isset($request_field['field_icon']) ? sanitize_text_field($request_field['field_icon']) : ''; |
| 1338 |
$show_in = isset($request_field['show_in']) ? $request_field['show_in'] : ''; |
| 1339 |
$user_roles = isset($request_field['user_roles']) ? $request_field['user_roles'] : ''; |
| 1340 |
$decimal_point = isset($request_field['decimal_point']) ? absint($request_field['decimal_point']) : ''; // decimal point for DECIMAL data type |
| 1341 |
$decimal_point = $decimal_point > 0 ? ($decimal_point > 10 ? 10 : $decimal_point) : ''; |
| 1342 |
$validation_pattern = isset($request_field['validation_pattern']) ? sanitize_text_field($request_field['validation_pattern']) : ''; |
| 1343 |
$validation_msg = isset($request_field['validation_msg']) ? sanitize_text_field($request_field['validation_msg']) : ''; |
| 1344 |
|
| 1345 |
if ( empty( $htmlvar_name ) && $field_type == 'fieldset') { |
| 1346 |
$htmlvar_name = $field_type_key; |
| 1347 |
} |
| 1348 |
|
| 1349 |
if ( empty( $htmlvar_name ) ) { |
| 1350 |
$htmlvar_name = sanitize_key( str_replace( array( '-', ' ', '"', "'" ), array( '_', '_', '', '' ), $request_field['site_title'] ) ); |
| 1351 |
if ( str_replace( '_', '', $htmlvar_name ) != '' ) { |
| 1352 |
$htmlvar_name = substr( $htmlvar_name, 0, 50 ); |
| 1353 |
} else { |
| 1354 |
$htmlvar_name = time(); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
|
| 1358 |
if (is_array($show_in)) { |
| 1359 |
$show_in = implode(",", $request_field['show_in']); |
| 1360 |
$show_in = sanitize_text_field($show_in); |
| 1361 |
} |
| 1362 |
|
| 1363 |
if (is_array($user_roles)) { |
| 1364 |
$user_roles = implode(",", $request_field['user_roles']); |
| 1365 |
$user_roles = sanitize_text_field($user_roles); |
| 1366 |
} |
| 1367 |
|
| 1368 |
$option_values = ''; |
| 1369 |
if (isset($request_field['option_values'])) |
| 1370 |
$option_values = $request_field['option_values']; |
| 1371 |
|
| 1372 |
if (isset($request_field['extra']) && !empty($request_field['extra'])) |
| 1373 |
$extra_fields = $request_field['extra']; |
| 1374 |
|
| 1375 |
if ($sort_order == '') { |
| 1376 |
|
| 1377 |
$last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . $table_name); |
| 1378 |
|
| 1379 |
$sort_order = (int) $last_order + 1; |
| 1380 |
} |
| 1381 |
|
| 1382 |
if (!empty($user_meta_info)) { |
| 1383 |
|
| 1384 |
$excluded = uwp_get_excluded_fields(); |
| 1385 |
|
| 1386 |
if (!in_array($htmlvar_name, $excluded)) { |
| 1387 |
// Create custom columns |
| 1388 |
switch ($field_type): |
| 1389 |
|
| 1390 |
case 'checkbox': |
| 1391 |
case 'multiselect': |
| 1392 |
case 'select': |
| 1393 |
|
| 1394 |
$op_size = '500'; |
| 1395 |
|
| 1396 |
// only make the field as big as it needs to be. |
| 1397 |
if (isset($option_values) && $option_values && $field_type == 'select') { |
| 1398 |
$option_values_arr = explode(',', $option_values); |
| 1399 |
if (is_array($option_values_arr)) { |
| 1400 |
$op_max = 0; |
| 1401 |
foreach ($option_values_arr as $op_val) { |
| 1402 |
if (strlen($op_val) && strlen($op_val) > $op_max) {$op_max = strlen($op_val); } |
| 1403 |
} |
| 1404 |
if ($op_max) {$op_size = $op_max; } |
| 1405 |
} |
| 1406 |
}elseif (isset($option_values) && $option_values && $field_type == 'multiselect') { |
| 1407 |
if (strlen($option_values)) { |
| 1408 |
$op_size = strlen($option_values); |
| 1409 |
} |
| 1410 |
} |
| 1411 |
|
| 1412 |
$meta_field_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "`VARCHAR( $op_size ) NULL"; |
| 1413 |
|
| 1414 |
if ($default_value != '') { |
| 1415 |
$meta_field_add .= " DEFAULT '" . $default_value . "'"; |
| 1416 |
} |
| 1417 |
|
| 1418 |
$alter_result = $wpdb->query($meta_field_add); |
| 1419 |
if ($alter_result === false) { |
| 1420 |
return __('Column change failed, you may have too many columns.', 'userswp'); |
| 1421 |
} |
| 1422 |
|
| 1423 |
if (isset($request_field['cat_display_type'])) |
| 1424 |
$extra_fields = $request_field['cat_display_type']; |
| 1425 |
|
| 1426 |
if (isset($request_field['multi_display_type'])) |
| 1427 |
$extra_fields = $request_field['multi_display_type']; |
| 1428 |
|
| 1429 |
|
| 1430 |
break; |
| 1431 |
|
| 1432 |
case 'textarea': |
| 1433 |
case 'html': |
| 1434 |
case 'url': |
| 1435 |
case 'file': |
| 1436 |
|
| 1437 |
$alter_result = $wpdb->query("ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` TEXT NULL"); |
| 1438 |
if ($alter_result === false) { |
| 1439 |
return __('Column change failed, you may have too many columns.', 'userswp'); |
| 1440 |
} |
| 1441 |
if (isset($request_field['advanced_editor'])) |
| 1442 |
$extra_fields = $request_field['advanced_editor']; |
| 1443 |
|
| 1444 |
break; |
| 1445 |
|
| 1446 |
case 'fieldset': |
| 1447 |
// Nothing happened for fieldset |
| 1448 |
break; |
| 1449 |
|
| 1450 |
default: |
| 1451 |
if ($data_type != 'VARCHAR' && $data_type != '') { |
| 1452 |
if ($data_type == 'FLOAT' && $decimal_point > 0) { |
| 1453 |
$default_value_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` DECIMAL(11, " . (int) $decimal_point . ") NULL"; |
| 1454 |
} else { |
| 1455 |
$default_value_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` " . $data_type . " NULL"; |
| 1456 |
} |
| 1457 |
|
| 1458 |
if (is_numeric($default_value) && $default_value != '') { |
| 1459 |
$default_value_add .= " DEFAULT '" . $default_value . "'"; |
| 1460 |
} |
| 1461 |
} else { |
| 1462 |
$default_value_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` VARCHAR( 254 ) NULL"; |
| 1463 |
if ($default_value != '') { |
| 1464 |
$default_value_add .= " DEFAULT '" . $default_value . "'"; |
| 1465 |
} |
| 1466 |
} |
| 1467 |
|
| 1468 |
$alter_result = $wpdb->query($default_value_add); |
| 1469 |
if ($alter_result === false) { |
| 1470 |
return __('Column change failed, you may have too many columns.', 'userswp'); |
| 1471 |
} |
| 1472 |
break; |
| 1473 |
endswitch; |
| 1474 |
} |
| 1475 |
|
| 1476 |
$extra_field_query = ''; |
| 1477 |
if (!empty($extra_fields)) { |
| 1478 |
$extra_field_query = serialize($extra_fields); |
| 1479 |
} |
| 1480 |
|
| 1481 |
$wpdb->query( |
| 1482 |
|
| 1483 |
$wpdb->prepare( |
| 1484 |
|
| 1485 |
"update " . $table_name . " set |
| 1486 |
form_type = %s, |
| 1487 |
site_title = %s, |
| 1488 |
form_label = %s, |
| 1489 |
field_type = %s, |
| 1490 |
data_type = %s, |
| 1491 |
decimal_point = %s, |
| 1492 |
field_type_key = %s, |
| 1493 |
htmlvar_name = %s, |
| 1494 |
default_value = %s, |
| 1495 |
sort_order = %s, |
| 1496 |
is_active = %s, |
| 1497 |
for_admin_use = %s, |
| 1498 |
is_default = %s, |
| 1499 |
is_required = %s, |
| 1500 |
is_dummy = %s, |
| 1501 |
is_public = %s, |
| 1502 |
is_register_field = %s, |
| 1503 |
is_search_field = %s, |
| 1504 |
is_register_only_field = %s, |
| 1505 |
required_msg = %s, |
| 1506 |
css_class = %s, |
| 1507 |
field_icon = %s, |
| 1508 |
show_in = %s, |
| 1509 |
user_roles = %s, |
| 1510 |
option_values = %s, |
| 1511 |
extra_fields = %s, |
| 1512 |
validation_pattern = %s, |
| 1513 |
validation_msg = %s |
| 1514 |
where id = %d", |
| 1515 |
|
| 1516 |
array( |
| 1517 |
$form_type, |
| 1518 |
$site_title, |
| 1519 |
$form_label, |
| 1520 |
$field_type, |
| 1521 |
$data_type, |
| 1522 |
$decimal_point, |
| 1523 |
$field_type_key, |
| 1524 |
$htmlvar_name, |
| 1525 |
$default_value, |
| 1526 |
$sort_order, |
| 1527 |
$is_active, |
| 1528 |
$for_admin_use, |
| 1529 |
$is_default, |
| 1530 |
$is_required, |
| 1531 |
$is_dummy, |
| 1532 |
$is_public, |
| 1533 |
$is_register_field, |
| 1534 |
$is_search_field, |
| 1535 |
$is_register_only_field, |
| 1536 |
$required_msg, |
| 1537 |
$css_class, |
| 1538 |
$field_icon, |
| 1539 |
$show_in, |
| 1540 |
$user_roles, |
| 1541 |
$option_values, |
| 1542 |
$extra_field_query, |
| 1543 |
$validation_pattern, |
| 1544 |
$validation_msg, |
| 1545 |
$cf |
| 1546 |
) |
| 1547 |
) |
| 1548 |
|
| 1549 |
); |
| 1550 |
|
| 1551 |
$lastid = trim($cf); |
| 1552 |
|
| 1553 |
do_action('uwp_after_custom_fields_updated', $lastid); |
| 1554 |
|
| 1555 |
} else { |
| 1556 |
|
| 1557 |
switch ($field_type): |
| 1558 |
|
| 1559 |
case 'checkbox': |
| 1560 |
$data_type = 'TINYINT'; |
| 1561 |
|
| 1562 |
$meta_field_add = $data_type . "( 1 ) NOT NULL "; |
| 1563 |
if ((int) $default_value === 1) { |
| 1564 |
$meta_field_add .= " DEFAULT '1'"; |
| 1565 |
} |
| 1566 |
|
| 1567 |
$add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add); |
| 1568 |
if ($add_result === false) { |
| 1569 |
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp'); |
| 1570 |
} |
| 1571 |
break; |
| 1572 |
case 'multiselect': |
| 1573 |
case 'select': |
| 1574 |
$data_type = 'VARCHAR'; |
| 1575 |
$op_size = '500'; |
| 1576 |
|
| 1577 |
// only make the field as big as it needs to be. |
| 1578 |
if (isset($option_values) && $option_values && $field_type == 'select') { |
| 1579 |
$option_values_arr = explode(',', $option_values); |
| 1580 |
|
| 1581 |
if (is_array($option_values_arr)) { |
| 1582 |
$op_max = 0; |
| 1583 |
|
| 1584 |
foreach ($option_values_arr as $op_val) { |
| 1585 |
if (strlen($op_val) && strlen($op_val) > $op_max) { |
| 1586 |
$op_max = strlen($op_val); |
| 1587 |
} |
| 1588 |
} |
| 1589 |
|
| 1590 |
if ($op_max) { |
| 1591 |
$op_size = $op_max; |
| 1592 |
} |
| 1593 |
} |
| 1594 |
} elseif (isset($option_values) && $option_values && $field_type == 'multiselect') { |
| 1595 |
if (strlen($option_values)) { |
| 1596 |
$op_size = strlen($option_values); |
| 1597 |
} |
| 1598 |
|
| 1599 |
if (isset($request_field['multi_display_type'])) { |
| 1600 |
$extra_fields = $request_field['multi_display_type']; |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
$meta_field_add = $data_type . "( $op_size ) NULL "; |
| 1605 |
if ($default_value != '') { |
| 1606 |
$meta_field_add .= " DEFAULT '" . $default_value . "'"; |
| 1607 |
} |
| 1608 |
|
| 1609 |
$add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add); |
| 1610 |
if ($add_result === false) { |
| 1611 |
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp'); |
| 1612 |
} |
| 1613 |
break; |
| 1614 |
case 'textarea': |
| 1615 |
case 'html': |
| 1616 |
case 'url': |
| 1617 |
case 'file': |
| 1618 |
|
| 1619 |
$data_type = 'TEXT'; |
| 1620 |
|
| 1621 |
$meta_field_add = $data_type . " NULL "; |
| 1622 |
|
| 1623 |
$add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add); |
| 1624 |
if ($add_result === false) { |
| 1625 |
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp'); |
| 1626 |
} |
| 1627 |
|
| 1628 |
break; |
| 1629 |
|
| 1630 |
case 'datepicker': |
| 1631 |
|
| 1632 |
$data_type = 'DATE'; |
| 1633 |
|
| 1634 |
$meta_field_add = $data_type . " NULL "; |
| 1635 |
|
| 1636 |
$add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add); |
| 1637 |
if ($add_result === false) { |
| 1638 |
return __('Column creation failed, you may have too many columns or the default value must have in valid date format.', 'userswp'); |
| 1639 |
} |
| 1640 |
|
| 1641 |
break; |
| 1642 |
|
| 1643 |
case 'time': |
| 1644 |
|
| 1645 |
$data_type = 'TIME'; |
| 1646 |
|
| 1647 |
$meta_field_add = $data_type . " NULL "; |
| 1648 |
|
| 1649 |
$add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add); |
| 1650 |
if ($add_result === false) { |
| 1651 |
return __('Column creation failed, you may have too many columns or the default value must have in valid time format.', 'userswp'); |
| 1652 |
} |
| 1653 |
|
| 1654 |
break; |
| 1655 |
|
| 1656 |
default: |
| 1657 |
|
| 1658 |
if ($data_type != 'VARCHAR' && $data_type != '') { |
| 1659 |
$meta_field_add = $data_type . " NULL "; |
| 1660 |
|
| 1661 |
if ($data_type == 'FLOAT' && $decimal_point > 0) { |
| 1662 |
$meta_field_add = "DECIMAL(11, " . (int) $decimal_point . ") NULL "; |
| 1663 |
} |
| 1664 |
|
| 1665 |
if (is_numeric($default_value) && $default_value != '') { |
| 1666 |
$meta_field_add .= " DEFAULT '" . $default_value . "'"; |
| 1667 |
} |
| 1668 |
} else { |
| 1669 |
$meta_field_add = " VARCHAR( 254 ) NULL "; |
| 1670 |
|
| 1671 |
if ($default_value != '') { |
| 1672 |
$meta_field_add .= " DEFAULT '" . $default_value . "'"; |
| 1673 |
} |
| 1674 |
} |
| 1675 |
|
| 1676 |
$add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add); |
| 1677 |
if ($add_result === false) { |
| 1678 |
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp'); |
| 1679 |
} |
| 1680 |
break; |
| 1681 |
endswitch; |
| 1682 |
|
| 1683 |
$extra_field_query = ''; |
| 1684 |
if (!empty($extra_fields)) { |
| 1685 |
$extra_field_query = serialize($extra_fields); |
| 1686 |
} |
| 1687 |
|
| 1688 |
$wpdb->query( |
| 1689 |
|
| 1690 |
$wpdb->prepare( |
| 1691 |
|
| 1692 |
"insert into " . $table_name . " set |
| 1693 |
form_type = %s, |
| 1694 |
site_title = %s, |
| 1695 |
form_label = %s, |
| 1696 |
field_type = %s, |
| 1697 |
data_type = %s, |
| 1698 |
decimal_point = %s, |
| 1699 |
field_type_key = %s, |
| 1700 |
htmlvar_name = %s, |
| 1701 |
default_value = %s, |
| 1702 |
sort_order = %d, |
| 1703 |
is_active = %s, |
| 1704 |
for_admin_use = %s, |
| 1705 |
is_default = %s, |
| 1706 |
is_required = %s, |
| 1707 |
is_dummy = %s, |
| 1708 |
is_public = %s, |
| 1709 |
is_register_field = %s, |
| 1710 |
is_search_field = %s, |
| 1711 |
is_register_only_field = %s, |
| 1712 |
required_msg = %s, |
| 1713 |
css_class = %s, |
| 1714 |
field_icon = %s, |
| 1715 |
show_in = %s, |
| 1716 |
user_roles = %s, |
| 1717 |
option_values = %s, |
| 1718 |
extra_fields = %s, |
| 1719 |
validation_pattern = %s, |
| 1720 |
validation_msg = %s ", |
| 1721 |
|
| 1722 |
array( |
| 1723 |
$form_type, |
| 1724 |
$site_title, |
| 1725 |
$form_label, |
| 1726 |
$field_type, |
| 1727 |
$data_type, |
| 1728 |
$decimal_point, |
| 1729 |
$field_type_key, |
| 1730 |
$htmlvar_name, |
| 1731 |
$default_value, |
| 1732 |
$sort_order, |
| 1733 |
$is_active, |
| 1734 |
$for_admin_use, |
| 1735 |
$is_default, |
| 1736 |
$is_required, |
| 1737 |
$is_dummy, |
| 1738 |
$is_public, |
| 1739 |
$is_register_field, |
| 1740 |
$is_search_field, |
| 1741 |
$is_register_only_field, |
| 1742 |
$required_msg, |
| 1743 |
$css_class, |
| 1744 |
$field_icon, |
| 1745 |
$show_in, |
| 1746 |
$user_roles, |
| 1747 |
$option_values, |
| 1748 |
$extra_field_query, |
| 1749 |
$validation_pattern, |
| 1750 |
$validation_msg |
| 1751 |
) |
| 1752 |
|
| 1753 |
) |
| 1754 |
|
| 1755 |
); |
| 1756 |
|
| 1757 |
$lastid = $wpdb->insert_id; |
| 1758 |
|
| 1759 |
$lastid = trim($lastid); |
| 1760 |
|
| 1761 |
} |
| 1762 |
|
| 1763 |
return (int) $lastid; |
| 1764 |
|
| 1765 |
|
| 1766 |
} else { |
| 1767 |
return 'invalid_key'; |
| 1768 |
} |
| 1769 |
|
| 1770 |
} |
| 1771 |
|
| 1772 |
public function set_field_order($field_ids = array()) |
| 1773 |
{ |
| 1774 |
|
| 1775 |
global $wpdb; |
| 1776 |
|
| 1777 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 1778 |
|
| 1779 |
$count = 0; |
| 1780 |
if (!empty($field_ids)): |
| 1781 |
$user_meta_info = false; |
| 1782 |
foreach ($field_ids as $id) { |
| 1783 |
|
| 1784 |
$cf = trim($id, '_'); |
| 1785 |
|
| 1786 |
$user_meta_info = $wpdb->query( |
| 1787 |
$wpdb->prepare( |
| 1788 |
"update " . $table_name . " set |
| 1789 |
sort_order=%d |
| 1790 |
where id= %d", |
| 1791 |
array($count, $cf) |
| 1792 |
) |
| 1793 |
); |
| 1794 |
$count++; |
| 1795 |
} |
| 1796 |
|
| 1797 |
return $user_meta_info; |
| 1798 |
else: |
| 1799 |
return false; |
| 1800 |
endif; |
| 1801 |
} |
| 1802 |
|
| 1803 |
public function admin_form_field_delete($field_id = '') { |
| 1804 |
global $wpdb; |
| 1805 |
|
| 1806 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 1807 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 1808 |
$meta_table = get_usermeta_table_prefix() . 'uwp_usermeta'; |
| 1809 |
|
| 1810 |
if ($field_id != '') { |
| 1811 |
$cf = trim($field_id, '_'); |
| 1812 |
|
| 1813 |
if ($field = $wpdb->get_row($wpdb->prepare("select * from " . $table_name . " where id= %d", array($cf)))) { |
| 1814 |
|
| 1815 |
$wpdb->query($wpdb->prepare("delete from " . $table_name . " where id= %d ", array($cf))); |
| 1816 |
|
| 1817 |
$form_type = $field->form_type; |
| 1818 |
|
| 1819 |
// Also delete register form field |
| 1820 |
$wpdb->query($wpdb->prepare("delete from " . $extras_table_name . " where site_htmlvar_name= %s ", array($field->htmlvar_name))); |
| 1821 |
|
| 1822 |
// delete the meta column |
| 1823 |
$col_name = sanitize_sql_orderby($field->htmlvar_name); |
| 1824 |
$wpdb->query("ALTER TABLE `{$meta_table}` DROP COLUMN $col_name"); |
| 1825 |
|
| 1826 |
do_action('uwp_after_custom_field_deleted', $cf, $field->htmlvar_name, $form_type); |
| 1827 |
|
| 1828 |
return $field_id; |
| 1829 |
} else |
| 1830 |
return 0; |
| 1831 |
} else |
| 1832 |
return 0; |
| 1833 |
} |
| 1834 |
|
| 1835 |
public function builder_extra_fields_smr($output, $result_str, $cf, $field_info) { |
| 1836 |
|
| 1837 |
ob_start(); |
| 1838 |
|
| 1839 |
$value = ''; |
| 1840 |
if (isset($field_info->option_values)) { |
| 1841 |
$value = esc_attr($field_info->option_values); |
| 1842 |
}elseif (isset($cf['defaults']['option_values']) && $cf['defaults']['option_values']) { |
| 1843 |
$value = esc_attr($cf['defaults']['option_values']); |
| 1844 |
} |
| 1845 |
|
| 1846 |
$field_type = isset($field_info->field_type) ? $field_info->field_type : $cf['field_type']; |
| 1847 |
$field_type_key = isset($field_info->field_type_key) ? $field_info->field_type_key : ''; |
| 1848 |
if(!$field_type_key){ |
| 1849 |
$field_type_key = isset($_REQUEST['field_type_key']) ? esc_html($_REQUEST['field_type_key']) : ''; |
| 1850 |
} |
| 1851 |
?> |
| 1852 |
<li class="uwp-setting-name"> |
| 1853 |
<label for="option_values" class="uwp-tooltip-wrap"> |
| 1854 |
<?php |
| 1855 |
$tip = __('Option Values should be separated by comma.', 'userswp'); |
| 1856 |
if($field_type != 'multiselect'){ |
| 1857 |
$tip .= '<br/><small>'.__('If using for a tick filter place a / and then either a 1 for true or 0 for false', 'userswp'); |
| 1858 |
$tip .= '<br/>'.__('eg: No Dogs Allowed/0,Dogs Allowed/1', 'userswp').'</small>'; |
| 1859 |
} |
| 1860 |
if ($field_type == 'multiselect' || $field_type == 'select') { |
| 1861 |
$tip .= '<br/><small>'.__('Like: Apple,Bannana,Pear,Peach', 'userswp'); |
| 1862 |
$tip .= '<br/>'.__('Or you can show Selection/Value shown: Pets Allowed/Yes,Pets not Allowed/No', 'userswp'); |
| 1863 |
$tip .= '<br/>'.__('- If using OPTGROUP tag to grouping options, use {optgroup}OPTGROUP-LABEL|OPTION-1,OPTION-2{/optgroup}', 'userswp'); |
| 1864 |
$tip .= '<br/>'.__('eg: {optgroup}Pets Allowed|No Dogs Allowed/0,Dogs Allowed/1{/optgroup},{optgroup}Sports|Cricket/Cricket,Football/Football,Hockey{/optgroup}', 'userswp').'</small>'; |
| 1865 |
} |
| 1866 |
?> |
| 1867 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php echo $tip; ?>"></span> |
| 1868 |
<?php _e('Option Values :', 'userswp'); ?> |
| 1869 |
</label> |
| 1870 |
<div class="uwp-input-wrap"> |
| 1871 |
|
| 1872 |
<?php if(isset($field_type_key) && $field_type_key == 'uwp_country' ){ |
| 1873 |
|
| 1874 |
// @todo here we should show a multiselect to either include or exclude countries |
| 1875 |
_e('A full country list will be shown','userswp'); |
| 1876 |
?> |
| 1877 |
|
| 1878 |
<?php }else{?> |
| 1879 |
<input type="text" name="option_values" id="option_values" value="<?php echo $value; ?>"/> |
| 1880 |
<?php }?> |
| 1881 |
|
| 1882 |
<br/> |
| 1883 |
|
| 1884 |
</div> |
| 1885 |
</li> |
| 1886 |
<?php |
| 1887 |
|
| 1888 |
$html = ob_get_clean(); |
| 1889 |
return $output . $html; |
| 1890 |
} |
| 1891 |
|
| 1892 |
public function builder_extra_fields_datepicker($output, $result_str, $cf, $field_info) { |
| 1893 |
ob_start(); |
| 1894 |
$extra = array(); |
| 1895 |
if (isset($field_info->extra_fields) && $field_info->extra_fields != '') { |
| 1896 |
$extra = unserialize($field_info->extra_fields); |
| 1897 |
} |
| 1898 |
?> |
| 1899 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 1900 |
<label for="date_format" class="uwp-tooltip-wrap"> |
| 1901 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Select the date format.', 'userswp'); ?>"></span> |
| 1902 |
<?php _e('Date Format :', 'userswp'); ?> |
| 1903 |
</label> |
| 1904 |
<div class="uwp-input-wrap" style="overflow:inherit;"> |
| 1905 |
<?php |
| 1906 |
$date_formats = array( |
| 1907 |
'm/d/Y', |
| 1908 |
'd/m/Y', |
| 1909 |
'Y/m/d', |
| 1910 |
'm-d-Y', |
| 1911 |
'd-m-Y', |
| 1912 |
'Y-m-d', |
| 1913 |
'F j, Y', |
| 1914 |
); |
| 1915 |
|
| 1916 |
$date_formats = apply_filters('uwp_date_formats', $date_formats); |
| 1917 |
?> |
| 1918 |
<select name="extra[date_format]" id="date_format" class="aui-select2"> |
| 1919 |
<?php |
| 1920 |
foreach ($date_formats as $format) { |
| 1921 |
$selected = ''; |
| 1922 |
if (!empty($extra) && esc_attr($extra['date_format']) == $format) { |
| 1923 |
$selected = "selected='selected'"; |
| 1924 |
} |
| 1925 |
echo "<option $selected value='$format'>$format (" . date_i18n($format, time()) . ")</option>"; |
| 1926 |
} |
| 1927 |
?> |
| 1928 |
</select> |
| 1929 |
|
| 1930 |
</div> |
| 1931 |
</li> |
| 1932 |
<?php |
| 1933 |
|
| 1934 |
$html = ob_get_clean(); |
| 1935 |
return $output . $html; |
| 1936 |
} |
| 1937 |
|
| 1938 |
public function builder_extra_fields_password($output, $result_str, $cf, $field_info) { |
| 1939 |
ob_start(); |
| 1940 |
|
| 1941 |
//confirm password field |
| 1942 |
$extra = array(); |
| 1943 |
if (isset($field_info->extra_fields) && $field_info->extra_fields != '') { |
| 1944 |
$extra = unserialize($field_info->extra_fields); |
| 1945 |
} |
| 1946 |
$value = isset($extra['confirm_password']) ? $extra['confirm_password'] : '1'; |
| 1947 |
if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'password') { |
| 1948 |
?> |
| 1949 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 1950 |
<label for="cat_sort" class="uwp-tooltip-wrap"> |
| 1951 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Lets you display confirm password form field.', 'userswp'); ?>"></span> |
| 1952 |
<?php _e('Display confirm password field?:', 'userswp'); ?> |
| 1953 |
</label> |
| 1954 |
|
| 1955 |
<div class="uwp-input-wrap"> |
| 1956 |
<input type="hidden" name="extra[confirm_password]" value="0" /> |
| 1957 |
<input type="checkbox" name="extra[confirm_password]" value="1" <?php checked( $value, 1, true );?> onclick="" /> |
| 1958 |
</div> |
| 1959 |
</li> |
| 1960 |
<?php |
| 1961 |
} |
| 1962 |
$html = ob_get_clean(); |
| 1963 |
return $output . $html; |
| 1964 |
} |
| 1965 |
|
| 1966 |
public function builder_extra_fields_email($output, $result_str, $cf, $field_info) { |
| 1967 |
ob_start(); |
| 1968 |
//confirm email field |
| 1969 |
$extra = array(); |
| 1970 |
if (isset($field_info->extra_fields) && $field_info->extra_fields != '') { |
| 1971 |
$extra = unserialize($field_info->extra_fields); |
| 1972 |
} |
| 1973 |
$value = isset($extra['confirm_email']) ? $extra['confirm_email'] : '0'; |
| 1974 |
|
| 1975 |
if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'email') { |
| 1976 |
?> |
| 1977 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 1978 |
<label for="cat_sort" class="uwp-tooltip-wrap"> |
| 1979 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Lets you display confirm email form field.', 'userswp'); ?>"></span> |
| 1980 |
<?php _e('Display confirm email field?:', 'userswp'); ?> |
| 1981 |
</label> |
| 1982 |
|
| 1983 |
<div class="uwp-input-wrap"> |
| 1984 |
<input type="hidden" name="extra[confirm_email]" value="0" /> |
| 1985 |
<input type="checkbox" name="extra[confirm_email]" value="1" <?php checked( $value, 1, true );?> onclick="" /> |
| 1986 |
</div> |
| 1987 |
</li> |
| 1988 |
<?php |
| 1989 |
} |
| 1990 |
$html = ob_get_clean(); |
| 1991 |
return $output . $html; |
| 1992 |
} |
| 1993 |
|
| 1994 |
public function builder_extra_fields_file($output, $result_str, $cf, $field_info) { |
| 1995 |
ob_start(); |
| 1996 |
|
| 1997 |
$file_obj = new UsersWP_Files(); |
| 1998 |
$allowed_file_types = $file_obj->allowed_mime_types(); |
| 1999 |
|
| 2000 |
$extra_fields = isset($field_info->extra_fields) && $field_info->extra_fields != '' ? maybe_unserialize($field_info->extra_fields) : ''; |
| 2001 |
$uwp_file_types = !empty($extra_fields) && !empty($extra_fields['uwp_file_types']) ? $extra_fields['uwp_file_types'] : array('*'); |
| 2002 |
?> |
| 2003 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 2004 |
<label for="uwp_file_types" class="uwp-tooltip-wrap"> |
| 2005 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Select file types to allowed for file uploading. (Select multiple file types by holding down "Ctrl" key.)', 'userswp'); ?>"></span> |
| 2006 |
<?php _e('Allowed file types :', 'userswp'); ?> |
| 2007 |
</label> |
| 2008 |
<div class="uwp-input-wrap"> |
| 2009 |
<select name="extra[uwp_file_types][]" id="uwp_file_types" multiple="multiple" class="aui-select2" style="height:100px;width:90%;"> |
| 2010 |
<option value="*" <?php selected(true, in_array('*', $uwp_file_types)); ?>><?php _e('All types', 'userswp'); ?></option> |
| 2011 |
<?php foreach ($allowed_file_types as $format => $types) { ?> |
| 2012 |
<optgroup label="<?php echo esc_attr(wp_sprintf(__('%s formats', 'userswp'), __($format, 'userswp'))); ?>"> |
| 2013 |
<?php foreach ($types as $ext => $type) { ?> |
| 2014 |
<option value="<?php echo esc_attr($ext); ?>" <?php selected(true, in_array($ext, $uwp_file_types)); ?>><?php echo '.' . $ext; ?></option> |
| 2015 |
<?php } ?> |
| 2016 |
</optgroup> |
| 2017 |
<?php } ?> |
| 2018 |
</select> |
| 2019 |
</div> |
| 2020 |
</li> |
| 2021 |
<?php |
| 2022 |
|
| 2023 |
$html = ob_get_clean(); |
| 2024 |
return $output . $html; |
| 2025 |
} |
| 2026 |
|
| 2027 |
public function builder_data_type_text($output, $result_str, $cf, $field_info) { |
| 2028 |
ob_start(); |
| 2029 |
|
| 2030 |
$dt_value = ''; |
| 2031 |
if (isset($field_info->data_type)) { |
| 2032 |
$dt_value = esc_attr($field_info->data_type); |
| 2033 |
}elseif (isset($cf['defaults']['data_type']) && $cf['defaults']['data_type']) { |
| 2034 |
$dt_value = $cf['defaults']['data_type']; |
| 2035 |
} |
| 2036 |
?> |
| 2037 |
<li class="uwp-setting-name uwp-advanced-setting"> |
| 2038 |
<label for="data_type" class="uwp-tooltip-wrap"> |
| 2039 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Select Custom Field type', 'userswp'); ?>"></span> |
| 2040 |
<?php _e('Field Data Type:', 'userswp'); ?> |
| 2041 |
</label> |
| 2042 |
<div class="uwp-input-wrap"> |
| 2043 |
|
| 2044 |
<select name="data_type" id="data_type" class="aui-select2" |
| 2045 |
onchange="uwp_data_type_changed(this, '<?php echo $result_str; ?>');"> |
| 2046 |
<option |
| 2047 |
value="XVARCHAR" <?php if ($dt_value == 'VARCHAR') { |
| 2048 |
echo 'selected="selected"'; |
| 2049 |
} ?>><?php _e('Text Field', 'userswp'); ?></option> |
| 2050 |
<option |
| 2051 |
value="INT" <?php if ($dt_value == 'INT') { |
| 2052 |
echo 'selected="selected"'; |
| 2053 |
} ?>><?php _e('Number Field', 'userswp'); ?></option> |
| 2054 |
<option |
| 2055 |
value="FLOAT" <?php if ($dt_value == 'FLOAT') { |
| 2056 |
echo 'selected="selected"'; |
| 2057 |
} ?>><?php _e('Decimal Field', 'userswp'); ?></option> |
| 2058 |
</select> |
| 2059 |
|
| 2060 |
</div> |
| 2061 |
</li> |
| 2062 |
|
| 2063 |
<?php |
| 2064 |
$value = ''; |
| 2065 |
if (isset($field_info->decimal_point)) { |
| 2066 |
$value = esc_attr($field_info->decimal_point); |
| 2067 |
}elseif (isset($cf['defaults']['decimal_point']) && $cf['defaults']['decimal_point']) { |
| 2068 |
$value = $cf['defaults']['decimal_point']; |
| 2069 |
} |
| 2070 |
?> |
| 2071 |
|
| 2072 |
<li class="decimal-point-wrapper uwp-setting-name uwp-advanced-setting" |
| 2073 |
style="<?php echo ($dt_value == 'FLOAT') ? '' : 'display:none' ?>"> |
| 2074 |
<label for="decimal_point" class="uwp-tooltip-wrap"> |
| 2075 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Decimal places to display after point', 'userswp'); ?>"></span> |
| 2076 |
<?php _e('Select decimal precision:', 'userswp'); ?> |
| 2077 |
</label> |
| 2078 |
<div class="uwp-input-wrap"> |
| 2079 |
<select name="decimal_point" id="decimal_point" class="aui-select2"> |
| 2080 |
<option value=""><?php echo __('Select', 'userswp'); ?></option> |
| 2081 |
<?php for ($i = 1; $i <= 10; $i++) { |
| 2082 |
$selected = $i == $value ? 'selected="selected"' : ''; ?> |
| 2083 |
<option value="<?php echo $i; ?>" <?php echo $selected; ?>><?php echo $i; ?></option> |
| 2084 |
<?php } ?> |
| 2085 |
</select> |
| 2086 |
</div> |
| 2087 |
</li> |
| 2088 |
<?php |
| 2089 |
|
| 2090 |
$output = ob_get_clean(); |
| 2091 |
return $output; |
| 2092 |
} |
| 2093 |
|
| 2094 |
public function advance_admin_custom_fields($field_info, $cf) { |
| 2095 |
$hide_register_field = (isset($cf['defaults']['is_register_field']) && $cf['defaults']['is_register_field'] === false) ? "style='display:none;'" : ''; |
| 2096 |
$hide_register_field = (isset($field_info->for_admin_use) && $field_info->for_admin_use == '1') ? "style='display:none;'" : $hide_register_field; |
| 2097 |
|
| 2098 |
$value = 0; |
| 2099 |
if (isset($field_info->is_register_field)) { |
| 2100 |
$value = (int) $field_info->is_register_field; |
| 2101 |
} else if (isset($cf['defaults']['is_register_field']) && $cf['defaults']['is_register_field']) { |
| 2102 |
$value = ($cf['defaults']['is_register_field']) ? 1 : 0; |
| 2103 |
} |
| 2104 |
|
| 2105 |
//register only field |
| 2106 |
$hide_register_only_field = (isset($cf['defaults']['is_register_only_field']) && $cf['defaults']['is_register_only_field'] === false) ? "style='display:none;'" : ''; |
| 2107 |
$hide_register_only_field = (isset($field_info->for_admin_use) && $field_info->for_admin_use == '1') ? "style='display:none;'" : $hide_register_only_field; |
| 2108 |
$register_only_value = 0; |
| 2109 |
if (isset($field_info->is_register_only_field)) { |
| 2110 |
$register_only_value = (int) $field_info->is_register_only_field; |
| 2111 |
} else if (isset($cf['defaults']['is_register_only_field']) && $cf['defaults']['is_register_only_field']) { |
| 2112 |
$register_only_value = ($cf['defaults']['is_register_only_field']) ? 1 : 0; |
| 2113 |
} |
| 2114 |
?> |
| 2115 |
<li <?php echo $hide_register_field; ?> class="cf-incin-reg-form uwp-setting-name uwp-advanced-setting"> |
| 2116 |
<label for="cat_sort" class="uwp-tooltip-wrap"> |
| 2117 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Lets you use this field as register form field, set from register tab above.', 'userswp'); ?>"></span> |
| 2118 |
<?php _e('Include this field in register form:', 'userswp'); ?> |
| 2119 |
</label> |
| 2120 |
|
| 2121 |
<?php |
| 2122 |
if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'username') { |
| 2123 |
?> |
| 2124 |
<div> |
| 2125 |
<input type="hidden" name="is_register_field" value="1" /> |
| 2126 |
<p><?php _e('This is mandatory register form field.', 'userswp'); ?></p> |
| 2127 |
</div> |
| 2128 |
<?php |
| 2129 |
} else { |
| 2130 |
?> |
| 2131 |
<div class="uwp-input-wrap"> |
| 2132 |
<input type="hidden" name="is_register_field" value="0" /> |
| 2133 |
<input type="checkbox" name="is_register_field" value="1" <?php checked( $value, 1, true );?> /> |
| 2134 |
</div> |
| 2135 |
<?php } ?> |
| 2136 |
</li> |
| 2137 |
|
| 2138 |
<li <?php echo $hide_register_only_field; ?> class="cf-inconlyin-reg-form uwp-setting-name uwp-advanced-setting"> |
| 2139 |
<label for="cat_sort" class="uwp-tooltip-wrap"> |
| 2140 |
<span class="uwp-help-tip dashicons dashicons-editor-help" title="<?php _e('Lets you use this field as register ONLY form field.', 'userswp'); ?>"></span> |
| 2141 |
<?php _e('Include this field ONLY in register form:', 'userswp'); ?> |
| 2142 |
</label> |
| 2143 |
|
| 2144 |
<?php |
| 2145 |
if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'username') { |
| 2146 |
?> |
| 2147 |
<div> |
| 2148 |
<input type="hidden" name="is_register_only_field" value="1" /> |
| 2149 |
<p><?php _e('This field is applicable only for register form.', 'userswp'); ?></p> |
| 2150 |
</div> |
| 2151 |
<?php |
| 2152 |
} else { |
| 2153 |
?> |
| 2154 |
<div class="uwp-input-wrap"> |
| 2155 |
<input type="hidden" name="is_register_only_field" value="0" /> |
| 2156 |
<input type="checkbox" name="is_register_only_field" value="1" <?php checked( $register_only_value, 1, true );?> /> |
| 2157 |
</div> |
| 2158 |
<?php } ?> |
| 2159 |
</li> |
| 2160 |
<?php |
| 2161 |
} |
| 2162 |
|
| 2163 |
public function return_empty_string() { |
| 2164 |
return ""; |
| 2165 |
} |
| 2166 |
|
| 2167 |
public function register_available_fields_head($heading, $form_type) |
| 2168 |
{ |
| 2169 |
switch ($form_type) |
| 2170 |
{ |
| 2171 |
case 'register': |
| 2172 |
$heading = __('Available register form fields.', 'userswp'); |
| 2173 |
break; |
| 2174 |
} |
| 2175 |
return $heading; |
| 2176 |
} |
| 2177 |
|
| 2178 |
|
| 2179 |
public function register_available_fields_note($note, $form_type) |
| 2180 |
{ |
| 2181 |
switch ($form_type) |
| 2182 |
{ |
| 2183 |
case 'register': |
| 2184 |
$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'); |
| 2185 |
break; |
| 2186 |
} |
| 2187 |
return $note; |
| 2188 |
} |
| 2189 |
|
| 2190 |
|
| 2191 |
public function register_selected_fields_head($heading, $form_type) |
| 2192 |
{ |
| 2193 |
switch ($form_type) |
| 2194 |
{ |
| 2195 |
case 'register': |
| 2196 |
$heading = __('List of fields those will appear in register form.', 'userswp'); |
| 2197 |
break; |
| 2198 |
|
| 2199 |
} |
| 2200 |
return $heading; |
| 2201 |
} |
| 2202 |
|
| 2203 |
|
| 2204 |
public function register_selected_fields_note($note, $form_type) |
| 2205 |
{ |
| 2206 |
switch ($form_type) |
| 2207 |
{ |
| 2208 |
case 'register': |
| 2209 |
$note = __('Click to expand and view field related settings. You may drag and drop to arrange fields order in register form.', 'userswp'); |
| 2210 |
break; |
| 2211 |
|
| 2212 |
} |
| 2213 |
return $note; |
| 2214 |
} |
| 2215 |
|
| 2216 |
public function register_available_fields($form_type) |
| 2217 |
{ |
| 2218 |
global $wpdb; |
| 2219 |
|
| 2220 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 2221 |
|
| 2222 |
$existing_fields = $wpdb->get_results("select site_htmlvar_name from " . $extras_table_name . " where form_type ='" . $form_type . "'"); |
| 2223 |
|
| 2224 |
$existing_field_ids = array(); |
| 2225 |
if (!empty($existing_fields)) { |
| 2226 |
foreach ($existing_fields as $existing_field) { |
| 2227 |
$existing_field_ids[] = $existing_field->site_htmlvar_name; |
| 2228 |
} |
| 2229 |
} |
| 2230 |
?> |
| 2231 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/> |
| 2232 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="register"> |
| 2233 |
<ul> |
| 2234 |
<?php |
| 2235 |
|
| 2236 |
$fields = $this->register_fields($form_type); |
| 2237 |
|
| 2238 |
if (!empty($fields)) { |
| 2239 |
foreach ($fields as $field) { |
| 2240 |
$field = stripslashes_deep($field); // strip slashes |
| 2241 |
|
| 2242 |
|
| 2243 |
$fieldset_width = ''; |
| 2244 |
if ($field['field_type'] == 'fieldset') { |
| 2245 |
$fieldset_width = 'width:100%;'; |
| 2246 |
} |
| 2247 |
|
| 2248 |
$display = ''; |
| 2249 |
if (in_array($field['htmlvar_name'], $existing_field_ids)) |
| 2250 |
$display = 'display:none;'; |
| 2251 |
|
| 2252 |
$style = 'style="' . $display . $fieldset_width . '"'; |
| 2253 |
?> |
| 2254 |
<li <?php echo $style; ?> > |
| 2255 |
|
| 2256 |
<a id="uwp-<?php echo $field['htmlvar_name']; ?>" |
| 2257 |
class="uwp-draggable-form-items uwp-<?php echo $field['field_type']; ?>" |
| 2258 |
href="javascript:void(0);" data-field-type="<?php echo $field['field_type']; ?>"> |
| 2259 |
|
| 2260 |
<?php if ($icon = uwp_get_field_icon($field['field_icon'])) { |
| 2261 |
echo $icon; |
| 2262 |
} else { |
| 2263 |
echo '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 2264 |
}?> |
| 2265 |
|
| 2266 |
<?php echo $field['site_title']; ?> |
| 2267 |
|
| 2268 |
</a> |
| 2269 |
</li> |
| 2270 |
|
| 2271 |
|
| 2272 |
<?php |
| 2273 |
} |
| 2274 |
} |
| 2275 |
?> |
| 2276 |
</ul> |
| 2277 |
<?php |
| 2278 |
} |
| 2279 |
|
| 2280 |
public function register_fields($form_type) |
| 2281 |
{ |
| 2282 |
|
| 2283 |
global $wpdb; |
| 2284 |
|
| 2285 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 2286 |
$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 order by sort_order asc", array('account', '1')), ARRAY_A); |
| 2287 |
|
| 2288 |
return apply_filters('uwp_register_fields', $fields, $form_type); |
| 2289 |
} |
| 2290 |
|
| 2291 |
public function register_selected_fields($form_type) |
| 2292 |
{ |
| 2293 |
global $wpdb; |
| 2294 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 2295 |
?> |
| 2296 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="register"> |
| 2297 |
<ul class="core uwp_form_extras uwp-tabs-selected"><?php |
| 2298 |
|
| 2299 |
$fields = $wpdb->get_results( |
| 2300 |
$wpdb->prepare( |
| 2301 |
"select * from " . $extras_table_name . " where form_type = %s order by sort_order asc", |
| 2302 |
array($form_type) |
| 2303 |
) |
| 2304 |
); |
| 2305 |
|
| 2306 |
if (!empty($fields)) { |
| 2307 |
foreach ($fields as $field) { |
| 2308 |
$result_str = $field; |
| 2309 |
$field_ins_upd = 'display'; |
| 2310 |
|
| 2311 |
$default = false; |
| 2312 |
|
| 2313 |
$this->register_field_adminhtml($result_str, $field_ins_upd, $default); |
| 2314 |
} |
| 2315 |
}?> |
| 2316 |
</ul> |
| 2317 |
<?php |
| 2318 |
} |
| 2319 |
|
| 2320 |
public function register_field_adminhtml($result_str, $field_ins_upd = '', $default = false, $request = array()) |
| 2321 |
{ |
| 2322 |
global $wpdb; |
| 2323 |
|
| 2324 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 2325 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 2326 |
|
| 2327 |
$cf = $result_str; |
| 2328 |
if (!is_object($cf) && (is_int($cf) || ctype_digit($cf))) { |
| 2329 |
$field_info = $wpdb->get_row($wpdb->prepare("select * from " . $extras_table_name . " where id= %d", array($cf))); |
| 2330 |
} elseif (is_object($cf)) { |
| 2331 |
//$field_info = $cf; |
| 2332 |
$result_str = $cf->id; |
| 2333 |
$field_info = $wpdb->get_row($wpdb->prepare("select * from " . $extras_table_name . " where id= %d", array((int) $cf->id))); |
| 2334 |
} else { |
| 2335 |
$field_info = false; |
| 2336 |
} |
| 2337 |
|
| 2338 |
if (isset($request['field_type']) && $request['field_type'] != '') |
| 2339 |
$field_type = esc_attr($request['field_type']); |
| 2340 |
else |
| 2341 |
$field_type = $field_info->field_type; |
| 2342 |
|
| 2343 |
|
| 2344 |
$field_site_name = ''; |
| 2345 |
if (isset($request['site_title'])) { |
| 2346 |
$field_site_name = $request['site_title']; |
| 2347 |
} |
| 2348 |
|
| 2349 |
if ($field_info) { |
| 2350 |
$account_field_info = $wpdb->get_row($wpdb->prepare("select * from " . $table_name . " where htmlvar_name= %s", array($field_info->site_htmlvar_name))); |
| 2351 |
if (isset($account_field_info->site_title)) { |
| 2352 |
if ($account_field_info->field_type == 'fieldset') { |
| 2353 |
$field_site_name = __('Fieldset:', 'userswp') . ' ' . $account_field_info->site_title; |
| 2354 |
} else { |
| 2355 |
$field_site_name = $account_field_info->site_title; |
| 2356 |
} |
| 2357 |
} |
| 2358 |
$field_info = stripslashes_deep($field_info); // strip slashes |
| 2359 |
} |
| 2360 |
$field_site_name = sanitize_title($field_site_name); |
| 2361 |
|
| 2362 |
if (isset($request['form_type'])) { |
| 2363 |
$form_type = esc_attr($request['form_type']); |
| 2364 |
} else { |
| 2365 |
$form_type = $field_info->form_type; |
| 2366 |
} |
| 2367 |
|
| 2368 |
if (isset($request['htmlvar_name']) && $request['htmlvar_name'] != '') { |
| 2369 |
$htmlvar_name = esc_attr($request['htmlvar_name']); |
| 2370 |
} else { |
| 2371 |
$htmlvar_name = $field_info->site_htmlvar_name; |
| 2372 |
} |
| 2373 |
|
| 2374 |
if (isset($htmlvar_name)) { |
| 2375 |
if (!is_object($field_info)) {$field_info = new stdClass(); } |
| 2376 |
$field_info->field_icon = $wpdb->get_var( |
| 2377 |
$wpdb->prepare("SELECT field_icon FROM " . $table_name . " WHERE htmlvar_name = %s", array($htmlvar_name)) |
| 2378 |
); |
| 2379 |
} |
| 2380 |
|
| 2381 |
$icon = isset($field_info->field_icon) ? $field_info->field_icon : ''; |
| 2382 |
if ( uwp_is_fa_icon( $icon ) ) { |
| 2383 |
$field_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>'; |
| 2384 |
} elseif ( uwp_is_icon_url( $icon ) ) { |
| 2385 |
$field_icon = '<b style="background-image: url("' . $icon . '")"></b>'; |
| 2386 |
} elseif (isset($field_info->field_type) && $field_info->field_type == 'fieldset') { |
| 2387 |
$field_icon = '<i class="fas fa-arrows-alt-h" aria-hidden="true"></i>'; |
| 2388 |
} else { |
| 2389 |
$field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 2390 |
} |
| 2391 |
?> |
| 2392 |
<li class="text li-settings" id="licontainer_<?php echo $result_str; ?>"> |
| 2393 |
<i class="fas fa-caret-down toggle-arrow" aria-hidden="true" onclick="uwp_show_hide(this);"></i> |
| 2394 |
<form> |
| 2395 |
<div class="title title<?php echo $result_str; ?> uwp-fieldset"> |
| 2396 |
<?php |
| 2397 |
$nonce = wp_create_nonce('uwp_form_extras_nonce' . $result_str); |
| 2398 |
echo $field_icon; |
| 2399 |
?> |
| 2400 |
<b><?php echo uwp_ucwords(' ' . $field_site_name); ?></b> |
| 2401 |
|
| 2402 |
</div> |
| 2403 |
|
| 2404 |
<div id="field_frm<?php echo $result_str; ?>" class="field_frm" |
| 2405 |
style="display:<?php if ($field_ins_upd == 'submit') { |
| 2406 |
echo 'block;'; |
| 2407 |
} else { |
| 2408 |
echo 'none;'; |
| 2409 |
} ?>"> |
| 2410 |
<input type="hidden" name="_wpnonce" value="<?php echo $nonce; ?>"/> |
| 2411 |
<input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr($result_str); ?>"/> |
| 2412 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/> |
| 2413 |
<input type="hidden" name="field_type" id="field_type" value="<?php echo $field_type; ?>"/> |
| 2414 |
<input type="hidden" name="is_active" id="is_active" value="1"/> |
| 2415 |
<ul class="widefat post fixed" style="width:100%;"> |
| 2416 |
|
| 2417 |
<input type="hidden" name="site_htmlvar_name" value="<?php echo $htmlvar_name ?>"/> |
| 2418 |
|
| 2419 |
<li> |
| 2420 |
<div class="uwp-input-wrap"> |
| 2421 |
<p><?php _e('No options available', 'userswp'); ?></p> |
| 2422 |
</div> |
| 2423 |
</li> |
| 2424 |
|
| 2425 |
<li> |
| 2426 |
<div class="uwp-input-wrap"> |
| 2427 |
<?php |
| 2428 |
$no_actions = array('username', 'email'); |
| 2429 |
$no_actions = apply_filters('uwp_register_fields_without_actions', $no_actions); |
| 2430 |
if (!in_array($field_info->site_htmlvar_name, $no_actions)) { ?> |
| 2431 |
<input type="button" class="button button-primary" name="save" id="save" |
| 2432 |
value="<?php esc_attr_e('Save', 'userswp'); ?>" |
| 2433 |
onclick="save_register_field('<?php echo $result_str; ?>')"/> |
| 2434 |
<input type="button" name="delete" value="<?php esc_attr_e('Delete', 'userswp'); ?>" |
| 2435 |
onclick="delete_register_field('<?php echo $result_str; ?>', '<?php echo $nonce; ?>','<?php echo $htmlvar_name ?>')" |
| 2436 |
class="button"/> |
| 2437 |
<?php } ?> |
| 2438 |
|
| 2439 |
</div> |
| 2440 |
</li> |
| 2441 |
</ul> |
| 2442 |
|
| 2443 |
</div> |
| 2444 |
</form> |
| 2445 |
</li> |
| 2446 |
<?php |
| 2447 |
} |
| 2448 |
|
| 2449 |
/** |
| 2450 |
* Handles the create custom field ajax request. |
| 2451 |
* |
| 2452 |
* @since 1.0.0 |
| 2453 |
* @package userswp |
| 2454 |
* @param array $data Submitted $_REQUEST data. |
| 2455 |
* @return void |
| 2456 |
*/ |
| 2457 |
public function create_field() { |
| 2458 |
|
| 2459 |
$form_type = isset($_REQUEST['form_type']) ? sanitize_text_field($_REQUEST['form_type']) : ''; |
| 2460 |
$field_type = isset($_REQUEST['field_type']) ? sanitize_text_field($_REQUEST['field_type']) : ''; |
| 2461 |
$field_type_key = isset($_REQUEST['field_type_key']) ? sanitize_text_field($_REQUEST['field_type_key']) : ''; |
| 2462 |
$field_action = isset($_REQUEST['field_ins_upd']) ? sanitize_text_field($_REQUEST['field_ins_upd']) : ''; |
| 2463 |
$field_id = isset($_REQUEST['field_id']) ? sanitize_text_field($_REQUEST['field_id']) : ''; |
| 2464 |
|
| 2465 |
$field_id = $field_id != '' ? trim($field_id, '_') : $field_id; |
| 2466 |
|
| 2467 |
$field_ids = array(); |
| 2468 |
if (!empty($_REQUEST['licontainer']) && is_array($_REQUEST['licontainer'])) { |
| 2469 |
foreach ($_REQUEST['licontainer'] as $lic_id) { |
| 2470 |
$field_ids[] = sanitize_text_field($lic_id); |
| 2471 |
} |
| 2472 |
} |
| 2473 |
|
| 2474 |
/* ------- check nonce field ------- */ |
| 2475 |
if (isset($_REQUEST['update']) && $_REQUEST['update'] == "update" && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
| 2476 |
echo $this->set_field_order($field_ids); |
| 2477 |
} |
| 2478 |
|
| 2479 |
/* ---- Show field form in admin ---- */ |
| 2480 |
if ($field_type != '' && $field_id != '' && $field_action == 'new' && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
| 2481 |
$this->form_field_adminhtml($field_type, $field_id, $field_action,$field_type_key, $form_type); |
| 2482 |
} |
| 2483 |
|
| 2484 |
|
| 2485 |
/* ---- Delete field ---- */ |
| 2486 |
if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
| 2487 |
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
| 2488 |
return; |
| 2489 |
|
| 2490 |
echo $this->admin_form_field_delete($field_id); |
| 2491 |
} |
| 2492 |
|
| 2493 |
/* ---- Save field ---- */ |
| 2494 |
if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce']) && isset($_REQUEST['create_field']) && isset($_REQUEST['manage_field_type']) && $_REQUEST['manage_field_type'] == 'custom_fields') { |
| 2495 |
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'custom_fields_' . $field_id)) |
| 2496 |
return; |
| 2497 |
|
| 2498 |
foreach ($_REQUEST as $pkey => $pval) { |
| 2499 |
if (is_array($_REQUEST[$pkey])) { |
| 2500 |
$tags = 'skip_field'; |
| 2501 |
} else { |
| 2502 |
$tags = ''; |
| 2503 |
} |
| 2504 |
|
| 2505 |
if ($tags != 'skip_field') { |
| 2506 |
$_REQUEST[$pkey] = strip_tags($_REQUEST[$pkey], $tags); |
| 2507 |
} |
| 2508 |
} |
| 2509 |
|
| 2510 |
$return = $this->admin_form_field_save($_REQUEST); |
| 2511 |
|
| 2512 |
if (is_int($return)) { |
| 2513 |
$lastid = $return; |
| 2514 |
$this->form_field_adminhtml($field_type, $lastid, 'submit',$field_type_key, $form_type); |
| 2515 |
} else { |
| 2516 |
echo $return; |
| 2517 |
} |
| 2518 |
} |
| 2519 |
|
| 2520 |
wp_die(); |
| 2521 |
|
| 2522 |
} |
| 2523 |
|
| 2524 |
public function register_ajax_handler() |
| 2525 |
{ |
| 2526 |
if (isset($_REQUEST['create_field'])) { |
| 2527 |
$field_id = isset($_REQUEST['field_id']) ? trim(sanitize_text_field($_REQUEST['field_id']), '_') : ''; |
| 2528 |
$field_action = isset($_REQUEST['field_ins_upd']) ? sanitize_text_field($_REQUEST['field_ins_upd']) : ''; |
| 2529 |
|
| 2530 |
/* ------- check nonce field ------- */ |
| 2531 |
if (isset($_REQUEST['update']) && $_REQUEST['update'] == 'update') { |
| 2532 |
$field_ids = array(); |
| 2533 |
if (!empty($_REQUEST['licontainer']) && is_array($_REQUEST['licontainer'])) { |
| 2534 |
foreach ($_REQUEST['licontainer'] as $lic_id) { |
| 2535 |
$field_ids[] = sanitize_text_field($lic_id); |
| 2536 |
} |
| 2537 |
} |
| 2538 |
|
| 2539 |
$return = uwp_form_extras_field_order($field_ids, "register"); |
| 2540 |
|
| 2541 |
if (is_array($return)) { |
| 2542 |
$return = json_encode($return); |
| 2543 |
} |
| 2544 |
|
| 2545 |
echo $return; |
| 2546 |
} |
| 2547 |
|
| 2548 |
/* ---- Show field form in admin ---- */ |
| 2549 |
if ($field_action == 'new') { |
| 2550 |
$form_type = isset($_REQUEST['form_type']) ? sanitize_text_field($_REQUEST['form_type']) : ''; |
| 2551 |
$fields = $this->register_fields($form_type); |
| 2552 |
|
| 2553 |
|
| 2554 |
$_REQUEST['site_field_id'] = isset($_REQUEST['field_id']) ? sanitize_text_field($_REQUEST['field_id']) : ''; |
| 2555 |
$_REQUEST['is_default'] = '0'; |
| 2556 |
|
| 2557 |
if (!empty($fields)) { |
| 2558 |
foreach ($fields as $val) { |
| 2559 |
$val = stripslashes_deep($val); |
| 2560 |
|
| 2561 |
if ($val['htmlvar_name'] == $_REQUEST['htmlvar_name']) { |
| 2562 |
$_REQUEST['field_type'] = $val['field_type']; |
| 2563 |
$_REQUEST['site_title'] = $val['site_title']; |
| 2564 |
} |
| 2565 |
} |
| 2566 |
} |
| 2567 |
|
| 2568 |
|
| 2569 |
$htmlvar_name = isset($_REQUEST['htmlvar_name']) ? sanitize_text_field($_REQUEST['htmlvar_name']) : ''; |
| 2570 |
|
| 2571 |
$this->register_field_adminhtml($htmlvar_name, $field_action, false, $_REQUEST); |
| 2572 |
} |
| 2573 |
|
| 2574 |
/* ---- Delete field ---- */ |
| 2575 |
if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce'])) { |
| 2576 |
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id)) |
| 2577 |
return; |
| 2578 |
|
| 2579 |
echo $this->register_field_delete($field_id); |
| 2580 |
} |
| 2581 |
|
| 2582 |
/* ---- Save field ---- */ |
| 2583 |
if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce'])) { |
| 2584 |
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id)) |
| 2585 |
return; |
| 2586 |
|
| 2587 |
foreach ($_REQUEST as $pkey => $pval) { |
| 2588 |
$tags = is_array($_REQUEST[$pkey]) ? 'skip_field' : ''; |
| 2589 |
|
| 2590 |
if ($tags != 'skip_field') { |
| 2591 |
$_REQUEST[$pkey] = strip_tags(sanitize_text_field($_REQUEST[$pkey]), $tags); |
| 2592 |
} |
| 2593 |
} |
| 2594 |
|
| 2595 |
|
| 2596 |
$return = $this->register_field_save($_REQUEST); |
| 2597 |
|
| 2598 |
if (is_int($return)) { |
| 2599 |
$lastid = $return; |
| 2600 |
|
| 2601 |
$this->register_field_adminhtml($lastid, 'submit'); |
| 2602 |
} else { |
| 2603 |
echo $return; |
| 2604 |
} |
| 2605 |
} |
| 2606 |
} |
| 2607 |
die(); |
| 2608 |
} |
| 2609 |
|
| 2610 |
public function register_field_save($request_field = array()) |
| 2611 |
{ |
| 2612 |
global $wpdb; |
| 2613 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 2614 |
|
| 2615 |
$result_str = isset($request_field['field_id']) ? trim($request_field['field_id']) : ''; |
| 2616 |
|
| 2617 |
$cf = trim($result_str, '_'); |
| 2618 |
|
| 2619 |
/*-------- check duplicate validation --------*/ |
| 2620 |
|
| 2621 |
$site_htmlvar_name = isset($request_field['site_htmlvar_name']) ? $request_field['site_htmlvar_name'] : $request_field['htmlvar_name']; |
| 2622 |
$form_type = $request_field['form_type']; |
| 2623 |
$field_type = $request_field['field_type']; |
| 2624 |
|
| 2625 |
$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 ", |
| 2626 |
array($cf, $site_htmlvar_name, $form_type))); |
| 2627 |
|
| 2628 |
|
| 2629 |
if (!$check_html_variable) { |
| 2630 |
|
| 2631 |
if ($cf != '') { |
| 2632 |
|
| 2633 |
$user_meta_info = $wpdb->get_row( |
| 2634 |
$wpdb->prepare( |
| 2635 |
"select * from " . $extras_table_name . " where id = %d", |
| 2636 |
array($cf) |
| 2637 |
) |
| 2638 |
); |
| 2639 |
|
| 2640 |
} |
| 2641 |
|
| 2642 |
if ($form_type == '') $form_type = 'register'; |
| 2643 |
|
| 2644 |
|
| 2645 |
$site_htmlvar_name = $request_field['site_htmlvar_name']; |
| 2646 |
$field_id = (isset($request_field['field_id']) && $request_field['field_id']) ? str_replace('new', '', $request_field['field_id']) : ''; |
| 2647 |
|
| 2648 |
if (!empty($user_meta_info)) { |
| 2649 |
|
| 2650 |
$wpdb->query( |
| 2651 |
$wpdb->prepare( |
| 2652 |
"update " . $extras_table_name . " set |
| 2653 |
form_type = %s, |
| 2654 |
field_type = %s, |
| 2655 |
site_htmlvar_name = %s, |
| 2656 |
sort_order = %s |
| 2657 |
where id = %d", |
| 2658 |
array( |
| 2659 |
$form_type, |
| 2660 |
$field_type, |
| 2661 |
$site_htmlvar_name, |
| 2662 |
$field_id, |
| 2663 |
$cf |
| 2664 |
) |
| 2665 |
|
| 2666 |
) |
| 2667 |
|
| 2668 |
); |
| 2669 |
|
| 2670 |
$lastid = trim($cf); |
| 2671 |
|
| 2672 |
|
| 2673 |
} else { |
| 2674 |
|
| 2675 |
|
| 2676 |
$wpdb->query( |
| 2677 |
$wpdb->prepare( |
| 2678 |
|
| 2679 |
"insert into " . $extras_table_name . " set |
| 2680 |
form_type = %s, |
| 2681 |
field_type = %s, |
| 2682 |
site_htmlvar_name = %s, |
| 2683 |
sort_order = %s", |
| 2684 |
array($form_type, |
| 2685 |
$field_type, |
| 2686 |
$site_htmlvar_name, |
| 2687 |
$field_id |
| 2688 |
) |
| 2689 |
) |
| 2690 |
); |
| 2691 |
$lastid = $wpdb->insert_id; |
| 2692 |
$lastid = trim($lastid); |
| 2693 |
} |
| 2694 |
|
| 2695 |
return (int) $lastid; |
| 2696 |
|
| 2697 |
|
| 2698 |
} else { |
| 2699 |
return 'invalid_key'; |
| 2700 |
} |
| 2701 |
} |
| 2702 |
|
| 2703 |
public function register_field_delete($field_id = '') |
| 2704 |
{ |
| 2705 |
|
| 2706 |
global $wpdb; |
| 2707 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 2708 |
|
| 2709 |
if ($field_id != '') { |
| 2710 |
$cf = trim($field_id, '_'); |
| 2711 |
|
| 2712 |
$wpdb->query($wpdb->prepare("delete from " . $extras_table_name . " where id= %d ", array($cf))); |
| 2713 |
|
| 2714 |
return $field_id; |
| 2715 |
|
| 2716 |
} else |
| 2717 |
return 0; |
| 2718 |
|
| 2719 |
|
| 2720 |
} |
| 2721 |
|
| 2722 |
} |