$current_user->id, 'user_pass' => esc_attr( $_POST['pass1'] ) ) ); $changesSaved = 'yes'; } else { $changesSavedNoMatchingPass = 'yes'; } }elseif (( empty($_POST['pass1'] ) && !empty( $_POST['pass2'] )) || ( !empty($_POST['pass1'] ) && empty( $_POST['pass2'] )) ) { $changesSavedNoPass = 'yes'; } } } add_action('init', 'wppb_save_the_password'); function wppb_front_end_profile_info() { global $changesSaved; global $changesSavedNoMatchingPass; global $changesSavedNoPass; ob_start(); get_currentuserinfo(); $wppb_defaultOptions = get_option('wppb_default_settings'); $changesSavedNoEmail = 'no'; $changesSavedNoEmailExist = 'no'; $previousError = 'no'; $pictureUpload = 'no'; $avatarUpload = 'yes'; $uploadName = array(); $uploadSize = array(); /* Load registration file. */ require_once(ABSPATH . WPINC . '/registration.php'); /* Get user info. */ global $current_user; /* delete the attachment if set */ if (isset($_GET['userID']) && isset($_GET['field'])){ update_user_meta( $_GET['userID'], $_GET['field'], ''); } /* delete the avatar */ if (isset($_GET['userID']) && isset($_GET['fieldOriginal']) && isset($_GET['fieldResized'])){ update_user_meta( $_GET['userID'], $_GET['fieldOriginal'], ''); update_user_meta( $_GET['userID'], $_GET['fieldResized'], ''); } //fallback if the file was largen then post_max_size, case in which no errors can be saved in $_FILES[fileName]['error'] if (empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') { echo '

'; _e('The information size you were trying to submit was larger then '. ServerMaxUploadSizeMega .'b!
', 'profilebuilder'); _e('This is usually caused by a large file(s) trying to be uploaded.
', 'profilebuilder'); _e('Since it was also larger than '. ServerMaxPostSizeMega .'b no additional information is available.
', 'profilebuilder'); echo '

'; } /* If profile was saved, update profile. */ if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' && wp_verify_nonce($_POST['edit_nonce_field'],'verify_edit_user') ) { if (email_exists( $_POST['email'] ) != FALSE) $thisEmail = email_exists( $_POST['email'] ); else $thisEmail = $current_user->id; if ( !empty( $_POST['email'] ) && is_email( $_POST['email'] )){ // if the user entered a valid email address if (($thisEmail == $current_user->id)){ // if the entered email address is not already registered to some other user wp_update_user( array( 'ID' => $current_user->id, 'user_email' => esc_attr( $_POST['email'] ))); $changesSaved = 'yes'; }else{ $changesSavedNoEmailExist = 'yes'; } }else{ $changesSavedNoEmail = 'yes'; } /* Update user information. */ if ($wppb_defaultOptions['firstname'] == 'show'){ wp_update_user( array( 'ID' => $current_user->id, 'first_name' => esc_attr( $_POST['first_name'] ))); $changesSaved = 'yes'; } if ($wppb_defaultOptions['lastname'] == 'show'){ wp_update_user( array( 'ID' => $current_user->id, 'last_name' => esc_attr( $_POST['last_name'] ))); $changesSaved = 'yes'; } if ($wppb_defaultOptions['nickname'] == 'show'){ wp_update_user( array( 'ID' => $current_user->id, 'nickname' => esc_attr( $_POST['nickname'] ))); $changesSaved = 'yes'; } if ($wppb_defaultOptions['dispname'] == 'show'){ wp_update_user( array( 'ID' => $current_user->id, 'display_name' => esc_attr( $_POST['display_name'] ))); $changesSaved = 'yes'; } if ($wppb_defaultOptions['website'] == 'show'){ $wppbPos = strpos($_POST['website'], 'http://'); if($wppbPos !== FALSE){ wp_update_user( array( 'ID' => $current_user->id, 'user_url' => esc_attr( $_POST['website'] ))); $changesSaved = 'yes'; }else{ wp_update_user( array( 'ID' => $current_user->id, 'user_url' => 'http://'.esc_attr( $_POST['website'] ))); $changesSaved = 'yes'; } } if ($wppb_defaultOptions['aim'] == 'show'){ update_user_meta( $current_user->id, 'aim', esc_attr( $_POST['aim'] ) ); $changesSaved = 'yes'; } if ($wppb_defaultOptions['yahoo'] == 'show'){ update_user_meta( $current_user->id, 'yim', esc_attr( $_POST['yim'] ) ); $changesSaved = 'yes'; } if ($wppb_defaultOptions['jabber'] == 'show'){ update_user_meta( $current_user->id, 'jabber', esc_attr( $_POST['jabber'] ) ); $changesSaved = 'yes'; } if ($wppb_defaultOptions['bio'] == 'show'){ update_user_meta( $current_user->id, 'description', esc_attr( $_POST['description'] ) ); $changesSaved = 'yes'; } /* update the extra profile information */ $wppb_premium = wppb_plugin_dir . '/premium/functions/'; if (file_exists ( $wppb_premium.'extra.fields.php' )){ $wppbFetchArray = get_option('wppb_custom_fields'); foreach ( $wppbFetchArray as $key => $value){ switch ($value['item_type']) { case "input":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $_POST[$value['item_id'].$value['id']] ) ); break; } case "checkbox":{ $checkboxOption = ''; $checkboxValue = explode(',', $value['item_options']); foreach($checkboxValue as $thisValue){ $thisValue = str_replace(' ', '#@space@#', $thisValue); //we need to escape the space-codification we sent earlier in the post if (isset($_POST[$thisValue.$value['id']])){ $localValue = str_replace('#@space@#', ' ', $_POST[$thisValue.$value['id']]); $checkboxOption = $checkboxOption.$localValue.','; } } update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $checkboxOption ) ); break; } case "radio":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], $_POST[$value['item_id'].$value['id']] ); break; } case "select":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $_POST[$value['item_id'].$value['id']] ) ); break; } case "countrySelect":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $_POST[$value['item_id'].$value['id']] ) ); break; } case "timeZone":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $_POST[$value['item_id'].$value['id']] ) ); break; } case "datepicker":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $_POST[$value['item_id'].$value['id']] ) ); break; } case "textarea":{ update_user_meta( $current_user->id, 'custom_field_'.$value['id'], esc_attr( $_POST[$value['item_id'].$value['id']] ) ); break; } case "upload":{ $uploadedfile = $value['item_type'].$value['id']; //first we need to verify if we don't try to upload a 0b or 0 length file if ( (basename( $_FILES[$uploadedfile]['name']) != '')){ //second we need to verify if the uploaded file size is less then the set file size in php.ini if (($_FILES[$uploadedfile]['size'] < ServerMaxUploadSizeByte) && ($_FILES[$uploadedfile]['size'] !=0)){ //we need to prepare the basename of the file, so that ' becomes ` as ' gives an error $fileName = basename( $_FILES[$uploadedfile]['name']); $finalFileName = ''; for ($i=0; $i < strlen($fileName); $i++){ if ($fileName[$i] == "'") $finalFileName .= '`'; else $finalFileName .= $fileName[$i]; } //create the target path for uploading $target_path = "wp-content/uploads/profile_builder/attachments/"; $target_path = $target_path . 'userID_'.$current_user->id.'_attachment_'. $finalFileName; if (move_uploaded_file($_FILES[$uploadedfile]['tmp_name'], $target_path)){ $upFile = get_bloginfo('home').'/'.$target_path; update_user_meta( $current_user->id, 'custom_field_'.$value['id'], $upFile); $pictureUpload = 'yes'; }else{ //insert the name of the file in an array so that in case an error comes up, we know which files we just uploaded array_push($uploadName, basename( $_FILES[$uploadedfile]['name'])); } }else{ //insert the name of the file in an array so that in case an error comes up, we know which files we just uploaded array_push($uploadName, basename( $_FILES[$uploadedfile]['name'])); } } break; } case "avatar":{ $avatarUpload = 'no'; $uploadedfile = $value['item_type'].$value['id']; $target_path_original = "wp-content/uploads/profile_builder/avatars/"; $fileName = $_FILES[$uploadedfile]['name']; $finalFileName = ''; for ($i=0; $i < strlen($fileName); $i++){ if ($fileName[$i] == "'") $finalFileName .= '`'; elseif ($fileName[$i] == ' ') $finalFileName .= '_'; else $finalFileName .= $fileName[$i]; } $fileName = $finalFileName; $target_path = $target_path_original . 'userID_'.$current_user->id.'_originalAvatar_'. $fileName; $target_path_avatar = $target_path_original . 'userID_'.$current_user->id.'_resziedAvatarSize_'.$value['item_options'].'_orignalName_'.$fileName; /* when trying to upload file, be sure it's one of the accepted image file-types */ if ( (($_FILES[$uploadedfile]['type'] == 'image/jpeg') || ($_FILES[$uploadedfile]['type'] == 'image/jpg') || ($_FILES[$uploadedfile]['type'] == 'image/png') || ($_FILES[$uploadedfile]['type'] == 'image/bmp') || ($_FILES[$uploadedfile]['type'] == 'image/pjpeg') || ($_FILES[$uploadedfile]['type'] == 'image/x-png')) && (($_FILES[$uploadedfile]['size'] < ServerMaxUploadSizeByte) && ($_FILES[$uploadedfile]['size'] !=0)) ){ $avatarUpload = 'yes'; $wp_filetype = wp_check_filetype(basename( $_FILES[$uploadedfile]['name']), null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => $fileName, 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $target_path); $attach_id_avatar = wp_insert_attachment( $attachment, $target_path_avatar); $upFile = image_downsize( $attach_id, 'thumbnail' ); $upFile_avatar = image_downsize( $attach_id_avatar, 'thumbnail' ); $upFile = $upFile[0]; $upFile_avatar = $upFile_avatar[0]; //calculate memory needed for file creation and allocate dynamically, in case of large files $memoryNeeded = round(($upFile[0] * $upFile[1] * $upFile['bits'] * $upFile['channels'] / 8 + Pow(2, 16)) * 1.8); $memoryHave = memory_get_usage(); $memoryHave = memoryHave * Pow(1024,2); $memoryLimitMB = ini_get('memory_limit'); $memoryLimit = substr ( $memoryLimitMB, 0, strlen($memoryLimitMB)-1 ); $memoryLimit = $memoryLimit * Pow(1024,2); $newLimit = ceil( (($memoryHave + $memoryNeeded + $memoryLimit) / Pow(1024,2)) * 1.8 ); ini_set( 'memory_limit', $newLimit . 'M' ); //if file upload succeded if (move_uploaded_file($_FILES[$uploadedfile]['tmp_name'], $target_path)){ // update the usermeta field with the original file url update_user_meta( $current_user->id, 'custom_field_'.$value['id'], $upFile); // also upload a resized image of it (move_uploaded_file($_FILES[$uploadedfile]['tmp_name'], $target_path_avatar)); $extension = str_replace ( 'image/' , '' , $_FILES[$uploadedfile]['type']); if($extension=="jpg" || $extension=="jpeg" || $extension=="pjpeg" ) $src = imagecreatefromjpeg($upFile); elseif($extension=="png" || $extension=="x-png") $src = imagecreatefrompng($upFile); else $src = imagecreatefromgif($upFile); list($width,$height)=getimagesize($upFile); $newwidth=$value['item_options']; $newheight=$value['item_options']; $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $filename = $target_path_avatar; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); //restore the old value of the memory after imageprocessing is done ini_restore ( 'memory_limit' ); // update/add a new usermeta field containing the url to the resized image update_user_meta( $current_user->id, 'custom_field_resized'.$value['id'], $upFile_avatar); } else $avatarUpload = 'no'; }elseif ( (($_FILES[$uploadedfile]['size'] > ServerMaxUploadSizeByte) || ($_FILES[$uploadedfile]['size'] == 0)) && ($fileName != '') ) $avatarUpload = 'no'; elseif ($fileName == '') $avatarUpload = 'yes'; break; } } } } } ?>

'; _e('The avatar was successfully deleted.', 'profilebuilder'); echo'

'; unset($_GET['fileType']); }elseif ($_GET['fileType'] == 'attachment'){ echo '

'; _e('The attachment "', 'profilebuilder'); echo $_GET['fileName']; _e('" was successfully deleted.', 'profilebuilder'); echo'

'; unset($_GET['fileType']); unset($_GET['fileName']); } } /* all the other messages/errors */ $nrOfBadUploads = 0; $nrOfBadUploads = count($uploadName); if (($changesSaved == 'yes') && ($changesSavedNoMatchingPass == 'no') && ($changesSavedNoPass == 'no') && ($changesSavedNoEmail == 'no') && ($changesSavedNoEmailExist == 'no') && ($avatarUpload == 'yes') && ($nrOfBadUploads == 0)){ echo '

'; _e('The changes have been successfully saved.', 'profilebuilder'); echo'

'; } elseif (($changesSaved == 'yes') && ($changesSavedNoEmailExist == 'yes') && ($previousError == 'no')){ echo '

'; _e('The email address you entered is already registered to a different user.
The email address was ', 'profilebuilder'); echo''; _e('NOT', 'profilebuilder');echo''; _e(' updated along with the rest of the information.', 'profilebuilder'); echo '

'; $previousError = 'yes'; } if (($changesSaved == 'yes') && ($changesSavedNoEmail == 'yes') && ($previousError == 'no')){ echo '

'; _e('The email address you entered is invalid.
The email address was ', 'profilebuilder'); echo''; _e('NOT', 'profilebuilder');echo''; _e(' updated along with the rest of the information.', 'profilebuilder'); echo '

'; $previousError = 'yes'; } if (($changesSaved == 'yes') && ($changesSavedNoMatchingPass == 'yes') && ($previousError == 'no')){ echo '

'; _e('The passwords you entered do not match.
The password was ', 'profilebuilder'); echo''; _e('NOT', 'profilebuilder');echo''; _e(' updated along with the rest of the information.', 'profilebuilder'); echo '

'; $previousError = 'yes'; } if (($changesSaved == 'yes') && ($changesSavedNoPass == 'yes') && ($previousError == 'no')){ echo '

'; _e('You didn\'t complete both password fields.
The password was ', 'profilebuilder'); echo''; _e('NOT', 'profilebuilder');echo''; _e(' updated along with the rest of the information.', 'profilebuilder'); echo '

'; $previousError = 'yes'; } $wppb_premium = wppb_plugin_dir . '/premium/functions/'; if (file_exists ( $wppb_premium.'extra.fields.php' )){ if (($changesSaved == 'yes') && ($nrOfBadUploads > 0) && ($previousError == 'no')){ $lastOne = 0; echo '

'; _e('There was an error while trying to upload the following attachments:
', 'profilebuilder'); echo ''; foreach ($uploadName as $key => $name){ $lastOne++; echo $name; if ($nrOfBadUploads-$lastOne > 0) echo ';'; } echo ''; _e('
Possible cause: the size was bigger than ', 'profilebuilder'); echo ServerMaxUploadSizeMega; _e('b.
The listed attachements were ', 'profilebuilder'); echo''; _e('NOT', 'profilebuilder');echo''; _e(' updated along with the rest of the information.', 'profilebuilder'); echo '

'; $previousError = 'yes'; } if (($changesSaved == 'yes') && ($avatarUpload == 'no') && ($previousError == 'no')){ echo '

'; _e('There was an error while trying to upload your avatar picture.
Possible cause: size/incorrect file-type.
The avatar was ', 'profilebuilder'); echo''; _e('NOT', 'profilebuilder');echo''; _e(' updated along with the rest of the information.', 'profilebuilder'); echo '

'; $previousError = 'yes'; } } } ?>
'; ?>

'; _e(' Usernames cannot be changed.'); echo'

'; } ?>

'; } ?>

'; } ?> '; _e('(required)', 'profilebuilder');echo'

'; } ?>

'; } ?>

'; _e('(required)', 'profilebuilder');echo'

'; } ?>

'; } ?>

'; } ?>

'; } ?>

'; } ?>

'; } ?>

'; } ?> id); } ?>