| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
if( file_exists( dirname(__FILE__) . '/base.php') ) |
| 7 |
require_once('base.php'); |
| 8 |
|
| 9 |
class Edit_form extends PieReg_Base |
| 10 |
{ |
| 11 |
var $id; |
| 12 |
var $no; |
| 13 |
var $name; |
| 14 |
var $field; |
| 15 |
var $data; |
| 16 |
var $label_alignment; |
| 17 |
var $user; |
| 18 |
var $user_id; |
| 19 |
var $error; |
| 20 |
var $pie_success; |
| 21 |
var $pie_error; |
| 22 |
var $pie_error_msg; |
| 23 |
var $pie_success_msg; |
| 24 |
var $pages; |
| 25 |
function __construct($user,$form_id = "default") |
| 26 |
{ |
| 27 |
parent::__construct(); |
| 28 |
$this->data = $this->getCurrentFields($form_id); |
| 29 |
$this->user = $user; |
| 30 |
$this->user_id = $user->ID; |
| 31 |
$this->label_alignment = ((isset($this->data['form']['label_alignment']))?$this->data['form']['label_alignment']:""); |
| 32 |
} |
| 33 |
|
| 34 |
function createFieldID() |
| 35 |
{ |
| 36 |
return "field_".((isset($this->field['id']))?$this->field['id']:""); |
| 37 |
} |
| 38 |
function addValidation() |
| 39 |
{ |
| 40 |
if(!isset($this->field['validation_message'])) $this->field['validation_message'] = ""; |
| 41 |
if((isset($this->field['required']) && $this->field['required']) && !empty($this->field['validation_message'])) |
| 42 |
{ |
| 43 |
$val[] = 'data-errormessage-value-missing="'.$this->field['validation_message'].'"'; |
| 44 |
} |
| 45 |
|
| 46 |
if(isset($this->field['validation_rule'])) |
| 47 |
{ |
| 48 |
if( |
| 49 |
$this->field['validation_rule']=="number" || |
| 50 |
$this->field['type']=="number" || $this->field['validation_rule']=="alphanumeric" || |
| 51 |
$this->field['validation_rule']=="email" || $this->field['type']=="email" || |
| 52 |
$this->field['validation_rule']=="website" || $this->field['type']=="website" || |
| 53 |
$this->field['type']=="phone" || $this->field['type']=="date") |
| 54 |
{ |
| 55 |
$val[] = 'data-errormessage-custom-error="'.$this->field['validation_message'].'"'; |
| 56 |
} |
| 57 |
} |
| 58 |
else if($this->field['type']=="time") |
| 59 |
{ |
| 60 |
$val[] = 'data-errormessage-custom-error="'.$this->field['validation_message'].'"'; |
| 61 |
$val[] = 'data-errormessage-range-underflow="'.$this->field['validation_message'].'"'; |
| 62 |
$val[] = 'data-errormessage-range-overflow="'.$this->field['validation_message'].'"'; |
| 63 |
} |
| 64 |
|
| 65 |
if(isset($val) && sizeof($val) > 0) |
| 66 |
{ |
| 67 |
return implode(" ",$val); |
| 68 |
} |
| 69 |
} |
| 70 |
function validateRegistration($errors) |
| 71 |
{ |
| 72 |
global $wpdb; |
| 73 |
|
| 74 |
$global_options = $this->get_pr_global_options(); |
| 75 |
|
| 76 |
/* |
| 77 |
* Sanitizing post data |
| 78 |
*/ |
| 79 |
$this->pie_post_array = $this->piereg_sanitize_post_data_escape( ( (isset($_POST) && !empty($_POST))?$_POST : array() ) ); |
| 80 |
|
| 81 |
$regXemail = "/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/"; |
| 82 |
if ( empty( $this->pie_post_array['e_mail'] ) || !is_email($this->pie_post_array['e_mail']) ) |
| 83 |
{ |
| 84 |
$errors->add( "email" , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_invalid_Email_address",__('Invalid email address','pie-register' ))); |
| 85 |
} |
| 86 |
|
| 87 |
if(isset($this->pie_post_array['confirm_password'])){ |
| 88 |
if($this->pie_post_array['password'] != $this->pie_post_array['confirm_password'] && isset($this->pie_post_array['password'], $this->pie_post_array['confirm_password'])) |
| 89 |
{ |
| 90 |
$errors->add( "password" , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_password_Fields_do_not_match",__('New and Confirm Password fields do not match.','pie-register' ))); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
if(isset($this->pie_post_array['old_password']) && !wp_check_password( $this->pie_post_array['old_password'], $this->user->data->user_pass, $this->user->ID ) && !empty($this->pie_post_array['old_password'])) |
| 95 |
{ |
| 96 |
$errors->add( "password" , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_old_password_Fields_do_not_match",__('Incorrect Old Password entered.','pie-register' ))); |
| 97 |
}elseif(!empty($this->pie_post_array['password']) && empty($this->pie_post_array['old_password']) ){ |
| 98 |
$errors->add( "password" , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_old_password_Fields_do_not_match",__('Old password is invalid.','pie-register' ))); |
| 99 |
} |
| 100 |
elseif(isset($this->pie_post_array['password']) && $this->pie_post_array['old_password'] == $this->pie_post_array['password'] && !empty($this->pie_post_array['password']) && !empty($this->pie_post_array['old_password'])) |
| 101 |
{ |
| 102 |
$errors->add( "password" , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_old_password_and_new_password_same",__('Old and new passwords are identical.','pie-register' ))); |
| 103 |
} |
| 104 |
|
| 105 |
$piereg = get_option(OPTION_PIE_REGISTER); |
| 106 |
foreach($this->data as $field) |
| 107 |
{ |
| 108 |
|
| 109 |
$break = FALSE; |
| 110 |
//Printting Field |
| 111 |
switch($field['type']) |
| 112 |
{ |
| 113 |
case 'form': |
| 114 |
case 'username': |
| 115 |
case 'submit': |
| 116 |
case 'hidden': |
| 117 |
case 'invitation': |
| 118 |
case 'password': |
| 119 |
case 'honeypot': |
| 120 |
case 'terms': |
| 121 |
{ |
| 122 |
$break = TRUE; |
| 123 |
} |
| 124 |
break; |
| 125 |
} |
| 126 |
if($break) |
| 127 |
{ |
| 128 |
continue; |
| 129 |
} |
| 130 |
/* |
| 131 |
* Validate Show Profile |
| 132 |
*/ |
| 133 |
if(isset($field['show_in_profile']) && $field['show_in_profile'] == 0) |
| 134 |
{ |
| 135 |
continue; |
| 136 |
} |
| 137 |
|
| 138 |
$slug = $this->createFieldName($field['type']."_".$field['id']); |
| 139 |
if($field['type']=="username" || $field['type']=="password"){ |
| 140 |
$slug = $this->createFieldName($field['type']); |
| 141 |
} |
| 142 |
else if($field['type']=="name"){ |
| 143 |
$slug = $this->createFieldName("first_name"); |
| 144 |
} |
| 145 |
else if($field['type']=="email"){ |
| 146 |
$slug = $this->createFieldName("e_mail"); |
| 147 |
/* |
| 148 |
* If Email Verification on Then |
| 149 |
* Add since 2.0.13 |
| 150 |
*/ |
| 151 |
|
| 152 |
if($this->user->data->user_email != $this->pie_post_array['e_mail'] && !empty($global_options['email_edit_verification_step']) ) |
| 153 |
{ |
| 154 |
//Email dosen't exists |
| 155 |
if(strtolower($this->user->data->user_email) == strtolower($this->pie_post_array['e_mail']) || !email_exists($this->pie_post_array['e_mail'])) |
| 156 |
{ |
| 157 |
|
| 158 |
/* |
| 159 |
* Save New Email Address in user meta |
| 160 |
*/ |
| 161 |
update_user_meta($this->user->data->ID,"new_email_address", sanitize_email($this->pie_post_array['e_mail'])); |
| 162 |
/* |
| 163 |
* Generate Key |
| 164 |
*/ |
| 165 |
$email_key = wp_generate_password(32, false); |
| 166 |
/* |
| 167 |
* Email Key add in array for email template |
| 168 |
*/ |
| 169 |
if( intval($global_options['email_edit_verification_step']) == "1"){ |
| 170 |
$keys_array = array("reset_email_key"=>$email_key); |
| 171 |
$email_slug = "email_edit_verification"; |
| 172 |
$user_email_address = sanitize_email($this->pie_post_array['e_mail']); |
| 173 |
$email_edit_success_msg = __( 'Use the link sent to your email to verify and apply the change.', 'pie-register' ); |
| 174 |
}elseif(intval($global_options['email_edit_verification_step']) == "2"){ |
| 175 |
$keys_array = array("confirm_current_email_key"=>$email_key); |
| 176 |
$email_slug = "current_email_verification"; |
| 177 |
$user_email_address = sanitize_email($this->user->data->user_email); |
| 178 |
$email_edit_success_msg = __( 'Please confirm the link sent to your current Email to verify and make the change applied!', 'pie-register' ); |
| 179 |
} |
| 180 |
/* |
| 181 |
* Email send snipt |
| 182 |
*/ |
| 183 |
$subject = html_entity_decode($global_options["user_subject_email_{$email_slug}"],ENT_COMPAT,"UTF-8"); |
| 184 |
$subject = $this->filterSubject($this->user->data->user_login,$subject); |
| 185 |
$message_temp = ""; |
| 186 |
if($global_options["user_formate_email_{$email_slug}"] == "0"){ |
| 187 |
$message_temp = nl2br(wp_strip_all_tags($global_options["user_message_email_{$email_slug}"])); |
| 188 |
}else{ |
| 189 |
$message_temp = $global_options["user_message_email_{$email_slug}"]; |
| 190 |
} |
| 191 |
|
| 192 |
$message = $this->filterEmail($message_temp,$this->user->data->user_login, "",false,$keys_array ); |
| 193 |
$from_name = html_entity_decode($global_options["user_from_name_{$email_slug}"],ENT_COMPAT,"UTF-8"); |
| 194 |
$from_email = $global_options["user_from_email_{$email_slug}"]; |
| 195 |
$reply_email = $global_options["user_to_email_{$email_slug}"]; |
| 196 |
|
| 197 |
//Headers |
| 198 |
$headers = 'MIME-Version: 1.0' . "\r\n"; |
| 199 |
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; |
| 200 |
|
| 201 |
if(!empty($from_email) && filter_var($from_email,FILTER_VALIDATE_EMAIL))//Validating From |
| 202 |
$headers .= "From: ".$from_name." <".$from_email."> \r\n"; |
| 203 |
if($reply_email){ |
| 204 |
$headers .= "Reply-To: {$reply_email}\r\n"; |
| 205 |
$headers .= "Return-Path: {$reply_email}\r\n"; |
| 206 |
}else{ |
| 207 |
$headers .= "Reply-To: {$from_email}\r\n"; |
| 208 |
$headers .= "Return-Path: {$from_email}\r\n"; |
| 209 |
} |
| 210 |
|
| 211 |
$error_sending_email = false; |
| 212 |
if((isset($global_options['user_enable_'.$email_slug]) && $global_options['user_enable_'.$email_slug] == 1) && !wp_mail($user_email_address, $subject, $message , $headers)) |
| 213 |
{ |
| 214 |
$error_sending_email = true; |
| 215 |
$errors->add('check-error',apply_filters("piereg_problem_and_the_email_was_probably_not_sent",__("There was a problem sending the email.",'pie-register'))); |
| 216 |
$this->pr_error_log("'The e-mail could not be sent. Possible reason: mail() function may have disabled by your host.'".($this->get_error_log_info(__FUNCTION__,__LINE__,__FILE__))); |
| 217 |
} |
| 218 |
|
| 219 |
/* |
| 220 |
* Update Email Hash Key |
| 221 |
*/ |
| 222 |
update_user_meta($this->user->data->ID,"new_email_address_hashed",$email_key); |
| 223 |
$this->pie_post_array['e_mail'] = $this->user->data->user_email; |
| 224 |
|
| 225 |
if(!$error_sending_email): |
| 226 |
$this->pie_post_array['success'] = $email_edit_success_msg; |
| 227 |
else: |
| 228 |
$this->pie_post_array['success'] = ""; |
| 229 |
endif; |
| 230 |
|
| 231 |
}else{ |
| 232 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.__('This email address is already registered.','pie-register') ); |
| 233 |
} |
| 234 |
}else{ |
| 235 |
$this->user->data->user_email = sanitize_email($this->pie_post_array['e_mail']); |
| 236 |
$this->pie_post_array['e_mail'] = $this->user->data->user_email; |
| 237 |
} |
| 238 |
} |
| 239 |
/* |
| 240 |
* work just 2way login phone |
| 241 |
*/ |
| 242 |
elseif($field['type']=="two_way_login_phone"){ |
| 243 |
$slug = "piereg_two_way_login_phone"; |
| 244 |
$phone_format = "international"; |
| 245 |
} |
| 246 |
|
| 247 |
$required = (isset($field['required']))?$field['required']:""; |
| 248 |
if($field['type']=="upload"){ |
| 249 |
|
| 250 |
$field_name = sanitize_text_field($_FILES[$slug]['name']); |
| 251 |
if($_FILES[$slug]['name'] != '' and $field['file_types'] != ""){ |
| 252 |
$filter_array = stripcslashes($field['file_types']); |
| 253 |
$filter_array = explode(",",$filter_array); |
| 254 |
$result = $this->piereg_validate_files(sanitize_file_name($_FILES[$slug]['name']),$filter_array); |
| 255 |
if(!$result){ |
| 256 |
$errors->add( $slug , apply_filters("piereg_invalid_file",'<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_Invalid_File_Type",__('Invalid file type','pie-register' )))); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
} |
| 261 |
elseif($field['type']=="profile_pic") |
| 262 |
{ |
| 263 |
$field_name = sanitize_text_field($_FILES[$slug]['name']); |
| 264 |
if($_FILES[$slug]['name'] != ''){ |
| 265 |
$result = $this->piereg_validate_files(sanitize_file_name($_FILES[$slug]['name']),array("gif","GIF","jpeg","JPEG","jpg","JPG","png","PNG","bmp","BMP")); |
| 266 |
if(!$result){ |
| 267 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.apply_filters("piereg_Invalid_File_Type_In_Profile_Picture",__('Invalid file type used for profile picture.','pie-register' ))); |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
else if($field['type']=="invitation" && $piereg["enable_invitation_codes"]=="1") // AA - dkny |
| 273 |
{ |
| 274 |
|
| 275 |
$field_name = $code = $this->pie_post_array[$slug]; |
| 276 |
if($required != "" || $this->pie_post_array[$slug] != "") |
| 277 |
{ |
| 278 |
$codetable = $this->codeTable(); |
| 279 |
$codes = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $codetable where BINARY name = %s and status = %d", $code, 1) ); |
| 280 |
if(isset($wpdb->last_error) && !empty($wpdb->last_error)){ |
| 281 |
$this->pr_error_log($wpdb->last_error.($this->get_error_log_info(__FUNCTION__,__LINE__,__FILE__))); |
| 282 |
} |
| 283 |
if(is_array($codes)){ |
| 284 |
foreach($codes as $c) |
| 285 |
{ |
| 286 |
$times_used = $c->count; |
| 287 |
$usage = $c->code_usage; |
| 288 |
} |
| 289 |
} |
| 290 |
if(count($codes) != 1) |
| 291 |
{ |
| 292 |
$errors->add( $slug , apply_filters("piereg_invalid_invitaion_code",'<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.__('Invalid invitation code','pie-register' ))); |
| 293 |
} |
| 294 |
elseif($times_used >= $usage and $usage != 0) |
| 295 |
{ |
| 296 |
$errors->add( $slug , apply_filters("piereg_invitaion_code_expired",'<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.__('Invitation code has expired','pie-register' ))); |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
/* |
| 302 |
* Just for two way login |
| 303 |
*/ |
| 304 |
elseif($field['type']=="two_way_login_phone") |
| 305 |
{ |
| 306 |
include_once( $this->admin_path . 'includes/plugin.php' ); |
| 307 |
$twilio_option = get_option("pie_register_twilio"); |
| 308 |
$plugin_status = get_option('piereg_api_manager_addon_Twilio_activated'); |
| 309 |
if( is_plugin_active("pie-register-twilio/pie-register-twilio.php") && isset($twilio_option["enable_twilio"]) && $twilio_option["enable_twilio"] == 1 && $plugin_status == "Activated" ){ |
| 310 |
$slug = "piereg_two_way_login_phone"; |
| 311 |
}else{ |
| 312 |
$required = ""; |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
$field_name = ((isset($this->pie_post_array[$slug]))?$this->pie_post_array[$slug]:""); |
| 317 |
if( $field['type']=="dropdown" || $field['type']=="multiselect" ) |
| 318 |
{ |
| 319 |
$field_name = ( isset($this->pie_post_array[$slug][0]) ? $this->pie_post_array[$slug][0] : ""); |
| 320 |
} |
| 321 |
|
| 322 |
$rule = (isset($field['validation_rule']))?$field['validation_rule']:""; |
| 323 |
$validation_message = (!empty($field['validation_message']) ? $field['validation_message'] : ((isset($field['label']))?$field['label']:"") ." is required."); |
| 324 |
|
| 325 |
if( (!isset($field_name) || empty($field_name)) && $required) |
| 326 |
{ |
| 327 |
if($field['type']=="profile_pic"){ |
| 328 |
$uploaded = get_user_meta($this->user->data->ID , "pie_".$slug, true); |
| 329 |
|
| 330 |
if(empty($_FILES[$slug]['name']) && empty($uploaded) ) |
| 331 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$validation_message ); |
| 332 |
|
| 333 |
if(isset($this->pie_post_array['pie_'.$slug.'_removed']) && $this->pie_post_array['pie_'.$slug.'_removed'] == "1") |
| 334 |
{ |
| 335 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$validation_message ); |
| 336 |
} |
| 337 |
|
| 338 |
}elseif($field['type']=="math_captcha"){ |
| 339 |
|
| 340 |
} elseif($field['type']=="upload" && (isset($field['required']) && $field['required'] != "") ) |
| 341 |
{ |
| 342 |
if ( isset($this->pie_post_array['pie_'.$slug.'_removed']) && $this->pie_post_array['pie_'.$slug.'_removed'] && $_FILES[$slug]['name'] == '') |
| 343 |
{ |
| 344 |
$validation_message = $field['label']." ".__("is required.","pie-register"); |
| 345 |
$errors->add( $slug , "<strong>". esc_html(ucwords(__("error","pie-register"))).":</strong> " .$validation_message ); |
| 346 |
} |
| 347 |
} else{ |
| 348 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$validation_message ); |
| 349 |
} |
| 350 |
}else if((!isset($field_name) || empty($field_name)) && !$required){ |
| 351 |
continue; |
| 352 |
} |
| 353 |
else if($rule=="number" && !empty($field_name)) |
| 354 |
{ |
| 355 |
if(!is_numeric($field_name)) |
| 356 |
{ |
| 357 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$field['label'] .apply_filters("piereg_field_must_contain_only_numbers",__('Field must only contain numbers.','pie-register' ))); |
| 358 |
} |
| 359 |
} |
| 360 |
else if($rule=="alphanumeric" && !empty($field_name)) |
| 361 |
{ |
| 362 |
if(! preg_match("/^([a-z0-9 ])+$/i", $field_name)) |
| 363 |
{ |
| 364 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$field['label'] .apply_filters("piereg_field_may_only_contain_alpha_numeric_characters",__(' Field must only contain alpha-numeric characters.','pie-register' ))); |
| 365 |
} |
| 366 |
} |
| 367 |
else if($rule=="alphabetic" && !empty($field_name)) |
| 368 |
{ |
| 369 |
//if(! preg_match("/^[a-zA-Z ]+$/", $field_name)) |
| 370 |
if(! preg_match("/^[a-zA-Z\p{Cyrillic}\s\-]+$/u", $field_name)) |
| 371 |
{ |
| 372 |
$errors->add( $slug ,"<strong>". esc_html(__("Error","pie-register")).":</strong> ".$field['label'] .apply_filters("piereg_field_may_only_contain_alphabetic_characters",__(" Field must only contain letters." ,"pie-register"))); |
| 373 |
} |
| 374 |
} |
| 375 |
else if($rule=="email" && !empty($field_name)) |
| 376 |
{ |
| 377 |
$regXemail = "/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/"; |
| 378 |
if( !is_email($field_name) ) |
| 379 |
{ |
| 380 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$field['label'] .apply_filters("piereg_field_must_contain_a_valid_email_address",__(' Field must contain a valid email address.','pie-register' ))); |
| 381 |
} |
| 382 |
} |
| 383 |
else if( ($rule=="website" && !empty($field_name)) || (isset($field['field_name']) && $field['field_name'] == 'url') ) |
| 384 |
{ |
| 385 |
if(!filter_var($field_name,FILTER_VALIDATE_URL)) |
| 386 |
{ |
| 387 |
$errors->add( $slug , '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: '.$field['label'] .apply_filters("piereg_must_be_a_valid_URL",__(' Must be a valid URL.','pie-register' ))); |
| 388 |
} |
| 389 |
} |
| 390 |
if( (isset($phone_format) && $phone_format == "international") && isset($this->pie_post_array[$slug]) && !empty($this->pie_post_array[$slug]) ){ |
| 391 |
$regXinternational_phone = "/^(\+|00)?(?:[0-9]( |-)?){1,3}(?:[0-9]( |-)?){4,14}$/"; |
| 392 |
if(!preg_match($regXinternational_phone,$field_name)){ |
| 393 |
$errors->add( $slug ,"<strong>". esc_html(__("Error","pie-register")).":</strong> ".$field['label'] .apply_filters("piereg_invalid_phone_field",__(" invalid phone number." ,"pie-register"))); |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
$_POST = $this->pie_post_array; |
| 399 |
return $errors; |
| 400 |
} |
| 401 |
function UpdateUser() |
| 402 |
{ |
| 403 |
global $wpdb,$pie_success,$pie_error,$pie_error_msg,$pie_suucess_msg,$errors; |
| 404 |
$errors = new WP_Error(); |
| 405 |
|
| 406 |
$this->pie_post_array = apply_filters('piereg_useredit_data_before_updating', $this->pie_post_array); |
| 407 |
|
| 408 |
foreach($this->data as $field) |
| 409 |
{ |
| 410 |
//Some form fields which we can't save like paypal, submit,formdata |
| 411 |
|
| 412 |
if($field['type']=="default") |
| 413 |
{ |
| 414 |
$slug = $field['field_name']; |
| 415 |
$value = ((isset($this->pie_post_array[$slug]))?$this->pie_post_array[$slug]:""); |
| 416 |
if(update_user_meta($this->user_id, $slug, $value)) $this->pie_success = 1; |
| 417 |
else |
| 418 |
$this->pie_error = 1; |
| 419 |
} |
| 420 |
else if($field['type']=="email"){ |
| 421 |
$slug = "e_mail"; |
| 422 |
$value = $this->pie_post_array[$slug]; |
| 423 |
|
| 424 |
// get current user's data |
| 425 |
$user_data = get_userdata($this->user_id); |
| 426 |
|
| 427 |
if($user_data->data->user_email != $value){ |
| 428 |
// update the user email if the email address of the user and $_POST is not same when Email Change Verification is turned off |
| 429 |
if(wp_update_user( array( 'ID' => $this->user_id, 'user_email' => $value ))) $this->pie_success = 1; |
| 430 |
else |
| 431 |
$this->pie_error = 1; |
| 432 |
} |
| 433 |
} |
| 434 |
else if($field['type']=="name") |
| 435 |
{ |
| 436 |
$slug = "first_name"; |
| 437 |
$value = $this->pie_post_array[$slug]; |
| 438 |
if(update_user_meta($this->user_id, $slug, $value)) $this->pie_success = 1; |
| 439 |
else |
| 440 |
$this->pie_error = 1; |
| 441 |
|
| 442 |
$slug = "last_name"; |
| 443 |
$value = isset($this->pie_post_array[$slug]) ? $this->pie_post_array[$slug] : ''; |
| 444 |
if(update_user_meta($this->user_id, $slug, $value)) $this->pie_success = 1; |
| 445 |
else |
| 446 |
$this->pie_error = 1; |
| 447 |
} |
| 448 |
else |
| 449 |
{ |
| 450 |
if(!isset($field['id'])) continue; |
| 451 |
$slug = $this->createFieldName($field['type']."_".((isset($field['id']))?$field['id']:"")); |
| 452 |
|
| 453 |
if( $field['type'] == "upload" || $field['type'] == "profile_pic" ) |
| 454 |
{ |
| 455 |
if(isset($this->pie_post_array['pie_'.$slug.'_removed']) && $this->pie_post_array['pie_'.$slug.'_removed'] == "1") |
| 456 |
{ |
| 457 |
$this->pie_remove_upload( $this->user_id, $field, $slug ); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
switch($field['type']) : |
| 462 |
|
| 463 |
case 'text' : |
| 464 |
case 'textarea': |
| 465 |
case 'dropdown': |
| 466 |
case 'multiselect': |
| 467 |
case 'number': |
| 468 |
case 'radio': |
| 469 |
case 'checkbox': |
| 470 |
//case 'html': |
| 471 |
case 'address': |
| 472 |
case 'phone': |
| 473 |
case 'invitation': |
| 474 |
case 'date': |
| 475 |
case 'list': |
| 476 |
$field_name = ((isset($this->pie_post_array[$slug]))?$this->pie_post_array[$slug]:""); |
| 477 |
if(update_user_meta($this->user_id, "pie_".$slug, $field_name)) |
| 478 |
$this->pie_success = 1; |
| 479 |
else |
| 480 |
$this->pie_error = 1; |
| 481 |
break; |
| 482 |
case 'upload': |
| 483 |
if(isset($_FILES[$slug]['name']) && $_FILES[$slug]['name'] != ''){ |
| 484 |
$this->pie_upload_files($this->user_id,$field,$slug); |
| 485 |
$this->pie_success = 1; |
| 486 |
} |
| 487 |
break; |
| 488 |
case 'profile_pic': |
| 489 |
if(isset($_FILES[$slug]['name']) && $_FILES[$slug]['name'] != ''){ |
| 490 |
$this->pie_profile_pictures_upload($this->user_id,$field,$slug); |
| 491 |
} |
| 492 |
break; |
| 493 |
case 'time': |
| 494 |
if(isset($this->pie_post_array[$slug]['time_format']) && $this->pie_post_array[$slug]['time_format']) |
| 495 |
{ |
| 496 |
$this->pie_post_array[$slug]['hh'] = sprintf('%02d',intval($this->pie_post_array[$slug]['hh'])); |
| 497 |
if($this->pie_post_array[$slug]['hh'] > 12) |
| 498 |
$this->pie_post_array[$slug]['hh'] = "12"; |
| 499 |
|
| 500 |
$this->pie_post_array[$slug]['mm'] = sprintf('%02d',intval($this->pie_post_array[$slug]['mm'])); |
| 501 |
if($this->pie_post_array[$slug]['mm'] > 59) |
| 502 |
$this->pie_post_array[$slug]['mm'] = "59"; |
| 503 |
|
| 504 |
$field_name = $this->pie_post_array[$slug]; |
| 505 |
if(update_user_meta($this->user_id, "pie_".$slug, $field_name)) |
| 506 |
$this->pie_success = 1; |
| 507 |
else |
| 508 |
$this->pie_error = 1; |
| 509 |
}else{ |
| 510 |
$this->pie_post_array[$slug]['hh'] = sprintf('%02d',intval($this->pie_post_array[$slug]['hh'])); |
| 511 |
if($this->pie_post_array[$slug]['hh'] > 23) |
| 512 |
$this->pie_post_array[$slug]['hh'] = "23"; |
| 513 |
|
| 514 |
$this->pie_post_array[$slug]['mm'] = sprintf('%02d',intval($this->pie_post_array[$slug]['mm'])); |
| 515 |
if($this->pie_post_array[$slug]['mm'] > 59) |
| 516 |
$this->pie_post_array[$slug]['mm'] = "59"; |
| 517 |
|
| 518 |
$field_name = $this->pie_post_array[$slug]; |
| 519 |
if(update_user_meta($this->user_id, "pie_".$slug, $field_name)) |
| 520 |
$this->pie_success = 1; |
| 521 |
else |
| 522 |
$this->pie_error = 1; |
| 523 |
} |
| 524 |
break; |
| 525 |
/* |
| 526 |
* Just For Two Way Login |
| 527 |
*/ |
| 528 |
case 'two_way_login_phone': |
| 529 |
$slug = "piereg_two_way_login_phone"; |
| 530 |
$field_name = $this->pie_post_array[$slug]; |
| 531 |
if(update_user_meta($this->user_id, $slug, $field_name)) |
| 532 |
$this->pie_success = 1; |
| 533 |
else |
| 534 |
$this->pie_error = 1; |
| 535 |
break; |
| 536 |
|
| 537 |
//pie-register-woocommerce addon |
| 538 |
case 'wc_billing_address': |
| 539 |
do_action("pieregister_meta_update_woocommerce_billing_address", $this->user_id, $this->createFieldName($field['type']."_".$field['id']), $this->pie_post_array); |
| 540 |
$this->pie_success = 1; |
| 541 |
break; |
| 542 |
case 'wc_shipping_address': |
| 543 |
do_action("pieregister_meta_update_woocommerce_shipping_address", $this->user_id, $this->createFieldName($field['type']."_".$field['id']), $this->pie_post_array); |
| 544 |
$this->pie_success = 1; |
| 545 |
break; |
| 546 |
endswitch; |
| 547 |
} |
| 548 |
} |
| 549 |
if($this->pie_error) |
| 550 |
$this->pie_error_msg = __('Something went wrong while updating profile fields, please try again.','pie-register'); |
| 551 |
if($this->pie_success) |
| 552 |
$this->pie_success_msg = __('Your Profile has been updated.','pie-register'); |
| 553 |
return($this->pie_success); |
| 554 |
} |
| 555 |
|
| 556 |
} |
| 557 |
|
| 558 |
if( file_exists( get_stylesheet_directory().'/pie-register/pie_register_template/profile_edit/edit_form_template.php' ) ){ |
| 559 |
require_once( get_stylesheet_directory().'/pie-register/pie_register_template/profile_edit/edit_form_template.php' ); |
| 560 |
} |
| 561 |
else{ |
| 562 |
require_once(PIEREG_DIR_NAME.'/pie_register_template/profile_edit/edit_form_template.php'); |
| 563 |
} |