Viewing 3 replies - 1 through 3 (of 3 total)
  • @norbertk

    I have made some changes to your code snippet.

    /* 
     * Add field to account page 
     */
    
    function um_account_custom_fields( $args ) {
    
    	$args = str_replace( ',single_user_password', ',mobile_number,single_user_password', $args );
    	return $args;
    }
    add_filter( 'um_account_tab_general_fields', 'um_account_custom_fields', 10, 1 );
    
    /*
     * Add new tabs called "Notifications" and "Subscriptions"
     */
    
    add_filter( 'um_account_page_default_tabs_hook', 'my_custom_tab_in_um', 100 );
    
    function my_custom_tab_in_um( $tabs ) {
    
        $tabs[800]['notifications']['icon'] = 'um-faicon-envelope';
        $tabs[800]['notifications']['title'] = 'Notifications';
        $tabs[800]['notifications']['submit_title'] = 'Save';
        $tabs[800]['notifications']['custom'] = true;
    
        $tabs[800]['subscriptions']['icon'] = 'um-faicon-money';
        $tabs[800]['subscriptions']['title'] = 'Subscriptions';
        $tabs[800]['subscriptions']['show_button'] = false;
        $tabs[800]['subscriptions']['custom'] = true;
    
        return $tabs;
    } 
    
     /* 
      * Add content to the Notifications tab
      */
     
    add_filter( 'um_account_content_hook_notifications', 'um_account_content_hook_notifications', 10, 1 );
    
    function um_account_content_hook_notifications( $output ) {
    
        $output .= '<div class="um-field">';
    
        // Meta keys for the UM fields to display
        $names = array( 'email_daily_digest_options', 
                        'um_block_6470_5', 
                        'email_deal_alert_options',
                    );
    
        $fields = array(); 
        foreach( $names as $name ) {
            $fields[ $name ] = UM()->builtin()->get_specific_field( $name );
        }
    
        foreach( $fields as $key => $data ) {
            $output .= UM()->fields()->edit_field( $key, $data );
        }
    
        $output .= '</div>';
    
        return $output;
    }
    
     /* 
     * Add content to the Subscriptions tab
     */
    
    add_filter( 'um_account_content_hook_subscriptions', 'um_account_content_hook_subscriptions', 10, 1 );
    
    function um_account_content_hook_subscriptions( $output ) {
    
        $output .= '<div>Subscriptions content</div>';
    
    	return $output;
    }
     
    /* 
     * Ensure that the custom fields are updated when the account is updated 
     */
    
    add_action( 'um_account_pre_update_profile', 'um_customtab_notifications_update', 100, 2 );
    
    function um_customtab_notifications_update( $changes, $user_id ) {
    
        // meta keys to update
        $names = array( 'email_subscriptions', // Why ? not in the Tab
                        'email_daily_digest_options', 
                        'email_deal_alert_options' );
    
        foreach( $names as $name ) {
            if ( isset( $_POST[$name] )) {
                update_user_meta( $user_id, $name, sanitize_email( $_POST[$name] ));
            }
        }
    }
    Plugin Support andrewshu

    (@andrewshu)

    Hi @norbertk

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards

    Thread Starter norbertk

    (@norbertk)

    I am experiencing some strange behavior when a user tries to change data in a multi-checkbox field. Adding additional options in a multi-checkbox field works, but removing options does not.

    https://gist.github.com/NorbertKrupa/f4a9ef51988c3d639c4dd25cb91a65eb

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

The topic ‘Updating custom fields across multiple tabs’ is closed to new replies.