| 1 |
<?php |
| 2 |
/* handle field output */ |
| 3 |
function wppb_description_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ |
| 4 |
$item_title = apply_filters( 'wppb_'.$form_location.'_description_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_title_translation', $field['field-title'] ) ); |
| 5 |
$item_description = wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_description_translation', $field['description'] ); |
| 6 |
$input_value = ''; |
| 7 |
if( $form_location == 'edit_profile' ) { |
| 8 |
$profileuser = get_userdata( $user_id ); |
| 9 |
$input_value = $profileuser->description; |
| 10 |
} |
| 11 |
|
| 12 |
if ( trim( $input_value ) == '' ) |
| 13 |
$input_value = $field['default-value']; |
| 14 |
|
| 15 |
$input_value = ( isset( $request_data['description'] ) ? trim( $request_data['description'] ) : $input_value ); |
| 16 |
|
| 17 |
$extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location ); |
| 18 |
|
| 19 |
if ( $form_location != 'back_end' ){ |
| 20 |
$error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' ); |
| 21 |
|
| 22 |
if ( array_key_exists( $field['id'], $field_check_errors ) ) |
| 23 |
$error_mark = '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.wppb_required_field_error($field["field-title"]).'"/>'; |
| 24 |
|
| 25 |
$output = ' |
| 26 |
<label for="description">'.$item_title.$error_mark.'</label> |
| 27 |
<textarea rows="'.$field['row-count'].'" name="description" maxlength="'. apply_filters( 'wppb_maximum_character_length', '', $field ) .'" class="default_field_description '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" id="description" wrap="virtual" '. $extra_attr .'>'. esc_textarea( wp_unslash( $input_value ) ).'</textarea>'; |
| 28 |
if( !empty( $item_description ) ) |
| 29 |
$output .= '<span class="wppb-description-delimiter">'. $item_description .'</span>'; |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
return apply_filters( 'wppb_'.$form_location.'_description', $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); |
| 34 |
} |
| 35 |
add_filter( 'wppb_output_form_field_default-biographical-info', 'wppb_description_handler', 10, 6 ); |
| 36 |
|
| 37 |
|
| 38 |
/* handle field validation */ |
| 39 |
function wppb_check_description_value( $message, $field, $request_data, $form_location ){ |
| 40 |
if( $field['required'] == 'Yes' ){ |
| 41 |
if( ( isset( $request_data['description'] ) && ( trim( $request_data['description'] ) == '' ) ) || !isset( $request_data['description'] ) ){ |
| 42 |
return wppb_required_field_error($field["field-title"]); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return $message; |
| 47 |
} |
| 48 |
add_filter( 'wppb_check_form_field_default-biographical-info', 'wppb_check_description_value', 10, 4 ); |
| 49 |
|
| 50 |
/* handle field save */ |
| 51 |
function wppb_userdata_add_description( $userdata, $global_request ){ |
| 52 |
if ( isset( $global_request['description'] ) ){ |
| 53 |
$description = apply_filters( 'pre_user_description', trim ( $global_request['description'] ) ); |
| 54 |
$userdata['description'] = $description; |
| 55 |
} |
| 56 |
return $userdata; |
| 57 |
} |
| 58 |
add_filter( 'wppb_build_userdata', 'wppb_userdata_add_description', 10, 2 ); |