• Resolved HawksDev

    (@kc9ryt)


    Hello,
    I have created a custom tab for some of the custom fields that are on my registration field. The fields work as expected except if i make any changes to the main account tab. If i make and changes to my name or email it wipes out the data in the other tab. If i only update the data in the custom tab then everything works as expected. Here is a video of what it does:
    https://drive.google.com/file/d/1x1ggJ4XzSfzgyMkwTyx0_BkyX0B_HPYt/view?usp=sharing
    Below is the code that i am using:

    /* add custom tab for facility info */
    add_filter('um_account_page_default_tabs_hook', 'my_custom_tab_in_um2', 100 );
    function my_custom_tab_in_um2( $tabs ) {
    	$tabs[801]['orginfo']['icon'] = 'um-icon-medkit';
    	$tabs[801]['orginfo']['title'] = 'Agency/Facility Information';
    	$tabs[801]['orginfo']['submit_title'] = 'Update Agency/Facility Information';
    	$tabs[801]['orginfo']['custom'] = true;
    	return $tabs;
    }
    	
    /* make our new tab hookable */
    
    add_action('um_account_tab__orginfo', 'um_account_tab__orginfo');
    function um_account_tab__orginfo( $info ) {
    	global $ultimatemember;
    	extract( $info );
    
    	$output = $ultimatemember->account->get_tab_output('orginfo');
    	if ( $output ) { echo $output; }
    }
    
    /* Finally we add some content in the tab */
    add_filter('um_account_content_hook_orginfo', 'um_account_content_hook_orginfo');
    function um_account_content_hook_orginfo( $output ){
    	ob_start();
    	?>
    		<div class="um-field">
    			<?php
    			
    			$id = um_user('ID');
    			$output = '';
    			$names = array('title_position','office_phone','mobile_phone','Facility_Name','facility_legal_name','facility_main_phone','facility_24_7_phone','facility_address','facility_address_2','facility_county','facility_website','aspr_type','cms_type');
    		
    			$fields = array(); 
    			foreach( $names as $name )
    			$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
    			$fields = apply_filters('um_account_secure_fields', $fields, $id);
    			foreach( $fields as $key => $data )
    			$output .= UM()->fields()->edit_field( $key, $data );
    			?>
    		</div>	
    		
    	<?php
    		
    	$output .= ob_get_contents();
    	ob_end_clean();
    	return $output;
    }
    
    add_action('um_account_pre_update_profile', 'getUMFormData', 100);
    
    function getUMFormData(){
      $id = um_user('ID');
      $names = array('title_position','office_phone','mobile_phone','Facility_Name','facility_legal_name','facility_main_phone','facility_24_7_phone','facility_address','facility_address_2','facility_county','facility_website','aspr_type','cms_type');
    
      foreach( $names as $name )
    		update_user_meta( $id, $name, $_POST[$name] );
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • @kc9ryt

    Don’t clear the $output = ''; which you get from the hook as a parameter.

    Use echo UM()->fields()->edit_field ....
    instead of the variable $output .= ....

    • This reply was modified 4 years, 3 months ago by missveronica.
    • This reply was modified 4 years, 3 months ago by missveronica.
    • This reply was modified 4 years, 3 months ago by missveronica.
    Thread Starter HawksDev

    (@kc9ryt)

    @missveronicatv

    So i have made that change but im guessing im missing something..would you be able to show me what you mean? This is what i did:

    function um_account_content_hook_orginfo( $output ){
    	ob_start();
    	?>
    		<div class="um-field">
    			<?php
    			
    			$id = um_user('ID');
    			//$output = '';
    			$names = array('title_position','office_phone','mobile_phone','Facility_Name','facility_legal_name','facility_main_phone','facility_24_7_phone','facility_address','facility_address_2','facility_county','facility_website','aspr_type','cms_type');
    		
    			$fields = array(); 
    			foreach( $names as $name )
    			$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
    			$fields = apply_filters('um_account_secure_fields', $fields, $id);
    			foreach( $fields as $key => $data )
    			//$output .= UM()->fields()->edit_field( $key, $data );
    ;			echo UM()->fields()->edit_field( $key, $data );
    			?>
    		</div>	
    		
    	<?php
    		
    	$output .= ob_get_contents();
    	ob_end_clean();
    	return $output;
    }
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kc9ryt

    It looks correct. Does the tab shown in the Account form?

    Regards,

    Thread Starter HawksDev

    (@kc9ryt)

    @champsupertramp

    It sorta does. It only shows the last input field versus originally showing all the fields and just not updating correctly. That why I assumed I was missing something.

    @kc9ryt

    The missing update of fields might be an UM caching issue.

    Test by clearing the UM cache at: UM Dashboard -> User Cache -> Clear Cache

    Add this code by the end of the function getUMFormData after updating all meta data:

    UM()->user()->remove_cache( $id );
    um_fetch_user( $id );
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kc9ryt

    Please update your code for saving the custom fields. It should not update those fields from your custom tab when updating the fields in the General tab:

    add_action('um_account_pre_update_profile', 'getUMFormData', 100);
    function getUMFormData(){
      $id = um_user('ID');
      $names = array('title_position','office_phone','mobile_phone','Facility_Name','facility_legal_name','facility_main_phone','facility_24_7_phone','facility_address','facility_address_2','facility_county','facility_website','aspr_type','cms_type');
    
      foreach( $names as $name )
          if( isset( $_POST[$name] ) ){ 
    	update_user_meta( $id, $name, $_POST[$name] );
          }
    }

    Regards,

    Thread Starter HawksDev

    (@kc9ryt)

    @champsupertramp

    Looks like just by updating how the data is saved seems to have fixed everything. Thanks for your help!!!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know.

    Regards,

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Custom Account Tab Data Overwritten’ is closed to new replies.