← All changes
|
front-end/default-fields/description/description.php
+82
-51
2.0.3
→
4.0.3
View file →
| @@ -1,51 +1,82 @@ | ||
| 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" 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 ); | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * Sanitize Default Biographical Info (stored as the WordPress user description). | |
| 6 | + * | |
| 7 | + * @param array $request Request data (e.g. $_POST) that may contain a `description` key. | |
| 8 | + * @return string | |
| 9 | + */ | |
| 10 | +function wppb_sanitize_default_biographical_info_from_request( $request ) { | |
| 11 | + if ( ! is_array( $request ) || ! array_key_exists( 'description', $request ) ) { | |
| 12 | + return ''; | |
| 13 | + } | |
| 14 | + | |
| 15 | + $meta_value = sanitize_textarea_field( wp_unslash( $request['description'] ) ); | |
| 16 | + | |
| 17 | + if ( apply_filters( 'wppb_form_field_textarea_escape_on_save', false ) ) { | |
| 18 | + $meta_value = esc_textarea( $meta_value ); | |
| 19 | + } | |
| 20 | + | |
| 21 | + return apply_filters( 'pre_user_description', $meta_value ); | |
| 22 | +} | |
| 23 | + | |
| 24 | +/* handle field output */ | |
| 25 | +function wppb_description_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ | |
| 26 | + $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'], true ) ); | |
| 27 | + $item_description = wppb_icl_t( 'plugin profile-builder-pro', 'default_field_'.$field['id'].'_description_translation', $field['description'], true ); | |
| 28 | + $input_value = ''; | |
| 29 | + if( $form_location == 'edit_profile' ) { | |
| 30 | + $profileuser = get_userdata( $user_id ); | |
| 31 | + $input_value = $profileuser->description; | |
| 32 | + } | |
| 33 | + | |
| 34 | + if ( trim( $input_value ) == '' && !empty( $field['default-content'] ) ) | |
| 35 | + $input_value = $field['default-content']; | |
| 36 | + | |
| 37 | + $input_value = ( isset( $request_data['description'] ) ? trim( $request_data['description'] ) : $input_value ); | |
| 38 | + $input_value = apply_filters( 'wppb_form_description_field_value', $input_value, $field, $form_location ); | |
| 39 | + | |
| 40 | + $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location ); | |
| 41 | + | |
| 42 | + if ( $form_location != 'back_end' ){ | |
| 43 | + $error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' ); | |
| 44 | + | |
| 45 | + if ( array_key_exists( $field['id'], $field_check_errors ) ) | |
| 46 | + $error_mark = '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.wppb_required_field_error($field["field-title"]).'"/>'; | |
| 47 | + | |
| 48 | + $output = ' | |
| 49 | + <label for="description">'.$item_title.$error_mark.'</label> | |
| 50 | + <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>'; | |
| 51 | + if( !empty( $item_description ) ) | |
| 52 | + $output .= '<span class="wppb-description-delimiter">'. $item_description .'</span>'; | |
| 53 | + | |
| 54 | + } | |
| 55 | + | |
| 56 | + return apply_filters( 'wppb_'.$form_location.'_description', $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); | |
| 57 | +} | |
| 58 | +add_filter( 'wppb_output_form_field_default-biographical-info', 'wppb_description_handler', 10, 6 ); | |
| 59 | + | |
| 60 | + | |
| 61 | +/* handle field validation */ | |
| 62 | +function wppb_check_description_value( $message, $field, $request_data, $form_location ){ | |
| 63 | + if( $field['required'] == 'Yes' ){ | |
| 64 | + if( ( isset( $request_data['description'] ) && ( trim( $request_data['description'] ) == '' ) ) || !isset( $request_data['description'] ) ){ | |
| 65 | + return wppb_required_field_error($field["field-title"]); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + return $message; | |
| 70 | +} | |
| 71 | +add_filter( 'wppb_check_form_field_default-biographical-info', 'wppb_check_description_value', 10, 4 ); | |
| 72 | + | |
| 73 | +/* handle field save */ | |
| 74 | +function wppb_userdata_add_description( $userdata, $global_request, $form_args ){ | |
| 75 | + if( wppb_field_exists_in_form( 'Default - Biographical Info', $form_args ) ) { | |
| 76 | + if ( array_key_exists( 'description', $global_request ) ){ | |
| 77 | + $userdata['description'] = wppb_sanitize_default_biographical_info_from_request( $global_request ); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + return $userdata; | |
| 81 | +} | |
| 82 | +add_filter( 'wppb_build_userdata', 'wppb_userdata_add_description', 10, 3 ); | |