| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/* handle field output */ |
| 6 |
function wppb_email_confirmation_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){ |
| 7 |
if ( $field['field'] == 'Email Confirmation' ) { |
| 8 |
$item_title = apply_filters( 'wppb_' .$form_location.'_email_confirmation_custom_field_'.$field['id'].'_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ); |
| 9 |
$item_description = wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_description_translation', $field['description'], true ); |
| 10 |
|
| 11 |
$extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location ); |
| 12 |
|
| 13 |
if( $form_location == 'edit_profile' ) |
| 14 |
$input_value = get_the_author_meta( 'user_email', $user_id ); |
| 15 |
else |
| 16 |
$input_value = ''; |
| 17 |
|
| 18 |
$input_value = ( isset( $request_data['wppb_email_confirmation'] ) ? esc_attr( $request_data['wppb_email_confirmation'] ) : $input_value ); |
| 19 |
|
| 20 |
$error_mark = (($field['required'] == 'Yes') ? '<span class="wppb-required" title="' . wppb_required_field_error($field["field-title"]) . '">*</span>' : ''); |
| 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 |
$output = ' |
| 25 |
<label for="wppb_email_confirmation">'.$item_title.$error_mark.'</label> |
| 26 |
<input class="extra_field_email_confirmation" name="wppb_email_confirmation" type="email" id="wppb_email_confirmation" value="'. esc_attr( wp_unslash( $input_value ) ) .'" '. $extra_attr .'/>'; |
| 27 |
if( !empty( $item_description ) ) |
| 28 |
$output .= '<span class="wppb-description-delimiter">'.$item_description.'</span>'; |
| 29 |
|
| 30 |
return apply_filters( 'wppb_'.$form_location.'_email_confirmation_custom_field_'.$field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value ); |
| 31 |
} |
| 32 |
} |
| 33 |
add_filter( 'wppb_output_form_field_email-confirmation', 'wppb_email_confirmation_handler', 10, 6 ); |
| 34 |
|
| 35 |
|
| 36 |
/* handle field validation */ |
| 37 |
function wppb_check_email_confirmation_value( $message, $field, $request_data, $form_location ){ |
| 38 |
if( $field['field'] == 'Email Confirmation' ) { |
| 39 |
if ((isset($request_data['wppb_email_confirmation']) && (trim($request_data['wppb_email_confirmation']) == '')) && ($field['required'] == 'Yes')) |
| 40 |
return wppb_required_field_error($field["field-title"]); |
| 41 |
|
| 42 |
if ( (isset($request_data['wppb_email_confirmation'])) && ($field['required'] == 'Yes') && (strcasecmp($request_data['email'], $request_data['wppb_email_confirmation']) != 0) ) { |
| 43 |
return __('The email confirmation does not match your email address.', 'profile-builder'); |
| 44 |
} |
| 45 |
} |
| 46 |
return $message; |
| 47 |
} |
| 48 |
add_filter( 'wppb_check_form_field_email-confirmation', 'wppb_check_email_confirmation_value', 10, 4 ); |
| 49 |
|
| 50 |
|
| 51 |
//Remove Email Confirmation field from UserListing merge tags (available Meta and Sort Variables list) |
| 52 |
function wppb_remove_email_confirmation_from_userlisting($manage_fields){ |
| 53 |
foreach ($manage_fields as $key => $value){ |
| 54 |
if ($value['field'] == 'Email Confirmation') unset($manage_fields[$key]); |
| 55 |
} |
| 56 |
return array_values($manage_fields); |
| 57 |
} |
| 58 |
add_filter('wppb_userlisting_merge_tags', 'wppb_remove_email_confirmation_from_userlisting'); |