← All changes
|
front-end/default-fields/first-name/first-name.php
+60
-51
2.0.3
→
4.0.3
View file →
| @@ -1,51 +1,60 @@ | ||
| 1 | -<?php | |
| 2 | -/* handle field output */ | |
| 3 | -function wppb_first_name_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ | |
| 4 | - $item_title = apply_filters( 'wppb_'.$form_location.'_firstname_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( 'first_name', $user_id ); | |
| 9 | - | |
| 10 | - if ( trim( $input_value ) == '' ) | |
| 11 | - $input_value = $field['default-value']; | |
| 12 | - | |
| 13 | - $input_value = ( isset( $request_data['first_name'] ) ? trim( $request_data['first_name'] ) : $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="first_name">'.$item_title.$error_mark.'</label> | |
| 23 | - <input class="text-input default_field_firstname" name="first_name" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70 ) .'" type="text" id="first_name" value="'. esc_attr( wp_unslash( $input_value ) ) .'" />'; | |
| 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.'_firstname', $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); | |
| 30 | -} | |
| 31 | -add_filter( 'wppb_output_form_field_default-first-name', 'wppb_first_name_handler', 10, 6 ); | |
| 32 | - | |
| 33 | - | |
| 34 | -/* handle field validation */ | |
| 35 | -function wppb_check_first_name_value( $message, $field, $request_data, $form_location ){ | |
| 36 | - if ( ( isset( $request_data['first_name'] ) && ( trim( $request_data['first_name'] ) == '' ) ) && ( $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-first-name', 'wppb_check_first_name_value', 10, 4 ); | |
| 42 | - | |
| 43 | - | |
| 44 | -/* handle field save */ | |
| 45 | -function wppb_userdata_add_first_name( $userdata, $global_request ){ | |
| 46 | - if ( isset( $global_request['first_name'] ) ) | |
| 47 | - $userdata['first_name'] = sanitize_text_field( trim( $global_request['first_name'] ) ); | |
| 48 | - | |
| 49 | - return $userdata; | |
| 50 | -} | |
| 51 | -add_filter( 'wppb_build_userdata', 'wppb_userdata_add_first_name', 10, 2 ); | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 3 | + | |
| 4 | +/* handle field output */ | |
| 5 | +function wppb_first_name_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ | |
| 6 | + $item_title = apply_filters( 'wppb_'.$form_location.'_firstname_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( 'first_name', $user_id ); | |
| 11 | + | |
| 12 | + if ( trim( $input_value ) == '' ) | |
| 13 | + $input_value = $field['default-value']; | |
| 14 | + | |
| 15 | + $input_value = ( isset( $request_data['first_name'] ) ? trim( $request_data['first_name'] ) : $input_value ); | |
| 16 | + $input_value = apply_filters( 'wppb_form_first_name_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="first_name">'.$item_title.$error_mark.'</label> | |
| 28 | + <input class="text-input default_field_firstname '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" name="first_name" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70, $field ) .'" type="text" id="first_name" value="'. esc_attr( 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.'_firstname', $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); | |
| 35 | +} | |
| 36 | +add_filter( 'wppb_output_form_field_default-first-name', 'wppb_first_name_handler', 10, 6 ); | |
| 37 | + | |
| 38 | + | |
| 39 | +/* handle field validation */ | |
| 40 | +function wppb_check_first_name_value( $message, $field, $request_data, $form_location ){ | |
| 41 | + if( $field['required'] == 'Yes' ){ | |
| 42 | + if( ( isset( $request_data['first_name'] ) && ( trim( $request_data['first_name'] ) == '' ) ) || !isset( $request_data['first_name'] ) ){ | |
| 43 | + return wppb_required_field_error($field["field-title"]); | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + return $message; | |
| 48 | +} | |
| 49 | +add_filter( 'wppb_check_form_field_default-first-name', 'wppb_check_first_name_value', 10, 4 ); | |
| 50 | + | |
| 51 | + | |
| 52 | +/* handle field save */ | |
| 53 | +function wppb_userdata_add_first_name( $userdata, $global_request, $form_args ){ | |
| 54 | + if( wppb_field_exists_in_form( 'Default - First Name', $form_args ) ) { | |
| 55 | + if ( isset( $global_request['first_name'] ) ) | |
| 56 | + $userdata['first_name'] = sanitize_text_field( trim( $global_request['first_name'] ) ); | |
| 57 | + } | |
| 58 | + return $userdata; | |
| 59 | +} | |
| 60 | +add_filter( 'wppb_build_userdata', 'wppb_userdata_add_first_name', 10, 3 ); | |