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