| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/* handle field output */ |
| 5 |
function wppb_website_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ |
| 6 |
$item_title = apply_filters( 'wppb_'.$form_location.'_website_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ); |
| 7 |
$item_description = wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_description_translation', $field['description'], true ); |
| 8 |
$input_value = ''; |
| 9 |
if( $form_location == 'edit_profile' ) |
| 10 |
$input_value = get_the_author_meta( 'user_url', $user_id ); |
| 11 |
|
| 12 |
if ( trim( $input_value ) == '' ) |
| 13 |
$input_value = $field['default-value']; |
| 14 |
|
| 15 |
$input_value = ( isset( $request_data['website'] ) ? trim( $request_data['website'] ) : $input_value ); |
| 16 |
$input_value = apply_filters( 'wppb_form_website_field_value', $input_value, $field, $form_location ); |
| 17 |
|
| 18 |
if ( $form_location != 'back_end' ){ |
| 19 |
$error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' ); |
| 20 |
|
| 21 |
if ( array_key_exists( $field['id'], $field_check_errors ) ) |
| 22 |
$error_mark = '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.wppb_required_field_error($field["field-title"]).'"/>'; |
| 23 |
|
| 24 |
$extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location ); |
| 25 |
|
| 26 |
$output = ' |
| 27 |
<label for="website">'.$item_title.$error_mark.'</label> |
| 28 |
<input class="text-input default_field_website '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" name="website" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70, $field ) .'" type="text" id="website" value="'.esc_url( wp_unslash( $input_value ) ).'" '. $extra_attr .'/>'; |
| 29 |
if( !empty( $item_description ) ) |
| 30 |
$output .= '<span class="wppb-description-delimiter">'. $item_description .'</span>'; |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
return apply_filters( 'wppb_'.$form_location.'_website', $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); |
| 35 |
} |
| 36 |
add_filter( 'wppb_output_form_field_default-website', 'wppb_website_handler', 10, 6 ); |
| 37 |
|
| 38 |
|
| 39 |
/* handle field validation */ |
| 40 |
function wppb_check_website_value( $message, $field, $request_data, $form_location ){ |
| 41 |
if( $field['required'] == 'Yes' ){ |
| 42 |
if( ( isset( $request_data['website'] ) && ( trim( $request_data['website'] ) == '' ) ) || !isset( $request_data['website'] ) ){ |
| 43 |
return wppb_required_field_error($field["field-title"]); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
return $message; |
| 48 |
} |
| 49 |
add_filter( 'wppb_check_form_field_default-website', 'wppb_check_website_value', 10, 4 ); |
| 50 |
|
| 51 |
|
| 52 |
/* handle field save */ |
| 53 |
function wppb_userdata_add_website( $userdata, $global_request, $form_args ){ |
| 54 |
if( wppb_field_exists_in_form( 'Default - Website', $form_args ) ) { |
| 55 |
if (isset($global_request['website'])) |
| 56 |
$userdata['user_url'] = esc_url_raw(trim($global_request['website'])); |
| 57 |
} |
| 58 |
|
| 59 |
return $userdata; |
| 60 |
} |
| 61 |
add_filter( 'wppb_build_userdata', 'wppb_userdata_add_website', 10, 3 ); |