PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.6
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / front-end / default-fields / email / email.php

email.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.6, at front-end/default-fields/email/email.php

139 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 /* handle field output */
5 function wppb_email_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){
6 $item_title = apply_filters( 'wppb_'.$form_location.'_email_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( 'user_email', $user_id );
11
12 if ( trim( $input_value ) == '' )
13 $input_value = $field['default-value'];
14
15 $input_value = ( isset( $request_data['email'] ) ? trim( $request_data['email'] ) : $input_value );
16 // filter must be applied on the $input_value so that the value returned to the form can be corrected too
17 $input_value = apply_filters( 'wppb_before_processing_email_from_forms' , $input_value );
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 $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location );
26
27 $email_input_status = !current_user_can( 'manage_options' ) ? apply_filters( 'wppb_set_input_status', '' ) : '';
28
29 $output = '
30 <label for="email">'.$item_title.$error_mark.'</label>
31 <input class="text-input default_field_email '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" name="email" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70, $field ) .'" type="email" id="email" value="'. esc_attr( $input_value ) .'" '. $extra_attr .' '. (( $form_location != 'register' ) ? $email_input_status : '') .' />';
32 if( !empty( $item_description ) )
33 $output .= '<span class="wppb-description-delimiter">'. $item_description .'</span>';
34
35 if( $form_location == 'edit_profile' && is_user_logged_in() ) {
36 if ( $email_input_status == 'enabled' ) {
37 $output .= '<span class="wppb-description-delimiter">' . __('If you change this, we will send you an email at your new address to confirm it. <br /><strong>The new address will not become active until confirmed.</strong>', 'profile-builder') . '</span>';
38 }
39 else if ( $email_input_status == 'disabled' ) {
40 $current_url = wppb_curpageurl();
41 $pending_request_nonce = wp_create_nonce( 'wppb_email_change_action_nonce' );
42 $arr_params = array( 'wppb_email_change_action' => 'cancel_pending_email_address_change','_wpnonce' => $pending_request_nonce );
43 $cancel_request_url = add_query_arg($arr_params, $current_url);
44 $pending_new_email_address = apply_filters('wppb_new_email_address','');
45
46 $output .= '<span class="wppb-description-delimiter">' . sprintf(__('There is a pending change request of your email to: %s', 'profile-builder'), '<strong>' . $pending_new_email_address . '</strong>');
47 $output .= '<a class="wppb-cancel-request" style="float: right;" href="' . esc_url($cancel_request_url) . '">' . __('Cancel request', 'profile-builder') . '</a></span>';
48 }
49 }
50
51
52 }
53
54 return apply_filters( 'wppb_'.$form_location.'_email', $output, $form_location, $field, $user_id, $field_check_errors, $request_data );
55 }
56 add_filter( 'wppb_output_form_field_default-e-mail', 'wppb_email_handler', 10, 6 );
57
58
59 /* handle field validation */
60 function wppb_check_email_value( $message, $field, $request_data, $form_location ){
61 global $wpdb;
62 // apply filter to allow stripping slashes if necessary
63 if ( isset( $request_data['email'] ) ) {
64 $request_data['email'] = apply_filters('wppb_before_processing_email_from_forms', $request_data['email']);
65 if ((isset($request_data['email']) && (trim($request_data['email']) == '')) && ($field['required'] == 'Yes'))
66 return wppb_required_field_error($field["field-title"]);
67
68 if (isset($request_data['email']) && !is_email(trim($request_data['email']))) {
69 return __('The email you entered is not a valid email address.', 'profile-builder');
70 }
71
72 if (empty($request_data['email'])) {
73 return __('You must enter a valid email address.', 'profile-builder');
74 }
75
76 $wppb_generalSettings = get_option('wppb_general_settings');
77 if (isset($wppb_generalSettings['emailConfirmation']) && ($wppb_generalSettings['emailConfirmation'] == 'yes')) {
78 $user_signup = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->base_prefix . "signups WHERE user_email = %s AND active=0", $request_data['email']));
79
80 if (!empty($user_signup)) {
81 if ($form_location == 'register') {
82 return __('This email is already reserved to be used soon.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder');
83 } else if ($form_location == 'edit_profile') {
84 $current_user = wp_get_current_user();
85
86 if (!current_user_can('edit_users')) {
87 if ($current_user->user_email != $request_data['email'])
88 return __('This email is already reserved to be used soon.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder');
89 }
90 }
91 }
92 }
93
94 $users = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_email = %s", $request_data['email']));
95
96 if (!empty($users)) {
97 if ($form_location == 'register')
98 return __('This email is already in use.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder');
99
100 if ($form_location == 'edit_profile') {
101 if( isset( $_SERVER['HTTP_REFERER'] ) )
102 $url_parts = parse_url( esc_url_raw( $_SERVER['HTTP_REFERER'] ) );
103
104 if (isset($url_parts['query'])) {
105 parse_str($url_parts['query'], $query);
106 }
107
108 if (isset($_GET['edit_user']) && !empty($_GET['edit_user'])) {
109 $current_user_id = absint($_GET['edit_user']);
110 } elseif (defined('DOING_AJAX') && DOING_AJAX && isset($query['edit_user']) && !empty($query['edit_user'])) {
111 $current_user_id = $query['edit_user'];
112 } else {
113 $current_user = wp_get_current_user();
114 $current_user_id = $current_user->ID;
115 }
116 foreach ($users as $user)
117 if ($user->ID != $current_user_id)
118 return __('This email is already in use.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder');
119 }
120 }
121 }
122
123 return $message;
124 }
125 add_filter( 'wppb_check_form_field_default-e-mail', 'wppb_check_email_value', 10, 4 );
126
127 /* handle field save */
128 function wppb_userdata_add_email( $userdata, $global_request, $form_args ){
129 if( wppb_field_exists_in_form( 'Default - E-mail', $form_args ) ) {
130 // apply filter to allow stripping slashes if necessary
131 if (isset($global_request['email'])) {
132 $global_request['email'] = apply_filters('wppb_before_processing_email_from_forms', $global_request['email']);
133 $userdata['user_email'] = sanitize_text_field(trim($global_request['email']));
134 }
135 }
136
137 return $userdata;
138 }
139 add_filter( 'wppb_build_userdata', 'wppb_userdata_add_email', 10, 3 );