• If you have a field set to not show in a user profile, when the user updates their profile, the field data will be cleared out.

    The ‘simplr_reg_profile_save_fields’ function in ‘simplr_form_functions.php’ is not checking to see if a field is visible before trying to update it.

    My code below adds a check to see if is set to be ‘show in profile’. Note this will also mean admins can not update this hidden field. An additional check to see if admin could be added if you want admins to be able to update it.

    
    function simplr_reg_profile_save_fields($user_id ) {
    	$custom = new SREG_Fields();
    	$data = $_POST;
    	$fields = $custom->fields->custom;
    	foreach($fields as $field):
    		if(@$field['show_in_profile'] != 'no') { //added this line to not clear or save data if set to hide on profile page
    			if(!in_array($field['key'] , simplr_get_excluded_profile_fields() )) {
    				if($field['type'] == 'date')
    				{
    					$dy = $data[$field['key'].'-dy'];
    					$mo = $data[$field['key'].'-mo'];
    					$yr = $data[$field['key'].'-yr'];
    					$dateinput = implode('-', array($yr,$mo,$dy));
    					update_user_meta($user_id,$field['key'],$dateinput);
    				} else {
    					update_user_meta($user_id, $field['key'], $data[$field['key']]);
    				}
    			}
    		} //added this line to not clear or save data if set to hide on profile page
    	endforeach;
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    sorry to bother you @adam1284, I just saw ur post and I’m not sure if this could help me.
    What I would like to do is on my user profile to have two sets of data. One for everykind of user about personal info, and the second one for vendors only which I would like to hide for those who are not vendors.

    Does your code hide the fields of set ?

    Thanks for ay help!
    Thomas

    Thread Starter adam1284

    (@adam1284)

    Hi Thomas,

    My code will not help you with that. I am not actually using this plugin anymore since they don’t appear to be updating it anymore.

    I switched to Profile Builder. With the Field Visibility addon, you would be able to do what you are looking for.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hidden Profile Fields data cleared’ is closed to new replies.